001package jmri.jmrix.rps.serial.configurexml; 002 003import jmri.jmrix.configurexml.AbstractSerialConnectionConfigXml; 004import jmri.jmrix.rps.serial.ConnectionConfig; 005import jmri.jmrix.rps.serial.SerialAdapter; 006import org.jdom2.Element; 007 008/** 009 * Handle XML persistance of layout connections by persisting the SeriaAdapter 010 * (and connections). Note this is named as the XML version of a 011 * ConnectionConfig object, but it's actually persisting the SerialAdapter. 012 * <p> 013 * This class is invoked from jmrix.JmrixConfigPaneXml on write, as that class 014 * is the one actually registered. Reads are brought here directly via the class 015 * attribute in the XML. 016 * 017 * @author Bob Jacobsen Copyright: Copyright (c) 2003, 2006, 2007, 2008 018 */ 019public class ConnectionConfigXml extends AbstractSerialConnectionConfigXml { 020 021 public ConnectionConfigXml() { 022 super(); 023 } 024 025 /** 026 * Write out the SerialNode objects too 027 * 028 * @param e Element being extended 029 */ 030 @Override 031 protected void extendElement(Element e) { 032 /* SerialNode node = (SerialNode) SerialTrafficController.instance().getNode(0); */ 033 /* int index = 1; */ 034 /* while (node != null) { */ 035 /* // add node as an element */ 036 /* Element n = new Element("node"); */ 037 /* n.setAttribute("name", "" + node.getNodeAddress()); */ 038 /* e.addContent(n); */ 039 /* // add parameters to the node as needed */ 040 /* n.addContent(makeParameter("nodetype", ""+node.getNodeType())); */ 041 /* */ 042 /* // look for the next node */ 043 /* node = (SerialNode) SerialTrafficController.instance().getNode(index); */ 044 /* index ++; */ 045 /* } */ 046 } 047 048 protected Element makeParameter(String name, String value) { 049 Element p = new Element("parameter"); 050 p.setAttribute("name", name); 051 p.addContent(value); 052 return p; 053 } 054 055 @Override 056 protected void getInstance() { 057 if (adapter == null ) { 058 adapter = new SerialAdapter(); 059 } 060 } 061 062 @Override 063 protected void getInstance(Object object) { 064 adapter = ((ConnectionConfig) object).getAdapter(); 065 } 066 067 @Override 068 protected void register() { 069 this.register(new ConnectionConfig(adapter)); 070 } 071 072 @Override 073 protected void unpackElement(Element shared, Element perNode) { 074 /* List l = shared.getChildren("node"); */ 075 /* for (int i = 0; i<l.size(); i++) { */ 076 /* Element n = (Element) l.get(i); */ 077 /* int addr = Integer.parseInt(n.getAttributeValue("name")); */ 078 /* int type = Integer.parseInt(findParmValue(n,"nodetype")); */ 079 /* */ 080 /* // create node (they register themselves) */ 081 /* SerialNode node = new SerialNode(addr, type); */ 082 /* */ 083 /* // Trigger initialization of this Node to reflect these parameters */ 084 /* SerialTrafficController.instance().initializeSerialNode(node); */ 085 /* } */ 086 } 087 088}