[jboss-user] [JBoss jBPM] - Re: how to find ProcessInstance current state or node

Johan.Parent do-not-reply at jboss.com
Wed Dec 26 11:40:02 EST 2007


Hi,

You can get the root token for your process. From there you can find out in which node(s) it resides.

A bit like below (this collects all the active nodes) but then again you'll need to do some instanceof work to see what type of node you actually got.


  | ...
  |  			ProcessInstance p = ctx.loadProcessInstance(id);
  | 			
  | 			// Second build a Set with all the active nodes in the process instance
  | 			Token t = p.getRootToken();
  | 			Map <String, Token> children = t.getChildren();
  | 			
  | 			// Put in the set
  | 			Set<Map.Entry<String,Token>> cSet = children.entrySet();
  | 			for (Iterator<Map.Entry<String,Token>> it = cSet.iterator(); it.hasNext();) {
  | 				Map.Entry<String,Token> e = it.next();
  | 				Token tok = e.getValue();
  | 				//
  | 				nodes.add(tok.getNode());
  | 			}
  | 			
  | 			
  | 			// Also add the node for this token (if any) to the set
  | 			Node here = t.getNode();
  | 			if (here != null)
  | 				nodes.add(here);
  | 
  | 
  | 


And oh yeah, since the hibernate proxies will get in the way of your instanceof logic you'll need to do something like below first (believe me ;)


  | 			// We need to this to access the real object otherwise
  | 			// we bump into the proxy object and instanceof won't work
  | 			if (nodeinstanceof HibernateProxy) {
  | 				node= ((HibernateProxy)node).getHibernateLazyInitializer().getImplementation();
  | 			}
  | 


Hope this helps,

Johan

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

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



More information about the jboss-user mailing list