[jbpm-commits] JBoss JBPM SVN: r5950 - in jbpm4/trunk/modules: devguide/src/main/docbook/en/modules and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Dec 11 05:55:27 EST 2009


Author: tom.baeyens at jboss.com
Date: 2009-12-11 05:55:27 -0500 (Fri, 11 Dec 2009)
New Revision: 5950

Removed:
   jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/examples/rules/process.png
Modified:
   jbpm4/trunk/modules/api/src/main/resources/jpdl-4.3.xsd
   jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch02-Incubation.xml
   jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/examples/rules/process.jpdl.xml
Log:
JBPM-2006 rules activity docs and xsd

Modified: jbpm4/trunk/modules/api/src/main/resources/jpdl-4.3.xsd
===================================================================
--- jbpm4/trunk/modules/api/src/main/resources/jpdl-4.3.xsd	2009-12-11 09:57:40 UTC (rev 5949)
+++ jbpm4/trunk/modules/api/src/main/resources/jpdl-4.3.xsd	2009-12-11 10:55:27 UTC (rev 5950)
@@ -203,7 +203,6 @@
                   </extension>
                 </complexContent>
               </complexType>
-              <!-- TODO add conditions -->
             </element>
           </sequence>
           <attributeGroup ref="tns:activityAttributes" />
@@ -479,7 +478,7 @@
         </complexType>
       </element>
 
-      <!-- ~~~ group ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
+      <!-- ~~~ GROUP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
       <element name="group">
         <annotation><documentation>Scope enclosing a number of activities.
         </documentation></annotation>
@@ -496,6 +495,69 @@
           <attributeGroup ref="tns:activityAttributes" />
         </complexType>
       </element>
+      
+      <!-- ~~~ RULES DECISION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
+      <element name="rules-decision">
+        <annotation><documentation>Selects one outgoing transition based on evaluation of rules.
+        </documentation></annotation>
+        <complexType>
+          <sequence>
+            <element name="description" minOccurs="0" type="string" />
+            <element ref="tns:transition" minOccurs="0" maxOccurs="unbounded" />
+            <element ref="tns:on" minOccurs="0" maxOccurs="unbounded">
+              <annotation><documentation>Events on which listeners can be registered.</documentation></annotation>
+            </element>
+          </sequence>
+          <attributeGroup ref="tns:activityAttributes" />
+        </complexType>
+      </element>
+
+      <!-- ~~~ RULES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
+      <element name="rules">
+        <annotation><documentation>Evaluates rules after feeding in some facts in a stateful knowledge session.
+        </documentation></annotation>
+        <complexType>
+          <sequence>
+            <element name="description" minOccurs="0" type="string" />
+            <element name="fact" minOccurs="0" maxOccurs="unbounded">
+              <complexType>
+                <attribute name="var" type="string" />
+                <attribute name="expr" type="string" />
+              </complexType>
+            </element>
+            <element name="transition" minOccurs="0" maxOccurs="unbounded">
+              <complexType>
+                <complexContent>
+                  <extension base="tns:transitionType">
+                    <sequence>
+                      <element name="condition" minOccurs="0" maxOccurs="unbounded">
+                        <complexType>
+                          <sequence>
+                            <element name="handler" minOccurs="0" type="tns:wireObjectType" />
+                          </sequence>
+                          <attribute name="expr" type="string">
+                            <annotation><documentation>The script text that will be evaluated.  
+                            </documentation></annotation>
+                          </attribute>
+                          <attribute name="lang" type="string">
+                            <annotation><documentation>Identification of the scripting language 
+                            to use.</documentation></annotation>
+                          </attribute>
+                        </complexType>
+                      </element>
+                    </sequence>
+                  </extension>
+                </complexContent>
+              </complexType>
+            </element>
+            <element ref="tns:on" minOccurs="0" maxOccurs="unbounded">
+              <annotation><documentation>Events on which listeners can be registered.</documentation></annotation>
+            </element>
+          </sequence>
+          <attributeGroup ref="tns:activityAttributes" />
+        </complexType>
+      </element>
+
     </choice>
   </group>
   

Modified: jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch02-Incubation.xml
===================================================================
--- jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch02-Incubation.xml	2009-12-11 09:57:40 UTC (rev 5949)
+++ jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch02-Incubation.xml	2009-12-11 10:55:27 UTC (rev 5950)
@@ -645,6 +645,10 @@
     </para>
     <para>Let's look at the next example how that works in practice.  We'll start 
     with the <literal>RulesDecision</literal> process</para>
+    <figure id="process.rules.decision">
+      <title>The rules decision example process</title>
+      <mediaobject><imageobject><imagedata align="center" fileref="images/process.rules.decision.png"/></imageobject></mediaobject>
+    </figure>
     <programlisting>&lt;process name=&quot;RulesDecision&quot;&gt;
 
   &lt;start&gt;
@@ -719,7 +723,134 @@
     <literal>13 Tempranillo</literal>s will go to 
     activity <literal>analyseManually</literal> </para>
   </section>
