001package jmri.jmrit.logixng.actions.configurexml; 002 003import jmri.*; 004import jmri.configurexml.JmriConfigureXmlException; 005import jmri.jmrit.logixng.DigitalActionManager; 006import jmri.jmrit.logixng.actions.JsonDecode; 007 008import org.jdom2.Element; 009 010/** 011 * Handle XML configuration for JsonDecode objects. 012 * 013 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010 014 * @author Daniel Bergqvist Copyright (C) 2024 015 */ 016public class JsonDecodeXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML { 017 018 public JsonDecodeXml() { 019 } 020 021 /** 022 * Default implementation for storing the contents of a JsonDecode 023 * 024 * @param o Object to store, of type JsonDecode 025 * @return Element containing the complete info 026 */ 027 @Override 028 public Element store(Object o) { 029 JsonDecode p = (JsonDecode) o; 030 031 Element element = new Element("JsonDecode"); // NOI18N 032 element.setAttribute("class", this.getClass().getName()); // NOI18N 033 element.addContent(new Element("systemName").addContent(p.getSystemName())); // NOI18N 034 035 storeCommon(p, element); 036 037 String jsonVariableName = p.getJsonLocalVariable(); 038 if (jsonVariableName != null) { 039 element.addContent(new Element("jsonVariable").addContent(jsonVariableName)); // NOI18N 040 } 041 042 String resultVariableName = p.getResultLocalVariable(); 043 if (resultVariableName != null) { 044 element.addContent(new Element("resultVariable").addContent(resultVariableName)); // NOI18N 045 } 046 047 return element; 048 } 049 050 @Override 051 public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException { 052 String sys = getSystemName(shared); 053 String uname = getUserName(shared); 054 JsonDecode h = new JsonDecode(sys, uname); 055 056 loadCommon(h, shared); 057 058 Element jsonVariableName = shared.getChild("jsonVariable"); // NOI18N 059 if (jsonVariableName != null) { 060 h.setJsonLocalVariable(jsonVariableName.getTextTrim()); 061 } 062 063 Element resultVariableName = shared.getChild("resultVariable"); // NOI18N 064 if (resultVariableName != null) { 065 h.setResultLocalVariable(resultVariableName.getTextTrim()); 066 } 067 068 InstanceManager.getDefault(DigitalActionManager.class).registerAction(h); 069 return true; 070 } 071 072// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(JsonDecodeXml.class); 073}