001package jmri.jmrit.logixng.expressions.configurexml; 002 003import jmri.InstanceManager; 004import jmri.jmrit.logixng.DigitalExpressionManager; 005import jmri.jmrit.logixng.MaleSocket; 006import jmri.jmrit.logixng.expressions.TriggerOnce; 007 008import org.jdom2.Element; 009 010/** 011 * Handle XML configuration for ActionLightXml objects. 012 * 013 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010 014 * @author Daniel Bergqvist Copyright (C) 2019 015 */ 016public class TriggerOnceXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML { 017 018 public TriggerOnceXml() { 019 } 020 021 /** 022 * Default implementation for storing the contents of a ActionMany 023 * 024 * @param o Object to store, of type ActionMany 025 * @return Element containing the complete info 026 */ 027 @Override 028 public Element store(Object o) { 029 TriggerOnce p = (TriggerOnce) o; 030 031 Element element = new Element("TriggerOnce"); 032 element.setAttribute("class", this.getClass().getName()); 033 element.addContent(new Element("systemName").addContent(p.getSystemName())); 034 035 storeCommon(p, element); 036 037 Element e2 = new Element("Socket"); 038 e2.addContent(new Element("socketName").addContent(p.getChild(0).getName())); 039 MaleSocket socket = p.getChild(0).getConnectedSocket(); 040 String socketSystemName; 041 if (socket != null) { 042 socketSystemName = socket.getSystemName(); 043 } else { 044 socketSystemName = p.getChildSocketSystemName(); 045 } 046 if (socketSystemName != null) { 047 e2.addContent(new Element("systemName").addContent(socketSystemName)); 048 } 049 element.addContent(e2); 050 051 return element; 052 } 053 054 @Override 055 public boolean load(Element shared, Element perNode) { 056 String sys = getSystemName(shared); 057 String uname = getUserName(shared); 058 TriggerOnce h; 059 if (uname == null) { 060 h = new TriggerOnce(sys, null); 061 } else { 062 h = new TriggerOnce(sys, uname); 063 } 064 065 loadCommon(h, shared); 066 067 Element socketElement = shared.getChild("Socket"); 068 String socketName = socketElement.getChild("socketName").getTextTrim(); 069 Element systemNameElement = socketElement.getChild("systemName"); 070 String systemName = null; 071 if (systemNameElement != null) { 072 systemName = systemNameElement.getTextTrim(); 073 } 074 h.getChild(0).setName(socketName); 075 h.setChildSocketSystemName(systemName); 076 077 InstanceManager.getDefault(DigitalExpressionManager.class).registerExpression(h); 078 return true; 079 } 080 081// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TriggerOnceXml.class); 082}