You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Rahul Akolkar <ra...@gmail.com> on 2009/02/04 20:22:53 UTC
Re: [SCXML] Some problem while using custom action
Again, please prefix Commons SCXML related posts with [SCXML] in the
email subject as I've added here.
On Wed, Feb 4, 2009 at 7:32 AM, Saurabh Agarwal <sa...@gmail.com> wrote:
> Hi All,
>
> I was trying to run the example of custom Action but it is not running .
>
> I am pasting the codde snippet of all the files for custom action , Please
> let me know where I am wrong :
>
<snip/>
Not sure what the StopClock class below is doing, I suspect it may be
inheriting from AbstractStateMachine. Since you have adapted some test
code, I would suggest adapting a complete test that uses custom
actions. Once you've parsed the document, I would also recommend
instantiating the SCXMLExecutor as described here [1] and using it as
described here [2].
-Rahul
[1] http://commons.apache.org/scxml/guide/core-engine.html
[2] http://commons.apache.org/scxml/guide/core-events.html
> 1. StopWatch.xml
> <scxml xmlns="http://www.w3.org/2005/07/scxml" *xmlns:my="
> http://my.custom-actions.domain/CUSTOM1"*
>
> version="1.0"
> initialstate="reset">
>
> <state id="reset">
> <onentry>
> *<my:hello name="saurabh" />*
> <!-- foo:bar also maps to Hello action -->
> <!--foo:bar name="custom action" /-->
> </onentry>
>
> </state>
> <state id="running">
> <transition event="watch.split" target="paused"/>
> <transition event="watch.stop" target="stopped"/>
> </state>
>
> <state id="paused">
> <transition event="watch.unsplit" target="running"/>
> <transition event="watch.stop" target="stopped"/>
> </state>
>
> <state id="stopped">
> <transition event="watch.reset" target="reset"/>
> </state>
>
> </scxml>
>
>
> *2. Code Snippet of my APP Starting the State machine :*
>
> protected void doInvite(SipServletRequest request)
> throws ServletException, IOException {
> log(" $$$ ############################ SimpleProxyServlet: Got
> request:\n" + request+" TO::"+request.getTo());
> log (" New log To::"+request.getTo().toString());
> HashMap aMap=new HashMap() ;
> aMap.put("SipMessage",request.toString() );
> SimpleContext sc=new SimpleContext(aMap);
>
>
> // (1) Create a list of custom actions, add as many as are needed
> *List customActions = new ArrayList();
> CustomAction ca =
> new CustomAction("http://my.custom-actions.domain/CUSTOM",
> "hello", Hello.class);
> customActions.add(ca);
>
> // (2) Parse the SCXML document containing the custom action(s)
> SCXML scxml = null;
> try {
> // try {URL url=new URL
> (StopClock.class.getClassLoader().getResource("PocAS/stopwatch.xml"));
> scxml =
> SCXMLParser.parse(StopClock.class.getClassLoader().getResource("PocAS/stopwatch.xml"),
> new SimpleErrorHandler(), customActions);
> // Also see other methods in SCXMLParser API
> // "url" points to SCXML document
> // "errorHandler" is SAX ErrorHandler
> } catch (SAXException ex) {
> Logger.getLogger(MainPocAS.class.getName()).log(Level.SEVERE,
> null, ex);
> } catch (ModelException ex) {
> Logger.getLogger(MainPocAS.class.getName()).log(Level.SEVERE,
> null, ex);
> }
> // Also see other methods in SCXMLParser API
> // "url" points to SCXML document
> // "errorHandler" is SAX ErrorHandler
>
> StopClock clock=new StopClock(scxml);*
>
> clock.getEngine().setRootContext(sc);
>
> // if(request.getTo().toString().equals("Alice1"))
> clock.fireEvent(StopClock.EVENT_RESET);
>
> 3 . Java File of Action ( Hello from commons-scxml - copypasting the imp
> snippet )
> public class Hello extends Action implements ExternalContent {
>
> /** Serial version UID. */
> private static final long serialVersionUID = 1L;
> /** This is who we say hello to. */
> private String name;
> /** We count callbacks to execute() as part of the test suite. */
> public static int callbacks = 0;
>
> /** Public constructor is needed for the I in SCXML IO. */
> public Hello() {
> super();
> System.out.println("Hello: Got in Hello constructor...");
> }
>
> /**
> * Get the name.
> *
> * @return Returns the name.
> */
> public String getName() {
> System.out.println("Hello: getName");
> return name;
> }
>
> /**
> * Set the name.
> *
> * @param name The name to set.
> */
> public void setName(String name) {
> this.name = name;
> System.out.println("Hello: setName");
> }
>
> /**
> * @inheritDoc
> */
> public void execute(final EventDispatcher evtDispatcher,
> final ErrorReporter errRep, final SCInstance scInstance,
> final Log appLog, final Collection derivedEvents)
> throws ModelException, SCXMLExpressionException {
>
> System.out.println("Hello: execute");
> if (appLog.isInfoEnabled()) {
> appLog.info("Hello " + name);
> }
> // For derived events payload testing
> TriggerEvent event =
> new TriggerEvent("helloevent", TriggerEvent.SIGNAL_EVENT,
> name);
> derivedEvents.add(event);
> callbacks++;
> }
>
> public List getExternalNodes() {
> throw new UnsupportedOperationException("Not supported yet.");
> }
> }
>
>
>
>
> Please let me know what I am doing wrong .
>
> Thanks & Regards
> Saurabh
>
>
> --
>
> "Successful people make more mistakes because they do more "
> Thanks
> Saurabh Agarwal
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org