001package jmri.jmrit.logixng.expressions.configurexml; 002 003import java.util.List; 004 005import jmri.InstanceManager; 006import jmri.configurexml.JmriConfigureXmlException; 007import jmri.jmrit.logixng.Module; 008import jmri.jmrit.logixng.*; 009import jmri.jmrit.logixng.Module.ParameterData; 010import jmri.jmrit.logixng.expressions.DigitalCallModule; 011import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectNamedBeanXml; 012 013import org.jdom2.Element; 014 015/** 016 * Handle XML configuration for ExpressionLightXml objects. 017 * 018 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010 019 * @author Daniel Bergqvist Copyright (C) 2019 020 */ 021public class DigitalCallModuleXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML { 022 023 public DigitalCallModuleXml() { 024 } 025 026 /** 027 * Default implementation for storing the contents of a SE8cSignalHead 028 * 029 * @param o Object to store, of type TripleLightSignalHead 030 * @return Element containing the complete info 031 */ 032 @Override 033 public Element store(Object o) { 034 DigitalCallModule p = (DigitalCallModule) o; 035 036 Element element = new Element("CallDigitalExpressionModule"); 037 element.setAttribute("class", this.getClass().getName()); 038 element.addContent(new Element("systemName").addContent(p.getSystemName())); 039 040 storeCommon(p, element); 041 042 var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<Module>(); 043 element.addContent(selectNamedBeanXml.store(p.getSelectNamedBean(), "namedBean")); 044 045 Element parameters = new Element("Parameters"); 046 for (ParameterData pd : p.getParameterData()) { 047 Element elementParameter = new Element("Parameter"); 048 elementParameter.addContent(new Element("name").addContent(pd._name)); 049 elementParameter.addContent(new Element("initialValueType").addContent(pd._initialValueType.name())); 050 elementParameter.addContent(new Element("initialValueData").addContent(pd._initialValueData)); 051 elementParameter.addContent(new Element("returnValueType").addContent(pd._returnValueType.name())); 052 elementParameter.addContent(new Element("returnValueData").addContent(pd._returnValueData)); 053 parameters.addContent(elementParameter); 054 } 055 element.addContent(parameters); 056 057 return element; 058 } 059 060 @Override 061 public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException { 062 String sys = getSystemName(shared); 063 String uname = getUserName(shared); 064 DigitalCallModule h = new DigitalCallModule(sys, uname); 065 066 loadCommon(h, shared); 067 068 var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<Module>(); 069 selectNamedBeanXml.load(shared.getChild("namedBean"), h.getSelectNamedBean()); 070 selectNamedBeanXml.loadLegacy(shared, h.getSelectNamedBean(), "module", null, null, null, null); 071 072 List<Element> parameterList = shared.getChild("Parameters").getChildren(); // NOI18N 073 log.debug("Found {} parameters", parameterList.size() ); // NOI18N 074 075 for (Element e : parameterList) { 076 Element elementName = e.getChild("name"); 077 078 SymbolTable.InitialValueType initialValueType = null; 079 Element elementType = e.getChild("initialValueType"); 080 if (elementType == null) { 081 elementType = e.getChild("initalValueType"); // Spelling error in previous versions of JMRI 082 } 083 if (elementType != null) { 084 initialValueType = SymbolTable.InitialValueType.valueOf(elementType.getTextTrim()); 085 } 086 087 Element elementInitialValueData = e.getChild("initialValueData"); 088 089 Module.ReturnValueType returnValueType = null; 090 elementType = e.getChild("returnValueType"); 091 if (elementType != null) { 092 returnValueType = Module.ReturnValueType.valueOf(elementType.getTextTrim()); 093 } 094 095 Element elementReturnValueData = e.getChild("returnValueData"); 096 097 if (elementName == null) throw new IllegalArgumentException("Element 'name' does not exists"); 098 if (initialValueType == null) throw new IllegalArgumentException("Element 'initialValueType' does not exists"); 099 if (elementInitialValueData == null) throw new IllegalArgumentException("Element 'initialValueData' does not exists"); 100 if (returnValueType == null) throw new IllegalArgumentException("Element 'returnValueType' does not exists"); 101 if (elementReturnValueData == null) throw new IllegalArgumentException("Element 'returnValueData' does not exists"); 102 103 h.addParameter(elementName.getTextTrim(), 104 initialValueType, elementInitialValueData.getTextTrim(), 105 returnValueType, elementReturnValueData.getTextTrim()); 106 } 107 108 InstanceManager.getDefault(DigitalExpressionManager.class).registerExpression(h); 109 return true; 110 } 111 112 private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DigitalCallModuleXml.class); 113}