Search in sources :

Example 1 with DataConversionException

use of org.jdom2.DataConversionException in project pcgen by PCGen.

the class NameGenPanel method loadRuleSet.

private RuleSet loadRuleSet(Element ruleSet) throws DataConversionException {
    RuleSet rs = new RuleSet(allVars, ruleSet.getAttributeValue("title"), ruleSet.getAttributeValue("id"), ruleSet.getAttributeValue("usage"));
    java.util.List<?> elements = ruleSet.getChildren();
    ListIterator<?> elementsIterator = elements.listIterator();
    int num = 0;
    while (elementsIterator.hasNext()) {
        Element child = (Element) elementsIterator.next();
        String elementName = child.getName();
        if (elementName.equals("CATEGORY")) {
            loadCategory(child, rs);
        } else if (elementName.equals("RULE")) {
            rs.add(loadRule(child, rs.getId() + num));
        }
        num++;
    }
    return rs;
}
Also used : RuleSet(pcgen.core.doomsdaybook.RuleSet) DataElement(pcgen.core.doomsdaybook.DataElement) Element(org.jdom2.Element)

Example 2 with DataConversionException

use of org.jdom2.DataConversionException in project pcgen by PCGen.

the class NameGenPanel method loadRule.

private String loadRule(Element rule, String id) throws DataConversionException {
    Rule dataRule = new Rule(allVars, id, id, rule.getAttribute("weight").getIntValue());
    java.util.List<?> elements = rule.getChildren();
    for (final Object element : elements) {
        Element child = (Element) element;
        String elementName = child.getName();
        if (elementName.equals("GETLIST")) {
            String listId = child.getAttributeValue("idref");
            dataRule.add(listId);
        } else if (elementName.equals("SPACE")) {
            SpaceRule sp = new SpaceRule();
            allVars.addDataElement(sp);
            dataRule.add(sp.getId());
        } else if (elementName.equals("HYPHEN")) {
            HyphenRule hy = new HyphenRule();
            allVars.addDataElement(hy);
            dataRule.add(hy.getId());
        } else if (elementName.equals("CR")) {
            CRRule cr = new CRRule();
            allVars.addDataElement(cr);
            dataRule.add(cr.getId());
        } else if (elementName.equals("GETRULE")) {
            String ruleId = child.getAttributeValue("idref");
            dataRule.add(ruleId);
        }
    }
    allVars.addDataElement(dataRule);
    return dataRule.getId();
}
Also used : SpaceRule(pcgen.core.doomsdaybook.SpaceRule) HyphenRule(pcgen.core.doomsdaybook.HyphenRule) CRRule(pcgen.core.doomsdaybook.CRRule) DataElement(pcgen.core.doomsdaybook.DataElement) Element(org.jdom2.Element) CRRule(pcgen.core.doomsdaybook.CRRule) HyphenRule(pcgen.core.doomsdaybook.HyphenRule) Rule(pcgen.core.doomsdaybook.Rule) SpaceRule(pcgen.core.doomsdaybook.SpaceRule)

Example 3 with DataConversionException

use of org.jdom2.DataConversionException in project JMRI by JMRI.

the class BlockManagerXml method loadPath.

/**
     * Load path into an existing Block from XML.
     *
     * @param block   Block to receive path
     * @param element Element containing path information
     * @return true if path added to block; false otherwise
     * @throws jmri.configurexml.JmriConfigureXmlException if element contains
     *                                                     malformed or
     *                                                     schematically invalid
     *                                                     XMl
     */
public boolean loadPath(Block block, Element element) throws JmriConfigureXmlException {
    // load individual path
    int toDir = 0;
    int fromDir = 0;
    try {
        toDir = element.getAttribute("todir").getIntValue();
        fromDir = element.getAttribute("fromdir").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("Could not parse path attribute");
    } catch (NullPointerException e) {
        handleException("Block Path entry in file missing required attribute", null, block.getSystemName(), block.getUserName(), null);
    }
    Block toBlock = null;
    if (element.getAttribute("block") != null) {
        String name = element.getAttribute("block").getValue();
        toBlock = InstanceManager.getDefault(jmri.BlockManager.class).getBlock(name);
    }
    Path path = new Path(toBlock, toDir, fromDir);
    List<Element> settings = element.getChildren("beansetting");
    for (int i = 0; i < settings.size(); i++) {
        Element setting = settings.get(i);
        loadBeanSetting(path, setting);
    }
    // check if path already in block
    if (!block.hasPath(path)) {
        block.addPath(path);
        return true;
    } else {
        log.debug("Skipping load of duplicate path {}", path);
        return false;
    }
}
Also used : Path(jmri.Path) Element(org.jdom2.Element) Block(jmri.Block)

