SoarTechXmlToWme implements XmlToWme { private Symbol getValue(Element element) { final SymbolFactory syms = wmeFactory.getSymbols(); final String type = element.getAttribute(SoarTechWmeToXml.TYPE); if(type.length() == 0 && XmlTools.getFirstChild(element) != null) { return fromXmlInternal(element, null); } final String value; if(element.hasAttribute(SoarTechWmeToXml.VALUE)) { value = element.getAttribute(SoarTechWmeToXml.VALUE); } else { value = element.getTextContent(); } if (null == value) { return syms.createString(""); } else if(SoarTechWmeToXml.DOUBLE.equals(type)) { return syms.createDouble(Double.valueOf(value)); } else if(SoarTechWmeToXml.INTEGER.equals(type)) { return syms.createInteger(Long.valueOf(value)); } else { return syms.createString(value); } } SoarTechXmlToWme(WmeFactory<?> wmeFactory); static SoarTechXmlToWme forInput(InputOutput io); static SoarTechXmlToWme forRhsFunction(RhsFunctionContext rhsContext); Identifier fromXml(Element element); Identifier fromXml(Element element, Identifier targetId);  }
@Test public void testValueAttributeIsHandled() throws Exception { final Agent agent = new Agent(); agent.getProperties().set(SoarProperties.WAITSNC, true); agent.getProductions().loadProduction( "testValueAttributeIsHandled (state <s> ^superstate nil ^io.input-link <il>) -->" + "(<il> ^xml (from-st-xml |" + "<ignored>" + "<name value='hello'/>" + "<age type='integer' value='33'/>" + "<weight type='double' value='180.5'/>" + "</ignored>|))"); agent.runFor(1, RunType.DECISIONS); final Identifier il = agent.getInputOutput().getInputLink(); final MatcherBuilder m = Wmes.matcher(agent); final Identifier xml = m.attr("xml").find(il).getValue().asIdentifier(); assertNotNull(xml); assertEquals("hello", m.attr("name").find(xml).getValue().asString().getValue()); assertEquals(33, m.attr("age").find(xml).getValue().asInteger().getValue()); assertEquals(180.5, m.attr("weight").find(xml).getValue().asDouble().getValue(), 0.0001); }