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.ActionSignalHead; 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 ActionSignalHeadXml objects. 015 * 016 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010 017 * @author Daniel Bergqvist Copyright (C) 2019 018 */ 019public class ActionSignalHeadXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML { 020 021 public ActionSignalHeadXml() { 022 } 023 024 /** 025 * Default implementation for storing the contents of a SE8cSignalHead 026 * 027 * @param o Object to store, of type TripleLightSignalHead 028 * @return Element containing the complete info 029 */ 030 @Override 031 public Element store(Object o) { 032 ActionSignalHead p = (ActionSignalHead) o; 033 034 Element element = new Element("ActionSignalHead"); 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<SignalHead>(); 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("appearanceAddressing").addContent(p.getAppearanceAddressing().name())); 050 element.addContent(new Element("appearance").addContent(Integer.toString(p.getAppearance()))); 051 element.addContent(new Element("appearanceReference").addContent(p.getAppearanceReference())); 052 element.addContent(new Element("appearanceLocalVariable").addContent(p.getAppearanceLocalVariable())); 053 element.addContent(new Element("appearanceFormula").addContent(p.getAppearanceFormula())); 054 055 var selectExampleNamedBeanXml = new LogixNG_SelectNamedBeanXml<SignalHead>(); 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 ActionSignalHead h = new ActionSignalHead(sys, uname); 066 067 loadCommon(h, shared); 068 069 var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<SignalHead>(); 070 selectNamedBeanXml.load(shared.getChild("namedBean"), h.getSelectNamedBean()); 071 selectNamedBeanXml.loadLegacy(shared, h.getSelectNamedBean(), "signalHead"); 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(ActionSignalHead.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("appearanceAddressing"); 095 if (elem != null) { 096 h.setAppearanceAddressing(NamedBeanAddressing.valueOf(elem.getTextTrim())); 097 } 098 099 Element appearanceElement = shared.getChild("appearance"); 100 if (appearanceElement != null) { 101 try { 102 int appearance = Integer.parseInt(appearanceElement.getTextTrim()); 103 h.setAppearance(appearance); 104 } catch (NumberFormatException e) { 105 log.error("cannot parse apperance: {}", appearanceElement.getTextTrim(), e); 106 } 107 } 108 109 elem = shared.getChild("appearanceReference"); 110 if (elem != null) h.setAppearanceReference(elem.getTextTrim()); 111 112 elem = shared.getChild("appearanceLocalVariable"); 113 if (elem != null) h.setAppearanceLocalVariable(elem.getTextTrim()); 114 115 elem = shared.getChild("appearanceFormula"); 116 if (elem != null) h.setAppearanceFormula(elem.getTextTrim()); 117 118 } catch (ParserException e) { 119 throw new JmriConfigureXmlException(e); 120 } 121 122 var selectExampleNamedBeanXml = new LogixNG_SelectNamedBeanXml<SignalHead>(); 123 selectExampleNamedBeanXml.load(shared.getChild("exampleNamedBean"), h.getSelectExampleNamedBean()); 124 selectExampleNamedBeanXml.loadLegacy(shared, h.getSelectExampleNamedBean(), "exampleSignalHead", null, null, null, null); 125 126 InstanceManager.getDefault(DigitalActionManager.class).registerAction(h); 127 return true; 128 } 129 130 private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionSignalHeadXml.class); 131}