[jboss-svn-commits] JBL Code SVN: r15338 - in labs/jbossrules/trunk/drools-compiler/src: main/java/org/drools/xml and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Sep 24 11:58:55 EDT 2007


Author: fmeyer
Date: 2007-09-24 11:58:55 -0400 (Mon, 24 Sep 2007)
New Revision: 15338

Modified:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/DrlDumper.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/AndHandler.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/OrHandler.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlDumper.java
   labs/jbossrules/trunk/drools-compiler/src/main/resources/META-INF/drools-4.0.xsd
   labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/lang/DRL.g
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/XmlPackageReaderTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseAccumulate.xml
Log:
JBRULES-1210 Implemented support to multi-pattern accumulate to the XML parser.

*related/parent  JBRULES-1040 

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/DrlDumper.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/DrlDumper.java	2007-09-24 15:42:49 UTC (rev 15337)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/DrlDumper.java	2007-09-24 15:58:55 UTC (rev 15338)
@@ -153,7 +153,11 @@
     public void visitAccumulateDescr(final AccumulateDescr descr) {
         String tmpstr = new String();
         tmpstr += " accumulate (";
-        visitPatternDescr( descr.getInputPattern() );
+        if ( descr.isSinglePattern() ) { 
+        	visitPatternDescr( descr.getInputPattern() );
+        } else {
+        	visit(descr.getInput());
+        }
         tmpstr += this.template.substring( 2 );
 
         if ( descr.isExternalFunction() ) {

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/AndHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/AndHandler.java	2007-09-24 15:42:49 UTC (rev 15337)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/AndHandler.java	2007-09-24 15:58:55 UTC (rev 15338)
@@ -20,11 +20,13 @@
 import java.util.LinkedList;
 import java.util.ListIterator;
 
+import org.drools.lang.descr.AccumulateDescr;
 import org.drools.lang.descr.AndDescr;
 import org.drools.lang.descr.ConditionalElementDescr;
 import org.drools.lang.descr.EvalDescr;
 import org.drools.lang.descr.ExistsDescr;
 import org.drools.lang.descr.ForallDescr;
+import org.drools.lang.descr.MultiPatternDestinationDescr;
 import org.drools.lang.descr.NotDescr;
 import org.drools.lang.descr.OrDescr;
 import org.drools.lang.descr.PatternDescr;
@@ -51,6 +53,7 @@
             this.validParents.add( RuleDescr.class );
             this.validParents.add( OrDescr.class );
             this.validParents.add( LiteralRestrictionHandler.class );
+            this.validParents.add( AccumulateDescr.class );
 
             this.validPeers = new HashSet();
             this.validPeers.add( null );
@@ -90,6 +93,9 @@
         if ( parent instanceof RuleDescr || parent instanceof QueryDescr ) {
             final RuleDescr ruleDescr = (RuleDescr) parent;
             ruleDescr.setLhs( andDescr );
+        } else if ( parent instanceof MultiPatternDestinationDescr) {
+        	final MultiPatternDestinationDescr mpDescr = (MultiPatternDestinationDescr) parent;
+        	mpDescr.setInput(andDescr);        	
         } else if ( parent instanceof ConditionalElementDescr ) {
             final ConditionalElementDescr ceDescr = (ConditionalElementDescr) parent;
             ceDescr.addDescr( andDescr );

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/OrHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/OrHandler.java	2007-09-24 15:42:49 UTC (rev 15337)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/OrHandler.java	2007-09-24 15:58:55 UTC (rev 15338)
@@ -20,6 +20,7 @@
 import java.util.LinkedList;
 import java.util.ListIterator;
 
+import org.drools.lang.descr.AccumulateDescr;
 import org.drools.lang.descr.AndDescr;
 import org.drools.lang.descr.ConditionalElementDescr;
 import org.drools.lang.descr.EvalDescr;
@@ -44,6 +45,7 @@
             this.validParents = new HashSet();
             this.validParents.add( AndDescr.class );
             this.validParents.add( PatternDescr.class );
+            this.validParents.add( AccumulateDescr.class );
 
             this.validPeers = new HashSet();
             this.validPeers.add( null );

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlDumper.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlDumper.java	2007-09-24 15:42:49 UTC (rev 15337)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlDumper.java	2007-09-24 15:58:55 UTC (rev 15338)
@@ -134,7 +134,13 @@
     public void visitAccumulateDescr(final AccumulateDescr descr) {
         String tmpstr = new String();
         tmpstr += this.template + " <from> <accumulate> ";
-        visit( descr.getInputPattern() );
+        
+        if ( descr.isSinglePattern() ) { 
+        	visitPatternDescr( descr.getInputPattern() );
+        } else {
+        	this.patternContext = false;
+        	visit(descr.getInput());
+        }
         tmpstr += this.template;
 
         if ( descr.isExternalFunction() ) tmpstr += "<external-function evaluator=\"" + descr.getFunctionIdentifier() + "\" expression=\"" + descr.getExpression() + "\"/>";

Modified: labs/jbossrules/trunk/drools-compiler/src/main/resources/META-INF/drools-4.0.xsd
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/resources/META-INF/drools-4.0.xsd	2007-09-24 15:42:49 UTC (rev 15337)
+++ labs/jbossrules/trunk/drools-compiler/src/main/resources/META-INF/drools-4.0.xsd	2007-09-24 15:58:55 UTC (rev 15338)
@@ -1,381 +1,332 @@
 <?xml version="1.0" encoding="UTF-8"?>
-        
-<xs:schema
-        xmlns:drools="http://drools.org/drools-4.0"
-        xmlns:xs="http://www.w3.org/2001/XMLSchema"
-        elementFormDefault="qualified"
-        targetNamespace="http://drools.org/drools-4.0">
-
-    <xs:element name="package">
-		<xs:complexType>
-			<xs:choice maxOccurs="unbounded" minOccurs="0">
-				<xs:element ref="drools:import"/>
-				<xs:element ref="drools:global"/>
-				<xs:element ref="drools:function"/>
-				<xs:element ref="drools:rule"/>
-				<xs:element ref="drools:query"/>
-			</xs:choice>
-			<xs:attribute name="name" type="xs:string" use="required"/>
-		</xs:complexType>
-	</xs:element>
-    
-    <xs:element name="rule">
-		<xs:complexType>
-			<xs:sequence>
-				<xs:element maxOccurs="unbounded" minOccurs="0" ref="drools:rule-attribute"/>
-				<xs:element ref="drools:lhs"/>
-				<xs:element ref="drools:rhs"/>
-			</xs:sequence>
-			<xs:attribute name="name" type="xs:string" use="required"/>
-		</xs:complexType>
-        <!-- All rules must have unique names -->
-		<xs:key name="ruleName">
-			<xs:selector xpath="drools:rule"/>
-			<xs:field xpath="@name"/>
-		</xs:key>
-	</xs:element>
-    
-    <xs:element name="query">
-		<xs:complexType>
-			<xs:sequence>
-				<xs:element ref="drools:lhs"/>
-			</xs:sequence>
-			<xs:attribute name="name" type="xs:string" use="required"/>
-		</xs:complexType>
-        <!-- All rules must have unique names -->
-		<xs:key name="queryName">
-			<xs:selector xpath="drools:query"/>
-			<xs:field xpath="@name"/>
-		</xs:key>
-	</xs:element>
-
-    <xs:element name="rule-attribute">
-		<xs:complexType>
-			<xs:attribute name="name" type="xs:string" use="required"/>
-			<xs:attribute name="value" type="xs:string" use="required"/>
-		</xs:complexType>
-	</xs:element>
-    
-    <xs:element name="import">
-		<xs:complexType>
-			<xs:attribute name="name" type="xs:string" use="required"/>
-		</xs:complexType>
-	</xs:element>
-    
-    <xs:element name="global">
-		<xs:complexType>
-			<xs:attribute name="type" type="xs:string" use="required"/>
-			<xs:attribute name="identifier" type="xs:string" use="required"/>
-		</xs:complexType>
-	</xs:element>
-	<xs:element name="function">
-		<xs:complexType>
-			<xs:sequence>
-				<xs:element maxOccurs="unbounded" minOccurs="0" ref="drools:parameter"/>
-				<xs:element name="body" type="xs:string"/>
-			</xs:sequence>
-			<xs:attribute name="name" type="xs:string" use="required"/>
-			<xs:attribute name="return-type" type="xs:string" use="required"/>
-		</xs:complexType>
-	</xs:element>
-	<xs:element name="parameter">
-		<xs:complexType>
-			<xs:attribute name="type" type="xs:string" use="required"/>
-			<xs:attribute name="identifier" type="xs:string" use="required"/>
-		</xs:complexType>
-	</xs:element>
-
-	<xs:element name="rhs" type="xs:string"/>
-
-	<xs:element name="lhs">
-		<xs:complexType>
-			<xs:choice maxOccurs="unbounded" minOccurs="0">
-                <xs:element ref="drools:abstractConditionalElement"/>
-                <xs:element ref="drools:not"/>
-				<xs:element ref="drools:exists"/>
-				<xs:element ref="drools:pattern"/>
-
-                <xs:element ref="drools:eval"/>
-                <xs:element ref="drools:forall"/>
-			</xs:choice>
-		</xs:complexType>
-	</xs:element>
-
-    <!-- Restriction Conective  -->
-    <xs:element name="abstractRestrictionConnective" type="drools:restrictionElementType" abstract="true"/>
-    <xs:element name="abstractConditionalElement" type="drools:conditionalElementType" abstract="true"/>
-    <xs:element name="abstractConstraintConective" type="drools:constraintConnectiveElementType" abstract="true"/>
-    
-    <xs:complexType name="restrictionElementType" >
-        <xs:choice maxOccurs="unbounded" minOccurs="0">
-            <xs:element ref="drools:literal-restriction"/>
-            <xs:element ref="drools:variable-restriction"/>
-            <xs:element ref="drools:return-value-restriction"/>
-            <xs:element ref="drools:qualified-identifier-restriction"/>
-        </xs:choice>
+<xs:schema xmlns:drools="http://drools.org/drools-4.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://drools.org/drools-4.0">
+  <xs:element name="package">
+    <xs:complexType>
+      <xs:choice maxOccurs="unbounded" minOccurs="0">
+        <xs:element ref="drools:import"/>
+        <xs:element ref="drools:global"/>
+        <xs:element ref="drools:function"/>
+        <xs:element ref="drools:rule"/>
+        <xs:element ref="drools:query"/>
+      </xs:choice>
+      <xs:attribute name="name" type="xs:string" use="required"/>
     </xs:complexType>
-
-    <xs:complexType name="conditionalElementType" >
-
-        <xs:choice maxOccurs="unbounded" minOccurs="0">
-            <xs:element ref="drools:not"/>
-            <xs:element ref="drools:exists"/>
-            <xs:element ref="drools:eval"/>
-            <xs:element ref="drools:pattern"/>
-        </xs:choice>
+  </xs:element>
+  <xs:element name="rule">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element maxOccurs="unbounded" minOccurs="0" ref="drools:rule-attribute"/>
+        <xs:element ref="drools:lhs"/>
+        <xs:element ref="drools:rhs"/>
+      </xs:sequence>
+      <xs:attribute name="name" type="xs:string" use="required"/>
     </xs:complexType>
-
-    <xs:complexType name="constraintConnectiveElementType" >
-        <xs:choice maxOccurs="unbounded" minOccurs="0">
-            <xs:element ref="drools:field-constraint"/>
-        </xs:choice>
+<!-- All rules must have unique names -->
+    <xs:key name="ruleName">
+      <xs:selector xpath="drools:rule"/>
+      <xs:field xpath="@name"/>
+    </xs:key>
+  </xs:element>
+  <xs:element name="query">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element ref="drools:lhs"/>
+      </xs:sequence>
+      <xs:attribute name="name" type="xs:string" use="required"/>
     </xs:complexType>
-
-    <xs:element name="and-restriction-connective" substitutionGroup="drools:abstractRestrictionConnective">
-        <xs:complexType>
-            <xs:complexContent>
-                <xs:extension base="drools:restrictionElementType">
-                    <xs:choice maxOccurs="unbounded" minOccurs="0" >
-                        <xs:element ref="drools:or-restriction-connective"/>
-                    </xs:choice>
-                </xs:extension>
-            </xs:complexContent>
-        </xs:complexType>
-    </xs:element>
-
-    <xs:element name="or-restriction-connective" substitutionGroup="drools:abstractRestrictionConnective">
-        <xs:complexType>
-            <xs:complexContent>
-                <xs:extension base="drools:restrictionElementType">
-                    <xs:choice maxOccurs="unbounded" minOccurs="0" >
-                        <xs:element ref="drools:and-restriction-connective"/>
-                    </xs:choice>
-                </xs:extension>
-            </xs:complexContent>
-        </xs:complexType>
-    </xs:element>
-
-
-    <!-- Conditional Element -->
-    <xs:element name="and-conditional-element" substitutionGroup="drools:abstractConditionalElement">
-        <xs:complexType>
-            <xs:complexContent>
-                <xs:extension base="drools:conditionalElementType">
-                    <xs:choice maxOccurs="unbounded" minOccurs="0" >
-                        <xs:element ref="drools:or-conditional-element"/>
-                    </xs:choice>
-                </xs:extension>
-            </xs:complexContent>
-        </xs:complexType>
-    </xs:element>
-
-    <xs:element name="or-conditional-element" substitutionGroup="drools:abstractConditionalElement">
-        <xs:complexType>
-            <xs:complexContent>
-                <xs:extension base="drools:conditionalElementType">
-                    <xs:choice maxOccurs="unbounded" minOccurs="0" >
-                        <xs:element ref="drools:and-conditional-element"/>
-                    </xs:choice>
-                </xs:extension>
-            </xs:complexContent>
-        </xs:complexType>
-    </xs:element>
-
-    <!-- Logical Connectives -->
-
-
-    <xs:element name="and-constraint-connective" substitutionGroup="drools:abstractConstraintConective">
-        <xs:complexType>
-            <xs:complexContent>
-                <xs:extension base="drools:constraintConnectiveElementType">
-                    <xs:choice maxOccurs="unbounded" minOccurs="0" >
-                        <xs:element ref="drools:or-constraint-connective"/>
-                    </xs:choice>
-                </xs:extension>
-            </xs:complexContent>
-        </xs:complexType>
-    </xs:element>
-
-    <xs:element name="or-constraint-connective" substitutionGroup="drools:abstractConstraintConective">
-        <xs:complexType>
-            <xs:complexContent>
-                <xs:extension base="drools:constraintConnectiveElementType">
-                    <xs:choice maxOccurs="unbounded" minOccurs="0" >
-                        <xs:element ref="drools:and-constraint-connective"/>
-                    </xs:choice>
-                </xs:extension>
-            </xs:complexContent>
-        </xs:complexType>
-    </xs:element>    
-
-
-    <xs:element name="not">
-		<xs:complexType>
-			<xs:choice maxOccurs="unbounded" minOccurs="1">
-                <xs:element ref="drools:abstractConditionalElement"/>
-
-                <xs:element ref="drools:not"/>
-                <xs:element ref="drools:exists"/>
-                <xs:element ref="drools:pattern"/>
-
-                <xs:element ref="drools:accumulate"/>
-                <xs:element ref="drools:collect"/>
-                <xs:element ref="drools:forall"/>
-            </xs:choice>
-		</xs:complexType>
-	</xs:element>
-
-	<xs:element name="exists">
-		<xs:complexType>
-			<xs:choice maxOccurs="unbounded" minOccurs="0">
-                <xs:element ref="drools:pattern"/>
-                <xs:element ref="drools:abstractConditionalElement"/>
-
-                <xs:element ref="drools:accumulate"/>
-                <xs:element ref="drools:collect"/>
-                <xs:element ref="drools:forall"/>                
-            </xs:choice>
-		</xs:complexType>
-	</xs:element>
-
-	<xs:element name="forall">
-		<xs:complexType>
-			<xs:choice maxOccurs="unbounded" minOccurs="0">
-				<xs:element ref="drools:pattern"/>
-			</xs:choice>
-		</xs:complexType>
-	</xs:element>
-
-    <xs:element name="collect">
-        <xs:complexType>
-            <xs:choice maxOccurs="1" minOccurs="1">
-                <xs:element ref="drools:pattern"/>
-            </xs:choice>
-        </xs:complexType>
-    </xs:element>
-
-    <xs:element name="expression" type="xs:string"/>
-
-    <xs:group name="accumulate">
-     <xs:sequence>
+<!-- All rules must have unique names -->
+    <xs:key name="queryName">
+      <xs:selector xpath="drools:query"/>
+      <xs:field xpath="@name"/>
+    </xs:key>
+  </xs:element>
+  <xs:element name="rule-attribute">
+    <xs:complexType>
+      <xs:attribute name="name" type="xs:string" use="required"/>
+      <xs:attribute name="value" type="xs:string" use="required"/>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="import">
+    <xs:complexType>
+      <xs:attribute name="name" type="xs:string" use="required"/>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="global">
+    <xs:complexType>
+      <xs:attribute name="type" type="xs:string" use="required"/>
+      <xs:attribute name="identifier" type="xs:string" use="required"/>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="function">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element maxOccurs="unbounded" minOccurs="0" ref="drools:parameter"/>
+        <xs:element name="body" type="xs:string"/>
+      </xs:sequence>
+      <xs:attribute name="name" type="xs:string" use="required"/>
+      <xs:attribute name="return-type" type="xs:string" use="required"/>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="parameter">
+    <xs:complexType>
+      <xs:attribute name="type" type="xs:string" use="required"/>
+      <xs:attribute name="identifier" type="xs:string" use="required"/>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="rhs" type="xs:string"/>
+  <xs:element name="lhs">
+    <xs:complexType>
+      <xs:choice maxOccurs="unbounded" minOccurs="0">
+        <xs:element ref="drools:abstractConditionalElement"/>
+        <xs:element ref="drools:not"/>
+        <xs:element ref="drools:exists"/>
         <xs:element ref="drools:pattern"/>
-        <xs:choice>
-            <xs:sequence>
-                <xs:element name="init" type="xs:string"/>
-                <xs:element name="action" type="xs:string"/>
-                <xs:element name="result" type="xs:string"/>
-            </xs:sequence>
-            <xs:element ref="drools:external-function"/>
-        </xs:choice>
-     </xs:sequence>
-    </xs:group>
-
-    <xs:element name="accumulate">
-        <xs:complexType>
-            <xs:choice maxOccurs="1" minOccurs="1">
-                <xs:group ref="drools:accumulate"/>
-            </xs:choice>
-        </xs:complexType>
-    </xs:element>
-
-    <xs:element name="from">
-        <xs:complexType>
-            <xs:choice maxOccurs="1">
-                <xs:element ref="drools:collect"/>
-                <xs:element ref="drools:expression"/>
-                <xs:element ref="drools:accumulate"/>
-            </xs:choice>
-        </xs:complexType>
-    </xs:element>
-
-	<xs:element name="eval" type="xs:string"/>
-
-    <xs:element name="pattern">
-		<xs:complexType>
-			<xs:choice maxOccurs="unbounded" minOccurs="0">
-				<xs:element ref="drools:field-binding"/>
-				<xs:element ref="drools:field-constraint"/>
-				<xs:element ref="drools:from"/>
-                <xs:element ref="drools:predicate"/>                
-                <xs:element ref="drools:abstractConstraintConective"/>                
-            </xs:choice>
-			<xs:attribute name="field-name" type="xs:string" use="optional"/>
-			<xs:attribute name="identifier" type="xs:string" use="optional"/>
-			<xs:attribute name="object-type" type="xs:string" use="required"/>
-		</xs:complexType>
-	</xs:element>
-
-	<xs:element name="field-constraint">
-		<xs:complexType>
-            <xs:complexContent>
-                <xs:extension base="drools:restrictionElementType">
-                    <xs:choice maxOccurs="unbounded" minOccurs="0" >
-                        <xs:element ref="drools:abstractRestrictionConnective"/>
-                    </xs:choice>
-                    <xs:attribute name="field-name" type="xs:string" use="required"/>
-                </xs:extension>
-            </xs:complexContent>
-		</xs:complexType>
-	</xs:element>
-
-	<xs:element name="field-binding">
-		<xs:complexType>
-			<xs:attribute name="field-name" type="xs:string" use="required"/>
-			<xs:attribute name="identifier" type="xs:string" use="required"/>
-		</xs:complexType>
-	</xs:element>
-
-    <xs:element name="literal-restriction">
-		<xs:complexType>
-			<xs:attribute name="evaluator" type="xs:string" use="required"/>
-			<xs:attribute name="value" type="xs:string" use="required"/>
-		</xs:complexType>
-	</xs:element>
-
-
-	<xs:element name="external-function">
-		<xs:complexType>
-			<xs:attribute name="evaluator" type="xs:string" use="required"/>
-			<xs:attribute name="expression" type="xs:string" use="required"/>
-		</xs:complexType>
-	</xs:element>
-
-    <xs:element name="variable-restriction">
-		<xs:complexType>
-			<xs:attribute name="evaluator" type="xs:string" use="required"/>
-			<xs:attribute name="identifier" type="xs:string" use="required"/>
-		</xs:complexType>
-	</xs:element>
-
-	<xs:element name="return-value-restriction">
-		<xs:complexType>
-			<xs:simpleContent>
-				<xs:extension base="xs:string">
-					<xs:attribute name="evaluator" type="xs:string" use="required"/>
-				</xs:extension>
-			</xs:simpleContent>
-		</xs:complexType>
-	</xs:element>
-
-    <xs:element name="qualified-identifier-restriction">
-        <xs:complexType>
-            <xs:simpleContent>
-                <xs:extension base="xs:string">
-                    <xs:attribute name="evaluator" type="xs:string" use="required"/>
-                </xs:extension>
-            </xs:simpleContent>
-        </xs:complexType>
-    </xs:element>
-
-    <xs:element name="predicate">
-        <xs:complexType>
-			<xs:simpleContent>
-				<xs:extension base="xs:string">
-                    <xs:attribute name="field-name" type="xs:string" use="optional"/>
-                    <xs:attribute name="identifier" type="xs:string" use="optional"/>
-                </xs:extension>
-			</xs:simpleContent>
-        </xs:complexType>
-    </xs:element>
-
+        <xs:element ref="drools:eval"/>
+        <xs:element ref="drools:forall"/>
+      </xs:choice>
+    </xs:complexType>
+  </xs:element>
+<!-- Restriction Conective  -->
+  <xs:element name="abstractRestrictionConnective" type="drools:restrictionElementType" abstract="true"/>
+  <xs:element name="abstractConditionalElement" type="drools:conditionalElementType" abstract="true"/>
+  <xs:element name="abstractConstraintConective" type="drools:constraintConnectiveElementType" abstract="true"/>
+  <xs:complexType name="restrictionElementType">
+    <xs:choice maxOccurs="unbounded" minOccurs="0">
+      <xs:element ref="drools:literal-restriction"/>
+      <xs:element ref="drools:variable-restriction"/>
+      <xs:element ref="drools:return-value-restriction"/>
+      <xs:element ref="drools:qualified-identifier-restriction"/>
+    </xs:choice>
+  </xs:complexType>
+  <xs:complexType name="conditionalElementType">
+    <xs:choice maxOccurs="unbounded" minOccurs="0">
+      <xs:element ref="drools:not"/>
+      <xs:element ref="drools:exists"/>
+      <xs:element ref="drools:eval"/>
+      <xs:element ref="drools:pattern"/>
+    </xs:choice>
+  </xs:complexType>
+  <xs:complexType name="constraintConnectiveElementType">
+    <xs:choice maxOccurs="unbounded" minOccurs="0">
+      <xs:element ref="drools:field-constraint"/>
+    </xs:choice>
+  </xs:complexType>
+  <xs:element name="and-restriction-connective" substitutionGroup="drools:abstractRestrictionConnective">
+    <xs:complexType>
+      <xs:complexContent>
+        <xs:extension base="drools:restrictionElementType">
+          <xs:choice maxOccurs="unbounded" minOccurs="0">
+            <xs:element ref="drools:or-restriction-connective"/>
+          </xs:choice>
+        </xs:extension>
+      </xs:complexContent>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="or-restriction-connective" substitutionGroup="drools:abstractRestrictionConnective">
+    <xs:complexType>
+      <xs:complexContent>
+        <xs:extension base="drools:restrictionElementType">
+          <xs:choice maxOccurs="unbounded" minOccurs="0">
+            <xs:element ref="drools:and-restriction-connective"/>
+          </xs:choice>
+        </xs:extension>
+      </xs:complexContent>
+    </xs:complexType>
+  </xs:element>
+<!-- Conditional Element -->
+  <xs:element name="and-conditional-element" substitutionGroup="drools:abstractConditionalElement">
+    <xs:complexType>
+      <xs:complexContent>
+        <xs:extension base="drools:conditionalElementType">
+          <xs:choice maxOccurs="unbounded" minOccurs="0">
+            <xs:element ref="drools:or-conditional-element"/>
+          </xs:choice>
+        </xs:extension>
+      </xs:complexContent>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="or-conditional-element" substitutionGroup="drools:abstractConditionalElement">
+    <xs:complexType>
+      <xs:complexContent>
+        <xs:extension base="drools:conditionalElementType">
+          <xs:choice maxOccurs="unbounded" minOccurs="0">
+            <xs:element ref="drools:and-conditional-element"/>
+          </xs:choice>
+        </xs:extension>
+      </xs:complexContent>
+    </xs:complexType>
+  </xs:element>
+<!-- Logical Connectives -->
+  <xs:element name="and-constraint-connective" substitutionGroup="drools:abstractConstraintConective">
+    <xs:complexType>
+      <xs:complexContent>
+        <xs:extension base="drools:constraintConnectiveElementType">
+          <xs:choice maxOccurs="unbounded" minOccurs="0">
+            <xs:element ref="drools:or-constraint-connective"/>
+          </xs:choice>
+        </xs:extension>
+      </xs:complexContent>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="or-constraint-connective" substitutionGroup="drools:abstractConstraintConective">
+    <xs:complexType>
+      <xs:complexContent>
+        <xs:extension base="drools:constraintConnectiveElementType">
+          <xs:choice maxOccurs="unbounded" minOccurs="0">
+            <xs:element ref="drools:and-constraint-connective"/>
+          </xs:choice>
+        </xs:extension>
+      </xs:complexContent>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="not">
+    <xs:complexType>
+      <xs:choice maxOccurs="unbounded" minOccurs="1">
+        <xs:element ref="drools:abstractConditionalElement"/>
+        <xs:element ref="drools:not"/>
+        <xs:element ref="drools:exists"/>
+        <xs:element ref="drools:pattern"/>
+        <xs:element ref="drools:accumulate"/>
+        <xs:element ref="drools:collect"/>
+        <xs:element ref="drools:forall"/>
+      </xs:choice>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="exists">
+    <xs:complexType>
+      <xs:choice maxOccurs="unbounded" minOccurs="0">
+        <xs:element ref="drools:pattern"/>
+        <xs:element ref="drools:abstractConditionalElement"/>
+        <xs:element ref="drools:accumulate"/>
+        <xs:element ref="drools:collect"/>
+        <xs:element ref="drools:forall"/>
+      </xs:choice>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="forall">
+    <xs:complexType>
+      <xs:choice maxOccurs="unbounded" minOccurs="0">
+        <xs:element ref="drools:pattern"/>
+      </xs:choice>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="collect">
+    <xs:complexType>
+      <xs:choice maxOccurs="1" minOccurs="1">
+        <xs:element ref="drools:pattern"/>
+      </xs:choice>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="expression" type="xs:string"/>
+  <xs:group name="accumulate">
+    <xs:sequence>
+      <xs:choice>
+        <xs:element ref="drools:pattern"/>
+        <xs:element ref="drools:abstractConditionalElement"/>
+      </xs:choice>
+      <xs:choice>
+        <xs:sequence>
+          <xs:element name="init" type="xs:string"/>
+          <xs:element name="action" type="xs:string"/>
+          <xs:element name="result" type="xs:string"/>
+        </xs:sequence>
+        <xs:element ref="drools:external-function"/>
+      </xs:choice>
+    </xs:sequence>
+  </xs:group>
+  <xs:element name="accumulate">
+    <xs:complexType>
+      <xs:choice maxOccurs="1" minOccurs="1">
+        <xs:group ref="drools:accumulate"/>
+      </xs:choice>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="from">
+    <xs:complexType>
+      <xs:choice maxOccurs="1">
+        <xs:element ref="drools:collect"/>
+        <xs:element ref="drools:expression"/>
+        <xs:element ref="drools:accumulate"/>
+      </xs:choice>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="eval" type="xs:string"/>
+  <xs:element name="pattern">
+    <xs:complexType>
+      <xs:choice maxOccurs="unbounded" minOccurs="0">
+        <xs:element ref="drools:field-binding"/>
+        <xs:element ref="drools:field-constraint"/>
+        <xs:element ref="drools:from"/>
+        <xs:element ref="drools:predicate"/>
+        <xs:element ref="drools:abstractConstraintConective"/>
+      </xs:choice>
+      <xs:attribute name="field-name" type="xs:string" use="optional"/>
+      <xs:attribute name="identifier" type="xs:string" use="optional"/>
+      <xs:attribute name="object-type" type="xs:string" use="required"/>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="field-constraint">
+    <xs:complexType>
+      <xs:complexContent>
+        <xs:extension base="drools:restrictionElementType">
+          <xs:choice maxOccurs="unbounded" minOccurs="0">
+            <xs:element ref="drools:abstractRestrictionConnective"/>
+          </xs:choice>
+          <xs:attribute name="field-name" type="xs:string" use="required"/>
+        </xs:extension>
+      </xs:complexContent>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="field-binding">
+    <xs:complexType>
+      <xs:attribute name="field-name" type="xs:string" use="required"/>
+      <xs:attribute name="identifier" type="xs:string" use="required"/>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="literal-restriction">
+    <xs:complexType>
+      <xs:attribute name="evaluator" type="xs:string" use="required"/>
+      <xs:attribute name="value" type="xs:string" use="required"/>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="external-function">
+    <xs:complexType>
+      <xs:attribute name="evaluator" type="xs:string" use="required"/>
+      <xs:attribute name="expression" type="xs:string" use="required"/>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="variable-restriction">
+    <xs:complexType>
+      <xs:attribute name="evaluator" type="xs:string" use="required"/>
+      <xs:attribute name="identifier" type="xs:string" use="required"/>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="return-value-restriction">
+    <xs:complexType>
+      <xs:simpleContent>
+        <xs:extension base="xs:string">
+          <xs:attribute name="evaluator" type="xs:string" use="required"/>
+        </xs:extension>
+      </xs:simpleContent>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="qualified-identifier-restriction">
+    <xs:complexType>
+      <xs:simpleContent>
+        <xs:extension base="xs:string">
+          <xs:attribute name="evaluator" type="xs:string" use="required"/>
+        </xs:extension>
+      </xs:simpleContent>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="predicate">
+    <xs:complexType>
+      <xs:simpleContent>
+        <xs:extension base="xs:string">
+          <xs:attribute name="field-name" type="xs:string" use="optional"/>
+          <xs:attribute name="identifier" type="xs:string" use="optional"/>
+        </xs:extension>
+      </xs:simpleContent>
+    </xs:complexType>
+  </xs:element>
 </xs:schema>

Modified: labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/lang/DRL.g
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/lang/DRL.g	2007-09-24 15:42:49 UTC (rev 15337)
+++ labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/lang/DRL.g	2007-09-24 15:58:55 UTC (rev 15338)
@@ -947,53 +947,6 @@
 	}
 	;
 	
-from_source[FromDescr from] returns [DeclarativeInvokerDescr ds]
-	@init {
-		$ds = null;
-		AccessorDescr ad = null;
-		FunctionCallDescr fc = null;
-	}
-	:	ident=identifier
-		{
-			ad = new AccessorDescr(ident.start.getText());	
-			ad.setLocation( offset(ident.start.getLine()), ident.start.getCharPositionInLine() );
-			ad.setStartCharacter( ((CommonToken)ident.start).getStartIndex() );
-			ad.setEndCharacter( ((CommonToken)ident.start).getStopIndex() );
-			$ds = ad;
-			location.setProperty(Location.LOCATION_FROM_CONTENT, ident.start.getText());
-		}
-		(	/* WARNING: $o : O() from x(y) could be also $o : O() from x followed
-			   by (y).  Resolve by always forcing (...) to be paren_chunk if
-			   after a from.  Setting k=1 will force this to happen.  No backtracking
-			   but you'll get a warning from ANTLR.  ANTLR resolves by choosing first
-			   alternative to win, which is the paren_chunk case not the loop exit.
-			*/
-			options {k=1;}
-		:	args=paren_chunk
-		{
-			if( $args.text != null ) {
-				ad.setVariableName( null );
-				fc = new FunctionCallDescr($ident.start.getText());
-				fc.setLocation( offset($ident.start.getLine()), $ident.start.getCharPositionInLine() );			
-				fc.setArguments($args.text);
-				fc.setStartCharacter( ((CommonToken)$ident.start).getStartIndex() );
-				fc.setEndCharacter( ((CommonToken)$ident.start).getStopIndex() );
-				location.setProperty(Location.LOCATION_FROM_CONTENT, $args.text);
-				$from.setEndCharacter( ((CommonToken)$args.stop).getStopIndex() );
-			}
-		}
-		)?
-		expression_chain[$from, ad]?
-	;	
-	finally {
-		if( ad != null ) {
-			if( fc != null ) {
-				ad.addFirstInvoker( fc );
-			}
-			location.setProperty(Location.LOCATION_FROM_CONTENT, ad.toString() );
-		}
-	}
-	
 
 accumulate_statement returns [AccumulateDescr d]
 	@init {
@@ -1068,8 +1021,56 @@
 			location.setType( Location.LOCATION_LHS_BEGIN_OF_CONDITION );
 			d.setEndCharacter( ((CommonToken)$RIGHT_PAREN).getStopIndex() );
 		} 
-	; 
+	; from_source[FromDescr from] returns [DeclarativeInvokerDescr ds]
+	@init {
+		$ds = null;
+		AccessorDescr ad = null;
+		FunctionCallDescr fc = null;
+	}
+	:	ident=identifier
+		{
+			ad = new AccessorDescr(ident.start.getText());	
+			ad.setLocation( offset(ident.start.getLine()), ident.start.getCharPositionInLine() );
+			ad.setStartCharacter( ((CommonToken)ident.start).getStartIndex() );
+			ad.setEndCharacter( ((CommonToken)ident.start).getStopIndex() );
+			$ds = ad;
+			location.setProperty(Location.LOCATION_FROM_CONTENT, ident.start.getText());
+		}
+		(	/* WARNING: $o : O() from x(y) could be also $o : O() from x followed
+			   by (y).  Resolve by always forcing (...) to be paren_chunk if
+			   after a from.  Setting k=1 will force this to happen.  No backtracking
+			   but you'll get a warning from ANTLR.  ANTLR resolves by choosing first
+			   alternative to win, which is the paren_chunk case not the loop exit.
+			*/
+			options {k=1;}
+		:	args=paren_chunk
+		{
+			if( $args.text != null ) {
+				ad.setVariableName( null );
+				fc = new FunctionCallDescr($ident.start.getText());
+				fc.setLocation( offset($ident.start.getLine()), $ident.start.getCharPositionInLine() );			
+				fc.setArguments($args.text);
+				fc.setStartCharacter( ((CommonToken)$ident.start).getStartIndex() );
+				fc.setEndCharacter( ((CommonToken)$ident.start).getStopIndex() );
+				location.setProperty(Location.LOCATION_FROM_CONTENT, $args.text);
+				$from.setEndCharacter( ((CommonToken)$args.stop).getStopIndex() );
+			}
+		}
+		)?
+		expression_chain[$from, ad]?
+	;	
+	finally {
+		if( ad != null ) {
+			if( fc != null ) {
+				ad.addFirstInvoker( fc );
+			}
+			location.setProperty(Location.LOCATION_FROM_CONTENT, ad.toString() );
+		}
+	}
 	
+
+
+	
 expression_chain[FromDescr from, AccessorDescr as] 
 	@init {
   		FieldAccessDescr fa = null;

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/XmlPackageReaderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/XmlPackageReaderTest.java	2007-09-24 15:42:49 UTC (rev 15337)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/XmlPackageReaderTest.java	2007-09-24 15:58:55 UTC (rev 15338)
@@ -12,6 +12,7 @@
 import org.drools.lang.descr.AccumulateDescr;
 import org.drools.lang.descr.AndDescr;
 import org.drools.lang.descr.AttributeDescr;
+import org.drools.lang.descr.BaseDescr;
 import org.drools.lang.descr.CollectDescr;
 import org.drools.lang.descr.EvalDescr;
 import org.drools.lang.descr.ExistsDescr;
@@ -106,7 +107,39 @@
         assertNull( accumulatedescr.getReverseCode());
         
     }
+    
+    
+    public void testAccumulateMultiPattern() throws Exception {
+        final XmlPackageReader xmlPackageReader = new XmlPackageReader();
+        xmlPackageReader.read( new InputStreamReader( getClass().getResourceAsStream( "test_ParseAccumulate.xml" ) ) );
+        final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
+        assertNotNull( packageDescr );
+        RuleDescr obj = (RuleDescr) packageDescr.getRules().get( 1 );
 
+        Object patternobj = obj.getLhs().getDescrs().get( 0 );
+        assertTrue( patternobj instanceof PatternDescr );
+        final PatternDescr patterncheese = (PatternDescr) patternobj;
+        assertEquals( patterncheese.getIdentifier(), "cheese" );
+        assertEquals( patterncheese.getObjectType(), "Cheese" );
+        
+        AccumulateDescr accumulatedescr = (AccumulateDescr) patterncheese.getSource();
+        assertEquals( "total += $cheese.getPrice();",
+                      accumulatedescr.getActionCode() );
+        assertEquals( "int total = 0;",
+                      accumulatedescr.getInitCode() );
+        assertEquals( "new Integer( total ) );",
+                      accumulatedescr.getResultCode() );
+        
+        AndDescr anddescr = (AndDescr) accumulatedescr.getInput();
+        
+        List descrlist = anddescr.getDescrs(); 
+        
+        PatternDescr[] listpattern = (PatternDescr[]) descrlist.toArray(new PatternDescr[descrlist.size()]);
+        
+        assertEquals(listpattern[0].getObjectType(), "Milk");
+        assertEquals(listpattern[1].getObjectType(), "Cup");
+    }
+    
     public void testParseForall() throws Exception {
         final XmlPackageReader xmlPackageReader = new XmlPackageReader();
         xmlPackageReader.read( new InputStreamReader( getClass().getResourceAsStream( "test_ParseForall.xml" ) ) );

Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseAccumulate.xml
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseAccumulate.xml	2007-09-24 15:42:49 UTC (rev 15337)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/xml/test_ParseAccumulate.xml	2007-09-24 15:58:55 UTC (rev 15338)
@@ -5,7 +5,8 @@
          xs:schemaLocation="http://drools.org/drools-4.0 drools-4.0.xsd">
 
 	<import name="import java.util.List"/>
-	<import name="org.drools.Cheese" />
+    <import name="org.drools.Person" />
+    <import name="org.drools.Cheese" />
 	<import name="org.drools.Cheesery" />
 
 	<global identifier="cheesery" type="Cheesery" />
@@ -48,4 +49,36 @@
             list1.add( $cheese );
         </rhs>
     </rule>
+
+    <rule name="multipatternaccumulate_rule">
+        <rule-attribute name="salience" value="10" />
+        <lhs>
+            <pattern identifier="cheese" object-type="Cheese">
+                <from>
+                    <accumulate>
+                        <and-conditional-element>
+                            <pattern object-type="Milk"></pattern>
+                            <pattern object-type="Cup"></pattern>
+                        </and-conditional-element>
+
+                        <init>
+                            int total = 0;
+                        </init>
+                        <action>
+                            total += $cheese.getPrice();
+                        </action>
+                        <result>
+                            new Integer( total ) );
+                        </result>
+                    </accumulate>
+                </from>
+            </pattern>
+        </lhs>
+        <rhs>
+            list1.add( $cheese );
+        </rhs>
+    </rule>
+
+
+
 </package>




More information about the jboss-svn-commits mailing list