简体   繁体   中英

how to read datamodel values from Apache-commons scxml api in java

I am using SCXML in my java application. I am using apache-commons-scxml api to implement the state machine. I am able to set the value in data model through sxml api but not able to read that value in java code.

Each time read operation fetch the default value that is set in scxml document instead of reading the latest value that is set at runtime. However if we log the expression in scxml doc for the same value then it will print the updated value but in java code I am not able to get the updated value.

Below is the datamodel:

<datamodel><!-- Usage where the value is an XML data tree -->           
   <data id="XYZ">
      <A xmlns="">T</DevID> 
      <B xmlns="">F</Result>            
   </data>
</datamodel>

Reading the data model:

List<Data> dataTest = handlerFSM.getEngine().getStateMachine().getDatamodel().getData();
Iterator<Data> itrTest = dataTest.iterator();
while(itrTest.hasNext()){
  Data d = itrTest.next();
  if(d.getId().equals("XYZ")){
  NodeList nodeList = d.getNode().getChildNodes();
}

Setting the value:

nodeList.item(1).setTextContent("dummy");

Reading the value:

nodeList1.item(1).getTextContent();

All the time read operation gives the value "F" not "dummy" that is set at runtime. Any idea how to read the updated value(in this case "dummy") of the node in java code through apache commons-scxml api?

You can do this:

org.w3c.dom.Node xyz = (org.w3c.dom.Node) handlerFSM.getEngine().getRootContext().get("xyz");

xyz.getFirstChild().setTextContent("dummy");

To my understanding getStateMachine().getDataModel() will only give you the static data model as it was defined in the XML file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM