001package jmri.jmrit.logixng.expressions.configurexml; 002 003import jmri.*; 004import jmri.configurexml.JmriConfigureXmlException; 005import jmri.jmrit.logix.OBlock; 006import jmri.jmrit.logixng.*; 007import jmri.jmrit.logixng.expressions.ExpressionOBlock; 008import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectNamedBeanXml; 009import jmri.jmrit.logixng.util.parser.ParserException; 010 011import org.jdom2.Element; 012 013/** 014 * Handle XML configuration for ExpressionOBlockXml objects. 015 * 016 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010 017 * @author Daniel Bergqvist Copyright (C) 2019 018 */ 019public class ExpressionOBlockXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML { 020 021 public ExpressionOBlockXml() { 022 } 023 024 /** 025 * Default implementation for storing the contents of a SE8cSignalHead 026 * 027 * @param o Object to store, of type TripleOBlockSignalHead 028 * @return Element containing the complete info 029 */ 030 @Override 031 public Element store(Object o) { 032 ExpressionOBlock p = (ExpressionOBlock) o; 033 034 Element element = new Element("ExpressionOBlock"); 035 element.setAttribute("class", this.getClass().getName()); 036 element.addContent(new Element("systemName").addContent(p.getSystemName())); 037 038 storeCommon(p, element); 039 040 var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<OBlock>(); 041 element.addContent(selectNamedBeanXml.store(p.getSelectNamedBean(), "namedBean")); 042 043 element.addContent(new Element("is_isNot").addContent(p.get_Is_IsNot().name())); 044 045 element.addContent(new Element("stateAddressing").addContent(p.getStateAddressing().name())); 046 element.addContent(new Element("oblockStatus").addContent(p.getBeanState().name())); 047 element.addContent(new Element("stateReference").addContent(p.getStateReference())); 048 element.addContent(new Element("stateLocalVariable").addContent(p.getStateLocalVariable())); 049 element.addContent(new Element("stateFormula").addContent(p.getStateFormula())); 050 051 return element; 052 } 053 054 @Override 055 public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException { 056 String sys = getSystemName(shared); 057 String uname = getUserName(shared); 058 ExpressionOBlock h = new ExpressionOBlock(sys, uname); 059 060 loadCommon(h, shared); 061 062 var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<OBlock>(); 063 selectNamedBeanXml.load(shared.getChild("namedBean"), h.getSelectNamedBean()); 064 selectNamedBeanXml.loadLegacy(shared, h.getSelectNamedBean(), "oblock"); 065 066 try { 067 Element is_IsNot = shared.getChild("is_isNot"); 068 if (is_IsNot != null) { 069 h.set_Is_IsNot(Is_IsNot_Enum.valueOf(is_IsNot.getTextTrim())); 070 } 071 072 Element elem = shared.getChild("stateAddressing"); 073 if (elem != null) { 074 h.setStateAddressing(NamedBeanAddressing.valueOf(elem.getTextTrim())); 075 } 076 077 Element oblockState = shared.getChild("oblockStatus"); 078 if (oblockState != null) { 079 h.setBeanState(OBlock.OBlockStatus.valueOf(oblockState.getTextTrim())); 080 } 081 082 elem = shared.getChild("stateReference"); 083 if (elem != null) h.setStateReference(elem.getTextTrim()); 084 085 elem = shared.getChild("stateLocalVariable"); 086 if (elem != null) h.setStateLocalVariable(elem.getTextTrim()); 087 088 elem = shared.getChild("stateFormula"); 089 if (elem != null) h.setStateFormula(elem.getTextTrim()); 090 091 } catch (ParserException e) { 092 throw new JmriConfigureXmlException(e); 093 } 094 095 InstanceManager.getDefault(DigitalExpressionManager.class).registerExpression(h); 096 return true; 097 } 098 099// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ExpressionOBlockXml.class); 100}