Search in sources :

Example 6 with Attribute

use of ucar.nc2.Attribute in project robovm by robovm.

the class X509AttributeCertificateHolder method getAttributes.

/**
     * Return an  array of attributes matching the passed in type OID.
     *
     * @param type the type of the attribute being looked for.
     * @return an array of Attribute of the requested type, zero length if none present.
     */
public Attribute[] getAttributes(ASN1ObjectIdentifier type) {
    ASN1Sequence seq = attrCert.getAcinfo().getAttributes();
    List list = new ArrayList();
    for (int i = 0; i != seq.size(); i++) {
        Attribute attr = Attribute.getInstance(seq.getObjectAt(i));
        if (attr.getAttrType().equals(type)) {
            list.add(attr);
        }
    }
    if (list.size() == 0) {
        return EMPTY_ARRAY;
    }
    return (Attribute[]) list.toArray(new Attribute[list.size()]);
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) Attribute(org.bouncycastle.asn1.x509.Attribute) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with Attribute

use of ucar.nc2.Attribute in project JMRI by JMRI.

the class AbstractTurnoutManagerConfigXML method loadTurnouts.

/**
     * Utility method to load the individual Turnout objects. If there's no
     * additional info needed for a specific turnout type, invoke this with the
     * parent of the set of Turnout elements.
     *
     * @param shared Element containing the Turnout elements to load.
     * @param perNode Element containing per-node Turnout data.
     * @return true if succeeded
     */
