@Override protected ParseResult parseTokenWithSeparator( LoadContext context, FactSetDefinition def, String value) { StringTokenizer aTok = new StringTokenizer(value, Constants.PIPE); String fileType = aTok.nextToken(); if (!aTok.hasMoreTokens()) { return new ParseResult.Fail( getTokenName() + " expects 2 PIPE separated values, found 1 in: " + value, context); } String identifier = aTok.nextToken(); if (aTok.hasMoreTokens()) { return new ParseResult.Fail( getTokenName() + " expects 3 PIPE separated values, found too many in: " + value, context); } Class<? extends Loadable> cl; if ("GLOBAL".equals(fileType)) { cl = CDOMObject.class; } else { cl = StringPClassUtil.getClassFor(fileType); if (cl == null) { throw new IllegalArgumentException( "Invalid Data Definition Location (no class): " + fileType); } } def.setUsableLocation(cl); def.setFactSetName(identifier); return ParseResult.SUCCESS; }
@Override public String[] unparse(LoadContext context, FactSetDefinition def) { Class cl = def.getUsableLocation(); String name = def.getFactSetName(); if (cl == null) { if (name == null) { return null; } else { context.addWriteMessage("Found FactDefinition with location but no name"); return null; } } else if (name == null) { context.addWriteMessage("Found FactDefinition with name but no location"); return null; } return new String[] {StringPClassUtil.getStringFor(cl) + Constants.PIPE + name}; }
@Test public void testValidStringNo() throws PersistenceLayerException { assertNull(fd.getFactSetName()); assertNull(fd.getUsableLocation()); assertTrue(token.parseToken(context, fd, "DOMAIN|Caster").passed()); assertNotNull(fd.getFactSetName()); assertNotNull(fd.getUsableLocation()); assertEquals("Caster", fd.getFactSetName()); assertEquals(Domain.class, fd.getUsableLocation()); String[] unparsed = token.unparse(context, fd); assertNotNull(unparsed); assertEquals(1, unparsed.length); assertEquals("DOMAIN|Caster", unparsed[0]); }
@Test public void testValidStringString() throws PersistenceLayerException { assertNull(fd.getFactSetName()); assertNull(fd.getUsableLocation()); assertTrue(token.parseToken(context, fd, "SKILL|Possibility").passed()); assertNotNull(fd.getFactSetName()); assertNotNull(fd.getUsableLocation()); assertEquals("Possibility", fd.getFactSetName()); assertEquals(Skill.class, fd.getUsableLocation()); String[] unparsed = token.unparse(context, fd); assertNotNull(unparsed); assertEquals(1, unparsed.length); assertEquals("SKILL|Possibility", unparsed[0]); }