001package jmri.jmrit.logixng.implementation.configurexml;
002
003import jmri.InstanceManager;
004import jmri.jmrit.logixng.NamedTable;
005import jmri.jmrit.logixng.NamedTableManager;
006import jmri.jmrit.logixng.Table;
007import jmri.jmrit.logixng.implementation.DefaultCsvNamedTable;
008
009import org.jdom2.Element;
010
011/**
012 * Handle XML configuration for DefaultCsvNamedTable objects.
013 *
014 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
015 * @author Daniel Bergqvist Copyright (C) 2019
016 */
017public class DefaultCsvNamedTableXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
018
019    public DefaultCsvNamedTableXml() {
020    }
021    
022    /**
023     * Default implementation for storing the contents of a DefaultCsvNamedTable
024     *
025     * @param o Object to store, of type DefaultCsvNamedTable
026     * @return Element containing the complete info
027     */
028    @Override
029    public Element store(Object o) {
030        DefaultCsvNamedTable p = (DefaultCsvNamedTable) o;
031
032        Element element = new Element("CsvTable");
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("fileName").addContent(p.getFileName()));
039        Table.CsvType csvType = p.getCsvType();
040        Element csvElement = new Element("csvType");
041        if (csvType == null)
042        {
043            csvElement.addContent(Table.CsvType.TABBED.name());
044        } else {
045            csvElement.addContent(p.getCsvType().name());
046        }
047        element.addContent(csvElement);
048        return element;
049    }
050    
051    @Override
052    public boolean load(Element shared, Element perNode) {
053        String sys = getSystemName(shared);
054        String uname = getUserName(shared);
055        String fileName = shared.getChild("fileName").getTextTrim();
056        Table.CsvType csvType = Table.CsvType.TABBED;
057        if (shared.getChild("csvType") != null) {
058            csvType = Table.CsvType.valueOf(shared.getChild("csvType").getText());
059        }
060        NamedTable h = InstanceManager.getDefault(NamedTableManager.class).newCSVTable(sys, uname, fileName, csvType);
061        
062        loadCommon(h, shared);
063        
064        return true;
065    }
066    
067//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DefaultCsvNamedTableXml.class);
068}