001package apps.startup.configurexml; 002 003import apps.startup.StartupPauseModel; 004 005import jmri.InstanceManager; 006import jmri.configurexml.AbstractXmlAdapter; 007import jmri.util.startup.StartupActionsManager; 008 009import org.jdom2.Attribute; 010import org.jdom2.Element; 011 012/** 013 * Handle XML persistence for {@link apps.startup.StartupPauseModel} objects. 014 * 015 * @author Randall Wood (c) 2016 016 * @see apps.startup.StartupPauseFactory 017 */ 018public class StartupPauseModelXml extends AbstractXmlAdapter { 019 020// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(StartupPauseModelXml.class); 021 022 public StartupPauseModelXml() { 023 } 024 025 @Override 026 public Element store(Object o) { 027 Element element = new Element("perform"); // NOI18N 028 element.setAttribute("name", "Pause"); 029 element.setAttribute("type", "Pause"); 030 element.setAttribute("enabled", ((StartupPauseModel) o).isEnabled() ? "yes" : "no"); 031 element.setAttribute("class", this.getClass().getName()); 032 Element property = new Element("property"); // NOI18N 033 property.setAttribute("name", "delay"); // NOI18N 034 property.setAttribute("value", Integer.toString(((StartupPauseModel) o).getDelay())); 035 element.addContent(property); 036 return element; 037 } 038 039 @Override 040 public boolean loadDeferred() { 041 return true; 042 } 043 044 @Override 045 public boolean load(Element shared, Element perNode) { 046 boolean result = false; 047 StartupPauseModel model = new StartupPauseModel(); 048 049 Attribute enabled = shared.getAttribute("enabled"); 050 if (enabled != null) { 051 model.setEnabled("yes".equals(enabled.getValue())); 052 } else { 053 model.setEnabled(true); 054 } 055 056 int delay = 0; 057 for (Element child : shared.getChildren("property")) { // NOI18N 058 if (child.getAttributeValue("name").equals("delay") // NOI18N 059 && child.getAttributeValue("value") != null) { // NOI18N 060 delay = Integer.parseInt(child.getAttributeValue("value")); // NOI18N 061 } 062 } 063 if (delay != 0) { 064 model.setDelay(delay); 065 } 066 067 // store the model 068 InstanceManager.getDefault(StartupActionsManager.class).addAction(model); 069 return result; 070 } 071 072}