You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Daniel Schwager <Da...@dtnet.de> on 2008/07/16 21:12:30 UTC

[SCXML] JEXL, object setter does not work ?

Hi Rahul,

i created a statemachine with an JEXL context. In 
my XML-description, I do the following:

	....
	<onentry>
		<log	expr="'job said: ' + job.stateInformation" />
		<assign name="job.stateInformation" expr="'SET MY
JOB'"/>
	</onentry>
	....

The context has injected an object Bean-Job with the property
stateInformation.
The setter/getter are available:
		StateMachineJob smJob = new StateMachineJob();
		smJob.setStateInformation ("OK - DONE");
		sm.setVariable("job", smJob);

If i run the automat, i got:
	INFO - null: job said: OK - DONE
	WARN - UNDEFINED_VARIABLE (job.stateInformation = null):

So, I'm not able to set my job.setStateInformation() ...
If I try the same with a normal "String" variable instead of an object
with setter/getter, 
the assignment works fine.

Did I miss something ?

regards
Danny


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


AW: [SCXML] JEXL, object setter does not work ?

Posted by Daniel Schwager <Da...@dtnet.de>.
Hi Rahul,

> <Da...@dtnet.de> wrote:
> > Hi Rahul,
> >
> > i created a statemachine with an JEXL context. In
> > my XML-description, I do the following:
> > .....
> > So, I'm not able to set my job.setStateInformation() ...
> 

> Von: Rahul Akolkar
> Usage for <assign> is really limited to the variants described at the
> bottom of this page:
> 
>   http://commons.apache.org/scxml/guide/datamodel.html
> 
> It is not intelligent enough to do the kind of property assignment
> you're attempting here. It will take the "name" to be the variable
> name in its entirety and not attempt to parse it in any fashion.
> 
> When using JEXL, I'd recommend implementing a <jexl:script> custom
> action and solving a broad suite of such issues. Using the
> ScriptFactory [1] API in JEXL 1.1 that should be fairly trivial.
> 
> Ofcourse, JEXL allows you to call the setter directly i.e.
> job.setStateInformation('SOME INFO') as the expression.
> 

Great idea - the action is realy simple !!
	<state id="state1">
		<onentry>
			<jexl:script command="z=4+5 ; x=x+1"/>
			<jexl:script command="job.setJobName('HALLO')"
outputvar="out"/>
			<log label="output" expr="'show z:'+z" />
			<log label="output" expr="'show x:'+x" />
			<log label="output" expr="'show out:'+out" />
		</onentry>
	</state>
Thanks for this.

Regards
Danny


public class JexlScriptAction extends Action {
	private static final long serialVersionUID = 1L;

	private String command;
	private String outputvar;

	public JexlScriptAction() {
		super();
	}

	public void execute(final EventDispatcher evtDispatcher,
			final ErrorReporter errRep, final SCInstance
scInstance,
			final Log appLog, final Collection
derivedEvents)
			throws ModelException, SCXMLExpressionException
{
		try {
			Script script =
ScriptFactory.createScript(command);
			Object result = script.execute((JexlContext)
scInstance
					.getRootContext());
			if (outputvar != null)
	
scInstance.getRootContext().getVars().put(outputvar, result);
		} catch (Exception e) {
			String err = "Execution of jexl-script:' " +
command + "' failed: "
					+ e.getMessage();
			errRep.onError("DTS02", err, null);
		}

	}
	public String getCommand() {
		return command;
	}
	public void setCommand(String command) {
		this.command = command;
	}
	public String getOutputvar() {
		return outputvar;
	}
	public void setOutputvar(String outputVar) {
		this.outputvar = outputVar;
	}
}

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


Re: [SCXML] JEXL, object setter does not work ?

Posted by Rahul Akolkar <ra...@gmail.com>.
On Wed, Jul 16, 2008 at 3:12 PM, Daniel Schwager
<Da...@dtnet.de> wrote:
> Hi Rahul,
>
> i created a statemachine with an JEXL context. In
> my XML-description, I do the following:
>
>        ....
>        <onentry>
>                <log    expr="'job said: ' + job.stateInformation" />
>                <assign name="job.stateInformation" expr="'SET MY
> JOB'"/>
>        </onentry>
>        ....
>
> The context has injected an object Bean-Job with the property
> stateInformation.
> The setter/getter are available:
>                StateMachineJob smJob = new StateMachineJob();
>                smJob.setStateInformation ("OK - DONE");
>                sm.setVariable("job", smJob);
>
> If i run the automat, i got:
>        INFO - null: job said: OK - DONE
>        WARN - UNDEFINED_VARIABLE (job.stateInformation = null):
>
> So, I'm not able to set my job.setStateInformation() ...
> If I try the same with a normal "String" variable instead of an object
> with setter/getter,
> the assignment works fine.
>
> Did I miss something ?
>
<snip/>

Usage for <assign> is really limited to the variants described at the
bottom of this page:

  http://commons.apache.org/scxml/guide/datamodel.html

It is not intelligent enough to do the kind of property assignment
you're attempting here. It will take the "name" to be the variable
name in its entirety and not attempt to parse it in any fashion.

When using JEXL, I'd recommend implementing a <jexl:script> custom
action and solving a broad suite of such issues. Using the
ScriptFactory [1] API in JEXL 1.1 that should be fairly trivial.

Ofcourse, JEXL allows you to call the setter directly i.e.
job.setStateInformation('SOME INFO') as the expression.

-Rahul

[1] http://commons.apache.org/jexl/apidocs-1.1/org/apache/commons/jexl/ScriptFactory.html


> regards
> Danny
>
>

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


Re: Answer: AW: [SCXML] JEXL, object setter does not work ?

Posted by Rahul Akolkar <ra...@gmail.com>.
On Wed, Jul 16, 2008 at 4:39 PM, Daniel Schwager
<Da...@dtnet.de> wrote:
> Hi,
>
> here we are - this is a bug in jexl ...
>        https://issues.apache.org/jira/browse/JEXL-27
>
<snip/>

For the archives, theres more to it than that (see post a few minutes ago).

-Rahul


>
> regards
> Danny
>
>

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


Answer: AW: [SCXML] JEXL, object setter does not work ?

Posted by Daniel Schwager <Da...@dtnet.de>.
Hi,

here we are - this is a bug in jexl ...
	https://issues.apache.org/jira/browse/JEXL-27

 
regards
Danny


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