@Override public String[] unparse(LoadContext context, CDOMObject obj) { Changes<ShieldProfProvider> changes = context.obj.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<String>(); 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()]); }
@Override protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) { String shieldProf; Prerequisite prereq = null; // Do not initialize, null is significant! boolean isPre = false; if (value.indexOf("[") == -1) { // Supported version of PRExxx using |. Needs to be at the front of the // Parsing code because many objects expect the pre to have been determined // Ahead of time. Until deprecated code is removed, it will have to stay // like this. shieldProf = value; StringTokenizer tok = new StringTokenizer(shieldProf, Constants.PIPE); 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; shieldProf = value.substring(0, preStart); isPre = true; } } } else { return new ParseResult.Fail( "Use of [] for Prerequisites has been removed. " + "Please use | based standard", context); } ParseResult pr = checkForIllegalSeparator('|', shieldProf); if (!pr.passed()) { return pr; } boolean foundAny = false; boolean foundOther = false; StringTokenizer tok = new StringTokenizer(shieldProf, Constants.PIPE); List<CDOMReference<ShieldProf>> shieldProfs = new ArrayList<CDOMReference<ShieldProf>>(); List<CDOMReference<Equipment>> equipTypes = new ArrayList<CDOMReference<Equipment>>(); while (tok.hasMoreTokens()) { String aProf = tok.nextToken(); if (Constants.LST_PERCENT_LIST.equals(aProf)) { foundOther = true; ChooseSelectionActor<ShieldProf> cra; if (prereq == null) { cra = this; } else { ConditionalSelectionActor<ShieldProf> cca = new ConditionalSelectionActor<ShieldProf>(this); cca.addPrerequisite(prereq); cra = cca; } context.obj.addToList(obj, ListKey.NEW_CHOOSE_ACTOR, cra); } else if (Constants.LST_ALL.equalsIgnoreCase(aProf)) { foundAny = true; shieldProfs.add(context.ref.getCDOMAllReference(SHIELDPROF_CLASS)); } else if (aProf.startsWith("SHIELDTYPE.") || aProf.startsWith("SHIELDTYPE=")) { foundOther = true; CDOMReference<Equipment> ref = TokenUtilities.getTypeReference( context, EQUIPMENT_CLASS, "SHIELD." + aProf.substring(11)); if (ref == null) { return ParseResult.INTERNAL_ERROR; } equipTypes.add(ref); } else { foundOther = true; shieldProfs.add(context.ref.getCDOMReference(SHIELDPROF_CLASS, aProf)); } } if (foundAny && foundOther) { return new ParseResult.Fail( "Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context); } if (!shieldProfs.isEmpty() || !equipTypes.isEmpty()) { ShieldProfProvider pp = new ShieldProfProvider(shieldProfs, equipTypes); if (prereq != null) { pp.addPrerequisite(prereq); } context.obj.addToList(obj, ListKey.AUTO_SHIELDPROF, pp); } return ParseResult.SUCCESS; }