001package jmri.jmrit.logixng.actions.configurexml; 002 003import java.util.List; 004 005import jmri.InstanceManager; 006import jmri.SystemConnectionMemo; 007import jmri.configurexml.JmriConfigureXmlException; 008import jmri.jmrit.logixng.*; 009import jmri.jmrit.logixng.actions.ActionThrottleFunction; 010import jmri.jmrit.logixng.actions.ActionThrottleFunction.FunctionState; 011import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectEnumXml; 012import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectIntegerXml; 013 014import org.jdom2.Element; 015 016/** 017 * Handle XML configuration for ActionLightXml objects. 018 * 019 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010 020 * @author Daniel Bergqvist Copyright (C) 2023 021 */ 022public class ActionThrottleFunctionXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML { 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 ActionThrottleFunction p = (ActionThrottleFunction) o; 033 034 var selectAddressXml = new LogixNG_SelectIntegerXml(); 035 var selectFunctionXml = new LogixNG_SelectIntegerXml(); 036 var selectOnOffXml = new LogixNG_SelectEnumXml<FunctionState>(); 037 038 Element element = new Element("ThrottleFunction"); 039 element.setAttribute("class", this.getClass().getName()); 040 element.addContent(new Element("systemName").addContent(p.getSystemName())); 041 042 storeCommon(p, element); 043 044 element.addContent(selectAddressXml.store(p.getSelectAddress(), "address")); 045 element.addContent(selectFunctionXml.store(p.getSelectFunction(), "function")); 046 element.addContent(selectOnOffXml.store(p.getSelectOnOff(), "onOff")); 047 048 if (p.getMemo() != null) { 049 element.addContent(new Element("systemConnection") 050 .addContent(p.getMemo().getSystemPrefix())); 051 } 052 053 return element; 054 } 055 056 @Override 057 public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException { 058 059 String sys = getSystemName(shared); 060 String uname = getUserName(shared); 061 ActionThrottleFunction h = new ActionThrottleFunction(sys, uname); 062 063 var selectAddressXml = new LogixNG_SelectIntegerXml(); 064 var selectFunctionXml = new LogixNG_SelectIntegerXml(); 065 var selectOnOffXml = new LogixNG_SelectEnumXml<FunctionState>(); 066 067 loadCommon(h, shared); 068 069 selectAddressXml.load(shared.getChild("address"), h.getSelectAddress()); 070 selectFunctionXml.load(shared.getChild("function"), h.getSelectFunction()); 071 selectOnOffXml.load(shared.getChild("onOff"), h.getSelectOnOff()); 072 073 Element systemConnection = shared.getChild("systemConnection"); 074 if (systemConnection != null) { 075 String systemConnectionName = systemConnection.getTextTrim(); 076 List<SystemConnectionMemo> systemConnections = 077 jmri.InstanceManager.getList(SystemConnectionMemo.class); 078 079 for (SystemConnectionMemo memo : systemConnections) { 080 if (memo.getSystemPrefix().equals(systemConnectionName)) { 081 h.setMemo(memo); 082 break; 083 } 084 } 085 } 086 087 InstanceManager.getDefault(DigitalActionManager.class).registerAction(h); 088 return true; 089 } 090 091// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionThrottleFunctionXml.class); 092}