3 Replies Latest reply on Jul 2, 2009 5:09 AM by evilsephiroth

    JBPM BPEL 1.1.1 Getting variables of processInstance

    evilsephiroth

      Hi, i've been playing with JBPM BPEL 1.1.1. and deployed some workflow.

      My problem is that i can't get the name and the value of the variables that

      the workflow consumes...

      
      JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance("bpel.cfg.xml");
      JbpmContext context=jbpmConfiguration.createJbpmContext();
      ProcessInstance inst= cont.getProcessInstance(new Long(46)) //My process with 2 variables associated of type String
      Map varsMap=inst.getContextInstance().getVariables();
      
      


      With the code above i can get the variables but these variables are MessageValue and i don't know a generic mode to get the String value of

      the variables from this MessageValue. I've searched even in MessageValuePart but the data is in Binary..


      I don't know if there's a converter or helper that can translate from messageValue saved for every process instance in variables...



      Any help is appreciated.

        • 1. Re: JBPM BPEL 1.1.1 Getting variables of processInstance
          evilsephiroth

          up...

          No one has encountered this problem?

          • 2. Re: JBPM BPEL 1.1.1 Getting variables of processInstance
            dhanushgopinath

            I dont think there is any converter as of now.

            Here is how I did it

             JbpmContext jbpmContext = GetJbpmConfiguration().createJbpmContext();
             ProcessInstance processInstance = GetJbpmGraphSession(jbpmContext)
             .getProcessInstance(Long.parseLong(strProcessInstanceId));
            
             // Get the context instance
             ContextInstance processContextInstance = processInstance
             .getContextInstance();
             // get the all token variables map
             Map allTokenVariablsMap = processContextInstance.getTokenVariableMaps();
             // get the correct token for the variable
             Token tokenForVariable = GET THE CORRECT TOKEN HERE FROM THE MAP
             // get the variable from the context instance
             Object variable = processContextInstance.getVariable(strVariableName,
             tokenForVariable);
            
             // Variable will be an instance of MessageValue
             if (variable instanceof MessageValue) {
             MessageValue messageElement = (MessageValue) variable;
             Map partElems = messageElement.getParts();
            
             // Get the first Element
             String partName = (String) partElems.keySet().iterator().next();
             Element partElement = (Element) partElems.values().iterator()
             .next();


            The partElement is an XML Element . You can recurse through this and get the values using a DOM Parser.


            • 3. Re: JBPM BPEL 1.1.1 Getting variables of processInstance
              evilsephiroth

              yes i was doing something similar to get the variables. The problem is the parsing of the element. I want to implement a generic parser for all the processes deployed on the console. But every process has its implementation of variables so i can't effectively know in what node is the variable data(some in the first child, some other in nested childs).

              if (variable instanceof MessageValue) {
               MessageValue messageElement = (MessageValue) variable;
               Map partElems = messageElement.getParts();
              
               // Get the first Element
               String partName = (String) partElems.keySet().iterator().next();
               org.apache.xerces.dom.DeferredElementNSImpl partElement = (org.apache.xerces.dom.DeferredElementNSImpl) partElems.values().iterator()
               .next();
               String valueVar=partElement.getFirstChild().getFirstChild().getNodeValue();
               }


              This code won't work for all processes because in another process this line will be :

              valueVar=partElement.getFirstChild().getNodeValue();

              I was thinking a node searcher/comparer to variable Name but i hope something simpler will come out...

              any help is appreciated.