Search in sources :

Example 26 with Element

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

the class AbstractMemoryManagerConfigXML method loadMemories.

/**
     * Utility method to load the individual Memory objects. If there's no
     * additional info needed for a specific Memory type, invoke this with the
     * parent of the set of Memory elements.
     *
     * @param memories Element containing the Memory elements to load.
     */
@SuppressWarnings("unchecked")
public void loadMemories(Element memories) {
    List<Element> memoryList = memories.getChildren("memory");
    if (log.isDebugEnabled()) {
        log.debug("Found " + memoryList.size() + " Memory objects");
    }
    MemoryManager tm = InstanceManager.memoryManagerInstance();
    for (int i = 0; i < memoryList.size(); i++) {
        String sysName = getSystemName(memoryList.get(i));
        if (sysName == null) {
            log.warn("unexpected null in systemName " + (memoryList.get(i)));
            break;
        }
        String userName = getUserName(memoryList.get(i));
        checkNameNormalization(sysName, userName, tm);
        if (log.isDebugEnabled()) {
            log.debug("create Memory: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
        }
        Memory m = tm.newMemory(sysName, userName);
        if (memoryList.get(i).getAttribute("value") != null) {
            loadValue(memoryList.get(i), m);
        }
        // load common parts
        loadCommon(m, memoryList.get(i));
    }
}
Also used : Memory(jmri.Memory) Element(org.jdom2.Element) MemoryManager(jmri.MemoryManager)

Example 27 with Element

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

the class JmriUserPreferencesManager method readPreferencesState.

private void readPreferencesState() {
    Element element = this.readElement(CLASSPREFS_ELEMENT, CLASSPREFS_NAMESPACE);
    if (element != null) {
        element.getChildren("preferences").stream().forEach((preferences) -> {
            String clazz = preferences.getAttributeValue("class");
            log.debug("Reading class preferences for \"{}\"", clazz);
            preferences.getChildren("multipleChoice").stream().forEach((mc) -> {
                mc.getChildren("option").stream().forEach((option) -> {
                    int value = 0;
                    try {
                        option.getAttribute("value").getIntValue();
                    } catch (DataConversionException ex) {
                        log.error("failed to convert positional attribute");
                    }
                    this.setMultipleChoiceOption(clazz, option.getAttributeValue("item"), value);
                });
            });
            preferences.getChildren("reminderPrompts").stream().forEach((rp) -> {
                rp.getChildren("reminder").stream().forEach((reminder) -> {
                    log.debug("Setting preferences state \"true\" for \"{}\", \"{}\"", clazz, reminder.getText());
                    this.setPreferenceState(clazz, reminder.getText(), true);
                });
            });
        });
    }
}
Also used : Element(org.jdom2.Element) DataConversionException(org.jdom2.DataConversionException) Point(java.awt.Point)

Example 28 with Element

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

the class JmriUserPreferencesManager method saveWindowDetails.

private void saveWindowDetails() {
    this.setChangeMade(false);
    if (this.allowSave) {
        if (!windowDetails.isEmpty()) {
            Element element = new Element(WINDOWS_ELEMENT, WINDOWS_NAMESPACE);
            for (Entry<String, WindowLocations> entry : windowDetails.entrySet()) {
                Element window = new Element("window");
                window.setAttribute("class", entry.getKey());
                if (entry.getValue().saveLocation) {
                    try {
                        window.setAttribute("locX", Double.toString(entry.getValue().getLocation().getX()));
                        window.setAttribute("locY", Double.toString(entry.getValue().getLocation().getY()));
                    } catch (NullPointerException ex) {
                    // Expected if the location has not been set or the window is open
                    }
                }
                if (entry.getValue().saveSize) {
                    try {
                        double height = entry.getValue().getSize().getHeight();
                        double width = entry.getValue().getSize().getWidth();
                        // Do not save the width or height if set to zero
                        if (!(height == 0.0 && width == 0.0)) {
                            window.setAttribute("width", Double.toString(width));
                            window.setAttribute("height", Double.toString(height));
                        }
                    } catch (NullPointerException ex) {
                    // Expected if the size has not been set or the window is open
                    }
                }
                if (!entry.getValue().parameters.isEmpty()) {
                    Element properties = new Element("properties");
                    entry.getValue().parameters.entrySet().stream().map((property) -> {
                        Element propertyElement = new Element("property");
                        propertyElement.addContent(new Element("key").setText(property.getKey()));
                        Object value = property.getValue();
                        if (value != null) {
                            propertyElement.addContent(new Element("value").setAttribute("class", value.getClass().getName()).setText(value.toString()));
                        }
                        return propertyElement;
                    }).forEach((propertyElement) -> {
                        properties.addContent(propertyElement);
                    });
                    window.addContent(properties);
                }
                element.addContent(window);
            }
            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 29 with Element

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

the class AbstractReporterManagerConfigXML method loadReporters.

/**
     * Utility method to load the individual Reporter objects. If there's no
     * additional info needed for a specific Reporter type, invoke this with the
     * parent of the set of Reporter elements.
     *
     * @param reporters Element containing the Reporter elements to load.
     * @return true if successful
     */
@SuppressWarnings("unchecked")
public boolean loadReporters(Element reporters) {
    boolean result = true;
    List<Element> reporterList = reporters.getChildren("reporter");
    if (log.isDebugEnabled()) {
        log.debug("Found " + reporterList.size() + " reporters");
    }
    ReporterManager tm = InstanceManager.getDefault(jmri.ReporterManager.class);
    for (int i = 0; i < reporterList.size(); i++) {
        String sysName = getSystemName(reporterList.get(i));
        if (sysName == null) {
            log.warn("unexpected null in systemName " + reporterList.get(i) + " " + reporterList.get(i).getAttributes());
            result = false;
            break;
        }
        String userName = getUserName(reporterList.get(i));
        if (log.isDebugEnabled()) {
            log.debug("create Reporter: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
        }
        Reporter r = tm.newReporter(sysName, userName);
        loadCommon(r, reporterList.get(i));
    }
    return result;
}
Also used : ReporterManager(jmri.ReporterManager) Element(org.jdom2.Element) Reporter(jmri.Reporter)

Example 30 with Element

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

the class AbstractSensorManagerConfigXML method loadSensors.

/**
     * Utility method to load the individual Sensor objects. If there's no
     * additional info needed for a specific sensor type, invoke this with the
     * parent of the set of Sensor elements.
     *
     * @param sensors Element containing the Sensor elements to load.
     * @return true if succeeded
     */
@SuppressWarnings("unchecked")
public boolean loadSensors(Element sensors) throws jmri.configurexml.JmriConfigureXmlException {
    boolean result = true;
    List<Element> sensorList = sensors.getChildren("sensor");
    if (log.isDebugEnabled()) {
        log.debug("Found " + sensorList.size() + " sensors");
    }
    SensorManager tm = InstanceManager.sensorManagerInstance();
    long goingActive = 0L;
    long goingInActive = 0L;
    if (sensors.getChild("globalDebounceTimers") != null) {
        Element timer = sensors.getChild("globalDebounceTimers");
        try {
            if (timer.getChild("goingActive") != null) {
                String active = timer.getChild("goingActive").getText();
                goingActive = Long.valueOf(active);
                tm.setDefaultSensorDebounceGoingActive(goingActive);
            }
        } catch (NumberFormatException ex) {
            log.error(ex.toString());
        }
        try {
            if (timer.getChild("goingInActive") != null) {
                String inActive = timer.getChild("goingInActive").getText();
                goingInActive = Long.valueOf(inActive);
                tm.setDefaultSensorDebounceGoingInActive(goingInActive);
            }
        } catch (NumberFormatException ex) {
            log.error(ex.toString());
        }
    }
    for (int i = 0; i < sensorList.size(); i++) {
        String sysName = getSystemName(sensorList.get(i));
        if (sysName == null) {
            handleException("Unexpected missing system name while loading sensors", null, null, null, null);
            result = false;
            break;
        }
        boolean inverted = false;
        String userName = getUserName(sensorList.get(i));
        checkNameNormalization(sysName, userName, tm);
        if (sensorList.get(i).getAttribute("inverted") != null) {
            if (sensorList.get(i).getAttribute("inverted").getValue().equals("true")) {
                inverted = true;
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("create sensor: (" + sysName + ")");
        }
        Sensor s;
        try {
            s = tm.newSensor(sysName, userName);
        } catch (IllegalArgumentException e) {
            handleException("Could not create sensor", null, sysName, userName, null);
            result = false;
            continue;
        }
        // load common parts
        loadCommon(s, sensorList.get(i));
        if (sensorList.get(i).getChild("debounceTimers") != null) {
            Element timer = sensorList.get(i).getChild("debounceTimers");
            try {
                if (timer.getChild("goingActive") != null) {
                    String active = timer.getChild("goingActive").getText();
                    s.setSensorDebounceGoingActiveTimer(Long.valueOf(active));
                }
            } catch (NumberFormatException ex) {
                log.error(ex.toString());
            }
            try {
                if (timer.getChild("goingInActive") != null) {
                    String inActive = timer.getChild("goingInActive").getText();
                    s.setSensorDebounceGoingInActiveTimer(Long.valueOf(inActive));
                }
            } catch (NumberFormatException ex) {
                log.error(ex.toString());
            }
        }
        if (sensorList.get(i).getChild("useGlobalDebounceTimer") != null) {
            if (sensorList.get(i).getChild("useGlobalDebounceTimer").getText().equals("yes")) {
                s.useDefaultTimerSettings(true);
            }
        }
        s.setInverted(inverted);
        if (sensorList.get(i).getChild("pullResistance") != null) {
            String pull = sensorList.get(i).getChild("pullResistance").getText();
            log.debug("setting pull to {} for sensor {}", pull, s);
            s.setPullResistance(jmri.Sensor.PullResistance.getByShortName(pull));
        }
    }
    return result;
}
Also used : SensorManager(jmri.SensorManager) Element(org.jdom2.Element) Sensor(jmri.Sensor)

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