Search in sources :

Example 21 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class JmriUserPreferencesManager method saveSimplePreferenceState.

private void saveSimplePreferenceState() {
    this.setChangeMade(false);
    if (this.allowSave) {
        Element element = new Element(SETTINGS_ELEMENT, SETTINGS_NAMESPACE);
        getSimplePreferenceStateList().stream().forEach((setting) -> {
            element.addContent(new Element("setting").addContent(setting));
        });
        this.saveElement(element);
        this.resetChangeMade();
    }
}
Also used : Element(org.jdom2.Element)

Example 22 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class AbstractAudioManagerConfigXML method store.

/**
     * Default implementation for storing the contents of a AudioManager
     *
     * @param o Object to store, of type AudioManager
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Element audio = new Element("audio");
    setStoreElementClass(audio);
    AudioManager am = (AudioManager) o;
    if (am != null) {
        java.util.Iterator<String> iter = am.getSystemNameList().iterator();
        // don't return an element if there are not any audios to include
        if (!iter.hasNext()) {
            return null;
        }
        // (no need to store the automatically created Listener object by itself)
        if (am.getSystemNameList(Audio.SOURCE).isEmpty() && am.getSystemNameList(Audio.BUFFER).isEmpty()) {
            return null;
        }
        // finally, don't store if the only Sources and Buffers are for the
        // virtual sound decoder (VSD)
        int vsdObjectCount = 0;
        // count all VSD objects
        for (String sname : am.getSystemNameList()) {
            if (log.isDebugEnabled()) {
                log.debug("Check if " + sname + " is a VSD object");
            }
            if (sname.length() >= 8 && sname.substring(3, 8).equalsIgnoreCase("$VSD:")) {
                log.debug("...yes");
                vsdObjectCount++;
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("Found " + vsdObjectCount + " VSD objects of " + am.getSystemNameList(Audio.SOURCE).size() + am.getSystemNameList(Audio.BUFFER).size() + " objects");
        }
        // the number of VSD objects - if so, exit.
        if (am.getSystemNameList(Audio.SOURCE).size() + am.getSystemNameList(Audio.BUFFER).size() == vsdObjectCount) {
            log.debug("Only VSD objects - nothing to store");
            return null;
        }
        // store global information
        audio.setAttribute("distanceattenuated", am.getActiveAudioFactory().isDistanceAttenuated() ? "yes" : "no");
        // store the audios
        while (iter.hasNext()) {
            String sname = iter.next();
            if (sname == null) {
                log.error("System name null during store");
                continue;
            }
            if (log.isDebugEnabled()) {
                log.debug("system name is " + sname);
            }
            if (sname.length() >= 8 && sname.substring(3, 8).equalsIgnoreCase("$VSD:")) {
                if (log.isDebugEnabled()) {
                    log.debug("Skipping storage of VSD object " + sname);
                }
                continue;
            }
            Audio a = am.getBySystemName(sname);
            // Transient objects for current element and any children
            Element e = null;
            Element ce = null;
            int type = a.getSubType();
            if (type == Audio.BUFFER) {
                AudioBuffer ab = (AudioBuffer) a;
                e = new Element("audiobuffer").setAttribute("systemName", sname);
                e.addContent(new Element("systemName").addContent(sname));
                // store common part
                storeCommon(ab, e);
                // store sub-type specific data
                String url = ab.getURL();
                ce = new Element("url").addContent("" + (url.isEmpty() ? "" : FileUtil.getPortableFilename(url)));
                e.addContent(ce);
                ce = new Element("looppoint");
                ce.setAttribute("start", "" + ab.getStartLoopPoint());
                ce.setAttribute("end", "" + ab.getEndLoopPoint());
                e.addContent(ce);
                ce = new Element("streamed");
                ce.addContent("" + (ab.isStreamed() ? "yes" : "no"));
                e.addContent(ce);
            } else if (type == Audio.LISTENER) {
                AudioListener al = (AudioListener) a;
                e = new Element("audiolistener").setAttribute("systemName", sname);
                e.addContent(new Element("systemName").addContent(sname));
                // store common part
                storeCommon(al, e);
                // store sub-type specific data
                ce = new Element("position");
                ce.setAttribute("x", "" + al.getPosition().x);
                ce.setAttribute("y", "" + al.getPosition().y);
                ce.setAttribute("z", "" + al.getPosition().z);
                e.addContent(ce);
                ce = new Element("velocity");
                ce.setAttribute("x", "" + al.getVelocity().x);
                ce.setAttribute("y", "" + al.getVelocity().y);
                ce.setAttribute("z", "" + al.getVelocity().z);
                e.addContent(ce);
                ce = new Element("orientation");
                ce.setAttribute("atX", "" + al.getOrientation(Audio.AT).x);
                ce.setAttribute("atY", "" + al.getOrientation(Audio.AT).y);
                ce.setAttribute("atZ", "" + al.getOrientation(Audio.AT).z);
                ce.setAttribute("upX", "" + al.getOrientation(Audio.UP).x);
                ce.setAttribute("upY", "" + al.getOrientation(Audio.UP).y);
                ce.setAttribute("upZ", "" + al.getOrientation(Audio.UP).z);
                e.addContent(ce);
                ce = new Element("gain");
                ce.addContent("" + al.getGain());
                e.addContent(ce);
                ce = new Element("metersperunit");
                ce.addContent("" + al.getMetersPerUnit());
                e.addContent(ce);
            } else if (type == Audio.SOURCE) {
                AudioSource as = (AudioSource) a;
                e = new Element("audiosource").setAttribute("systemName", sname);
                e.addContent(new Element("systemName").addContent(sname));
                // store common part
                storeCommon(as, e);
                // store sub-type specific data
                ce = new Element("position");
                ce.setAttribute("x", "" + as.getPosition().x);
                ce.setAttribute("y", "" + as.getPosition().y);
                ce.setAttribute("z", "" + as.getPosition().z);
                e.addContent(ce);
                ce = new Element("velocity");
                ce.setAttribute("x", "" + as.getVelocity().x);
                ce.setAttribute("y", "" + as.getVelocity().y);
                ce.setAttribute("z", "" + as.getVelocity().z);
                e.addContent(ce);
                ce = new Element("assignedbuffer");
                if (as.getAssignedBuffer() != null) {
                    ce.addContent("" + as.getAssignedBufferName());
                }
                e.addContent(ce);
                ce = new Element("gain");
                ce.addContent("" + as.getGain());
                e.addContent(ce);
                ce = new Element("pitch");
                ce.addContent("" + as.getPitch());
                e.addContent(ce);
                ce = new Element("distances");
                ce.setAttribute("ref", "" + as.getReferenceDistance());
                float f = as.getMaximumDistance();
                ce.setAttribute("max", "" + f);
                e.addContent(ce);
                ce = new Element("loops");
                ce.setAttribute("min", "" + as.getMinLoops());
                ce.setAttribute("max", "" + as.getMaxLoops());
                //                    ce.setAttribute("mindelay", ""+as.getMinLoopDelay());
                //                    ce.setAttribute("maxdelay", ""+as.getMaxLoopDelay());
                e.addContent(ce);
                ce = new Element("fadetimes");
                ce.setAttribute("in", "" + as.getFadeIn());
                ce.setAttribute("out", "" + as.getFadeOut());
                e.addContent(ce);
                ce = new Element("dopplerfactor");
                ce.addContent("" + as.getDopplerFactor());
                e.addContent(ce);
                ce = new Element("positionrelative");
                ce.addContent("" + (as.isPositionRelative() ? "yes" : "no"));
                e.addContent(ce);
            }
            log.debug("store Audio " + sname);
            audio.addContent(e);
        }
    }
    return audio;
}
Also used : AudioSource(jmri.jmrit.audio.AudioSource) AudioManager(jmri.AudioManager) Element(org.jdom2.Element) AudioListener(jmri.jmrit.audio.AudioListener) AudioBuffer(jmri.jmrit.audio.AudioBuffer) Audio(jmri.Audio)

Example 23 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class JmriUserPreferencesManager method saveComboBoxLastSelections.

private void saveComboBoxLastSelections() {
    this.setChangeMade(false);
    if (this.allowSave && !comboBoxLastSelection.isEmpty()) {
        Element element = new Element(COMBOBOX_ELEMENT, COMBOBOX_NAMESPACE);
        // Do not store blank last entered/selected values
        comboBoxLastSelection.entrySet().stream().filter((cbls) -> (cbls.getValue() != null && !cbls.getValue().isEmpty())).map((cbls) -> {
            Element combo = new Element("comboBox");
            combo.setAttribute("name", cbls.getKey());
            combo.setAttribute("lastSelected", cbls.getValue());
            return combo;
        }).forEach((combo) -> {
            element.addContent(combo);
        });
        this.saveElement(element);
        this.resetChangeMade();
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) ProfileManager(jmri.profile.ProfileManager) Point(java.awt.Point) HashMap(java.util.HashMap) JmriJFrame(jmri.util.JmriJFrame) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) JDOMException(org.jdom2.JDOMException) JDOMUtil(jmri.util.jdom.JDOMUtil) ProfileUtils(jmri.profile.ProfileUtils) Map(java.util.Map) Bean(jmri.beans.Bean) Profile(jmri.profile.Profile) Method(java.lang.reflect.Method) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) BoxLayout(javax.swing.BoxLayout) InstanceManager(jmri.InstanceManager) UserPreferencesManager(jmri.UserPreferencesManager) Logger(org.slf4j.Logger) JmriException(jmri.JmriException) TableColumnPreferences(jmri.swing.JmriJTablePersistenceManager.TableColumnPreferences) Set(java.util.Set) JOptionPane(javax.swing.JOptionPane) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SortOrder(javax.swing.SortOrder) Dimension(java.awt.Dimension) List(java.util.List) FileUtil(jmri.util.FileUtil) JLabel(javax.swing.JLabel) ConfigureManager(jmri.ConfigureManager) JmriJTablePersistenceManager(jmri.swing.JmriJTablePersistenceManager) Entry(java.util.Map.Entry) JCheckBox(javax.swing.JCheckBox) DataConversionException(org.jdom2.DataConversionException) NodeIdentity(jmri.util.node.NodeIdentity) JPanel(javax.swing.JPanel) Toolkit(java.awt.Toolkit) Element(org.jdom2.Element) Element(org.jdom2.Element)

Example 24 with Element

use of org.neo4j.ogm.domain.gh806.Element 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 25 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class AbstractLightManagerConfigXML method store.

/**
     * Default implementation for storing the contents of a LightManager
     *
     * @param o Object to store, of type LightManager
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Element lights = new Element("lights");
    setStoreElementClass(lights);
    LightManager tm = (LightManager) o;
    if (tm != null) {
        java.util.Iterator<String> iter = tm.getSystemNameList().iterator();
        // don't return an element if there are not lights to include
        if (!iter.hasNext()) {
            return null;
        }
        // store the lights
        while (iter.hasNext()) {
            String sname = iter.next();
            if (sname == null) {
                log.error("System name null during store");
                break;
            }
            log.debug("system name is " + sname);
            Light lgt = tm.getBySystemName(sname);
            Element elem = new Element("light");
            elem.addContent(new Element("systemName").addContent(sname));
            // store common parts
            storeCommon(lgt, elem);
            // write variable intensity attributes
            elem.setAttribute("minIntensity", "" + lgt.getMinIntensity());
            elem.setAttribute("maxIntensity", "" + lgt.getMaxIntensity());
            // write transition attribute
            elem.setAttribute("transitionTime", "" + lgt.getTransitionTime());
            // save child lightcontrol entries
            ArrayList<LightControl> lcList = lgt.getLightControlList();
            Element lcElem = null;
            for (int i = 0; i < lcList.size(); i++) {
                LightControl lc = lcList.get(i);
                if (lc != null) {
                    lcElem = new Element("lightcontrol");
                    int type = lc.getControlType();
                    lcElem.setAttribute("controlType", "" + type);
                    if (type == Light.SENSOR_CONTROL) {
                        lcElem.setAttribute("controlSensor", lc.getControlSensorName());
                        lcElem.setAttribute("sensorSense", "" + lc.getControlSensorSense());
                    } else if (type == Light.FAST_CLOCK_CONTROL) {
                        lcElem.setAttribute("fastClockOnHour", "" + lc.getFastClockOnHour());
                        lcElem.setAttribute("fastClockOnMin", "" + lc.getFastClockOnMin());
                        lcElem.setAttribute("fastClockOffHour", "" + lc.getFastClockOffHour());
                        lcElem.setAttribute("fastClockOffMin", "" + lc.getFastClockOffMin());
                    } else if (type == Light.TURNOUT_STATUS_CONTROL) {
                        lcElem.setAttribute("controlTurnout", lc.getControlTurnoutName());
                        lcElem.setAttribute("turnoutState", "" + lc.getControlTurnoutState());
                    } else if (type == Light.TIMED_ON_CONTROL) {
                        lcElem.setAttribute("timedControlSensor", lc.getControlTimedOnSensorName());
                        lcElem.setAttribute("duration", "" + lc.getTimedOnDuration());
                    }
                    if (type == Light.TWO_SENSOR_CONTROL) {
                        lcElem.setAttribute("controlSensor", lc.getControlSensorName());
                        lcElem.setAttribute("controlSensor2", lc.getControlSensor2Name());
                        lcElem.setAttribute("sensorSense", "" + lc.getControlSensorSense());
                    }
                    elem.addContent(lcElem);
                }
            }
            lights.addContent(elem);
        }
    }
    return lights;
}
Also used : Light(jmri.Light) Element(org.jdom2.Element) LightManager(jmri.LightManager) LightControl(jmri.implementation.LightControl)

Aggregations

Element (org.jdom2.Element)3327 Document (org.jdom2.Document)502 Test (org.junit.Test)457 ArrayList (java.util.ArrayList)327 IOException (java.io.IOException)268 Attribute (org.jdom2.Attribute)207 JDOMException (org.jdom2.JDOMException)202 Element (org.osate.aadl2.Element)143 Namespace (org.jdom2.Namespace)136 Test (org.junit.jupiter.api.Test)131 List (java.util.List)130 SAXBuilder (org.jdom2.input.SAXBuilder)125 File (java.io.File)124 HashMap (java.util.HashMap)117 XMLOutputter (org.jdom2.output.XMLOutputter)103 XConfiguration (org.apache.oozie.util.XConfiguration)98 Configuration (org.apache.hadoop.conf.Configuration)96 NamedElement (org.osate.aadl2.NamedElement)77 StringReader (java.io.StringReader)67 Iterator (java.util.Iterator)63