@SuppressWarnings("unchecked")
public boolean loadTurnouts(Element shared, Element perNode) {
    boolean result = true;
    List<Element> operationList = shared.getChildren("operations");
    if (operationList.size() > 1) {
        log.warn("unexpected extra elements found in turnout operations list");
        result = false;
    }
    if (operationList.size() > 0) {
        TurnoutOperationManagerXml tomx = new TurnoutOperationManagerXml();
        tomx.load(operationList.get(0), null);
    }
    List<Element> turnoutList = shared.getChildren("turnout");
    if (log.isDebugEnabled()) {
        log.debug("Found " + turnoutList.size() + " turnouts");
    }
    TurnoutManager tm = InstanceManager.turnoutManagerInstance();
    try {
        if (shared.getChild("defaultclosedspeed") != null) {
            String closedSpeed = shared.getChild("defaultclosedspeed").getText();
            if (closedSpeed != null && !closedSpeed.equals("")) {
                tm.setDefaultClosedSpeed(closedSpeed);
            }
        }
    } catch (jmri.JmriException ex) {
        log.error(ex.toString());
    }
    try {
        if (shared.getChild("defaultthrownspeed") != null) {
            String thrownSpeed = shared.getChild("defaultthrownspeed").getText();
            if (thrownSpeed != null && !thrownSpeed.equals("")) {
                tm.setDefaultThrownSpeed(thrownSpeed);
            }
        }
    } catch (jmri.JmriException ex) {
        log.error(ex.toString());
    }
    for (int i = 0; i < turnoutList.size(); i++) {
        Element elem = turnoutList.get(i);
        String sysName = getSystemName(elem);
        if (sysName == null) {
            log.error("unexpected null in systemName " + elem);
            result = false;
            break;
        }
        String userName = getUserName(elem);
        checkNameNormalization(sysName, userName, tm);
        if (log.isDebugEnabled()) {
            log.debug("create turnout: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
        }
        Turnout t = tm.getBySystemName(sysName);
        if (t == null) {
            t = tm.newTurnout(sysName, userName);
        //Nothing is logged in the console window as the newTurnoutFunction already does this.
        } else if (userName != null) {
            t.setUserName(userName);
        }
        // Load common parts
        loadCommon(t, elem);
        // now add feedback if needed
        Attribute a;
        a = elem.getAttribute("feedback");
        if (a != null) {
            try {
                t.setFeedbackMode(a.getValue());
            } catch (IllegalArgumentException e) {
                log.error("Can not set feedback mode: '" + a.getValue() + "' for turnout: '" + sysName + "' user name: '" + (userName == null ? "" : userName) + "'");
                result = false;
            }
        }
        a = elem.getAttribute("sensor1");
        if (a != null) {
            try {
                t.provideFirstFeedbackSensor(a.getValue());
            } catch (jmri.JmriException e) {
                result = false;
            }
        }
        a = elem.getAttribute("sensor2");
        if (a != null) {
            try {
                t.provideSecondFeedbackSensor(a.getValue());
            } catch (jmri.JmriException e) {
                result = false;
            }
        }
        // check for turnout inverted
        t.setInverted(getAttributeBool(elem, "inverted", false));
        // check for turnout decoder
        a = turnoutList.get(i).getAttribute("decoder");
        if (a != null) {
            t.setDecoderName(a.getValue());
        }
        // check for turnout lock mode
        a = turnoutList.get(i).getAttribute("lockMode");
        if (a != null) {
            if (a.getValue().equals("both")) {
                t.enableLockOperation(Turnout.CABLOCKOUT + Turnout.PUSHBUTTONLOCKOUT, true);
            }
            if (a.getValue().equals("cab")) {
                t.enableLockOperation(Turnout.CABLOCKOUT, true);
                t.enableLockOperation(Turnout.PUSHBUTTONLOCKOUT, false);
            }
            if (a.getValue().equals("pushbutton")) {
                t.enableLockOperation(Turnout.PUSHBUTTONLOCKOUT, true);
                t.enableLockOperation(Turnout.CABLOCKOUT, false);
            }
        }
        // check for turnout locked
        a = turnoutList.get(i).getAttribute("locked");
        if (a != null) {
            t.setLocked(Turnout.CABLOCKOUT + Turnout.PUSHBUTTONLOCKOUT, a.getValue().equals("true"));
        }
        // number of bits, if present - if not, defaults to 1
        a = turnoutList.get(i).getAttribute("numBits");
        if (a == null) {
            t.setNumberOutputBits(1);
        } else {
            int iNum = Integer.parseInt(a.getValue());
            if ((iNum == 1) || (iNum == 2)) {
                t.setNumberOutputBits(iNum);
            } else {
                log.warn("illegal number of output bits for control of turnout " + sysName);
                t.setNumberOutputBits(1);
                result = false;
            }
        }
        // control type, if present - if not, defaults to 0
        a = turnoutList.get(i).getAttribute("controlType");
        if (a == null) {
            t.setControlType(0);
        } else {
            int iType = Integer.parseInt(a.getValue());
            if (iType >= 0) {
                t.setControlType(iType);
            } else {
                log.warn("illegal control type for control of turnout " + sysName);
                t.setControlType(0);
                result = false;
            }
        }
        // operation stuff
        List<Element> myOpList = turnoutList.get(i).getChildren("operation");
        if (myOpList.size() > 0) {
            if (myOpList.size() > 1) {
                log.warn("unexpected extra elements found in turnout-specific operations");
                result = false;
            }
            TurnoutOperation toper = TurnoutOperationXml.loadOperation(myOpList.get(0));
            t.setTurnoutOperation(toper);
        } else {
            a = turnoutList.get(i).getAttribute("automate");
            if (a != null) {
                String str = a.getValue();
                if (str.equals("Off")) {
                    t.setInhibitOperation(true);
                } else if (!str.equals("Default")) {
                    t.setInhibitOperation(false);
                    TurnoutOperation toper = TurnoutOperationManager.getInstance().getOperation(str);
                    t.setTurnoutOperation(toper);
                } else {
                    t.setInhibitOperation(false);
                }
            }
        }
        //  set initial state from sensor feedback if appropriate
        t.setInitialKnownStateFromFeedback();
        try {
            t.setDivergingSpeed("Global");
            if (elem.getChild("divergingSpeed") != null) {
                String speed = elem.getChild("divergingSpeed").getText();
                if (speed != null && !speed.equals("") && !speed.contains("Global")) {
                    t.setDivergingSpeed(speed);
                }
            }
        } catch (jmri.JmriException ex) {
            log.error(ex.toString());
        }
        try {
            t.setStraightSpeed("Global");
            if (elem.getChild("straightSpeed") != null) {
                String speed = elem.getChild("straightSpeed").getText();
                if (speed != null && !speed.equals("") && !speed.contains("Global")) {
                    t.setStraightSpeed(speed);
                }
            }
        } catch (jmri.JmriException ex) {
            log.error(ex.toString());
        }
    }
    return result;
}
Also used : TurnoutOperation(jmri.TurnoutOperation) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) TurnoutManager(jmri.TurnoutManager) TurnoutOperationManagerXml(jmri.configurexml.TurnoutOperationManagerXml) Turnout(jmri.Turnout)

