Search in sources :

Example 1 with TransitionChoice

use of pcgen.cdom.base.TransitionChoice in project pcgen by PCGen.

the class BioSetLoader method parseTokens.

private void parseTokens(LoadContext context, AgeSet ageSet, StringTokenizer tok) {
    final PObject dummy = new PObject();
    try {
        while (tok.hasMoreTokens()) {
            // in the code below, I use "new String()" to unlink the string from the containing file to save memory,
            // but I don't intern() the string because it's not fully parsed yet so don't want to add permgen overhead
            // to a string that's just going to get GC'd eventually
            //
            // This pessimization might be removable if we get all impls of CDOMToken.parseToken() to intern. But right
            // now there are too many of them...
            String currentTok = tok.nextToken();
            if (currentTok.startsWith("BONUS:")) {
                if (context.processToken(dummy, "BONUS", new String(currentTok.substring(6)))) {
                    context.commit();
                } else {
                    context.rollback();
                    Logging.errorPrint("Error in BONUS parse: " + currentTok);
                    Logging.replayParsedMessages();
                }
            } else if (currentTok.startsWith("KIT:")) {
                if (context.processToken(dummy, "KIT", new String(currentTok.substring(4)))) {
                    context.commit();
                } else {
                    context.rollback();
                    Logging.errorPrint("Error in KIT parse: " + currentTok);
                    Logging.replayParsedMessages();
                }
            } else {
                Logging.errorPrint("Unexpected token in AGESET: " + currentTok);
            }
        }
        List<BonusObj> bonuses = dummy.getListFor(ListKey.BONUS);
        if (bonuses != null) {
            ageSet.addBonuses(bonuses);
        }
        List<TransitionChoice<Kit>> kits = dummy.getListFor(ListKey.KIT_CHOICE);
        if (kits != null) {
            ageSet.addKits(kits);
        }
    } catch (PersistenceLayerException e) {
        Logging.errorPrint("Error in token parse: " + e.getLocalizedMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) BonusObj(pcgen.core.bonus.BonusObj) PObject(pcgen.core.PObject) TransitionChoice(pcgen.cdom.base.TransitionChoice)

Aggregations

TransitionChoice (pcgen.cdom.base.TransitionChoice)1 PObject (pcgen.core.PObject)1 BonusObj (pcgen.core.bonus.BonusObj)1 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)1