+
+  <!-- ### RULES ####################################################### -->
+  <section id="rules">
+    <title><literal>rules</literal> activity</title>
+    <para>A <literal>rules</literal> is an automatic activity that will 
+    create a stateful knowledge session, feed a number of facts in it and 
+    fire all rules.  The idea is that the rules will update or create 
+    process variables that will be used later in the process.  Facts 
+    can be specified as sub elements of the rules activity.
+    </para>
+    <table><title><literal>rules</literal> elements:</title>
+      <tgroup cols="3" rowsep="1" colsep="1">
+        <thead>
+          <row>
+            <entry>Element</entry>
+            <entry>Multiplicity</entry>
+            <entry>Description</entry>
+          </row>
+        </thead>
+        <tbody>
+          <row>
+            <entry><literal>fact</literal></entry>
+            <entry>0..*</entry>
+            <entry>A fact that will be fed into the stateful rule session.
+            </entry>
+          </row>
+        </tbody>
+      </tgroup>
+    </table>
+    <table><title><literal>fact</literal> attributes:</title>
+      <tgroup cols="5" rowsep="1" colsep="1">
+        <thead>
+          <row>
+            <entry>Attribute</entry>
+            <entry>Type</entry>
+            <entry>Default</entry>
+            <entry>Required?</entry>
+            <entry>Description</entry>
+          </row>
+        </thead>
+        <tbody>
+          <row>
+            <entry>var</entry>
+            <entry>variable name</entry>
+            <entry></entry>
+            <entry>either <literal>var</literal> or <literal>expr</literal> is required</entry>
+            <entry>the variable name for which the value should be inserted as a fact.  
+            </entry>
+          </row>
+          <row>
+            <entry>expr</entry>
+            <entry>expression</entry>
+            <entry></entry>
+            <entry>either <literal>var</literal> or <literal>expr</literal> is required</entry>
+            <entry>the expression for which the resulting value should be inserted as a fact.  
+            </entry>
+          </row>
+        </tbody>
+      </tgroup>
+    </table>
+    <para>If a rules activity has one outgoing transition, then that one is 
+    taken automatically.  But multiple outgoing transitions can be specified
+    with conditions on them, just like with the <literal>decision</literal> activity
+    when using the conditions. 
+    </para>
+    <para>For example:</para>
+    <figure id="process.rules">
+      <title>The rules example process</title>
+      <mediaobject><imageobject><imagedata align="center" fileref="images/process.rules.png"/></imageobject></mediaobject>
+    </figure>
+    <programlisting>&lt;process name=&quot;Rules&quot;&gt;
+
+  &lt;start&gt;
+    &lt;transition to=&quot;evaluateStatus&quot;/&gt;
+  &lt;/start&gt;
+
+  <emphasis role="bold">&lt;rules name=&quot;evaluateStatus&quot;&gt;
+    &lt;fact var=&quot;room&quot; /&gt;
+    &lt;transition to=&quot;checkForFires&quot;/&gt;
+  &lt;/rules&gt;</emphasis>
+
+  &lt;decision name=&quot;checkForFires&quot;&gt;
+    &lt;transition to=&quot;getFireExtinguisher&quot;&gt;
+      &lt;condition expr=&quot;#{room.onFire}&quot; /&gt;
+    &lt;/transition&gt;
+    &lt;transition to=&quot;goToPub&quot;/&gt;
+  &lt;/decision&gt;
+
+  &lt;state name=&quot;getFireExtinguisher&quot;/&gt;
+  &lt;state name=&quot;goToPub&quot;/&gt;
+
+&lt;/process&gt;</programlisting>
+    <para>The process first checks with rules if the room is on fire.
+    The Room class looks like this:</para>
+    <programlisting>public class Room implements Serializable {
+
+  int temperature = 21; 
+  boolean smoke = false;
+  boolean isOnFire = false;
   
+  public Room(int temperature, boolean smoke) {
+    this.temperature = temperature;
+    this.smoke = smoke;
+  }
+  
+  ...getters and setters...
+}</programlisting>
+    <para>Following rules are deployed in the same business archive:</para>
+    <programlisting>rule &quot;CheckRoomOnFire&quot;
+  when
+    room : org.jbpm.examples.rules.Room( temperature &gt; 30, smoke == true )
+  then 
+    room.setOnFire( true );
+end</programlisting>
+   <para>So when a new <literal>Rules</literal> process instance is started 
+   like this:</para>
+   <programlisting>Map&lt;String, Object&gt; variables = new HashMap&lt;String, Object&gt;();
+variables.put(&quot;room&quot;, new Room(350, true));
+
+ProcessInstance processInstance = 
+    executionService.startProcessInstanceByKey(&quot;Rules&quot;, variables);</programlisting>
+    <para>Then the process will end up in the activity <literal>getFireExtinguisher</literal>
+    </para>
+    <para>And when the process is started with a Room(21, false), it will end up in the 
+    activity <literal>goToPub</literal>
+    </para>
+  </section>
+  
   <section>
     <title>Creating identity groups</title>
     <para>The identity service methods to create groups are based on 

Modified: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/examples/rules/process.jpdl.xml
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/examples/rules/process.jpdl.xml	2009-12-11 09:57:40 UTC (rev 5949)
+++ jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/examples/rules/process.jpdl.xml	2009-12-11 10:55:27 UTC (rev 5950)
@@ -1,14 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
-<process name="Rules" xmlns="http://jbpm.org/4/jpdl">
+<process name="Rules" xmlns="http://jbpm.org/4.3/jpdl">
 
 	<start g="49,93,80,40">
     <transition to="evaluateStatus"/>
 	</start>
 
 	<rules name="evaluateStatus">
-	  <fact var="room" />
-    <transition to="checkForFires"/>
+    <fact var="room" />
+    <transition to="checkForFires" />
 	</rules>
 
   <decision g="215,93,80,40" name="checkForFires">

Deleted: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/examples/rules/process.png
===================================================================
(Binary files differ)



More information about the jbpm-commits mailing list