Search in sources :

Example 41 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.Attribute in project JMRI by JMRI.

the class LayoutBlockManagerXml method loadLayoutBlocks.

/**
     * Utility method to load the individual LayoutBlock objects. If there's no
     * additional info needed for a specific layoutblock type, invoke this with
     * the parent of the set of layoutblock elements.
     *
     * @param layoutblocks Element containing the layoutblock elements to load.
     */
public void loadLayoutBlocks(Element layoutblocks) {
    LayoutBlockManager tm = InstanceManager.getDefault(LayoutBlockManager.class);
    if (layoutblocks.getAttribute("blockrouting") != null) {
        if (layoutblocks.getAttribute("blockrouting").getValue().equals("yes")) {
            tm.enableAdvancedRouting(true);
        }
    }
    if (layoutblocks.getAttribute("routingStablisedSensor") != null) {
        try {
            tm.setStabilisedSensor(layoutblocks.getAttribute("routingStablisedSensor").getValue());
        } catch (jmri.JmriException e) {
        }
    }
    List<Element> layoutblockList = layoutblocks.getChildren("layoutblock");
    if (log.isDebugEnabled()) {
        log.debug("Found " + layoutblockList.size() + " layoutblocks");
    }
    for (int i = 0; i < layoutblockList.size(); i++) {
        String sysName = getSystemName(layoutblockList.get(i));
        if (sysName == null) {
            log.warn("unexpected null in systemName " + ((layoutblockList.get(i))) + " " + ((layoutblockList.get(i))).getAttributes());
            break;
        }
        String userName = getUserName(layoutblockList.get(i));
        LayoutBlock b = tm.createNewLayoutBlock(sysName, userName);
        // load common parts
        loadCommon(b, layoutblockList.get(i));
        if (b != null) {
            // set attributes
            Color color = ColorUtil.stringToColor(((layoutblockList.get(i))).getAttribute("trackcolor").getValue());
            b.setBlockTrackColor(color);
            color = ColorUtil.stringToColor(((layoutblockList.get(i))).getAttribute("occupiedcolor").getValue());
            b.setBlockOccupiedColor(color);
            Attribute a = ((layoutblockList.get(i))).getAttribute("extracolor");
            if (a != null) {
                b.setBlockExtraColor(ColorUtil.stringToColor(a.getValue()));
            }
            a = ((layoutblockList.get(i))).getAttribute("occupancysensor");
            if (a != null) {
                b.setOccupancySensorName(a.getValue());
            }
            a = ((layoutblockList.get(i))).getAttribute("memory");
            if (a != null) {
                b.setMemoryName(a.getValue());
            }
            a = ((layoutblockList.get(i))).getAttribute("occupancysensorsense");
            int sense = Sensor.ACTIVE;
            try {
                sense = ((layoutblockList.get(i))).getAttribute("occupiedsense").getIntValue();
            } catch (org.jdom2.DataConversionException e) {
                log.error("failed to convert occupiedsense attribute");
            }
            b.setOccupiedSense(sense);
            if (((layoutblockList.get(i))).getChild("metric") != null) {
                String stMetric = ((layoutblockList.get(i))).getChild("metric").getText();
                try {
                    b.setBlockMetric(Integer.valueOf(stMetric));
                } catch (java.lang.NumberFormatException e) {
                    log.error("failed to convert metric attribute for block " + b.getDisplayName());
                }
            }
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Color(java.awt.Color) LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager)

Example 42 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.Attribute in project JMRI by JMRI.

the class WarrantManagerXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    WarrantManager manager = InstanceManager.getDefault(WarrantManager.class);
    if (shared.getChildren().isEmpty()) {
        return true;
    }
    List<Element> warrantList = shared.getChildren("warrant");
    if (log.isDebugEnabled())
        log.debug("Found {} Warrant objects", warrantList.size());
    for (int i = 0; i < warrantList.size(); i++) {
        Element elem = warrantList.get(i);
        if (elem.getAttribute("systemName") == null) {
            log.warn("unexpected null for systemName in elem {}", elem);
            break;
        }
        String sysName = null;
        if (elem.getAttribute("systemName") != null)
            sysName = elem.getAttribute("systemName").getValue();
        String userName = null;
        if (elem.getAttribute("userName") != null)
            userName = elem.getAttribute("userName").getValue();
        boolean SCWa = true;
        log.debug("loading warrant {}", sysName);
        Attribute wType = elem.getAttribute("wtype");
        if (wType == null) {
            log.debug("wtype is null for {}", sysName);
            SCWa = false;
        } else if (!wType.getValue().equals("SC")) {
            log.debug("wtype is {} for {}", wType.getValue(), sysName);
            SCWa = false;
        }
        long timeToPlatform = 500;
        Attribute TTP = elem.getAttribute("timeToPlatform");
        if (TTP != null) {
            try {
                timeToPlatform = TTP.getLongValue();
            } catch (DataConversionException e) {
                log.debug("ignoring DataConversionException (and reverting to default value): " + e.toString());
            }
        }
        Warrant warrant = manager.createNewWarrant(sysName, userName, SCWa, timeToPlatform);
        if (warrant == null) {
            log.info("Warrant \"{}\" (userName={}) previously loaded. This version not loaded.", sysName, userName);
            continue;
        }
        if (SCWa) {
            if (elem.getAttribute("forward") != null) {
                ((SCWarrant) warrant).setForward(elem.getAttribute("forward").getValue().equals("true"));
            }
            warrant.setNoRamp(SCWa);
            warrant.setShareRoute(SCWa);
        }
        List<Element> orders = elem.getChildren("blockOrder");
        for (int k = 0; k < orders.size(); k++) {
            BlockOrder bo = loadBlockOrder(orders.get(k));
            if (bo == null) {
                break;
            }
            warrant.addBlockOrder(bo);
        }
        String c = elem.getChildText("comment");
        if (c != null) {
            warrant.setComment(c);
        }
        Element order = elem.getChild("viaOrder");
        if (order != null) {
            warrant.setViaOrder(loadBlockOrder(order));
        }
        order = elem.getChild("avoidOrder");
        if (order != null) {
            warrant.setAvoidOrder(loadBlockOrder(order));
        }
        boolean forward = true;
        List<Element> throttleCmds = elem.getChildren("throttleCommand");
        if (throttleCmds != null) {
            for (int k = 0; k < throttleCmds.size(); k++) {
                ThrottleSetting ts = loadThrottleCommand(throttleCmds.get(k));
                warrant.addThrottleCommand(ts);
                if (ts.getCommand().toUpperCase().equals("FORWARD")) {
                    forward = ts.getValue().toUpperCase().equals("TRUE");
                }
            }
        }
        if (SCWa) {
            if (elem.getAttribute("forward") != null) {
                forward = elem.getAttribute("forward").getValue().equals("true");
            }
            ((SCWarrant) warrant).setForward(forward);
            warrant.setNoRamp(SCWa);
            warrant.setShareRoute(SCWa);
        }
        Element train = elem.getChild("train");
        if (train != null) {
            loadTrain(train, warrant);
        }
    }
    return true;
}
Also used : SCWarrant(jmri.jmrit.logix.SCWarrant) Warrant(jmri.jmrit.logix.Warrant) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ThrottleSetting(jmri.jmrit.logix.ThrottleSetting) WarrantManager(jmri.jmrit.logix.WarrantManager) SCWarrant(jmri.jmrit.logix.SCWarrant) DataConversionException(org.jdom2.DataConversionException) BlockOrder(jmri.jmrit.logix.BlockOrder)

Example 43 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.Attribute in project JMRI by JMRI.

the class WarrantManagerXml method loadBlockOrder.

static BlockOrder loadBlockOrder(Element elem) {
    OBlock block = null;
    List<Element> blocks = elem.getChildren("block");
    if (blocks.size() > 1)
        log.error("More than one block present: {}", blocks.size());
    if (blocks.size() > 0) {
        // sensor
        String name = blocks.get(0).getAttribute("systemName").getValue();
        try {
            block = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class).provideOBlock(name);
        } catch (IllegalArgumentException ex) {
            log.error("Unknown Block \"{}\" is null in BlockOrder.", name);
            return null;
        }
        if (log.isDebugEnabled())
            log.debug("Load Block {}.", name);
    } else {
        log.error("Null BlockOrder element");
        return null;
    }
    Attribute attr = elem.getAttribute("pathName");
    String pathName = null;
    if (attr != null)
        pathName = attr.getValue();
    attr = elem.getAttribute("entryName");
    String entryName = null;
    if (attr != null)
        entryName = attr.getValue();
    attr = elem.getAttribute("exitName");
    String exitName = null;
    if (attr != null)
        exitName = attr.getValue();
    return new BlockOrder(block, pathName, entryName, exitName);
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) OBlock(jmri.jmrit.logix.OBlock) BlockOrder(jmri.jmrit.logix.BlockOrder)

Example 44 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.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 45 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.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)

Aggregations

Attribute (org.jdom2.Attribute)148 Element (org.jdom2.Element)104 Document (org.jdom2.Document)18 ArrayList (java.util.ArrayList)17 DataConversionException (org.jdom2.DataConversionException)16 Editor (jmri.jmrit.display.Editor)15 Test (org.junit.Test)15 IOException (java.io.IOException)14 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 Attribute (org.bouncycastle.asn1.x509.Attribute)11 HashMap (java.util.HashMap)10 List (java.util.List)9 HashSet (java.util.HashSet)7 Map (java.util.Map)7 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)7 Attribute (ucar.nc2.Attribute)7 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