commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Schwager" <Daniel.Schwa...@dtnet.de>
Subject AW: [SCXML] JEXL, object setter does not work ?
Date Fri, 18 Jul 2008 08:03:56 GMT
Hi Rahul,

> <Daniel.Schwager@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


Mime
View raw message