use of pcgen.cdom.base.ChooseSelectionActor in project pcgen by PCGen.
the class LangToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
String lang = value;
ParseResult pr = checkSeparatorsAndNonEmpty('|', lang);
if (!pr.passed()) {
return pr;
}
boolean foundAny = false;
boolean foundOther = false;
StringTokenizer tok = new StringTokenizer(lang, Constants.PIPE);
boolean isPre = false;
// Do not initialize, null is significant!
Prerequisite prereq = null;
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
if (PreParserFactory.isPreReqString(token)) {
if (isPre) {
String errorText = "Invalid " + getTokenName() + ": " + value + " PRExxx must be at the END of the Token";
Logging.errorPrint(errorText);
return new ParseResult.Fail(errorText, context);
}
prereq = getPrerequisite(token);
if (prereq == null) {
return new ParseResult.Fail("Error generating Prerequisite " + prereq + " in " + getFullName(), context);
}
int preStart = value.indexOf(token) - 1;
lang = value.substring(0, preStart);
isPre = true;
}
}
boolean firstToken = true;
tok = new StringTokenizer(lang, Constants.PIPE);
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
if (Constants.LST_DOT_CLEAR.equals(token)) {
if (!firstToken) {
return new ParseResult.Fail("Non-sensical situation was " + "encountered while parsing " + getTokenName() + ": When used, .CLEAR must be the first argument", context);
}
context.getObjectContext().removeList(obj, ListKey.AUTO_LANGUAGE);
} else if (Constants.LST_PERCENT_LIST.equals(token)) {
ChooseSelectionActor<Language> cra;
if (prereq == null) {
cra = this;
} else {
ConditionalSelectionActor<Language> cca = new ConditionalSelectionActor<>(this);
cca.addPrerequisite(prereq);
cra = cca;
}
foundOther = true;
context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, cra);
} else if (Constants.LST_ALL.equals(token)) {
foundAny = true;
context.getObjectContext().addToList(obj, ListKey.AUTO_LANGUAGE, new QualifiedObject<>(context.getReferenceContext().getCDOMAllReference(LANGUAGE_CLASS), prereq));
} else {
foundOther = true;
CDOMReference<Language> ref = TokenUtilities.getTypeOrPrimitive(context, LANGUAGE_CLASS, token);
if (ref == null) {
return new ParseResult.Fail(" Error was encountered while parsing " + getTokenName(), context);
}
context.getObjectContext().addToList(obj, ListKey.AUTO_LANGUAGE, new QualifiedObject<>(ref, prereq));
}
firstToken = false;
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.ChooseSelectionActor in project pcgen by PCGen.
the class ShieldProfToken method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Changes<ShieldProfProvider> changes = context.getObjectContext().getListChanges(obj, ListKey.AUTO_SHIELDPROF);
Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
Collection<ShieldProfProvider> added = changes.getAdded();
Set<String> set = new TreeSet<>();
Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
boolean foundAny = false;
boolean foundOther = false;
if (listAdded != null && !listAdded.isEmpty()) {
for (ChooseSelectionActor<?> cra : listAdded) {
if (cra.getSource().equals(getTokenName())) {
try {
set.add(cra.getLstFormat());
foundOther = true;
} catch (PersistenceLayerException e) {
context.addWriteMessage("Error writing Prerequisite: " + e);
return null;
}
}
}
}
if (added != null) {
for (ShieldProfProvider spp : added) {
StringBuilder sb = new StringBuilder();
sb.append(spp.getLstFormat());
if (spp.hasPrerequisites()) {
sb.append('|');
sb.append(getPrerequisiteString(context, spp.getPrerequisiteList()));
}
String ab = sb.toString();
boolean isUnconditionalAll = Constants.LST_ALL.equals(ab);
foundAny |= isUnconditionalAll;
foundOther |= !isUnconditionalAll;
set.add(ab);
}
}
if (foundAny && foundOther) {
context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + set);
return null;
}
if (set.isEmpty()) {
//okay
return null;
}
return set.toArray(new String[set.size()]);
}
Aggregations