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.Hold; 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 HoldXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML { 017 018 public HoldXml() { 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 Hold p = (Hold) o; 030 031 Element element = new Element("Hold"); 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("TriggerSocket"); 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.getTriggerExpressionSocketSystemName(); 045 } 046 if (socketSystemName != null) { 047 e2.addContent(new Element("systemName").addContent(socketSystemName)); 048 } 049 element.addContent(e2); 050 051 e2 = new Element("HoldSocket"); 052 e2.addContent(new Element("socketName").addContent(p.getChild(1).getName())); 053 socket = p.getChild(1).getConnectedSocket(); 054 if (socket != null) { 055 socketSystemName = socket.getSystemName(); 056 } else { 057 socketSystemName = p.getHoldActionSocketSystemName(); 058 } 059 if (socketSystemName != null) { 060 e2.addContent(new Element("systemName").addContent(socketSystemName)); 061 } 062 element.addContent(e2); 063 064 return element; 065 } 066 067 @Override 068 public boolean load(Element shared, Element perNode) { 069 String sys = getSystemName(shared); 070 String uname = getUserName(shared); 071 Hold h = new Hold(sys, uname); 072 073 loadCommon(h, shared); 074 075 Element socketElement = shared.getChild("TriggerSocket"); 076 String socketName = socketElement.getChild("socketName").getTextTrim(); 077 Element systemNameElement = socketElement.getChild("systemName"); 078 String systemName = null; 079 if (systemNameElement != null) { 080 systemName = systemNameElement.getTextTrim(); 081 } 082 h.getChild(0).setName(socketName); 083 h.setTriggerExpressionSocketSystemName(systemName); 084 085 socketElement = shared.getChild("HoldSocket"); 086 socketName = socketElement.getChild("socketName").getTextTrim(); 087 systemNameElement = socketElement.getChild("systemName"); 088 systemName = null; 089 if (systemNameElement != null) { 090 systemName = systemNameElement.getTextTrim(); 091 } 092 h.getChild(1).setName(socketName); 093 h.setHoldActionSocketSystemName(systemName); 094 095 InstanceManager.getDefault(DigitalExpressionManager.class).registerExpression(h); 096 return true; 097 } 098 099// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(HoldXml.class); 100}