Search in sources :

Example 61 with Attribute

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

the class OBlockManagerXml method loadPath.

OPath loadPath(Element elem, OBlock block) {
    String pName = elem.getAttribute("pathName").getValue();
    OPath path = getPath(block, pName);
    try {
        Attribute attr = elem.getAttribute("fromDirection");
        if (attr != null) {
            path.setFromBlockDirection(attr.getIntValue());
        }
        attr = elem.getAttribute("toDirection");
        if (attr != null) {
            path.setToBlockDirection(attr.getIntValue());
        }
        attr = elem.getAttribute("length");
        if (attr != null) {
            path.setLength(attr.getFloatValue());
        }
    } catch (org.jdom2.DataConversionException e) {
        log.error("Could not parse attribute of path (" + pName + ") block (" + block.getSystemName() + ")");
    }
    Attribute attr = elem.getAttribute("fromPortal");
    if (attr != null) {
        Portal portal = getPortal(attr.getValue());
        if (portal != null) {
            path.setFromPortal(portal);
            portal.addPath(path);
        }
    }
    attr = elem.getAttribute("toPortal");
    if (attr != null) {
        Portal portal = getPortal(attr.getValue());
        if (portal != null) {
            path.setToPortal(portal);
            portal.addPath(path);
        }
    }
    List<Element> settings = elem.getChildren("setting");
    if (log.isDebugEnabled()) {
        log.debug("Path (" + pName + ") has " + settings.size() + " settings.");
    }
    java.util.HashSet<String> turnouts = new java.util.HashSet<String>();
    int dups = 0;
    for (int i = 0; i < settings.size(); i++) {
        Element setElem = settings.get(i);
        int setting = 0;
        try {
            setting = setElem.getAttribute("set").getIntValue();
        } catch (org.jdom2.DataConversionException e) {
            log.error("Could not parse 'set' attribute for path (" + pName + ") block (" + block.getSystemName() + ")");
        }
        String sysName = setElem.getAttribute("turnout").getValue();
        if (!turnouts.contains(sysName)) {
            Turnout to = InstanceManager.turnoutManagerInstance().provideTurnout(sysName);
            turnouts.add(sysName);
            BeanSetting bs = new BeanSetting(to, sysName, setting);
            path.addSetting(bs);
        } else {
            dups++;
        }
    }
    if (dups > 0) {
        log.warn(dups + " duplicate settings not loaded for path \"" + pName + "\"");
    }
    return path;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) OPath(jmri.jmrit.logix.OPath) BeanSetting(jmri.BeanSetting) Portal(jmri.jmrit.logix.Portal) Turnout(jmri.Turnout)

Example 62 with Attribute

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

the class OBlockManagerXml method loadPortal.

