001package jmri.util.startup.configurexml; 002 003import jmri.util.startup.PerformFileModel; 004 005import jmri.util.startup.StartupActionsManager; 006import jmri.InstanceManager; 007import jmri.util.FileUtil; 008 009import org.jdom2.Attribute; 010import org.jdom2.Element; 011 012/** 013 * Handle XML persistence of PerformFileModel objects 014 * 015 * @author Bob Jacobsen Copyright: Copyright (c) 2003 016 * @author Ken Cameron Copyright: 2014(c) 017 * @see jmri.util.startup.PerformFileModelFactory 018 */ 019public class PerformFileModelXml extends jmri.configurexml.AbstractXmlAdapter { 020 021 public PerformFileModelXml() { 022 } 023 024 /** 025 * Default implementation for storing the model contents 026 * 027 * @param o Object to store, of type PerformActonModel 028 * @return Element containing the complete info 029 */ 030 @Override 031 public Element store(Object o) { 032 Element e = new Element("perform"); 033 PerformFileModel g = (PerformFileModel) o; 034 035 e.setAttribute("name", FileUtil.getPortableFilename(g.getFileName())); 036 e.setAttribute("type", "XmlFile"); 037 e.setAttribute("enabled", g.isEnabled() ? "yes" : "no"); 038 e.setAttribute("class", this.getClass().getName()); 039 return e; 040 } 041 042 /** 043 * Object should be loaded after basic GUI constructed 044 * 045 * @return true to defer loading 046 * @see jmri.configurexml.AbstractXmlAdapter#loadDeferred() 047 * @see jmri.configurexml.XmlAdapter#loadDeferred() 048 */ 049 @Override 050 public boolean loadDeferred() { 051 return true; 052 } 053 054 @Override 055 public boolean load(Element shared, Element perNode) { 056 boolean result = true; 057 String fileName = FileUtil.getAbsoluteFilename(shared.getAttribute("name").getValue()); 058 PerformFileModel m = new PerformFileModel(); 059 060 Attribute enabled = shared.getAttribute("enabled"); 061 if (enabled != null) { 062 m.setEnabled("yes".equals(enabled.getValue())); 063 } else { 064 m.setEnabled(true); 065 } 066 067 m.setFileName(fileName); 068 InstanceManager.getDefault(StartupActionsManager.class).addAction(m); 069 return result; 070 } 071 072 // initialize logging 073// private final static Logger log = LoggerFactory.getLogger(PerformFileModelXml.class); 074 075}