001package jmri.jmrit.logixng.actions.configurexml; 002 003import jmri.*; 004import jmri.configurexml.JmriConfigureXmlException; 005import jmri.jmrit.logixng.DigitalActionManager; 006import jmri.jmrit.logixng.NamedBeanAddressing; 007import jmri.jmrit.logixng.actions.ActionSignalMast; 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 ActionSignalMastXml objects. 015 * 016 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010 017 * @author Daniel Bergqvist Copyright (C) 2019 018 */ 019public class ActionSignalMastXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML { 020 021 public ActionSignalMastXml() { 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 ActionSignalMast p = (ActionSignalMast) o; 033 034 Element element = new Element("ActionSignalMast"); 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("operationAddressing").addContent(p.getOperationAddressing().name())); 044 element.addContent(new Element("operationType").addContent(p.getOperationType().name())); 045 element.addContent(new Element("operationReference").addContent(p.getOperationReference())); 046 element.addContent(new Element("operationLocalVariable").addContent(p.getOperationLocalVariable())); 047 element.addContent(new Element("operationFormula").addContent(p.getOperationFormula())); 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 ActionSignalMast h = new ActionSignalMast(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("operationAddressing"); 075 if (elem != null) { 076 h.setOperationAddressing(NamedBeanAddressing.valueOf(elem.getTextTrim())); 077 } 078 079 Element queryType = shared.getChild("operationType"); 080 if (queryType != null) { 081 h.setOperationType(ActionSignalMast.OperationType.valueOf(queryType.getTextTrim())); 082 } 083 084 elem = shared.getChild("operationReference"); 085 if (elem != null) h.setOperationReference(elem.getTextTrim()); 086 087 elem = shared.getChild("operationLocalVariable"); 088 if (elem != null) h.setOperationLocalVariable(elem.getTextTrim()); 089 090 elem = shared.getChild("operationFormula"); 091 if (elem != null) h.setOperationFormula(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(DigitalActionManager.class).registerAction(h); 126 return true; 127 } 128 129 private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionSignalMastXml.class); 130}