[SCXML] Using the API to create an SCXML object

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[SCXML] Using the API to create an SCXML object

Diptendu Dutta
Hello,

I am trying to create an SCXML object programmatically using the API rather
than from an XML text file.

State state1, state2;
Assign assign1, assign2;
Transition transition1, transition2, transition3;
OnEntry onentry1, onentry2;

SCXML machine = new SCXML();
machine.setDatamodelName("jexl");
machine.setInitial("Start");
machine.setVersion("1.0");

   state1 = new State();
   state1.setId("Start");

   machine.addChild(state1);

   transition1 = new Transition();
   transition1.setEvent("run");
   transition1.setCond("currentIntent eq 'startBot'");
   transition1.setNext("StartBot");
   state1.addTransition(transition1);

   transition2 = new Transition();
   transition2.setEvent("run");
   transition2.setNext("Exit");
   state1.addTransition(transition2);

   state2 = new State();
   state2.setId("StartBot");
   machine.addChild(state2);
   assign1 = new Assign();
   assign1.setLocation("currentResponse");
   assign1.setExpr("{'textResponse1' : 'Hello I am LearnITy Bot'}");
   onentry1 = new OnEntry();
   onentry1.addAction(assign1);
   state2.addOnEntry(onentry1);

   transition3 = new Transition();
   transition3.setEvent("run");
   transition3.setNext("Start");
   state2.addTransition(transition3);

  Final end = new Final();
  end.setId("Exit");
  machine.addChild(end);

   assign2 = new Assign();
   assign2.setLocation("currentResponse");
   assign2.setExpr("{'textResponse1' : 'Goodbye, it was nice talking to
you'}");
   onentry2 = new OnEntry();
   onentry2.addAction(assign2);
   end.addOnEntry(onentry2);

Context jexlContext = new JexlContext();
Evaluator evaluator = new JexlEvaluator();
  SCXMLExecutor engine = new SCXMLExecutor(evaluator, new
SimpleDispatcher(),  new SimpleErrorReporter());

engine.setStateMachine( machine );
engine.setRootContext(jexlContext);
engine.addListener( machine , new SimpleSCXMLListener());
engine.go();

When I run the above code I am getting the following error:

java.lang.NullPointerException
at
org.apache.commons.scxml2.semantics.SCXMLSemanticsImpl.computeEntrySet(SCXMLSemanticsImpl.java:436)

Any help will be appreciated.

Regards,

Diptendu Dutta