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

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Aug 27 22:19:42 EDT 2009


Author: tsurdilovic
Date: 2009-08-27 22:19:41 -0400 (Thu, 27 Aug 2009)
New Revision: 11440

Added:
   branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/
   branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/AbortProcess.java
   branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/SignalEvent.java
   branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/StartProcess.java
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/StatefulKnowledgeSession.java
Log:
Drools5 Integration.

Added: branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/AbortProcess.java
===================================================================
--- branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/AbortProcess.java	                        (rev 0)
+++ branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/AbortProcess.java	2009-08-28 02:19:41 UTC (rev 11440)
@@ -0,0 +1,6 @@
+package org.jboss.seam.annotations.drools;
+
+public @interface AbortProcess
+{
+   
+}

Added: branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/SignalEvent.java
===================================================================
--- branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/SignalEvent.java	                        (rev 0)
+++ branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/SignalEvent.java	2009-08-28 02:19:41 UTC (rev 11440)
@@ -0,0 +1,46 @@
+package org.jboss.seam.annotations.drools;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Marks a method as causing drools process event to be signalled.
+ * You can either enter a specific process instance to be started or
+ * by omitting the process instance id, it uses event correlation
+ * to signal event to all process instance within a StatefulKnowledgeSession
+ * which are listening for the specific event type.
+ * 
+ * @author Tihomir Surdilovic
+ */
+ at Target( METHOD )
+ at Retention( RUNTIME )
+ at Documented
+public @interface SignalEvent
+{
+   /**
+    * An EL expression that evaluates to a StatefulKnowledgeSession.
+    * @return an EL expression
+    */
+   String ksession() default "";
+   
+   /**
+    * The process instance id to be started.
+    */
+   String processInstanceId() default "";
+   
+   /**
+    * The event type.
+    */
+   String eventType() default "";
+   
+   /**
+    * An EL expression that evaluates to Event Data.
+    * @return an EL expression
+    */
+   String eventData() default "";
+   
+}

Added: branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/StartProcess.java
===================================================================
--- branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/StartProcess.java	                        (rev 0)
+++ branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/StartProcess.java	2009-08-28 02:19:41 UTC (rev 11440)
@@ -0,0 +1,30 @@
+package org.jboss.seam.annotations.drools;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Marks a method as causing drools process to be started. 
+ *
+ * @author Tihomir Surdilovic
+ */
+ at Target( METHOD )
+ at Retention( RUNTIME )
+ at Documented
+public @interface StartProcess
+{
+   /**
+    * An EL expression that evaluates to a StatefulKnowledgeSession.
+    * @return an EL expression
+    */
+   String ksession() default "";
+   
+   /**
+    * The process id to be started.
+    */
+   String processId() default "";
+}

Modified: branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/StatefulKnowledgeSession.java
===================================================================
--- branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/StatefulKnowledgeSession.java	2009-08-27 20:37:26 UTC (rev 11439)
+++ branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/StatefulKnowledgeSession.java	2009-08-28 02:19:41 UTC (rev 11440)
@@ -4,15 +4,18 @@
 import java.io.Serializable;
 import java.util.Map;
 import java.util.Properties;
+import java.util.regex.Pattern;
 
 import org.drools.KnowledgeBaseFactory;
 import org.drools.logger.KnowledgeRuntimeLogger;
 import org.drools.logger.KnowledgeRuntimeLoggerFactory;
 import org.drools.runtime.KnowledgeSessionConfiguration;
+import org.drools.runtime.process.WorkItemHandler;
 import org.drools.spi.GlobalResolver;
 import org.drools.event.process.ProcessEventListener;
 import org.drools.event.rule.AgendaEventListener;
 import org.drools.event.rule.WorkingMemoryEventListener;
+import org.jboss.seam.Component;
 import org.jboss.seam.ScopeType;
 import org.jboss.seam.annotations.Destroy;
 import org.jboss.seam.annotations.Scope;
@@ -35,10 +38,14 @@
 public class StatefulKnowledgeSession implements Mutable, Serializable
 {
    private static final LogProvider log = Logging.getLogProvider(org.jboss.seam.drools.StatefulKnowledgeSession.class);
+   private static final Pattern DIVIDER = Pattern.compile(";");
+   private static final int WORKITEMHANDLER_NAME = 0;
+   private static final int WORKITEMHANDLER_TYPE = 1;
 
    private ValueExpression<org.drools.KnowledgeBase> knowledgeBase;
    private ValueExpression<org.jboss.seam.drools.FactProvider> factProvider;
    private String[] eventListeners;
+   private String[] workItemHandlers;
    private String knowledgeSessionConfig;
    private String auditLog;
    
@@ -89,6 +96,19 @@
             }
          }
          
+         if(workItemHandlers != null) {
+            for(String nextWorkItemHandler : workItemHandlers) {
+               String[] handlerParts = DIVIDER.split(nextWorkItemHandler.trim());
+               if(handlerParts.length != 2) {
+                  log.error("Unable to use workItemHandler definition: " + nextWorkItemHandler);
+               } else {
+                  WorkItemHandler handler = (WorkItemHandler) Component.getInstance(handlerParts[WORKITEMHANDLER_TYPE], true);
+                  log.info("Registering new WorkItemHandler: " + handlerParts[WORKITEMHANDLER_NAME]);
+                  ksession.getWorkItemManager().registerWorkItemHandler(handlerParts[WORKITEMHANDLER_NAME], handler);
+               }
+            }
+         }
+         
          if(auditLog != null) {
             auditLog+=System.currentTimeMillis();
             log.info("Setting auding log: " + auditLog);
@@ -188,5 +208,17 @@
    public void setAuditLog(String auditLog)
    {
       this.auditLog = auditLog;
-   }   
+   }
+
+   public String[] getWorkItemHandlers()
+   {
+      return workItemHandlers;
+   }
+
+   public void setWorkItemHandlers(String[] workItemHandlers)
+   {
+      this.workItemHandlers = workItemHandlers;
+   }
+   
+   
 }

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-27 20:37:26 UTC (rev 11439)
+++ branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools-2.2.xsd	2009-08-28 02:19:41 UTC (rev 11440)
@@ -93,6 +93,8 @@
 			<xs:choice minOccurs="0" maxOccurs="unbounded">
 				<xs:element minOccurs="0" maxOccurs="1"
 					ref="drools:event-listeners" />
+				<xs:element minOccurs="0" maxOccurs="1"
+					ref="drools:work-item-handlers" />
 			</xs:choice>
 			<xs:attributeGroup ref="components:attlist.component" />
 			<xs:attributeGroup ref="drools:attlist.StatefulKnowledgeSession" />
@@ -101,10 +103,12 @@
 	<xs:attributeGroup name="attlist.StatefulKnowledgeSession">
 		<xs:attribute name="knowledge-base" type="components:expressionType" />
 		<xs:attribute name="event-listeners" type="components:string" />
+		<xs:attribute name="work-item-handlers" type="components:string"/>		
 		<xs:attribute name="knowledge-session-config" type="components:string" />
 		<xs:attribute name="fact-provider" type="components:expressionType"/>
 		<xs:attribute name="audit-log" type="components:string"/>
 	</xs:attributeGroup>
+	<xs:element name="work-item-handlers" type="components:multiValuedProperty" />
 	
 	<xs:element name="stateless-knowledge-session">
 		<xs:annotation>



More information about the seam-commits mailing list