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