[SCXML] Context not visible ( Picking up values ) in the StateMachine.
Hi All , I need your help in getting the Context in my Custom Action Class. Here is the scenario: 1. I have a SIP Servlet (MainPOCAS) , In the servlet I am parsing a SCXML file and making a SCXML object out of that file . Then I make the Context ( tried SImpleContext , JexlContext ) and set it using StopClock clock=new StopClock(scxml); clock.getEngine().setRootContext((Context) jc); If I try retrieving the Context variable in the same class I can vey well retrieve it . 2. But when I try to retrieve the contest i my StateMachine Class , I get the value NULL , I am not able to understand why . What i think is that since I had set the root context of the scxml object I should be able to retrieve the context . Please let me know if there is any gap in my understanding . I am attaching the source code ( copy pasted from various examples from commons-scxml site ) MainPocAS ( SipServlet ) , StopClock.java ( StateMachine Class) Hello.java ( Custom Action class ). /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package PocAS; import java.io.IOException; import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.sip.Proxy; import javax.servlet.sip.SipErrorEvent; import javax.servlet.sip.SipErrorListener; import javax.servlet.sip.SipServlet; import javax.servlet.sip.SipServletRequest; import javax.servlet.sip.SipServletResponse; import java.io.IOException; import java.net.URL; import java.util.AbstractMap; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.apache.commons.jexl.JexlContext; import org.apache.commons.jexl.JexlHelper; import org.apache.commons.scxml.Context; import org.apache.commons.scxml.PathResolver; import org.apache.commons.scxml.SCXMLExecutor; import org.apache.commons.scxml.env.SimpleContext; import org.apache.commons.scxml.env.SimpleErrorHandler; import org.apache.commons.scxml.env.servlet.ServletContextResolver; import org.apache.commons.scxml.io.SCXMLParser; import org.apache.commons.scxml.model.CustomAction; import org.apache.commons.scxml.model.Event; import org.apache.commons.scxml.model.ModelException; import org.apache.commons.scxml.model.SCXML; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.ext.DefaultHandler2; import org.xml.sax.helpers.DefaultHandler; /** * * @author sauragar */ @javax.servlet.sip.annotation.SipServlet public class MainPocAS extends javax.servlet.sip.SipServlet implements SipErrorListener,Servlet { private static final long serialVersionUID = 3978425801979081269L; //Reference to context - The ctx Map is used as a central storage for this app javax.servlet.ServletContext ctx = null; 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,Saurabh ); SimpleContext sc=new SimpleContext(aMap); JexlContext jc = JexlHelper.createContext(); jc.setVars(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/CUSTOM1;, hello, Hello.class); CustomAction ca1 = new CustomAction(http://my.custom-actions.domain/CUSTOM2;, bar, Hello.class); customActions.add(ca); customActions.add(ca1); // (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((Context) jc); Context RCtx= clock.getEngine().getRootContext(); System.out.println( In Main Root Context ::+ RCtx.toString());
JXPath over Generic Collection?, How?
Hi All, Hopefully the solution is as easy as the question. I would like to perform evaluation on a (very simple) generic collection... as you can see below (HeirarchyPojo). I should be able to ask for a HeirarchyPojo's with name='Bill' or the 3rd Child... The problem is that nothing ever evaluate on this data structure. What's the deal with Generic Collections and JXPath? p.s this is not in the userguide and would be a most welcomed addition (if we can nut this out with your help). Cheers. package xpath.and.generics; import java.util.ArrayList; public class HeirarchyPojo extends ArrayListHeirarchyPojo{ public HeirarchyPojo(){} private String id; private String name; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
Re: JXPath - is JXPath dead in the water?
Hi Matt + Others, Thanks for your replies! I've taken your advice and re-seeded my question on a brand new thread with subject JXPath over Generic Collection?, How?. If anyone can help with this I would be MOST appreciative. Also, I am happy to contribute back to the project with examples if I can get some svn access. Big thanks, and hopefully you can please read my other post (fingers crossed). Andrew. On Tue, Feb 3, 2009 at 9:24 AM, Matt Benson gudnabr...@yahoo.com wrote: --- Adrian Mitev adrian.mi...@googlemail.com wrote: On Mon, Feb 2, 2009 at 5:10 PM, Matt Benson gudnabr...@yahoo.com wrote: --- Andrew Hughes ahhug...@gmail.com wrote: Hi All, Is JXPath dead in the water? I can't find a post here in 2009 and very limited posts in 2008. Hi Andrew, JXPath is considered to be in maintenance mode. In general, this means that this component is considered to be more or less complete and that for the most part, changes to the code will target bugs. Specifically with regard to JXPath, any new features considered would address shortcomings with support for the XPath 1.0 specification. If you encounter issues with JXPath feel free to post your questions to this list; if you don't get an answer the first time just keep pushing! ;) HTH, Matt Will XPath2 be supported in the near future? Originally that was under consideration, but to be honest everything I personally know about XPath (1.0) I learned in the course of supporting JXPath, so as JXPath's primary maintainer I presently don't consider myself capable of making such an upgrade. There is an open JIRA issue for XPath 2.0 support: http://issues.apache.org/jira/browse/JXPATH-67; further if you or anyone else has ideas on this feel free to start a discussion thread on d...@commons.apache.org (the real convention on these mailing lists is to preface your subject with the component ID e.g. [jxpath] XPath 2 support). A nice start might be a boiled-down list of the basic differences between versions 1 and 2. -Matt - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [SCXML] Context not visible ( Picking up values ) in the StateMachine.
On Sun, Feb 8, 2009 at 1:04 PM, Saurabh Agarwal sagarwal1...@gmail.com wrote: Hi Rahul , Thanks for such a quick reply: 1. Yeah I had come code to print context in constructor but actually I am testing it in reset() method of StopClock before which I had set the constructor. But alas then also I am not able to get the context Please help . snip/ AbstractStateMachine sets the underlying SCXMLExecutor in motion in the constructor (effectively). So the initial state (reset, in this case) is reached before the root context is set to the one you supply. If you fire another event after you set the root context, you will see the values you have supplied. 2. About the second thing I am not much clear , What I understand is thar you dont want me to use StopClock ( extending AbstractStateMachine ) . I dont understand the reason . What I want that when a event is fired , I want to do some functionality , Which I can do via extending AbstractStateMachine , Is my understanding wrong . snap/ Its correct, as long as you understand the limitations of using that base class (it isn't meant to be a solution for all scenarios -- you can ofcourse look at its source and create a variant for your needs). -Rahul Please help clarifying the above . Thanks for your time . Thanks Regards Saurabh On Sun, Feb 8, 2009 at 11:01 PM, Rahul Akolkar rahul.akol...@gmail.comwrote: On Sun, Feb 8, 2009 at 11:56 AM, Saurabh Agarwal sagarwal1...@gmail.com wrote: Hi All , I need your help in getting the Context in my Custom Action Class. Here is the scenario: 1. I have a SIP Servlet (MainPOCAS) , In the servlet I am parsing a SCXML file and making a SCXML object out of that file . Then I make the Context ( tried SImpleContext , JexlContext ) and set it using StopClock clock=new StopClock(scxml); snip/ At a quick glance it seems you are trying to retrieve the values in the context in the constructor above, but these are set in the line below. There are several other, more important things that jump out. I'm afraid I don't have much time ATM (you can take a deeper dive into the guide on the website), but the higher order bit is that it isn't necessary to create a AbstractStateMachine subclass and also instantiate SCXMLExecutor instances -- they are mutually exclusive patterns. The AbstractStateMachine class is meant for simple or introductory usecases, follows a specific usage pattern and doesn't require much knowledge of the Commons SCXML API. I wouldn't use it for any kind of SIP integration. -Rahul clock.getEngine().setRootContext((Context) jc); If I try retrieving the Context variable in the same class I can vey well retrieve it . 2. But when I try to retrieve the contest i my StateMachine Class , I get the value NULL , I am not able to understand why . What i think is that since I had set the root context of the scxml object I should be able to retrieve the context . Please let me know if there is any gap in my understanding . I am attaching the source code ( copy pasted from various examples from commons-scxml site ) MainPocAS ( SipServlet ) , StopClock.java ( StateMachine Class) Hello.java ( Custom Action class ). /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package PocAS; import java.io.IOException; import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.sip.Proxy; import javax.servlet.sip.SipErrorEvent; import javax.servlet.sip.SipErrorListener; import javax.servlet.sip.SipServlet; import javax.servlet.sip.SipServletRequest; import javax.servlet.sip.SipServletResponse; import java.io.IOException; import java.net.URL; import java.util.AbstractMap; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.apache.commons.jexl.JexlContext; import org.apache.commons.jexl.JexlHelper; import org.apache.commons.scxml.Context; import org.apache.commons.scxml.PathResolver; import org.apache.commons.scxml.SCXMLExecutor; import org.apache.commons.scxml.env.SimpleContext; import org.apache.commons.scxml.env.SimpleErrorHandler; import org.apache.commons.scxml.env.servlet.ServletContextResolver; import org.apache.commons.scxml.io.SCXMLParser; import org.apache.commons.scxml.model.CustomAction; import org.apache.commons.scxml.model.Event; import org.apache.commons.scxml.model.ModelException; import org.apache.commons.scxml.model.SCXML; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.ext.DefaultHandler2; import org.xml.sax.helpers.DefaultHandler; /** * * @author sauragar */ @javax.servlet.sip.annotation.SipServlet public class MainPocAS extends