use of pcgen.core.SubClass in project pcgen by PCGen.
the class FavoredClassTokenTest method testCategorizationPass.
@Test
public void testCategorizationPass() throws PersistenceLayerException {
construct(primaryContext, "TestWP1");
assertTrue(parse("TestWP1.Two"));
SubClass obj = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Two");
SubClassCategory cat = SubClassCategory.getConstant("TestWP2");
primaryContext.getReferenceContext().reassociateCategory(cat, obj);
obj = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Two");
cat = SubClassCategory.getConstant("TestWP1");
primaryContext.getReferenceContext().reassociateCategory(cat, obj);
assertCleanConstruction();
}
use of pcgen.core.SubClass in project pcgen by PCGen.
the class FavoredClassTokenTest method testCategorizationFail.
@Test
public void testCategorizationFail() throws PersistenceLayerException {
construct(primaryContext, "TestWP1");
assertTrue(parse("TestWP1.Two"));
SubClass obj = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Two");
SubClassCategory cat = SubClassCategory.getConstant("TestWP2");
primaryContext.getReferenceContext().reassociateCategory(cat, obj);
assertConstructionError();
}
use of pcgen.core.SubClass in project pcgen by PCGen.
the class ClassLoader method process.
@Override
public List<CDOMObject> process(StringBuilder sb, int line, String lineString, ConversionDecider decider) throws PersistenceLayerException, InterruptedException {
List<CDOMObject> list = new ArrayList<>();
String[] tokens = lineString.split(FIELD_SEPARATOR);
if (tokens.length == 0) {
return list;
}
String firstToken = tokens[0];
sb.append(firstToken);
Class<? extends CDOMObject> buildClass;
Class<? extends CDOMObject> buildParent = null;
if (firstToken.startsWith("SUBCLASS:")) {
buildClass = SubClass.class;
} else if (firstToken.startsWith("SUBCLASSLEVEL:")) {
buildClass = PCClassLevel.class;
buildParent = SubClass.class;
} else if (firstToken.startsWith("SUBSTITUTIONCLASS:")) {
buildClass = SubstitutionClass.class;
} else if (firstToken.startsWith("SUBSTITUTIONLEVEL:")) {
buildClass = PCClassLevel.class;
buildParent = SubstitutionClass.class;
} else if (firstToken.startsWith("CLASS:")) {
buildClass = PCClass.class;
} else {
buildClass = PCClassLevel.class;
buildParent = PCClass.class;
}
for (int tok = 1; tok < tokens.length; tok++) {
String token = tokens[tok];
sb.append(FIELD_SEPARATOR);
if (token.isEmpty()) {
continue;
}
CDOMObject obj = context.getReferenceContext().constructCDOMObject(buildClass, line + "Test" + tok);
CDOMObject parent = null;
if (obj instanceof PCClassLevel) {
obj.put(IntegerKey.LEVEL, 1);
parent = context.getReferenceContext().constructCDOMObject(buildParent, line + "Test" + tok);
try {
// Ensure processing against the PCClassLevel cannot cause side effects on the parent class
obj.put(ObjectKey.TOKEN_PARENT, parent.clone());
} catch (CloneNotSupportedException e) {
Logging.errorPrint("Unable to preare a copy of " + parent);
}
}
List<CDOMObject> injected = processToken(sb, firstToken, obj, parent, token, decider, line);
if (injected != null) {
list.addAll(injected);
}
context.purge(obj);
if (parent != null) {
context.purge(parent);
}
TokenConverter.clearConstants();
}
return list;
}
use of pcgen.core.SubClass in project pcgen by PCGen.
the class PCClassLoader method loadSubLines.
public void loadSubLines(LoadContext context) {
Collection<PCClass> allClasses = context.getReferenceContext().getConstructedCDOMObjects(PCClass.class);
for (PCClass cl : allClasses) {
List<SubClass> subClasses = cl.getListFor(ListKey.SUB_CLASS);
if (subClasses != null) {
for (SubClass sc : subClasses) {
sc.copyLevelsFrom(cl);
processSubLevelLines(context, cl, sc);
}
}
List<SubstitutionClass> substClasses = cl.getListFor(ListKey.SUBSTITUTION_CLASS);
if (substClasses != null) {
for (SubstitutionClass sc : substClasses) {
processSubLevelLines(context, cl, sc);
}
}
}
}
use of pcgen.core.SubClass in project pcgen by PCGen.
the class FavoredClassIntegrationTest method testRoundRobinSimpleCategorized.
@Test
public void testRoundRobinSimpleCategorized() throws PersistenceLayerException {
verifyCleanStart();
construct(primaryContext, "TestWP1");
construct(primaryContext, "TestWP2");
construct(secondaryContext, "TestWP1");
construct(secondaryContext, "TestWP2");
SubClass obj = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Sub");
SubClassCategory cat = SubClassCategory.getConstant("TestWP2");
primaryContext.getReferenceContext().reassociateCategory(cat, obj);
obj = secondaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Sub");
secondaryContext.getReferenceContext().reassociateCategory(cat, obj);
TestContext tc = new TestContext();
commit(testCampaign, tc, "TestWP1");
commit(modCampaign, tc, "TestWP2.Sub");
completeRoundRobin(tc);
}
Aggregations