001package jmri.jmrit.logixng.actions.configurexml; 002 003import jmri.InstanceManager; 004import jmri.configurexml.JmriConfigureXmlException; 005import jmri.jmrit.logixng.*; 006import jmri.jmrit.logixng.actions.Timeout; 007import jmri.jmrit.logixng.util.TimerUnit; 008import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectIntegerXml; 009import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectEnumXml; 010 011import org.jdom2.Element; 012 013/** 014 * Handle XML configuration for ActionLightXml objects. 015 * 016 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010 017 * @author Daniel Bergqvist Copyright (C) 2021 018 */ 019public class TimeoutXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML { 020 021 /** 022 * Default implementation for storing the contents of a SE8cSignalHead 023 * 024 * @param o Object to store, of type TripleTurnoutSignalHead 025 * @return Element containing the complete info 026 */ 027 @Override 028 public Element store(Object o) { 029 Timeout p = (Timeout) o; 030 031 var selectDelayXml = new LogixNG_SelectIntegerXml(); 032 var selectTimerUnitXml = new LogixNG_SelectEnumXml<TimerUnit>(); 033 034 Element element = new Element("Timeout"); 035 element.setAttribute("class", this.getClass().getName()); 036 element.addContent(new Element("systemName").addContent(p.getSystemName())); 037 038 storeCommon(p, element); 039 040 Element e2 = new Element("ExpressionSocket"); 041 e2.addContent(new Element("socketName").addContent(p.getChild(0).getName())); 042 MaleSocket socket = p.getExpressionSocket().getConnectedSocket(); 043 String socketSystemName; 044 if (socket != null) { 045 socketSystemName = socket.getSystemName(); 046 } else { 047 socketSystemName = p.getExpressionSocketSystemName(); 048 } 049 if (socketSystemName != null) { 050 e2.addContent(new Element("systemName").addContent(socketSystemName)); 051 } 052 element.addContent(e2); 053 054 e2 = new Element("ActionSocket"); 055 e2.addContent(new Element("socketName").addContent(p.getChild(1).getName())); 056 socket = p.getActionSocket().getConnectedSocket(); 057 if (socket != null) { 058 socketSystemName = socket.getSystemName(); 059 } else { 060 socketSystemName = p.getActionSocketSystemName(); 061 } 062 if (socketSystemName != null) { 063 e2.addContent(new Element("systemName").addContent(socketSystemName)); 064 } 065 element.addContent(e2); 066 067 element.addContent(selectDelayXml.store(p.getSelectDelay(), "timeToDelay")); 068 element.addContent(selectTimerUnitXml.store(p.getSelectTimerUnit(), "timerUnit")); 069 070 return element; 071 } 072 073 @Override 074 public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException { 075 076 String sys = getSystemName(shared); 077 String uname = getUserName(shared); 078 Timeout h = new Timeout(sys, uname); 079 080 var selectDelayXml = new LogixNG_SelectIntegerXml(); 081 var selectTimerUnitXml = new LogixNG_SelectEnumXml<TimerUnit>(); 082 083 loadCommon(h, shared); 084 085 selectDelayXml.load(shared.getChild("timeToDelay"), h.getSelectDelay()); 086 selectDelayXml.loadLegacy( 087 shared, h.getSelectDelay(), 088 "delayAddressing", 089 "delay", 090 "delayReference", 091 "delayLocalVariable", 092 "delayFormula"); 093 094 selectTimerUnitXml.load(shared.getChild("timerUnit"), h.getSelectTimerUnit()); 095 selectTimerUnitXml.loadLegacy( 096 shared, h.getSelectTimerUnit(), 097 "unitAddressing", // Not used 098 "unit", 099 "unitReference", // Not used 100 "unitLocalVariable", // Not used 101 "unitFormula"); // Not used 102 103 Element socketName = shared.getChild("ExpressionSocket").getChild("socketName"); 104 h.getChild(0).setName(socketName.getTextTrim()); 105 Element socketSystemName = shared.getChild("ExpressionSocket").getChild("systemName"); 106 if (socketSystemName != null) { 107 h.setExpressionSocketSystemName(socketSystemName.getTextTrim()); 108 } 109 110 socketName = shared.getChild("ActionSocket").getChild("socketName"); 111 h.getChild(1).setName(socketName.getTextTrim()); 112 socketSystemName = shared.getChild("ActionSocket").getChild("systemName"); 113 if (socketSystemName != null) { 114 h.setActionSocketSystemName(socketSystemName.getTextTrim()); 115 } 116 117 InstanceManager.getDefault(DigitalActionManager.class).registerAction(h); 118 return true; 119 } 120 121// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TimeoutXml.class); 122}