Example 8 with Attribute

use of ucar.nc2.Attribute in project JMRI by JMRI.

the class AbstractAudioManagerConfigXML method loadAudio.

/**
     * Utility method to load the individual Audio objects. If there's no
     * additional info needed for a specific Audio type, invoke this with the
     * parent of the set of Audio elements.
     *
     * @param audio Element containing the Audio elements to load.
     */
@SuppressWarnings("unchecked")
public void loadAudio(Element audio) {
    AudioManager am = InstanceManager.getDefault(jmri.AudioManager.class);
    // Count number of loaded Audio objects
    int loadedObjects = 0;
    // Load buffers first
    List<Element> audioList = audio.getChildren("audiobuffer");
    if (log.isDebugEnabled()) {
        log.debug("Found " + audioList.size() + " Audio Buffer objects");
    }
    for (int i = 0; i < audioList.size(); i++) {
        Element e = audioList.get(i);
        String sysName = getSystemName(e);
        if (sysName == null) {
            log.warn("unexpected null in systemName " + (e) + " " + (e).getAttributes());
            break;
        }
        String userName = getUserName(e);
        if (log.isDebugEnabled()) {
            log.debug("create Audio: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
        }
        try {
            AudioBuffer ab = (AudioBuffer) am.newAudio(sysName, userName);
            // load common parts
            loadCommon(ab, e);
            // load sub-type specific parts
            // Transient objects for reading child elements
            Element ce;
            String value;
            if ((ce = e.getChild("url")) != null) {
                ab.setURL(ce.getValue());
            }
            if ((ce = e.getChild("looppoint")) != null) {
                if ((value = ce.getAttributeValue("start")) != null) {
                    ab.setStartLoopPoint(Integer.parseInt(value));
                }
                if ((value = ce.getAttributeValue("end")) != null) {
                    ab.setEndLoopPoint(Integer.parseInt(value));
                }
            }
            if ((ce = e.getChild("streamed")) != null) {
                ab.setStreamed(ce.getValue().equals("yes"));
            }
        } catch (AudioException ex) {
            log.error("Error loading AudioBuffer (" + sysName + "): " + ex);
        }
    }
    loadedObjects += audioList.size();
    // Now load sources
    audioList = audio.getChildren("audiosource");
    if (log.isDebugEnabled()) {
        log.debug("Found " + audioList.size() + " Audio Source objects");
    }
    for (int i = 0; i < audioList.size(); i++) {
        Element e = audioList.get(i);
        String sysName = getSystemName(e);
        if (sysName == null) {
            log.warn("unexpected null in systemName " + (e) + " " + (e).getAttributes());
            break;
        }
        String userName = getUserName(e);
        if (log.isDebugEnabled()) {
            log.debug("create Audio: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
        }
        try {
            AudioSource as = (AudioSource) am.newAudio(sysName, userName);
            // load common parts
            loadCommon(as, e);
            // load sub-type specific parts
            // Transient objects for reading child elements
            Element ce;
            String value;
            if ((ce = e.getChild("position")) != null) {
                as.setPosition(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z"))));
            }
            if ((ce = e.getChild("velocity")) != null) {
                as.setVelocity(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z"))));
            }
            if ((ce = e.getChild("assignedbuffer")) != null) {
                if (ce.getValue().length() != 0 && !ce.getValue().equals("null")) {
                    as.setAssignedBuffer(ce.getValue());
                }
            }
            if ((ce = e.getChild("gain")) != null && ce.getValue().length() != 0) {
                as.setGain(Float.parseFloat(ce.getValue()));
            }
            if ((ce = e.getChild("pitch")) != null && ce.getValue().length() != 0) {
                as.setPitch(Float.parseFloat(ce.getValue()));
            }
            if ((ce = e.getChild("distances")) != null) {
                if ((value = ce.getAttributeValue("ref")) != null) {
                    as.setReferenceDistance(Float.parseFloat(value));
                }
                if ((value = ce.getAttributeValue("max")) != null) {
                    as.setMaximumDistance(Float.parseFloat(value));
                }
            }
            if ((ce = e.getChild("loops")) != null) {
                if ((value = ce.getAttributeValue("min")) != null) {
                    as.setMinLoops(Integer.parseInt(value));
                }
                if ((value = ce.getAttributeValue("max")) != null) {
                    as.setMaxLoops(Integer.parseInt(value));
                }
            //                    if ((value = ce.getAttributeValue("mindelay"))!=null)
            //                        as.setMinLoopDelay(Integer.parseInt(value));
            //                    if ((value = ce.getAttributeValue("maxdelay"))!=null)
            //                        as.setMaxLoopDelay(Integer.parseInt(value));
            }
            if ((ce = e.getChild("fadetimes")) != null) {
                if ((value = ce.getAttributeValue("in")) != null) {
                    as.setFadeIn(Integer.parseInt(value));
                }
                if ((value = ce.getAttributeValue("out")) != null) {
                    as.setFadeOut(Integer.parseInt(value));
                }
            }
            if ((ce = e.getChild("dopplerfactor")) != null && ce.getValue().length() != 0) {
                as.setDopplerFactor(Float.parseFloat(ce.getValue()));
            }
            if ((ce = e.getChild("positionrelative")) != null) {
                as.setPositionRelative(ce.getValue().equals("yes"));
            }
        } catch (AudioException ex) {
            log.error("Error loading AudioSource (" + sysName + "): " + ex);
        }
    }
    loadedObjects += audioList.size();
    // Finally, load Listeners if needed
    if (loadedObjects > 0) {
        audioList = audio.getChildren("audiolistener");
        if (log.isDebugEnabled()) {
            log.debug("Found " + audioList.size() + " Audio Listener objects");
        }
        for (int i = 0; i < audioList.size(); i++) {
            Element e = audioList.get(i);
            String sysName = getSystemName(e);
            if (sysName == null) {
                log.warn("unexpected null in systemName " + (e) + " " + (e).getAttributes());
                break;
            }
            String userName = getUserName(e);
            if (log.isDebugEnabled()) {
                log.debug("create Audio: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
            }
            try {
                AudioListener al = (AudioListener) am.newAudio(sysName, userName);
                // load common parts
                loadCommon(al, e);
                // load sub-type specific parts
                // Transient object for reading child elements
                Element ce;
                if ((ce = e.getChild("position")) != null) {
                    al.setPosition(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z"))));
                }
                if ((ce = e.getChild("velocity")) != null) {
                    al.setVelocity(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z"))));
                }
                if ((ce = e.getChild("orientation")) != null) {
                    al.setOrientation(new Vector3f(Float.parseFloat(ce.getAttributeValue("atX")), Float.parseFloat(ce.getAttributeValue("atY")), Float.parseFloat(ce.getAttributeValue("atZ"))), new Vector3f(Float.parseFloat(ce.getAttributeValue("upX")), Float.parseFloat(ce.getAttributeValue("upY")), Float.parseFloat(ce.getAttributeValue("upZ"))));
                }
                if ((ce = e.getChild("gain")) != null) {
                    al.setGain(Float.parseFloat(ce.getValue()));
                }
                if ((ce = e.getChild("metersperunit")) != null) {
                    al.setMetersPerUnit(Float.parseFloat((ce.getValue())));
                }
            } catch (AudioException ex) {
                log.error("Error loading AudioListener (" + sysName + "): " + ex);
            }
        }
        Attribute a;
        if ((a = audio.getAttribute("distanceattenuated")) != null) {
            am.getActiveAudioFactory().setDistanceAttenuated(a.getValue().equals("yes"));
        }
    }
}
Also used : AudioSource(jmri.jmrit.audio.AudioSource) AudioManager(jmri.AudioManager) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) AudioException(jmri.AudioException) Vector3f(javax.vecmath.Vector3f) AudioListener(jmri.jmrit.audio.AudioListener) AudioBuffer(jmri.jmrit.audio.AudioBuffer)

Example 9 with Attribute

use of ucar.nc2.Attribute in project JMRI by JMRI.

the class DefaultCatalogTreeManagerXml method addLeaves.

private void addLeaves(Element element, CatalogTreeNode node) {
    List<Element> leafList = element.getChildren("leaf");
    for (int i = 0; i < leafList.size(); i++) {
        Element elem = leafList.get(i);
        Attribute attr = elem.getAttribute("name");
        if (attr == null) {
            log.error("unexpected null leaf name. elem= " + elem + ", attrs= " + elem.getAttributes());
            continue;
        }
        String name = attr.getValue();
        attr = elem.getAttribute("path");
        if (attr == null) {
            log.error("unexpected null leaf path. elem= " + elem + ", attrs= " + elem.getAttributes());
            continue;
        }
        String path = attr.getValue();
        // use the method that maintains the same order
        node.addLeaf(new CatalogTreeLeaf(name, path, 0));
    }
}
Also used : CatalogTreeLeaf(jmri.jmrit.catalog.CatalogTreeLeaf) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 10 with Attribute

use of ucar.nc2.Attribute in project JMRI by JMRI.

the class PositionableLabelXml method loadCommonAttributes.

public void loadCommonAttributes(Positionable l, int defaultLevel, Element element) {
    Attribute a = element.getAttribute("forcecontroloff");
    if ((a != null) && a.getValue().equals("true")) {
        l.setControlling(false);
    } else {
        l.setControlling(true);
    }
    // find coordinates
    int x = 0;
    int y = 0;
    try {
        x = element.getAttribute("x").getIntValue();
        y = element.getAttribute("y").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert positional attribute");
    }
    l.setLocation(x, y);
    // find display level
    int level = defaultLevel;
    try {
        level = element.getAttribute("level").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse level attribute!");
    } catch (NullPointerException e) {
    // considered normal if the attribute not present
    }
    l.setDisplayLevel(level);
    a = element.getAttribute("hidden");
    if ((a != null) && a.getValue().equals("yes")) {
        l.setHidden(true);
        l.setVisible(false);
    }
    a = element.getAttribute("positionable");
    if ((a != null) && a.getValue().equals("true")) {
        l.setPositionable(true);
    } else {
        l.setPositionable(false);
    }
    a = element.getAttribute("showtooltip");
    if ((a != null) && a.getValue().equals("true")) {
        l.setShowTooltip(true);
    } else {
        l.setShowTooltip(false);
    }
    a = element.getAttribute("editable");
    if ((a != null) && a.getValue().equals("true")) {
        l.setEditable(true);
    } else {
        l.setEditable(false);
    }
    a = element.getAttribute("degrees");
    if (a != null && l instanceof PositionableLabel) {
        try {
            int deg = a.getIntValue();
            ((PositionableLabel) l).setDegrees(deg);
        } catch (org.jdom2.DataConversionException dce) {
        }
    }
    Element elem = element.getChild("tooltip");
    if (elem == null) {
        // pre JMRI 3.5.2
        elem = element.getChild("toolTip");
    }
    if (elem != null) {
        ToolTip tip = l.getTooltip();
        if (tip != null) {
            tip.setText(elem.getText());
        }
    }
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) PositionableLabel(jmri.jmrit.display.PositionableLabel) DataConversionException(org.jdom2.DataConversionException)

Aggregations

Attribute (org.jdom2.Attribute)106 Element (org.jdom2.Element)75 Editor (jmri.jmrit.display.Editor)15 DataConversionException (org.jdom2.DataConversionException)14 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)12 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)9 List (java.util.List)7 Color (java.awt.Color)6 File (java.io.File)6 HashMap (java.util.HashMap)6 ConfigureManager (jmri.ConfigureManager)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