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.Not; 007 008import org.jdom2.Element; 009 010/** 011 * Handle XML configuration for Not objects. 012 * 013 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010 014 * @author Daniel Bergqvist Copyright (C) 2021 015 */ 016public class NotXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML { 017 018 public NotXml() { 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 Not p = (Not) o; 030 031 Element element = new Element("Not"); 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.getSocketSystemName(); 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 Not h = new Not(sys, uname); 059 060 loadCommon(h, shared); 061 062 Element socketElement = shared.getChild("Socket"); 063 String socketName = socketElement.getChild("socketName").getTextTrim(); 064 Element systemNameElement = socketElement.getChild("systemName"); 065 String systemName = null; 066 if (systemNameElement != null) { 067 systemName = systemNameElement.getTextTrim(); 068 } 069 h.getChild(0).setName(socketName); 070 h.setSocketSystemName(systemName); 071 072 InstanceManager.getDefault(DigitalExpressionManager.class).registerExpression(h); 073 return true; 074 } 075 076// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(NotXml.class); 077}