6 Replies Latest reply on Jun 21, 2006 1:11 PM by ccrouch

    specifying context variables through the process definition

    ccrouch

      Forgive the newbie question...

      Looking at the jpdl schema it doesn't appear that there is a way to directly specify (inject) process context variables from the process definition itself. The nearest you can come is to specify a property on a delegation class such as an Action e.g.

      <action class='MyActionHandler'>
       <source>PATCH_ZIP/jboss2.jar</source>
       </action>


      Is this a deliberate design decision or did I miss seomthing?

      The use case I have is that I would like to define generic sub processes, and then add multiple instances of them to my super process, having each one vary in the values of a couple of context variables. But the best I can do is:

      <process-definition name='super'>
       ...
       <process-state name='p'>
       <sub-process name='sub' />
       <variable name='a' access='read' mapped-name='A' />
       </process-state>
      </process-definition>


      When in fact I really want to be able to specify a value for 'a' in the process-state which would get passed into the 'sub' process.

      Thanks in advance


        • 1. Re: specifying context variables through the process definit
          aguizar

          We do not have a syntax for automatically substituting the value of a variable while initializing an action handler field. You can, however, interpret the literal from the process definition as a variable name and retrieve the variable value from the execution context:

          public class MyActionHandler implements ActionHandler {
          
           private String source;
          
           public void execute(ExecutionContext executionContext) {
           Object value = executionContext.getVariable(source);
           // ... do something with the variable value
           }
          }

          Your process definition would specify the variable name rather than a specific value:
          <action class='MyActionHandler'>
           <source>pathToPatch</source>
          </action>

          Regarding child processes, you can assign values from the variables of the parent process to the variables of the child process, but not literal values. In your scenario, you can pass the required values in variables and then use the above technique to access these values from action handlers.

          • 2. Re: specifying context variables through the process definit
            ccrouch

            I can get what I need by associating an action with a node-enter event on the process-state and then having that action copy properties into context variables, i.e.

            "<process-definition name='super'>" +
             " <start-state>" +
             " <transition to='p' />" +
             " </start-state>" +
             " <process-state name='p'>" +
             " <event type='node-enter'>" +
             " <action name='copy' class='org.jbpm.tutorial.action.CopyActionHandler'>" +
             " <backup>JBOSS_HOME/lib/jboss-${timestamp}.jar</backup>"+
             " </action>" +
             " </event>" +
             " <sub-process name='sub' />" +
             " <variable name='backup'/>" +
             " <transition to='end' />" +
             " </process-state>" +
             " <end-state name='end' />" +
             "</process-definition>"


            and in CopyActionHolder

            executionContext.getContextInstance().setVariable("backup", getBackup());


            and

            "<process-definition name='sub'>" +
             " <start-state>" +
             " <transition to='end' />" +
             " <event type='node-leave'>" +
             " <action class='org.jbpm.tutorial.action.MyActionHandler'>" +
             " <source>JBOSSboo</source>"+
             " </action>" +
             " </event>" +
             " </start-state>" +
             " <end-state name='end' />" +
             "</process-definition>"


            then in MyActionHandler I can do

            Object object = executionContext.getContextInstance().getVariable("backup");


            This approach works, but seems like a bit of a hack.

            Thanks

            • 3. Re: specifying context variables through the process definit
              koen.aers

              Charles,

              You are correct. This is not (yet) supported AFAIK. If you would like it, file a JIRA issue and pray to the jBPM God that he likes it ;-)

              Cheers,
              Koen

              • 4. Re: specifying context variables through the process definit
                kukeltje

                Amen

                (I've been told by one of the apostles that a bottle of Dutch beer helps)

                • 5. Re: specifying context variables through the process definit
                  koen.aers

                  Dutch beer? I don't think the beer God will approve :-))

                  • 6. Re: specifying context variables through the process definit
                    ccrouch