Example 4 with DataConversionException

use of org.jdom2.DataConversionException in project JMRI by JMRI.

the class BlockManagerXml method loadBeanSetting.

/**
     * Load BeanSetting into an existing Path.
     *
     * @param path    Path to receive BeanSetting
     * @param element Element containing beansetting information
     */
public void loadBeanSetting(Path path, Element element) {
    int setting = 0;
    try {
        setting = element.getAttribute("setting").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("Could not parse beansetting attribute");
    }
    List<Element> turnouts = element.getChildren("turnout");
    if (turnouts.size() != 1) {
        log.error("invalid number of turnout element children");
    }
    String name = turnouts.get(0).getAttribute("systemName").getValue();
    try {
        Turnout t = InstanceManager.turnoutManagerInstance().provideTurnout(name);
        BeanSetting bs = new BeanSetting(t, name, setting);
        path.addSetting(bs);
    } catch (IllegalArgumentException ex) {
        log.warn("failed to create Turnout \"{}\" during Block load", name);
    }
}
Also used : BeanSetting(jmri.BeanSetting) Element(org.jdom2.Element) Turnout(jmri.Turnout)

Example 5 with DataConversionException

use of org.jdom2.DataConversionException in project JMRI by JMRI.

the class MergSD2SignalHeadXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    int aspects = 2;
    List<Element> l = shared.getChildren("turnoutname");
    if (l.size() == 0) {
        l = shared.getChildren("turnout");
        aspects = l.size() + 1;
    }
    NamedBeanHandle<Turnout> input1 = null;
    NamedBeanHandle<Turnout> input2 = null;
    NamedBeanHandle<Turnout> input3 = null;
    String yesno = "";
    boolean feather = false;
    boolean home = true;
    // put it together
    String sys = getSystemName(shared);
    String uname = getUserName(shared);
    if (shared.getAttribute("feather") != null) {
        yesno = shared.getAttribute("feather").getValue();
    }
    if ((yesno != null) && (!yesno.equals(""))) {
        if (yesno.equals("yes")) {
            feather = true;
        } else if (yesno.equals("no")) {
            feather = false;
        }
    }
    if (shared.getAttribute("home") != null) {
        yesno = shared.getAttribute("home").getValue();
    }
    if ((yesno != null) && (!yesno.equals(""))) {
        if (yesno.equals("yes")) {
            home = true;
        } else if (yesno.equals("no")) {
            home = false;
        }
    }
    try {
        aspects = shared.getAttribute("aspects").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse level attribute!");
    } catch (NullPointerException e) {
    // considered normal if the attribute not present
    }
    SignalHead h;
    //@TODO could re-arange this so that it falls through
    switch(aspects) {
        case 2:
            input1 = loadTurnout(l.get(0));
            break;
        case 3:
            input1 = loadTurnout(l.get(0));
            input2 = loadTurnout(l.get(1));
            break;
        case 4:
            input1 = loadTurnout(l.get(0));
            input2 = loadTurnout(l.get(1));
            input3 = loadTurnout(l.get(2));
            break;
        default:
            log.error("incorrect number of aspects " + aspects + " when loading Signal " + sys);
    }
    if (uname == null) {
        h = new MergSD2SignalHead(sys, aspects, input1, input2, input3, feather, home);
    } else {
        h = new MergSD2SignalHead(sys, uname, aspects, input1, input2, input3, feather, home);
    }
    loadCommon(h, shared);
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
    return true;
}
Also used : Element(org.jdom2.Element) MergSD2SignalHead(jmri.implementation.MergSD2SignalHead) SignalHead(jmri.SignalHead) MergSD2SignalHead(jmri.implementation.MergSD2SignalHead) Turnout(jmri.Turnout)

Aggregations

Element (org.jdom2.Element)49 Attribute (org.jdom2.Attribute)48 DataConversionException (org.jdom2.DataConversionException)18 Editor (jmri.jmrit.display.Editor)13 NamedIcon (jmri.jmrit.catalog.NamedIcon)11 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)9 Color (java.awt.Color)7 Point2D (java.awt.geom.Point2D)6 Point (java.awt.Point)5 ConfigureManager (jmri.ConfigureManager)4 AbstractXmlAdapter (jmri.configurexml.AbstractXmlAdapter)4 XmlAdapter (jmri.configurexml.XmlAdapter)4 DataElement (pcgen.core.doomsdaybook.DataElement)4 Block (jmri.Block)3 Memory (jmri.Memory)3 SignalHead (jmri.SignalHead)3 Turnout (jmri.Turnout)3 Portal (jmri.jmrit.logix.Portal)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 SortOrder (javax.swing.SortOrder)2