[seam-commits] Seam SVN: r11402 - in branches/community/Seam_2_2_Drools5: src/main/org/jboss/seam and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Aug 18 13:18:29 EDT 2009


Author: tsurdilovic
Date: 2009-08-18 13:18:28 -0400 (Tue, 18 Aug 2009)
New Revision: 11402

Modified:
   branches/community/Seam_2_2_Drools5/examples/drools/resources/WEB-INF/components.xml
   branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools-2.2.xsd
   branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeBase.java
Log:
Drools5 Integration.

Modified: branches/community/Seam_2_2_Drools5/examples/drools/resources/WEB-INF/components.xml
===================================================================
--- branches/community/Seam_2_2_Drools5/examples/drools/resources/WEB-INF/components.xml	2009-08-18 15:43:09 UTC (rev 11401)
+++ branches/community/Seam_2_2_Drools5/examples/drools/resources/WEB-INF/components.xml	2009-08-18 17:18:28 UTC (rev 11402)
@@ -13,6 +13,9 @@
     	<drools:rule-resources>
     		<value>classpath;numberguess.drl;DRL</value>
     	</drools:rule-resources>	
+    	<drools:event-listeners>
+    		<value>org.drools.event.knowledgebase.DefaultKnowledgeBaseEventListener</value>
+    	</drools:event-listeners>
     </drools:knowledge-base>
     
     <drools:knowledge-agent name="kagent" agent-name="myAgent" scan-resources="true" scan-directories="false" 

Modified: branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeBase.java
===================================================================
--- branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeBase.java	2009-08-18 15:43:09 UTC (rev 11401)
+++ branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeBase.java	2009-08-18 17:18:28 UTC (rev 11402)
@@ -16,6 +16,10 @@
 import org.drools.builder.KnowledgeBuilderErrors;
 import org.drools.builder.KnowledgeBuilderFactory;
 import org.drools.builder.ResourceType;
+import org.drools.event.knowledgebase.KnowledgeBaseEventListener;
+import org.drools.event.process.ProcessEventListener;
+import org.drools.event.rule.AgendaEventListener;
+import org.drools.event.rule.WorkingMemoryEventListener;
 import org.drools.io.ResourceFactory;
 import org.drools.template.ObjectDataCompiler;
 import org.jboss.seam.Component;
@@ -52,6 +56,7 @@
    private String knowledgeBuilderConfig;
    private String knowledgeBaseConfig;
    private String[] ruleResources;
+   private String[] eventListeners;
    private org.drools.KnowledgeBase kbase;
    
    @Create
@@ -117,9 +122,29 @@
       
       kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseconfig);
       kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
+      if(eventListeners != null) {
+         for(String eventListener : eventListeners) {
+            setEventListener(kbase, eventListener);
+         }
+      }
       
    }
    
+   protected void setEventListener(org.drools.KnowledgeBase kbase, String eventListener) {
+      try {
+         Class eventListenerClass = Class.forName(eventListener);
+         Object eventListenerObject = eventListenerClass.newInstance();
+        
+         if(eventListenerObject instanceof KnowledgeBaseEventListener) {
+            kbase.addEventListener((KnowledgeBaseEventListener) eventListenerObject);
+         } else {
+            log.warn("event Listener " + eventListener + " is not of valid type");
+         }
+      } catch(Exception e) {
+         log.warn("error adding event listener " + eventListener);
+      }
+   }
+   
    @Unwrap
    public org.drools.KnowledgeBase getKnowledgeBase()
    {

Modified: branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools-2.2.xsd
===================================================================
--- branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools-2.2.xsd	2009-08-18 15:43:09 UTC (rev 11401)
+++ branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools-2.2.xsd	2009-08-18 17:18:28 UTC (rev 11402)
@@ -72,6 +72,8 @@
 			<xs:choice minOccurs="0" maxOccurs="unbounded">
 				<xs:element minOccurs="0" maxOccurs="1"
 					ref="drools:rule-resources" />
+				<xs:element minOccurs="0" maxOccurs="1"
+					ref="drools:event-listeners" />
 			</xs:choice>
 			<xs:attributeGroup ref="components:attlist.component" />
 			<xs:attributeGroup ref="drools:attlist.KnowledgeBase" />



More information about the seam-commits mailing list