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