Search in sources :

Example 6 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class SourceLoader method parseLine.

public static void parseLine(LoadContext context, String lstLine, URI sourceFile) {
    final StringTokenizer colToken = new StringTokenizer(lstLine, SystemLoader.TAB_DELIM);
    while (colToken.hasMoreTokens()) {
        String colString = colToken.nextToken().trim();
        try {
            if (context.addStatefulToken(colString)) {
                context.commit();
            } else {
                context.rollback();
                Logging.replayParsedMessages();
            }
            Logging.clearParseMessages();
        } catch (PersistenceLayerException e) {
            Logging.errorPrint("Error parsing source: " + colString + " in: " + sourceFile);
        }
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) StringTokenizer(java.util.StringTokenizer)

Example 7 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class CodeControlLoader method parseLine.

@Override
public void parseLine(LoadContext context, String inputLine, URI sourceURI) throws PersistenceLayerException {
    int sepLoc = inputLine.indexOf('\t');
    if (sepLoc != -1) {
        Logging.errorPrint("Unsure what to do with line with multiple tokens: " + inputLine + " in file: " + sourceURI);
        return;
    }
    try {
        AbstractReferenceContext refContext = context.getReferenceContext();
        CodeControl controller = refContext.constructNowIfNecessary(CodeControl.class, "Controller");
        LstUtils.processToken(context, controller, sourceURI, inputLine);
    } catch (PersistenceLayerException ple) {
        Logging.errorPrint("Exception in Load: ", ple);
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) CodeControl(pcgen.cdom.inst.CodeControl) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext)

Example 8 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreParserFactory method parse.

public static List<Prerequisite> parse(final List<String> preStrings) {
    final List<Prerequisite> ret = new ArrayList<>(preStrings.size());
    for (String prestr : preStrings) {
        try {
            final PreParserFactory factory = PreParserFactory.getInstance();
            final Prerequisite prereq = factory.parse(prestr);
            ret.add(prereq);
        } catch (PersistenceLayerException ple) {
            //The message is now produced at a lower level, and thus has to be localised there.
            Logging.errorPrint(ple.getMessage(), ple);
        //Logging.errorPrintLocalised(PropertyFactory.getString("PrereqHandler.Unable_to_parse"), object); //$NON-NLS-1$
        }
    }
    return ret;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) ArrayList(java.util.ArrayList) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 9 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class AbstractPrerequisiteParser method parse.

/**
	 * Parses the PreRequisite.
	 * 
	 * @param kind the kind of the prerequisite (less the "PRE" prefix).
	 * @param formula The body of the prerequisite.
	 * @param invertResult Whether the prerequisite should invert the result.
	 * @param overrideQualify
	 *           if set true, this prerequisite will be enforced in spite
	 *           of any "QUALIFY" tag that may be present.
	 * @return PreReq 
	 * @throws PersistenceLayerException 
	 */
@Override
public Prerequisite parse(String kind, String formula, boolean invertResult, boolean overrideQualify) throws PersistenceLayerException {
    // Check to make sure that this class can parse this token
    boolean foundTag = false;
    for (int i = 0; i < kindsHandled().length; i++) {
        String arrayElement = kindsHandled()[i];
        if (arrayElement.equalsIgnoreCase(kind)) {
            foundTag = true;
            break;
        }
    }
    if (!foundTag) {
        throw new PersistenceLayerException(this.getClass().getName() + " can not parse a Prerequisite tag of '" + kind + ":" + formula + "'");
    }
    // If we can parse this token then set the kind and invert flag.
    Prerequisite prereq = new Prerequisite();
    prereq.setKind(kind);
    prereq.setOverrideQualify(overrideQualify);
    return prereq;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 10 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class AbstractPrerequisiteWriter method checkValidOperator.

protected void checkValidOperator(Prerequisite prereq, PrerequisiteOperator[] comparators) throws PersistenceLayerException {
    StringBuilder comparatorString = new StringBuilder(25);
    for (int i = 0; i < comparators.length; i++) {
        PrerequisiteOperator comparator = comparators[i];
        if (prereq.getOperator().equals(comparators[i])) {
            return;
        }
        if (i > 0) {
            comparatorString.append(", ");
        }
        comparatorString.append(comparator);
    }
    String kind = prereq.getKind();
    if (kind == null) {
        kind = "<NULL>";
    }
    throw new PersistenceLayerException("Cannot write token: LST syntax only supports " + comparatorString.toString() + " operators for PRE" + kind.toUpperCase() + ": " + prereq.toString());
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) PrerequisiteOperator(pcgen.core.prereq.PrerequisiteOperator)

Aggregations

PersistenceLayerException (pcgen.persistence.PersistenceLayerException)180 IOException (java.io.IOException)74 Prerequisite (pcgen.core.prereq.Prerequisite)62 StringWriter (java.io.StringWriter)17 StringTokenizer (java.util.StringTokenizer)17 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)15 LoadContext (pcgen.rules.context.LoadContext)14 URI (java.net.URI)12 Campaign (pcgen.core.Campaign)11 ParseResult (pcgen.rules.persistence.token.ParseResult)11 PCClass (pcgen.core.PCClass)10 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)10 PrerequisiteWriterInterface (pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface)10 URISyntaxException (java.net.URISyntaxException)8 TreeSet (java.util.TreeSet)8 CDOMReference (pcgen.cdom.base.CDOMReference)8 PlayerCharacter (pcgen.core.PlayerCharacter)8 PrerequisiteException (pcgen.core.prereq.PrerequisiteException)8 PCClassLoader (pcgen.persistence.lst.PCClassLoader)8