<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Re: dataInputAssociation <assignment> expressions
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/marnold">M Arnold</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/648375#648375">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hi,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I spend a little time working this out.  Sorry about the long post.  I took some notes, which I have reproduced below in case it helps anyone. I used jBPM 5.2.0 Final (the latest version at Jan 2012).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>It's all a bit weird... so I still think I'm doing something fundamentally wrong, because the way it works is hard to understand, and furthermore, it's hard to imagine anyone being able to use it as it is currently.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>If you create a simple WorkItemHandler like the class below:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><code><p>          public final class EchoWorkItemHandler implements WorkItemHandler {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                     @Override</p><p>                     public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {</p><p>                                Map<String, Object> parameters = workItem.getParameters(); </p><p>                                for (String parameterName : parameters.keySet()) {</p><p>                                           System.out.println("parameter: " + parameterName + </p><p>                                                            " is type " + parameters.get(parameterName).getClass().getCanonicalName() + </p><p>                                                            " and has value " + parameters.get(parameterName).toString());</p><p>                                } </p><p>                     }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                     @Override</p><p>                     public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {</p><p>                     }</p><p>          }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></code></p><p>Start a process like this, note the globals: one String, one BigDecimal, one org.w3c.dom.Node (from the BPMN2 document itself): </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><code><p>          Map<String, Object> parameters = new HashMap<String, Object>();</p><p>          parameters.put("globalString", "GLOBALSTRING");</p><p>          parameters.put("globalDecimal", new BigDecimal("1234.56"));</p><p>          parameters.put("globalNode", doc.getDocumentElement());                              // Put a the DOM of the BPMN2 file itself</p><p>     StatefulKnowledgeSession ksession = null;</p><p>          try {</p><p>                    ksession = kbase.newStatefulKnowledgeSession();</p><p>                    ksession.getWorkItemManager().registerWorkItemHandler("echoParameters", new EchoWorkItemHandler());</p><p>                    ksession.startProcess(processName, parameters);      </p><p>          } finally {</p><p>                    if (ksession != null) ksession.dispose();</p><p>          } </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></code></p><p>And the business process you execute is like this:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><code><p>          <?xml version="1.0" encoding="UTF-8"?></p><p><span>          <definitions xmlns:xsi="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a><span>"</span></p><p><span>                                   xmlns="</span><a class="jive-link-external-small" href="http://www.omg.org/spec/BPMN/20100524/MODEL" target="_blank">http://www.omg.org/spec/BPMN/20100524/MODEL</a><span>" </span></p><p><span>                                   xmlns:bpmndi="</span><a class="jive-link-external-small" href="http://www.omg.org/spec/BPMN/20100524/DI" target="_blank">http://www.omg.org/spec/BPMN/20100524/DI</a><span>"</span></p><p><span>                                   xmlns:dc="</span><a class="jive-link-external-small" href="http://www.omg.org/spec/DD/20100524/DC" target="_blank">http://www.omg.org/spec/DD/20100524/DC</a><span>" </span></p><p><span>                                   xmlns:di="</span><a class="jive-link-external-small" href="http://www.omg.org/spec/DD/20100524/DI" target="_blank">http://www.omg.org/spec/DD/20100524/DI</a><span>"</span></p><p><span>                                   xmlns:g="</span><a class="jive-link-external-small" href="http://www.jboss.org/drools/flow/gpd" target="_blank">http://www.jboss.org/drools/flow/gpd</a><span>" </span></p><p><span>                                   xmlns:tns="</span><a class="jive-link-external-small" href="http://www.jboss.org/drools" target="_blank">http://www.jboss.org/drools</a><span>"</span></p><p><span>                                   xsi:schemaLocation="</span><a class="jive-link-external-small" href="http://www.omg.org/spec/BPMN/20100524/MODEL" target="_blank">http://www.omg.org/spec/BPMN/20100524/MODEL</a><span> BPMN20.xsd"</span></p><p>                                   id="Definition" </p><p><span>                                   expressionLanguage="</span><a class="jive-link-external-small" href="http://www.mvel.org/2.0" target="_blank">http://www.mvel.org/2.0</a><span>"</span></p><p><span>                                   targetNamespace="</span><a class="jive-link-external-small" href="http://www.jboss.org/drools" target="_blank">http://www.jboss.org/drools</a><span>" </span></p><p><span>                                   typeLanguage="</span><a class="jive-link-external-small" href="http://www.java.com/javaTypes" target="_blank">http://www.java.com/javaTypes</a><span>"></span></p><p>                    <process id="com.xxxxx.processes.testDataInputAssociation" name="testDataInputAssociation" isExecutable="true" processType="Private"></p><p>                              <property id="globalString" itemSubjectRef="tns:_globalString" /></p><p>                              <property id="globalDecimal" itemSubjectRef="tns:_globalDecimal" /></p><p>                              <property id="globalNode" itemSubjectRef="tns:_globalNode" /></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                              <startEvent id="_1" name="Start"></p><p>                                        <outgoing>_1-_4</outgoing></p><p>                              </startEvent></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                              <task id="_4" tns:taskName="echoParameters" name="echo1"></p><p>                                        <incoming>_1-_4</incoming></p><p>                                        <outgoing>_4-_9</outgoing></p><p>                                        <ioSpecification id="InputOutputSpecification_4"></p><p>                                                  <dataInput id="_4_messageInput" name="messageIn" /> </p><p>                                                  <inputSet id="InputSet_1"></p><p>                                                            <dataInputRefs>_4_messageInput</dataInputRefs> </p><p>                                                  </inputSet></p><p>                                                  <outputSet /></p><p>                                        </ioSpecification></p><p>                                        <dataInputAssociation id="DataInputAssociation_4"></p><p>                                                  <sourceRef>globalDecimal</sourceRef></p><p>                                                  <targetRef>_4_messageInput</targetRef></p><p>                                        </dataInputAssociation> </p><p>                              </task></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                              <endEvent id="_9" name="End"></p><p>                                        <incoming>_4-_9</incoming></p><p>                                        <terminateEventDefinition id="TerminateEventDefinition_1" /></p><p>                              </endEvent></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                              <sequenceFlow id="_1-_4" sourceRef="_1" targetRef="_4" /></p><p>                              <sequenceFlow id="_4-_9" sourceRef="_4" targetRef="_9" /></p><p>                    </process></p><p>          </definitions></p></code></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Then what you get to System.out depends on the <dataInputAssociation>.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>1. If you have <sourceRef> and <targetRef> and no <assignment>, then the variable referred to by <sourceRef> will be copied to the variable referred to by <targetRef></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><code><p>          <dataInputAssociation id="DataInputAssociation_4"></p><p>                    <sourceRef>globalDecimal</sourceRef></p><p>                    <targetRef>_4_messageInput</targetRef></p><p>          </dataInputAssociation></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          parameter: messageIn is type java.math.BigDecimal and has value 1234.56</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          <dataInputAssociation id="DataInputAssociation_4"></p><p>                    <sourceRef>globalString</sourceRef></p><p>                    <targetRef>_4_messageInput</targetRef></p><p>          </dataInputAssociation></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          parameter: messageIn is type java.lang.String and has value GLOBALSTRING</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></code></p><p>2. If you have no <sourceRef> but a <targetRef> and a <assignment>, then whatever text you have in the <from> will be copied into the variable referred to by <targetRef>, so you'll always get a java.lang.String.  Anything you have in the <to> is completely ignored.  </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><code><p>          <dataInputAssociation id="DataInputAssociation_4"></p><p>                    <targetRef>_4_messageInput</targetRef></p><p>                    <assignment id="Assignment_1"></p><p>                              <from xsi:type="tFormalExpression" id="FormalExpression_1">VALUE</from></p><p>                              <to xsi:type="tFormalExpression" id="FormalExpression_2">This Is Ignored</to></p><p>                    </assignment></p><p>          </dataInputAssociation></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          parameter: messageIn is type java.lang.String and has value VALUE</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></code></p><p>3.1.1. If you have a <sourceRef> and a <targetRef> and an <assignment>, then the text in in the <from> and the <to> MUST be a valid XPath (must compile), but how they're used depends on the class of the variable referred to by <sourceRef>.  Check class org.jbpm.bpmn2.xpath.XPATHAssigmentAction. If <sourceRef> is an instanceof org.w3c.dom.Node, then <from> is an XPath expression which will select a part of the XML document from the variable referred to by <sourceRef>.  If selects an attribute, the variable referred to by <sourceRef> will be a java.lang.String with the attribute's value. If the variable referred to <targetRef> is null (would be for a <dataInputAssociation> for a <task>) then <to> ignored (but still must be a valid XPath!)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><code><p>          <dataInputAssociation id="DataInputAssociation_4"></p><p>                    <sourceRef>globalNode</sourceRef></p><p>                    <targetRef>_4_messageInput</targetRef></p><p>                    <assignment id="Assignment_1"></p><p>                              <from xsi:type="tFormalExpression" id="FormalExpression_1">/definitions/process/@name</from></p><p>                              <to xsi:type="tFormalExpression" id="FormalExpression_2">ThisOnlyHasToBeAValidXPathButIsIgnored</to> --></p><p>                    </assignment></p><p>          </dataInputAssociation></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          parameter: messageIn is type java.lang.String and has value testDataInputAssociation</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></code></p><p>3.1.2. If <sourceRef> is an instanceof org.w3c.dom.Node and <from> selects a text node, the variable referred to by <targetRef> will be a java.lang.String with the text node's text value. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><code><p>          <dataInputAssociation id="DataInputAssociation_4"></p><p>                    <sourceRef>globalNode</sourceRef></p><p>                    <targetRef>_4_messageInput</targetRef></p><p>                    <assignment id="Assignment_1"></p><p>                              <from xsi:type="tFormalExpression" id="FormalExpression_1">/definitions/process/task/ioSpecification/inputSet/dataInputRefs/text()</from></p><p>                              <to xsi:type="tFormalExpression" id="FormalExpression_2">ThisOnlyHasToBeAValidXPathButIsIgnored</to> --></p><p>                    </assignment></p><p>          </dataInputAssociation></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          parameter: messageIn is type java.lang.String and has value _4_messageInput</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></code></p><p>3.1.3. If <sourceRef> is an instanceof org.w3c.dom.Node and <from> selects any other single Node, the variable referred to by <targetRef> will be the single Node. (Using xerces as DOM implementation.)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><code><p>          <dataInputAssociation id="DataInputAssociation_4"></p><p>                    <sourceRef>globalNode</sourceRef></p><p>                    <targetRef>_4_messageInput</targetRef></p><p>                    <assignment id="Assignment_1"></p><p>                              <from xsi:type="tFormalExpression" id="FormalExpression_1">/definitions/process/task/ioSpecification/inputSet/dataInputRefs/text()</from></p><p>                              <to xsi:type="tFormalExpression" id="FormalExpression_2">ThisOnlyHasToBeAValidXPathButIsIgnored</to> --></p><p>                    </assignment></p><p>          </dataInputAssociation></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          parameter: messageIn is type org.apache.xerces.dom.ElementImpl and has value [dataInputRefs: null]</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></code></p><p>3.1.4. If <sourceRef> is an instanceof org.w3c.dom.Node and <from> selects multiple Nodes... haven't checked this yet!  </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>3.2. If <sourceRef> is an instanceof java.lang.String, then its value will be copied to the variable referred to by <targetRef>.  The <from> and <to> XPath expressions are ignored.  (But they still must be valid XPath expressions!) </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><code><p>          <dataInputAssociation id="DataInputAssociation_4"></p><p>                    <sourceRef>globalString</sourceRef></p><p>                    <targetRef>_4_messageInput</targetRef></p><p>                    <assignment id="Assignment_1"></p><p>                              <from xsi:type="tFormalExpression" id="FormalExpression_1">ThisOnlyHasToBeAValidXPathButIsIgnored</from></p><p>                              <to xsi:type="tFormalExpression" id="FormalExpression_2">ThisOnlyHasToBeAValidXPathButIsIgnored</to></p><p>                    </assignment> </p><p>          </dataInputAssociation> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          parameter: messageIn is type java.lang.String and has value GLOBALSTRING</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></code></p><p>3.3. If <sourceRef> is any other class (not instanceof org.w3c.dom.Node or java.lang.String) then you get a NullPointerException.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><code><p>          <dataInputAssociation id="DataInputAssociation_4"></p><p>                    <sourceRef>globalDecimal</sourceRef></p><p>                    <targetRef>_4_messageInput</targetRef></p><p>                    <assignment id="Assignment_1"></p><p>                              <from xsi:type="tFormalExpression" id="FormalExpression_1">ThisOnlyHasToBeAValidXPathButIsIgnored</from></p><p>                              <to xsi:type="tFormalExpression" id="FormalExpression_2">ThisOnlyHasToBeAValidXPathButIsIgnored</to></p><p>                    </assignment> </p><p>          </dataInputAssociation></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          [snip]</p><p>          Caused by: java.lang.NullPointerException</p><p>          at org.jbpm.bpmn2.xpath.XPATHAssignmentAction.execute(XPATHAssignmentAction.java:91)</p><p>          at org.jbpm.workflow.instance.node.WorkItemNodeInstance.handleAssignment(WorkItemNodeInstance.java:193)</p><p>          ... 17 more</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></code></p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/648375#648375">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>