commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rahul Akolkar" <rahul.akol...@gmail.com>
Subject Re: [SCXML] two scxml questions
Date Sat, 12 Jul 2008 02:29:54 GMT
On 7/11/08, Wolfgang Rabl <wolfgang.rabl@maven.at> wrote:
> Thanks very much, that was quite illustrating!
>
>  When working with custom actions, is it possible to pass over parameters
> other than Strings? Within the custom action implementation i get all the
> parameters and the childtagcontent as Strings and have to retrieve the
> corresponding datamodel information out of the scInstance parameter of the
> execute function. Is this the way to go or is there a simpler solution to
> pass over the parameters directly?
>
<snip/>

Instead of retrieving the corresponding datamodel (if that is indeed
what you are doing), you can use the expression evaluator [
scInstance.getEvaluator() ] instead. The former limits you to name
resolution, the latter gives you first-class expression evaluation.
You can see how that is used by looking at sources for existing
actions in the model package, for example, Var.java.

I will claim that there is no such thing as passing parameters
directly (its still passing strings, just that the strings are
expressions which are evaluated). Some environments have tricks that
enable them to pattern-match attribute values as being expressions
while other environments do this by providing additional meta-data
about attribute values being literal or expressions. The first is out
of question for custom actions (Commons SCXML supports pluggable ELs
so there isn't a single pattern to match) and its probably not any
easier to have another mechanism to describe where attributes values
are literals or not. Basically, the semantics of each attribute are
upto the custom action (and its implementation).

-Rahul


>  So for example if i have a scxml file i get foo and foo.bar only as strings
> and not as the objects they represent:
>
>    <state id="test">
>                <datamodel>
>                    <data name="foo"/>
>                </datamodel>
>               <onentry>
>                      <customAction1 param1="foo">
>                            <param2>foo.bar</param2>
>                      </customAction1>
>              </onentry>
>    </state>
>
>
>  thanks
>  Wolfgang
>
>
>  Rahul Akolkar schrieb:
>
> > On 7/9/08, Wolfgang Rabl <wolfgang.rabl@maven.at> wrote:
> >
> >
> >
> > > Hello,
> > >
> > >  Yes i will try the custom actions, but i dont think it would be a good
> idea
> > > to contribute my solution because I am quite unexperienced and it would
> not
> > > be a very good one :/ But i will see...
> > >
> > >  Nevertheless I have one further question regarding custom actions. As
> > > stated in
> > >
> http://commons.apache.org/scxml/guide/custom-actions.html
> > > it is possible to declare child Tags within the custom action if one
> > > implements the ExternalConten Interface. Are there any Examples for
> that? I
> > > do not know how to implement the necessary getExternalNodes() function.
> > > Whats the purpose of it? Is it to define the allowed childtags? and if
> so
> > > how are they defined? And how do i get access to the childtags within
> the
> > > execute funktion? It would realy be great if you could point me to an
> > > example implementation.
> > >
> > >
> > >
> > <snip/>
> >
> > Its easier to work without child tags, if possible (often, its not, so
> > see text below :-).
> >
> > Say you have a custom action like so (the semantics are not important
> > for the purposes of explaining the parsing):
> >
> >  <my:action>
> >      <my:foo/>
> >      <my:bar/>
> >  </my:action>
> >
> > Then the skeleton of the backing Action class may be implemented as:
> >
> >  public static class MyAction extends Action implements ExternalContent {
> >
> >    private List<Node> nodes = new ArrayList<Node>();
> >
> >    @Override
> >    public List<Node> getExternalNodes() {
> >      // this will be populated at parse time and used at execution time
> >      return nodes;
> >    }
> >
> >    @Override
> >    public void execute(...) throws ... {
> >      // Execute <my:action>, whatever the semantics are given
> >      // the child nodes.
> >      for (Node n : nodes) {
> >        // In this case, above loop executes twice since the "nodes"
> >        // list contains <my:foo/> and <my:bar/>
> >      }
> >    }
> >
> >  }
> >
> > -Rahul
> >
> >
> >
> >
> > >  thanks
> > >  Wolfgang
> > >
> > >
> > >
> > >
> > <snap/>

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


Mime
View raw message