Search in sources :

Example 56 with Element

use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.

the class AbstractNamedBeanManagerConfigXMLTest method testStoreNullProperty.

public void testStoreNullProperty() {
    // Create the manager to test
    AbstractNamedBeanManagerConfigXML x = new NamedBeanManagerConfigXMLTest();
    // create a NamedBean with two properties to store
    NamedBean from = new AbstractNamedBean("sys", "usr") {

        @Override
        public int getState() {
            return 0;
        }

        @Override
        public void setState(int i) {
        }

        @Override
        public String getBeanType() {
            return "";
        }
    };
    from.setProperty("foo", null);
    from.setProperty("biff", Boolean.valueOf(true));
    // create element for properties
    Element p = new Element("test");
    x.storeProperties(from, p);
    // create NamedBean to load
    NamedBean to = new AbstractNamedBean("sys", "usr") {

        @Override
        public int getState() {
            return 0;
        }

        @Override
        public void setState(int i) {
        }

        @Override
        public String getBeanType() {
            return "";
        }
    };
    x.loadProperties(to, p);
    // and test
    Assert.assertEquals(null, to.getProperty("foo"));
    Assert.assertEquals(Boolean.valueOf(true), to.getProperty("biff"));
}
Also used : AbstractNamedBean(jmri.implementation.AbstractNamedBean) AbstractNamedBean(jmri.implementation.AbstractNamedBean) NamedBean(jmri.NamedBean) Element(org.jdom2.Element)

Example 57 with Element

use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.

the class LocaleSelectorTest method testFindPartialCode.

public void testFindPartialCode() {
    LocaleSelector.suffixes = new String[] { "kl_KL", "kl" };
    Namespace xml = Namespace.XML_NAMESPACE;
    Element el = new Element("foo").setAttribute("temp", "a").addContent(new Element("temp").setAttribute("lang", "aa_BB", xml).addContent("b")).addContent(new Element("temp").setAttribute("lang", "kl", xml).addContent("c")).addContent(new Element("temp").setAttribute("lang", "kl_AA", xml).addContent("d"));
    String result = LocaleSelector.getAttribute(el, "temp");
    Assert.assertEquals("find default", "c", result);
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 58 with Element

use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.

the class LocaleSelectorTest method testFindFullCode.

public void testFindFullCode() {
    LocaleSelector.suffixes = new String[] { "kl_KL", "kl" };
    Namespace xml = Namespace.XML_NAMESPACE;
    Element el = new Element("foo").setAttribute("temp", "a").addContent(new Element("temp").setAttribute("lang", "aa_BB", xml).addContent("b")).addContent(new Element("temp").setAttribute("lang", "kl", xml).addContent("b")).addContent(new Element("temp").setAttribute("lang", "kl_KL", xml).addContent("c"));
    String result = LocaleSelector.getAttribute(el, "temp");
    Assert.assertEquals("find default", "c", result);
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 59 with Element

use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.

the class SE8cSignalHeadXml method addTurnoutElement.

Element addTurnoutElement(NamedBeanHandle<Turnout> to, String which) {
    Element el = new Element("turnoutname");
    el.setAttribute("defines", which);
    el.addContent(to.getName());
    return el;
}
Also used : Element(org.jdom2.Element)

Example 60 with Element

use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.

the class BlockBossLogicXml method store.

/**
     * Default implementation for storing the contents of all the BLockBossLogic
     * elements.
     * <P>
     * Static members in the BlockBossLogic class record the complete set of
     * items. This function writes those out as a single XML element.
     *
     * @param o Object to start process, but not actually used
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Enumeration<BlockBossLogic> e = BlockBossLogic.entries();
    if (!e.hasMoreElements()) {
        // nothing to write!
        return null;
    }
    Element blocks = new Element("signalelements");
    blocks.setAttribute("class", this.getClass().getName());
    while (e.hasMoreElements()) {
        BlockBossLogic p = e.nextElement();
        Element block = new Element("signalelement");
        block.setAttribute("signal", p.getDrivenSignal());
        block.setAttribute("mode", "" + p.getMode());
        if (p.getApproachSensor1() != null) {
            block.setAttribute("approachsensor1", p.getApproachSensor1());
        }
        if (p.getSensor1() != null) {
            block.addContent(storeSensor(p.getSensor1()));
        }
        if (p.getSensor2() != null) {
            block.addContent(storeSensor(p.getSensor2()));
        }
        if (p.getSensor3() != null) {
            block.addContent(storeSensor(p.getSensor3()));
        }
        if (p.getSensor4() != null) {
            block.addContent(storeSensor(p.getSensor4()));
        }
        if (p.getSensor5() != null) {
            block.addContent(storeSensor(p.getSensor5()));
        }
        if (p.getTurnout() != null) {
            block.setAttribute("watchedturnout", p.getTurnout());
        }
        if (p.getWatchedSignal1() != null) {
            block.setAttribute("watchedsignal1", p.getWatchedSignal1());
        }
        if (p.getWatchedSignal1Alt() != null) {
            block.setAttribute("watchedsignal1alt", p.getWatchedSignal1Alt());
        }
        if (p.getWatchedSignal2() != null) {
            block.setAttribute("watchedsignal2", p.getWatchedSignal2());
        }
        if (p.getWatchedSignal2Alt() != null) {
            block.setAttribute("watchedsignal2alt", p.getWatchedSignal2Alt());
        }
        if (p.getWatchedSensor1() != null) {
            block.setAttribute("watchedsensor1", p.getWatchedSensor1());
        }
        if (p.getWatchedSensor1Alt() != null) {
            block.setAttribute("watchedsensor1alt", p.getWatchedSensor1Alt());
        }
        if (p.getWatchedSensor2() != null) {
            block.setAttribute("watchedsensor2", p.getWatchedSensor2());
        }
        if (p.getWatchedSensor2Alt() != null) {
            block.setAttribute("watchedsensor2alt", p.getWatchedSensor2Alt());
        }
        block.setAttribute("limitspeed1", "" + p.getLimitSpeed1());
        block.setAttribute("limitspeed2", "" + p.getLimitSpeed2());
        block.setAttribute("useflashyellow", "" + p.getUseFlash());
        block.setAttribute("distantsignal", "" + p.getDistantSignal());
        // add comment, if present
        if (p.getComment() != null) {
            Element c = new Element("comment");
            c.addContent(p.getComment());
            block.addContent(c);
        }
        blocks.addContent(block);
    }
    return blocks;
}
Also used : BlockBossLogic(jmri.jmrit.blockboss.BlockBossLogic) Element(org.jdom2.Element)

Aggregations

Element (org.jdom2.Element)829 Attribute (org.jdom2.Attribute)76 Document (org.jdom2.Document)75 Test (org.junit.Test)70 File (java.io.File)53 ArrayList (java.util.ArrayList)45 JDOMException (org.jdom2.JDOMException)37 IOException (java.io.IOException)34 HashMap (java.util.HashMap)28 NamedIcon (jmri.jmrit.catalog.NamedIcon)27 List (java.util.List)26 XmlFile (jmri.jmrit.XmlFile)24 SAXBuilder (org.jdom2.input.SAXBuilder)21 Turnout (jmri.Turnout)20 DataConversionException (org.jdom2.DataConversionException)20 DocType (org.jdom2.DocType)19 Editor (jmri.jmrit.display.Editor)18 XMLOutputter (org.jdom2.output.XMLOutputter)18 Namespace (org.jdom2.Namespace)17 Point (java.awt.Point)15