3 Replies Latest reply on Nov 26, 2008 10:29 AM by Ronald van Kuijk

    ProcessState getSubProcessDefinition is null

    Don Tjandra Newbie

      Hi, I'm trying to access the sub-process child node of a process-state. My test program is listed below. I call getSubProcessDefinition and always get null. Any ideas what I'm doing wrong?

      import java.util.HashMap;
      import java.util.Map;
      
      import junit.framework.TestCase;
      
      import org.dom4j.Element;
      import org.jbpm.graph.def.ProcessDefinition;
      import org.jbpm.graph.node.ProcessState;
      import org.jbpm.graph.node.SubProcessResolver;
      
      public class TestSubprocess extends TestCase {
      
       private static class MapBasedProcessRepository implements SubProcessResolver {
       private Map<String,ProcessDefinition> processes =
       new HashMap<String,ProcessDefinition>();
      
       public void add(ProcessDefinition processDefinition) {
       processes.put(processDefinition.getName(), processDefinition);
       }
      
       @Override
       public ProcessDefinition findSubProcess(Element element) {
       // TODO Auto-generated method stub
       return processes.get(element.attributeValue("name"));
       }
      
       }
      
       public void testProcessInstance() {
       MapBasedProcessRepository subProcessResolver = new MapBasedProcessRepository();
       ProcessDefinition subProcessDefinition = ProcessDefinition.parseXmlString(
       "<process-definition name='sub-p'>" +
       " <start-state>" +
       " <transition to='s' />" +
       " </start-state>" +
       " <state name='s'>" +
       " <transition to='t'/>" +
       " </state>" +
       " <state name='t'>" +
       " <transition to='end'/>" +
       " </state>" +
       " <end-state name='end' />" +
       "</process-definition>"
       );
       subProcessResolver.add( subProcessDefinition );
      
       subProcessDefinition = ProcessDefinition.parseXmlString(
       "<process-definition name='sub-q'>" +
       " <start-state>" +
       " <transition to='s' />" +
       " </start-state>" +
       " <state name='s'>" +
       " <transition to='t'/>" +
       " </state>" +
       " <state name='t'>" +
       " <transition to='end'/>" +
       " </state>" +
       " <end-state name='end' />" +
       "</process-definition>"
       );
       subProcessResolver.add( subProcessDefinition );
      
       ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
       "<process-definition name='super'>" +
       " <start-state name='start'>" +
       " <transition to='p' />" +
       " </start-state>" +
       " <process-state name='p'>" +
       " <sub-process name='sub-p' binding='late'/>" +
       " <transition to='q' />" +
       " </process-state>" +
       " <process-state name='q'>" +
       " <sub-process name='sub_q' binding='late' />" +
       " <transition to='end' />" +
       " </process-state>" +
       " <end-state name='end' />" +
       "</process-definition>"
       );
       subProcessResolver.add( processDefinition );
      
       ProcessState.setDefaultSubProcessResolver(subProcessResolver);
       ProcessState processState = (ProcessState) processDefinition.getNode("p");
       System.out.println(processState);
       System.out.println(processState.getSubProcessDefinition());
      
       processState = (ProcessState) processDefinition.getNode("q");
       System.out.println(processState);
       System.out.println(processState.getSubProcessDefinition());
       }
      }
      


        • 1. Re: ProcessState getSubProcessDefinition is null
          Ronald van Kuijk Master

          that might be caused by the binding='late' I think. Try what happens if you start one process or what happens if you remove the binding is late. Not that that is the solution, just curious.

          • 2. Re: ProcessState getSubProcessDefinition is null
            Don Tjandra Newbie

            I tried without late binding and got same result. However after looking at the unit test it seems the subprocess need to be set explicitly and the superprocess then persisted in the database.

            // create the subprocess
             ProcessDefinition subProcessDefinition = new ProcessDefinition("sub");
             // store the subprocess in the database
             graphSession.saveProcessDefinition(subProcessDefinition);
            
             // create the super process
             ProcessDefinition superProcessDefinition = ProcessDefinition.parseXmlString(
             "<process-definition name='super'>" +
             " <process-state name='subprocess' />" +
             "</process-definition>");
             // resolve the reference to the subprocess
             ProcessState processState = (ProcessState) superProcessDefinition.getNode("subprocess");
             processState.setSubProcessDefinition(subProcessDefinition);
            
             // save and reload the superprocess
             superProcessDefinition = saveAndReload(superProcessDefinition);
            
             processState = (ProcessState) superProcessDefinition.getNode("subprocess");
             assertNotNull("sub", processState.getSubProcessDefinition().getName());
            


            • 3. Re: ProcessState getSubProcessDefinition is null
              Ronald van Kuijk Master

              hmmm I would not have expected this to be necessary when using your own subprocessresolver... but then again.. I'm not familiar with all the details of jBPM