001package jmri.jmrix.internal.configurexml; 002 003import jmri.jmrix.SerialPortAdapter; 004import jmri.jmrix.configurexml.AbstractConnectionConfigXml; 005import jmri.jmrix.internal.ConnectionConfig; 006import jmri.jmrix.internal.InternalAdapter; 007import org.jdom2.Element; 008 009/** 010 * Handle XML persistance of virtual layout connections 011 * <p> 012 * This class is invoked from jmrix.JmrixConfigPaneXml on write, as that class 013 * is the one actually registered. Reads are brought here directly via the class 014 * attribute in the XML. 015 * 016 * @author Bob Jacobsen Copyright: Copyright (c) 2003, 2010 017 */ 018public class ConnectionConfigXml extends AbstractConnectionConfigXml { 019 020 public ConnectionConfigXml() { 021 super(); 022 } 023 024 /** {@inheritDoc} */ 025 @Override 026 protected void getInstance() { 027 adapter = new InternalAdapter(); 028 } 029 030 protected SerialPortAdapter adapter; 031 032 protected void getInstance(Object object) { 033 adapter = ((ConnectionConfig) object).getAdapter(); 034 } 035 036 /** {@inheritDoc} */ 037 @Override 038 public Element store(Object o) { 039 getInstance(o); 040 041 if (adapter == null) return null; 042 043 Element e = new Element("connection"); 044 storeCommon(e, adapter); 045 046 e.setAttribute("class", this.getClass().getName()); 047 048 return e; 049 } 050 051 /** {@inheritDoc} */ 052 @Override 053 public boolean load(Element shared, Element perNode) { 054 boolean result = true; 055 getInstance(); 056 057 if (adapter == null) { 058 return false; 059 } 060 061 this.loadCommon(shared, perNode, adapter); 062 // register, so can be picked up 063 register(); 064 065 if (adapter.getDisabled()) { 066 return result; 067 } 068 adapter.configure(); 069 070 return result; 071 } 072 073 /** {@inheritDoc} */ 074 @Override 075 protected void register() { 076 this.register(new ConnectionConfig(adapter)); 077 } 078 079 @Override 080 protected void dispose() { 081 adapter.dispose(); 082 } 083 084}