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));
}
}
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);
});
});
});
}
}
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();
}
}
}
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;
}
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;
}
Aggregations