You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Nestor Urquiza <ne...@yahoo.com> on 2006/04/28 16:34:29 UTC

[scxml] adding an xml to the datamodel

Hello guys,
Here I am trying to include my external xml file into
the model using the snippet posted by Fasih:

//byteArraySettingsFileContent has the external xml
file content 
Data scenarioData = new Data();
//I need to understand how to set a node here with the
content of the above file.
/* The Fasih sippet was for setting up String
variables:
scenarioData.setName(Constants.SCENARIO_ID_PARAM);
scenarioData.setExpr("the content of the var here");  
         
scxml.setDatamodel(new Datamodel());
scxml.getDatamodel().addData(scenarioData);

Thanks you all,
Nestor

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [scxml] adding an xml to the datamodel

Posted by Nestor Urquiza <ne...@yahoo.com>.

--- Rahul Akolkar <ra...@gmail.com> wrote:

> On 4/28/06, Nestor Urquiza <ne...@yahoo.com>
> wrote:
> > Hello guys,
> > Here I am trying to include my external xml file
> into
> > the model using the snippet posted by Fasih:
> >
> > //byteArraySettingsFileContent has the external
> xml
> > file content
> > Data scenarioData = new Data();
> > //I need to understand how to set a node here with
> the
> > content of the above file.
> <snip/>
> 
> I have only glanced at this thread, maybe I missed
> something. You can
> obtain the org.w3.dom.Node instance whatever way you
> want and place it
> in the root context to achieve the same effect
> you're trying below. It
> doesn't have to be a <data> element (or Data class,
> if procedurally
> injected).

If I create the org.w3.dom.Node and I put the node
into a context variable foo, how can I access a
node/attribute using XPATH then?
Is something like
condition="foo/specificNode/@specificAttribute eq
'bar'" going to work?

> 
> The expression language evaluator doesn't know, nor
> does it care,
> where the "variable" came from -- whether it was a
> <var> / Var or
> <data> / Data or Context#setLocal() / set(), its all
> the same to the
> expression language.
> 
> Ofcourse, I need to write the data model section to
> the user guide so
> this is public knowledge. I'm out this weekend, if
> you want to post a
> ticket in bugzilla, it will be guaranteed to stay on
> our radar.
> 

Added Bug#:   	 39450

> There is one subtle difference between <var> and
> <data> with respect
> to the way an SCXMLExecutor instance resets itself.
> 
>  * <var>s being "scratch space" are deleted / lost
> on reset
> (Context#setLocal() / set() behaves the same way)
> 
>  * <data>s being part of the first class data model
> defined for a
> state, get reset to their initial value
> 
> But, the reset functionality is probably rarely used
> (and should be
> used with quite a bit of caution).
> 

Cool, in any case for some reason Data() is not
working for me when I insert a node using Digester.
Below my code that follows the reccomendations given
by Fasih:
(bSettingsFileContent  is a byte array with the
contents of my settings.xml file)

................

Digester digester = new Digester();
            digester.push( this );
            digester.addRule("datamodel", new
NodeCreateRule());
            digester.addSetNext("datamodel",
"addDataToModel");
            digester.parse(new ByteArrayInputStream(
bSettingsFileContent ));

...................

public void addDataToModel(Element e) {
     Data d = new Data();
     d.setNode(e);
     this.scxml.getDatamodel().addData(d);
  }

The node is inserted in the datamodel as I see while
debugging, however given the settings.xml file:

<datamodel>
	<data name="bubp">
		<root>
			<bubp>
				<client clientId="mk1" clientPswd="passmk1"
appType="SP">


the following does not work from my scxml file:

<n:if cond="Data('bubp', 'root/bubp/client/@appType')
eq 'SP'">

It does not work either if I put <bubp> as the root
node in my settings.xml file

Thanks!

> -Rahul
> 
> 
> > /* The Fasih sippet was for setting up String
> > variables:
> > scenarioData.setName(Constants.SCENARIO_ID_PARAM);
> > scenarioData.setExpr("the content of the var
> here");
> >
> > scxml.setDatamodel(new Datamodel());
> > scxml.getDatamodel().addData(scenarioData);
> >
> > Thanks you all,
> > Nestor
> >
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [scxml] adding an xml to the datamodel

Posted by Nestor Urquiza <ne...@yahoo.com>.
absolutely, thanks!

--- Rahul Akolkar <ra...@gmail.com> wrote:

> On 4/30/06, Nestor Urquiza <ne...@yahoo.com>
> wrote:
> > I finally got it ;-) and you said it already, the
> > datamodel is there in memory holding everything,
> not
> > only the special <datamodel> tag defined in the
> scxml
> > specs but also the context attached to the
> executor.
> >
> > So I was missing two lines in my addDataToModel()
> > below
> >
> > Node node = d.getNode();
> > rootCtx.set("bubp", node);
> >
> <snip/>
> 
> Or (for the sake of the mailing list archives), if
> you want to inject
> data (the earlier approach), replace the two lines
> above by:
> 
> d.setName("bubp");
> scxml.getDatamodel().addData(d);
> 
> i.e. need to explicitly set the name which will be
> used to refer to
> the <data> in expressions later.
> 
> Thanks for filing the related documentation bug
> 39450, will get to it
> in a day or two.
> 
> -Rahul
> 
> 
> > then I will answer my question:
> >
> > Given a settings file:
> >
> > <bubp>
> > <client clientId="mk1" clientPswd="passmk1"
> > appType="SP">
> > ........
> >
> > The condition to test if appType is equal to SP
> using
> > jexl is:
> >
> > <n:if cond="Data(bubp, 'client/@appType') eq
> 'SP'">
> > ........
> >
> > Thanks both of you guys!,
> > Nestor
> >
> >
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [scxml] adding an xml to the datamodel

Posted by Rahul Akolkar <ra...@gmail.com>.
On 4/30/06, Nestor Urquiza <ne...@yahoo.com> wrote:
> I finally got it ;-) and you said it already, the
> datamodel is there in memory holding everything, not
> only the special <datamodel> tag defined in the scxml
> specs but also the context attached to the executor.
>
> So I was missing two lines in my addDataToModel()
> below
>
> Node node = d.getNode();
> rootCtx.set("bubp", node);
>
<snip/>

Or (for the sake of the mailing list archives), if you want to inject
data (the earlier approach), replace the two lines above by:

d.setName("bubp");
scxml.getDatamodel().addData(d);

i.e. need to explicitly set the name which will be used to refer to
the <data> in expressions later.

Thanks for filing the related documentation bug 39450, will get to it
in a day or two.

-Rahul


> then I will answer my question:
>
> Given a settings file:
>
> <bubp>
> <client clientId="mk1" clientPswd="passmk1"
> appType="SP">
> ........
>
> The condition to test if appType is equal to SP using
> jexl is:
>
> <n:if cond="Data(bubp, 'client/@appType') eq 'SP'">
> ........
>
> Thanks both of you guys!,
> Nestor
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [scxml] adding an xml to the datamodel

Posted by Nestor Urquiza <ne...@yahoo.com>.
I finally got it ;-) and you said it already, the
datamodel is there in memory holding everything, not
only the special <datamodel> tag defined in the scxml
specs but also the context attached to the executor.

So I was missing two lines in my addDataToModel()
below   

Node node = d.getNode();
rootCtx.set("bubp", node);

then I will answer my question:

Given a settings file:

<bubp>
<client clientId="mk1" clientPswd="passmk1"
appType="SP">
........

The condition to test if appType is equal to SP using
jexl is:

<n:if cond="Data(bubp, 'client/@appType') eq 'SP'">
........

Thanks both of you guys!,
Nestor



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [scxml] adding an xml to the datamodel

Posted by Nestor Urquiza <ne...@yahoo.com>.

--- Rahul Akolkar <ra...@gmail.com> wrote:

> On 4/28/06, Nestor Urquiza <ne...@yahoo.com>
> wrote:
> > Hello guys,
> > Here I am trying to include my external xml file
> into
> > the model using the snippet posted by Fasih:
> >
> > //byteArraySettingsFileContent has the external
> xml
> > file content
> > Data scenarioData = new Data();
> > //I need to understand how to set a node here with
> the
> > content of the above file.
> <snip/>
> 
> I have only glanced at this thread, maybe I missed
> something. You can
> obtain the org.w3.dom.Node instance whatever way you
> want and place it
> in the root context to achieve the same effect
> you're trying below. It
> doesn't have to be a <data> element (or Data class,
> if procedurally
> injected).

If I create the org.w3.dom.Node and I put the node
into a context variable foo, how can I access a
node/attribute using XPATH then?
Is something like
condition="foo/specificNode/@specificAttribute eq
'bar'" going to work?

> 
> The expression language evaluator doesn't know, nor
> does it care,
> where the "variable" came from -- whether it was a
> <var> / Var or
> <data> / Data or Context#setLocal() / set(), its all
> the same to the
> expression language.
> 
> Ofcourse, I need to write the data model section to
> the user guide so
> this is public knowledge. I'm out this weekend, if
> you want to post a
> ticket in bugzilla, it will be guaranteed to stay on
> our radar.
> 

Added Bug#:   	 39450

> There is one subtle difference between <var> and
> <data> with respect
> to the way an SCXMLExecutor instance resets itself.
> 
>  * <var>s being "scratch space" are deleted / lost
> on reset
> (Context#setLocal() / set() behaves the same way)
> 
>  * <data>s being part of the first class data model
> defined for a
> state, get reset to their initial value
> 
> But, the reset functionality is probably rarely used
> (and should be
> used with quite a bit of caution).
> 

Cool, in any case for some reason Data() is not
working for me when I insert a node using Digester.
Below my code that follows the reccomendations given
by Fasih:
(bSettingsFileContent  is a byte array with the
contents of my settings.xml file)

................

Digester digester = new Digester();
            digester.push( this );
            digester.addRule("datamodel", new
NodeCreateRule());
            digester.addSetNext("datamodel",
"addDataToModel");
            digester.parse(new ByteArrayInputStream(
bSettingsFileContent ));

...................

public void addDataToModel(Element e) {
     Data d = new Data();
     d.setNode(e);
     this.scxml.getDatamodel().addData(d);
  }

The node is inserted in the datamodel as I see while
debugging, however given the settings.xml file:

<datamodel>
	<data name="bubp">
		<root>
			<bubp>
				<client clientId="mk1" clientPswd="passmk1"
appType="SP">


the following does not work from my scxml file:

<n:if cond="Data('bubp', 'root/bubp/client/@appType')
eq 'SP'">

It does not work either if I put <bubp> as the root
node in my settings.xml file

Thanks!

> -Rahul
> 
> 
> > /* The Fasih sippet was for setting up String
> > variables:
> > scenarioData.setName(Constants.SCENARIO_ID_PARAM);
> > scenarioData.setExpr("the content of the var
> here");
> >
> > scxml.setDatamodel(new Datamodel());
> > scxml.getDatamodel().addData(scenarioData);
> >
> > Thanks you all,
> > Nestor
> >
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [scxml] adding an xml to the datamodel

Posted by Rahul Akolkar <ra...@gmail.com>.
On 4/28/06, Nestor Urquiza <ne...@yahoo.com> wrote:
> Hello guys,
> Here I am trying to include my external xml file into
> the model using the snippet posted by Fasih:
>
> //byteArraySettingsFileContent has the external xml
> file content
> Data scenarioData = new Data();
> //I need to understand how to set a node here with the
> content of the above file.
<snip/>

I have only glanced at this thread, maybe I missed something. You can
obtain the org.w3.dom.Node instance whatever way you want and place it
in the root context to achieve the same effect you're trying below. It
doesn't have to be a <data> element (or Data class, if procedurally
injected).

The expression language evaluator doesn't know, nor does it care,
where the "variable" came from -- whether it was a <var> / Var or
<data> / Data or Context#setLocal() / set(), its all the same to the
expression language.

Ofcourse, I need to write the data model section to the user guide so
this is public knowledge. I'm out this weekend, if you want to post a
ticket in bugzilla, it will be guaranteed to stay on our radar.

There is one subtle difference between <var> and <data> with respect
to the way an SCXMLExecutor instance resets itself.

 * <var>s being "scratch space" are deleted / lost on reset
(Context#setLocal() / set() behaves the same way)

 * <data>s being part of the first class data model defined for a
state, get reset to their initial value

But, the reset functionality is probably rarely used (and should be
used with quite a bit of caution).

-Rahul


> /* The Fasih sippet was for setting up String
> variables:
> scenarioData.setName(Constants.SCENARIO_ID_PARAM);
> scenarioData.setExpr("the content of the var here");
>
> scxml.setDatamodel(new Datamodel());
> scxml.getDatamodel().addData(scenarioData);
>
> Thanks you all,
> Nestor
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org