Search in sources :

Example 86 with PersistenceLayerException

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

the class PreAbilityParserTest method testInvalidCharacter.

/**
	 * Test that an error is produced if separators are incorrect
	 * @throws Exception
	 */
@Test
public void testInvalidCharacter() throws Exception {
    try {
        PreAbilityParser parser = new PreAbilityParser();
        Prerequisite prereq = parser.parse("ability", "1,CATEGORY.Mutation,KEY_a|Key_b", false, false);
        fail("Should have thrown a PersistenceLayerException.");
    } catch (PersistenceLayerException e) {
    // Ignore, this is the expected result.
    }
}
Also used : PreAbilityParser(plugin.pretokens.parser.PreAbilityParser) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Prerequisite(pcgen.core.prereq.Prerequisite) Test(org.junit.Test)

Example 87 with PersistenceLayerException

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

the class PreAbilityParserTest method testInvalidSeparators.

/**
	 * Test that an error is produced if separators are incorrect
	 * @throws Exception
	 */
@Test
public void testInvalidSeparators() throws Exception {
    try {
        PreAbilityParser parser = new PreAbilityParser();
        Prerequisite prereq = parser.parse("ability", "1,CATEGORY.Mutation,,KEY_a", false, false);
        fail("Should have thrown a PersistenceLayerException.");
    } catch (PersistenceLayerException e) {
    // Ignore, this is the expected result.
    }
}
Also used : PreAbilityParser(plugin.pretokens.parser.PreAbilityParser) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Prerequisite(pcgen.core.prereq.Prerequisite) Test(org.junit.Test)

Example 88 with PersistenceLayerException

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

the class AdddomainsToken method unparse.

@Override
public String[] unparse(LoadContext context, PCClassLevel level) {
    AssociatedChanges<CDOMReference<Domain>> changes = context.getListContext().getChangesInList(getTokenName(), level, PCClass.ALLOWED_DOMAINS);
    Collection<CDOMReference<Domain>> removedItems = changes.getRemoved();
    if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear()) {
        context.addWriteMessage(getTokenName() + " does not support .CLEAR");
        return null;
    }
    MapToList<CDOMReference<Domain>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
    if (mtl == null || mtl.isEmpty()) {
        return null;
    }
    PrerequisiteWriter prereqWriter = new PrerequisiteWriter();
    Set<String> set = new TreeSet<>();
    for (CDOMReference<Domain> domain : mtl.getKeySet()) {
        for (AssociatedPrereqObject assoc : mtl.getListFor(domain)) {
            StringBuilder sb = new StringBuilder(domain.getLSTformat(false));
            List<Prerequisite> prereqs = assoc.getPrerequisiteList();
            Prerequisite prereq;
            if (prereqs == null || prereqs.isEmpty()) {
                prereq = null;
            } else if (prereqs.size() == 1) {
                prereq = prereqs.get(0);
            } else {
                context.addWriteMessage("Added Domain from " + getTokenName() + " had more than one " + "Prerequisite: " + prereqs.size());
                return null;
            }
            if (prereq != null) {
                sb.append('[');
                StringWriter swriter = new StringWriter();
                try {
                    prereqWriter.write(swriter, prereq);
                } catch (PersistenceLayerException e) {
                    context.addWriteMessage("Error writing Prerequisite: " + e);
                    return null;
                }
                sb.append(swriter.toString());
                sb.append(']');
            }
            set.add(sb.toString());
        }
    }
    return new String[] { StringUtil.join(set, Constants.DOT) };
}
Also used : PrerequisiteWriter(pcgen.persistence.lst.output.prereq.PrerequisiteWriter) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) StringWriter(java.io.StringWriter) TreeSet(java.util.TreeSet) Domain(pcgen.core.Domain) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 89 with PersistenceLayerException

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

the class PreWeaponProfWriter method write.

/**
	 * @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer, pcgen.core.prereq.Prerequisite)
	 */
@Override
public void write(Writer writer, Prerequisite prereq) throws PersistenceLayerException {
    checkValidOperator(prereq, operatorsHandled());
    try {
        if (prereq.getOperator().equals(PrerequisiteOperator.LT)) {
            writer.write('!');
        }
        writer.write("PREWEAPONPROF:" + (prereq.isOverrideQualify() ? "Q:" : ""));
        writer.write(prereq.getOperand());
        writer.write(',');
        writer.write(prereq.getKey());
    } catch (IOException e) {
        throw new PersistenceLayerException(e.getMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) IOException(java.io.IOException)

Example 90 with PersistenceLayerException

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

the class PreWieldWriter method write.

/**
	 * @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer, pcgen.core.prereq.Prerequisite)
	 */
@Override
public void write(Writer writer, Prerequisite prereq) throws PersistenceLayerException {
    checkValidOperator(prereq, operatorsHandled());
    try {
        if (prereq.getOperator().equals(PrerequisiteOperator.LT)) {
            writer.write('!');
        }
        writer.write("PREWIELD:" + (prereq.isOverrideQualify() ? "Q:" : "") + "1,");
        writer.write(prereq.getKey());
    } catch (IOException e) {
        throw new PersistenceLayerException(e.getMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) IOException(java.io.IOException)

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