Portal loadPortal(Element elem) {
    String sysName = null;
    String userName = elem.getAttribute("portalName").getValue();
    if (elem.getAttribute("systemName") == null) {
        if (log.isDebugEnabled()) {
            log.debug("Portal systemName is null");
        }
    } else {
        sysName = elem.getAttribute("systemName").getValue();
    }
    String fromBlockName = null;
    String toBlockName = null;
    // Portals must have user names.
    Portal portal = _portalMgr.getByUserName(userName);
    if (portal != null) {
        fromBlockName = portal.getFromBlock().getSystemName();
        toBlockName = portal.getToBlock().getSystemName();
    } else {
        portal = _portalMgr.providePortal(userName);
    }
    if (portal == null) {
        log.error("unable to create Portal (" + sysName + ", " + userName + ") " + elem + " " + elem.getAttributes());
        return null;
    }
    if (log.isDebugEnabled()) {
        log.debug("create Portal: (" + sysName + ", " + userName + ")");
    }
    OBlock fromBlock = null;
    Element eFromBlk = elem.getChild("fromBlock");
    if (eFromBlk != null && eFromBlk.getAttribute("blockName") != null) {
        String name = eFromBlk.getAttribute("blockName").getValue();
        if (fromBlockName != null && !fromBlockName.equals(name)) {
            log.error("Portal has user name \"" + userName + "\" conflicting with " + portal.toString());
        } else {
            fromBlock = getBlock(name);
            if (fromBlock != null) {
                portal.setFromBlock(fromBlock, false);
                fromBlock.addPortal(portal);
                List<Element> ePathsFromBlock = eFromBlk.getChildren("path");
                for (int i = 0; i < ePathsFromBlock.size(); i++) {
                    Element e = ePathsFromBlock.get(i);
                    String pathName = e.getAttribute("pathName").getValue();
                    String blockName = e.getAttribute("blockName").getValue();
                    if (log.isDebugEnabled()) {
                        log.debug("Load portal= " + userName + " fromBlock= " + fromBlock.getSystemName() + " pathName= " + pathName + " blockName= " + blockName);
                    }
                    /*(if (fromBlock.getSystemName().equals(blockName))*/
                    {
                        // path is in the fromBlock
                        OPath path = getPath(fromBlock, pathName);
                        portal.addPath(path);
                    }
                }
            }
        }
    } else {
        log.error("Portal \"" + userName + "\" has no fromBlock!");
    }
    OBlock toBlock = null;
    Element eToBlk = elem.getChild("toBlock");
    if (eToBlk != null && eToBlk.getAttribute("blockName") != null) {
        String name = eToBlk.getAttribute("blockName").getValue();
        if (toBlockName != null && !toBlockName.equals(name)) {
            log.error("Portal has user name \"" + userName + "\" conflicting with " + portal.toString());
        } else {
            toBlock = getBlock(name);
            if (toBlock != null) {
                portal.setToBlock(toBlock, false);
                toBlock.addPortal(portal);
                List<Element> ePathsToBlock = eToBlk.getChildren("path");
                for (int i = 0; i < ePathsToBlock.size(); i++) {
                    Element e = ePathsToBlock.get(i);
                    String pathName = e.getAttribute("pathName").getValue();
                    String blockName = e.getAttribute("blockName").getValue();
                    if (log.isDebugEnabled()) {
                        log.debug("Load portal= " + userName + " toBlock= " + toBlock.getSystemName() + " pathName= " + pathName + " blockName= " + blockName);
                    }
                    /*if (toBlock.getSystemName().equals(blockName))*/
                    {
                        // path is in the toBlock
                        OPath path = getPath(toBlock, pathName);
                        portal.addPath(path);
                    }
                }
            }
        }
    } else {
        log.error("Portal \"" + userName + "\" has no toBlock!");
    }
    Element eSignal = elem.getChild("fromSignal");
    if (eSignal != null) {
        String name = eSignal.getAttribute("signalName").getValue();
        float length = 0.0f;
        try {
            Attribute attr = eSignal.getAttribute("signalDelay");
            if (attr != null) {
                length = attr.getFloatValue();
            }
        } catch (org.jdom2.DataConversionException e) {
            log.error("Could not parse signalDelay for signal (" + name + ") in portal (" + userName + ")");
        }
        portal.setProtectSignal(Portal.getSignal(name), length, toBlock);
    }
    eSignal = elem.getChild("toSignal");
    if (eSignal != null) {
        String name = eSignal.getAttribute("signalName").getValue();
        float length = 0.0f;
        try {
            Attribute attr = eSignal.getAttribute("signalDelay");
            if (attr != null) {
                length = attr.getFloatValue();
            }
        } catch (org.jdom2.DataConversionException e) {
            log.error("Could not parse signalDelay for signal (" + name + ") in portal (" + userName + ")");
        }
        portal.setProtectSignal(Portal.getSignal(name), length, fromBlock);
    }
    if (log.isDebugEnabled()) {
        log.debug("End Load portal " + userName);
    }
    return portal;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Portal(jmri.jmrit.logix.Portal) OPath(jmri.jmrit.logix.OPath) OBlock(jmri.jmrit.logix.OBlock)

Example 63 with Attribute

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

the class CarLoads method load.

public void load(Element e) {
    if (e.getChild(Xml.LOADS) == null) {
        return;
    }
    Attribute a;
    Element defaults = e.getChild(Xml.LOADS).getChild(Xml.DEFAULTS);
    if (defaults != null) {
        if ((a = defaults.getAttribute(Xml.LOAD)) != null) {
            _loadName = a.getValue();
        }
        if ((a = defaults.getAttribute(Xml.EMPTY)) != null) {
            _emptyName = a.getValue();
        }
    }
    @SuppressWarnings("unchecked") List<Element> eLoads = e.getChild(Xml.LOADS).getChildren(Xml.LOAD);
    log.debug("readFile sees {} car loads", eLoads.size());
    for (Element eLoad : eLoads) {
        if ((a = eLoad.getAttribute(Xml.TYPE)) != null) {
            String type = a.getValue();
            addType(type);
            // old style had a list of names
            if ((a = eLoad.getAttribute(Xml.NAMES)) != null) {
                String names = a.getValue();
                // NOI18N
                String[] loadNames = names.split("%%");
                jmri.util.StringUtil.sort(loadNames);
                log.debug("Car load type: {} loads: {}", type, names);
                // addName puts new items at the start, so reverse load
                for (int j = loadNames.length; j > 0; ) {
                    addName(type, loadNames[--j]);
                }
            }
            // new style load and comments
            @SuppressWarnings("unchecked") List<Element> eCarLoads = eLoad.getChildren(Xml.CAR_LOAD);
            log.debug("{} car loads for type: {}", eCarLoads.size(), type);
            for (Element eCarLoad : eCarLoads) {
                if ((a = eCarLoad.getAttribute(Xml.NAME)) != null) {
                    String name = a.getValue();
                    addName(type, name);
                    if ((a = eCarLoad.getAttribute(Xml.PRIORITY)) != null) {
                        setPriority(type, name, a.getValue());
                    }
                    if ((a = eCarLoad.getAttribute(Xml.PICKUP_COMMENT)) != null) {
                        setPickupComment(type, name, a.getValue());
                    }
                    if ((a = eCarLoad.getAttribute(Xml.DROP_COMMENT)) != null) {
                        setDropComment(type, name, a.getValue());
                    }
                    if ((a = eCarLoad.getAttribute(Xml.LOAD_TYPE)) != null) {
                        setLoadType(type, name, a.getValue());
                    }
                }
            }
        }
    }
}
Also used : RollingStockAttribute(jmri.jmrit.operations.rollingstock.RollingStockAttribute) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 64 with Attribute

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

the class CarManager method load.

public void load(Element root) {
    // new format using elements starting version 3.3.1
    if (root.getChild(Xml.NEW_KERNELS) != null) {
        @SuppressWarnings("unchecked") List<Element> eKernels = root.getChild(Xml.NEW_KERNELS).getChildren(Xml.KERNEL);
        log.debug("Car manager sees {} kernels", eKernels.size());
        Attribute a;
        for (Element eKernel : eKernels) {
            if ((a = eKernel.getAttribute(Xml.NAME)) != null) {
                newKernel(a.getValue());
            }
        }
    } else // old format
    if (root.getChild(Xml.KERNELS) != null) {
        String names = root.getChildText(Xml.KERNELS);
        if (!names.equals("")) {
            // NOI18N
            String[] kernelNames = names.split("%%");
            log.debug("kernels: {}", names);
            for (String name : kernelNames) {
                newKernel(name);
            }
        }
    }
    if (root.getChild(Xml.CARS) != null) {
        @SuppressWarnings("unchecked") List<Element> eCars = root.getChild(Xml.CARS).getChildren(Xml.CAR);
        log.debug("readFile sees {} cars", eCars.size());
        for (Element eCar : eCars) {
            register(new Car(eCar));
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 65 with Attribute

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

the class TrainCustomCommon method load.

public void load(Element mc) {
    if (mc != null) {
        Attribute a;
        Element directory = mc.getChild(Xml.DIRECTORY);
        if (directory != null && (a = directory.getAttribute(Xml.NAME)) != null) {
            setDirectoryName(a.getValue());
        }
        Element file = mc.getChild(Xml.RUN_FILE);
        if (file != null && (a = file.getAttribute(Xml.NAME)) != null) {
            mcAppName = a.getValue();
        }
        Element common = mc.getChild(Xml.COMMON_FILE);
        if (common != null && (a = common.getAttribute(Xml.NAME)) != null) {
            csvNamesFileName = a.getValue();
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Aggregations

Attribute (org.jdom2.Attribute)104 Element (org.jdom2.Element)96 DataConversionException (org.jdom2.DataConversionException)17 Editor (jmri.jmrit.display.Editor)15 ArrayList (java.util.ArrayList)13 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 IOException (java.io.IOException)12 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)10 File (java.io.File)8 Color (java.awt.Color)7 List (java.util.List)7 HashMap (java.util.HashMap)6 Asn1Integer (com.android.hotspot2.asn1.Asn1Integer)5 Asn1Object (com.android.hotspot2.asn1.Asn1Object)5 Asn1Oid (com.android.hotspot2.asn1.Asn1Oid)5 OidMappings (com.android.hotspot2.asn1.OidMappings)5 ASN1Encodable (com.android.org.bouncycastle.asn1.ASN1Encodable)5 ASN1EncodableVector (com.android.org.bouncycastle.asn1.ASN1EncodableVector)5 ASN1Set (com.android.org.bouncycastle.asn1.ASN1Set)5 DERBitString (com.android.org.bouncycastle.asn1.DERBitString)5