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