[jboss-user] [JBoss jBPM] - dynamic commands

gogoasa do-not-reply at jboss.com
Tue Sep 18 17:29:54 EDT 2007


Hello,

Even if the predefined Commands that can be thrown at the CommandService are pretty rich, it would be nice to be able to throw any code you can think of, without the need to lookup the sources of the various Commands and try to figure out which combination would do the thing you want.

It would make sense then to use dynamic languages like Groovy or Beanshell to specify the command. A simple BeanShell-only command :

public class BshCommand implements Command {
  | 
  | 	protected String code;
  | 	
  | 	public BshCommand(String code) {
  | 		this.setCode(code);
  | 	}
  | 	
  | 	public Object execute(JbpmContext jbpmContext) throws Exception {
  | 		Interpreter interpreter = new Interpreter();
  | 		interpreter.set("jbpmContext", jbpmContext);
  | 		Object result = interpreter.eval(this.getCode());
  | 		return result;
  | 	}
  | 
  | 	public String getCode() {
  | 		return code;
  | 	}
  | 
  | 	public void setCode(String code) {
  | 		this.code = code;
  | 	}
  | 
  | }
  | 

which could be used like this :

Command cmd = new BshCommand("return jbpmContext.getProcessInstance(5);");
  | Object resp = service.execute(cmd);

As bsh is already a dependency, I think the possibilies of querying a remote ejb  would be greatly enhanced by just adding this command.

Using BSF the BshCommand could actually be named ScriptCommand and might execute any other cool scripting languages...

Best regards,
Adrian.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4085755#4085755

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4085755



More information about the jboss-user mailing list