001package jmri.jmrit.logixng.expressions.configurexml; 002 003import jmri.*; 004import jmri.configurexml.JmriConfigureXmlException; 005import jmri.jmrit.logixng.DigitalExpressionManager; 006import jmri.jmrit.logixng.NamedBeanAddressing; 007import jmri.jmrit.logixng.expressions.ExpressionSignalMast; 008import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectNamedBeanXml; 009import jmri.jmrit.logixng.util.parser.ParserException; 010 011import org.jdom2.Element; 012 013/** 014 * Handle XML configuration for ExpressionSignalMastXml objects. 015 * 016 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010 017 * @author Daniel Bergqvist Copyright (C) 2019 018 */ 019public class ExpressionSignalMastXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML { 020 021 public ExpressionSignalMastXml() { 022 } 023 024 /** 025 * Default implementation for storing the contents of a SE8cSignalMast 026 * 027 * @param o Object to store, of type TripleLightSignalMast 028 * @return Element containing the complete info 029 */ 030 @Override 031 public Element store(Object o) { 032 ExpressionSignalMast p = (ExpressionSignalMast) o; 033 034 Element element = new Element("ExpressionSignalMast"); 035 element.setAttribute("class", this.getClass().getName()); 036 element.addContent(new Element("systemName").addContent(p.getSystemName())); 037 038 storeCommon(p, element); 039 040 var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<SignalMast>(); 041 element.addContent(selectNamedBeanXml.store(p.getSelectNamedBean(), "namedBean")); 042 043 element.addContent(new Element("queryAddressing").addContent(p.getQueryAddressing().name())); 044 element.addContent(new Element("queryType").addContent(p.getQueryType().name())); 045 element.addContent(new Element("queryReference").addContent(p.getQueryReference())); 046 element.addContent(new Element("queryLocalVariable").addContent(p.getQueryLocalVariable())); 047 element.addContent(new Element("queryFormula").addContent(p.getQueryFormula())); 048 049 element.addContent(new Element("aspectAddressing").addContent(p.getAspectAddressing().name())); 050 element.addContent(new Element("aspect").addContent(p.getAspect())); 051 element.addContent(new Element("aspectReference").addContent(p.getAspectReference())); 052 element.addContent(new Element("aspectLocalVariable").addContent(p.getAspectLocalVariable())); 053 element.addContent(new Element("aspectFormula").addContent(p.getAspectFormula())); 054 055 var selectExampleNamedBeanXml = new LogixNG_SelectNamedBeanXml<SignalMast>(); 056 element.addContent(selectExampleNamedBeanXml.store(p.getSelectExampleNamedBean(), "exampleNamedBean")); 057 058 return element; 059 } 060 061 @Override 062 public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException { 063 String sys = getSystemName(shared); 064 String uname = getUserName(shared); 065 ExpressionSignalMast h = new ExpressionSignalMast(sys, uname); 066 067 loadCommon(h, shared); 068 069 var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<SignalMast>(); 070 selectNamedBeanXml.load(shared.getChild("namedBean"), h.getSelectNamedBean()); 071 selectNamedBeanXml.loadLegacy(shared, h.getSelectNamedBean(), "signalMast"); 072 073 try { 074 Element elem = shared.getChild("queryAddressing"); 075 if (elem != null) { 076 h.setQueryAddressing(NamedBeanAddressing.valueOf(elem.getTextTrim())); 077 } 078 079 Element queryType = shared.getChild("queryType"); 080 if (queryType != null) { 081 h.setQueryType(ExpressionSignalMast.QueryType.valueOf(queryType.getTextTrim())); 082 } 083 084 elem = shared.getChild("queryReference"); 085 if (elem != null) h.setQueryReference(elem.getTextTrim()); 086 087 elem = shared.getChild("queryLocalVariable"); 088 if (elem != null) h.setQueryLocalVariable(elem.getTextTrim()); 089 090 elem = shared.getChild("queryFormula"); 091 if (elem != null) h.setQueryFormula(elem.getTextTrim()); 092 093 094 elem = shared.getChild("aspectAddressing"); 095 if (elem != null) { 096 h.setAspectAddressing(NamedBeanAddressing.valueOf(elem.getTextTrim())); 097 } 098 099 Element aspectElement = shared.getChild("aspect"); 100 if (aspectElement != null) { 101 try { 102 h.setAspect(aspectElement.getTextTrim()); 103 } catch (NumberFormatException e) { 104 log.error("cannot parse aspect: {}", aspectElement.getTextTrim(), e); 105 } 106 } 107 108 elem = shared.getChild("aspectReference"); 109 if (elem != null) h.setAspectReference(elem.getTextTrim()); 110 111 elem = shared.getChild("aspectLocalVariable"); 112 if (elem != null) h.setAspectLocalVariable(elem.getTextTrim()); 113 114 elem = shared.getChild("aspectFormula"); 115 if (elem != null) h.setAspectFormula(elem.getTextTrim()); 116 117 } catch (ParserException e) { 118 throw new JmriConfigureXmlException(e); 119 } 120 121 var selectExampleNamedBeanXml = new LogixNG_SelectNamedBeanXml<SignalMast>(); 122 selectExampleNamedBeanXml.load(shared.getChild("exampleNamedBean"), h.getSelectExampleNamedBean()); 123 selectExampleNamedBeanXml.loadLegacy(shared, h.getSelectExampleNamedBean(), "exampleSignalMast", null, null, null, null); 124 125 InstanceManager.getDefault(DigitalExpressionManager.class).registerExpression(h); 126 return true; 127 } 128 129 private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ExpressionSignalMastXml.class); 130}