001package jmri.jmrit.logixng.actions.configurexml; 002 003import jmri.InstanceManager; 004import jmri.configurexml.JmriConfigureXmlException; 005import jmri.jmrit.logixng.DigitalActionManager; 006import jmri.jmrit.logixng.MaleSocket; 007import jmri.jmrit.logixng.actions.ActionListenOnBeansLocalVariable; 008import jmri.jmrit.logixng.NamedBeanType; 009 010import org.jdom2.Attribute; 011import org.jdom2.Element; 012 013/** 014 * Handle XML configuration for ActionListenOnBeansLocalVariable objects. 015 * 016 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010 017 * @author Daniel Bergqvist Copyright (C) 2022 018 */ 019public class ActionListenOnBeansLocalVariableXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML { 020 021 public ActionListenOnBeansLocalVariableXml() { 022 } 023 024 /** 025 * Default implementation for storing the contents of a SE8cSignalHead 026 * 027 * @param o Object to store, of type TripleTurnoutSignalHead 028 * @return Element containing the complete info 029 */ 030 @Override 031 public Element store(Object o) { 032 ActionListenOnBeansLocalVariable p = (ActionListenOnBeansLocalVariable) o; 033 034 Element element = new Element("ActionListenOnBeansLocalVariable"); 035 element.setAttribute("class", this.getClass().getName()); 036 element.addContent(new Element("systemName").addContent(p.getSystemName())); 037 038 storeCommon(p, element); 039 040 element.addContent(new Element("namedBeanType").addContent(p.getNamedBeanType().name())); 041 042 element.addContent(new Element("localVariableBeanToListenOn").addContent(p.getLocalVariableBeanToListenOn())); 043 044 element.addContent(new Element("localVariableNamedBean").addContent(p.getLocalVariableNamedBean())); 045 element.addContent(new Element("localVariableEvent").addContent(p.getLocalVariableEvent())); 046 element.addContent(new Element("localVariableNewValue").addContent(p.getLocalVariableNewValue())); 047 048 element.setAttribute("listenOnAllProperties", 049 p.getListenOnAllProperties()? "yes" : "no"); // NOI18N 050 051 Element e2 = new Element("Socket"); 052 e2.addContent(new Element("socketName").addContent(p.getChild(0).getName())); 053 MaleSocket socket = p.getExecuteSocket().getConnectedSocket(); 054 String socketSystemName; 055 if (socket != null) { 056 socketSystemName = socket.getSystemName(); 057 } else { 058 socketSystemName = p.getExecuteSocketSystemName(); 059 } 060 if (socketSystemName != null) { 061 e2.addContent(new Element("systemName").addContent(socketSystemName)); 062 } 063 element.addContent(e2); 064 065 return element; 066 } 067 068 @Override 069 public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException { 070 071 String sys = getSystemName(shared); 072 String uname = getUserName(shared); 073 ActionListenOnBeansLocalVariable h = new ActionListenOnBeansLocalVariable(sys, uname); 074 075 loadCommon(h, shared); 076 077 Element namedBeanTypeElement = shared.getChild("namedBeanType"); 078 NamedBeanType namedBeanType = 079 NamedBeanType.valueOf(namedBeanTypeElement.getTextTrim()); 080 h.setNamedBeanType(namedBeanType); 081 082 Element variableName = shared.getChild("localVariableBeanToListenOn"); 083 if (variableName != null) { 084 h.setLocalVariableBeanToListenOn(variableName.getTextTrim()); 085 } 086 087 variableName = shared.getChild("localVariableNamedBean"); 088 if (variableName != null) { 089 h.setLocalVariableNamedBean(variableName.getTextTrim()); 090 } 091 092 variableName = shared.getChild("localVariableEvent"); 093 if (variableName != null) { 094 h.setLocalVariableEvent(variableName.getTextTrim()); 095 } 096 097 variableName = shared.getChild("localVariableNewValue"); 098 if (variableName != null) { 099 h.setLocalVariableNewValue(variableName.getTextTrim()); 100 } 101 102 String listenOnAllProperties = "no"; 103 Attribute attribute = shared.getAttribute("listenOnAllProperties"); 104 if (attribute != null) { // NOI18N 105 listenOnAllProperties = attribute.getValue(); // NOI18N 106 } 107 h.setListenOnAllProperties("yes".equals(listenOnAllProperties)); 108 109 Element socketNameElement = shared.getChild("Socket").getChild("socketName"); 110 String socketName = socketNameElement.getTextTrim(); 111 Element socketSystemNameElement = shared.getChild("Socket").getChild("systemName"); 112 String socketSystemName = null; 113 if (socketSystemNameElement != null) { 114 socketSystemName = socketSystemNameElement.getTextTrim(); 115 } 116 117 h.getChild(0).setName(socketName); 118 h.setExecuteSocketSystemName(socketSystemName); 119 120 InstanceManager.getDefault(DigitalActionManager.class).registerAction(h); 121 return true; 122 } 123 124// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionListenOnBeansLocalVariableXml.class); 125}