[seam-commits] Seam SVN: r11492 - in branches/community/Seam_2_2_Drools5: examples/drools/resources/WEB-INF and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Sep 16 01:06:42 EDT 2009


Author: tsurdilovic
Date: 2009-09-16 01:06:41 -0400 (Wed, 16 Sep 2009)
New Revision: 11492

Added:
   branches/community/Seam_2_2_Drools5/examples/drools/resources/numberguesstemplate.drl
   branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/NumberGuessTemplateDataProvider.java
   branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/FlowProcess.java
   branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/FlowProcessInterceptor.java
Removed:
   branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/FlowProcessInterceptor.java
Modified:
   branches/community/Seam_2_2_Drools5/examples/drools/resources/WEB-INF/components.xml
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-09-15 20:49:34 UTC (rev 11491)
+++ branches/community/Seam_2_2_Drools5/examples/drools/resources/WEB-INF/components.xml	2009-09-16 05:06:41 UTC (rev 11492)
@@ -11,7 +11,7 @@
 	
 	<drools:knowledge-base name="kbase" knowledge-builder-config="kbuilderconfig.properties" knowledge-base-config="kbaseconfig.properties">
     	<drools:rule-resources>
-    		<value>classpath;numberguess.drl;DRL</value>
+    		<value>classpath;numberguesstemplate.drl;DRL;numberGuessTemplateDataProvider</value>
     	</drools:rule-resources>	
     	<drools:event-listeners>
     		<value>org.drools.event.knowledgebase.DefaultKnowledgeBaseEventListener</value>
@@ -108,6 +108,8 @@
            <value>org.drools.event.DebugAgendaEventListener</value>
         </drools:event-listeners>  -->
     <!-- </drools:managed-working-memory> -->
+    
+    
     <bpm:jbpm>
         <bpm:pageflow-definitions>
             <value>pageflow.jpdl.xml</value>

Added: branches/community/Seam_2_2_Drools5/examples/drools/resources/numberguesstemplate.drl
===================================================================
--- branches/community/Seam_2_2_Drools5/examples/drools/resources/numberguesstemplate.drl	                        (rev 0)
+++ branches/community/Seam_2_2_Drools5/examples/drools/resources/numberguesstemplate.drl	2009-09-16 05:06:41 UTC (rev 11492)
@@ -0,0 +1,55 @@
+template header
+wintext
+losetext
+guesscount
+increment
+
+package org.jboss.seam.example.numberguess
+import org.jboss.seam.drools.Decision;
+import java.lang.Integer;
+
+global Decision decision
+global Integer randomNumber
+global Game game
+template "numberGuess"
+
+rule High
+   when 
+      Guess(guess: value>randomNumber)
+   then 
+      game.setBiggest(guess - @{increment} );
+end
+
+rule Low
+   when
+      Guess(guess: value<randomNumber)
+   then 
+      game.setSmallest(guess + @{increment} );
+end
+
+rule Win
+   when 
+      Guess(value==randomNumber)
+   then 
+      decision.setOutcome("@{wintext}");
+end
+
+rule Lose
+   when 
+      Game(guessCount == @{guesscount} )
+   then
+      if ( decision.getOutcome()==null )
+      {
+         decision.setOutcome("@{losetext}");
+      }
+end
+
+rule Increment
+   salience -10
+   when
+      Guess()
+   then
+      game.incrementGuessCount();
+end
+
+end template
\ No newline at end of file

Added: branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/NumberGuessTemplateDataProvider.java
===================================================================
--- branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/NumberGuessTemplateDataProvider.java	                        (rev 0)
+++ branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/NumberGuessTemplateDataProvider.java	2009-09-16 05:06:41 UTC (rev 11492)
@@ -0,0 +1,38 @@
+package org.jboss.seam.example.numberguess;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.drools.TemplateDataProvider;
+
+ at Name("numberGuessTemplateDataProvider")
+public class NumberGuessTemplateDataProvider implements TemplateDataProvider
+{
+   Collection<Map<String, Object>> templateData = new ArrayList<Map<String,Object>>();
+   
+   @Create
+   public void init()
+   {
+      Map<String, Object> m1 = new HashMap<String, Object>();
+      m1.put("wintext", "win");
+      m1.put("losetext", "lose");
+      m1.put("guesscount", 9);
+      m1.put("increment", 1);
+      
+      templateData.add(m1);
+   }
+   
+   public Collection<Map<String, Object>> getTemplateData()
+   {
+      return templateData;
+   }
+
+   public void setTemplateData(Collection<Map<String, Object>> templateData)
+   {
+      this.templateData = templateData;
+   }
+}

Deleted: branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/FlowProcessInterceptor.java
===================================================================
--- branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/FlowProcessInterceptor.java	2009-09-15 20:49:34 UTC (rev 11491)
+++ branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/FlowProcessInterceptor.java	2009-09-16 05:06:41 UTC (rev 11492)
@@ -1,97 +0,0 @@
-package org.jboss.seam.annotations.drools;
-
-import java.lang.reflect.Method;
-import java.util.Map;
-
-import org.drools.runtime.process.ProcessInstance;
-import org.jboss.seam.Component;
-import org.jboss.seam.annotations.intercept.AroundInvoke;
-import org.jboss.seam.annotations.intercept.Interceptor;
-import org.jboss.seam.core.BijectionInterceptor;
-import org.jboss.seam.intercept.InvocationContext;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
-
-/**
- * Implements annotation-based flow process demarcation.
- *
- * @author Tihomir Surdilovic
- */
- at Interceptor(stateless=true, around=BijectionInterceptor.class)
-public class FlowProcessInterceptor
-{
-   private static final LogProvider log = Logging.getLogProvider( FlowProcessInterceptor.class );
-
-   @AroundInvoke
-   public Object aroundInvoke(InvocationContext invocation) throws Exception
-   {
-      if ( !beforeInvocation(invocation) )
-      {
-         return null;
-      }
-      else
-      {
-         return afterInvocation( invocation, invocation.proceed() );
-      }
-   }
-   
-   private boolean beforeInvocation(InvocationContext invocationContext) 
-   {
-      Method method = invocationContext.getMethod();
-      if ( method.isAnnotationPresent(StartProcess.class) ) 
-      {
-         log.info( "encountered @StartProcess" );
-         StartProcess tag = method.getAnnotation(StartProcess.class);   
-         org.drools.runtime.StatefulKnowledgeSession ksession = 
-            (org.drools.runtime.StatefulKnowledgeSession) Component.getInstance(tag.ksession(), true);
-         
-         if(tag.processData() != "") {
-            ksession.startProcess(tag.processName(), (Map<String, Object>) Component.getInstance(tag.processData()));
-         } else {
-            ksession.startProcess(tag.processName());
-         }
-      } 
-      else if ( method.isAnnotationPresent(AbortProcess.class) ) {
-         log.info( "encountered @AbortProcess" );
-         AbortProcess tag = method.getAnnotation(AbortProcess.class);
-         org.drools.runtime.StatefulKnowledgeSession ksession = 
-            (org.drools.runtime.StatefulKnowledgeSession) Component.getInstance(tag.ksession(), true);
-         ksession.getProcessInstances();
-         for(ProcessInstance processInstance: ksession.getProcessInstances()) {
-            if(processInstance.getProcessName().equals(tag.processName())) {
-               ksession.abortProcessInstance(processInstance.getId());
-            }
-         }
-      } 
-      else if ( method.isAnnotationPresent(SignalEvent.class) ) {
-         log.info( "encountered @SignalEvent" );
-         SignalEvent tag = method.getAnnotation(SignalEvent.class);
-         org.drools.runtime.StatefulKnowledgeSession ksession = 
-            (org.drools.runtime.StatefulKnowledgeSession) Component.getInstance(tag.ksession(), true);
-         
-         if(tag.processName() != "") {
-            for(ProcessInstance processInstance: ksession.getProcessInstances()) {
-               if(processInstance.getProcessName().equals(tag.processName())) {
-                  if (tag.eventData() != "") {
-                     processInstance.signalEvent(tag.eventType(), Component.getInstance(tag.eventData()));
-                  } else {
-                     processInstance.signalEvent(tag.eventType(), null);
-                  }
-               }
-            }
-         } else {
-            if (tag.eventData() != "") {
-               ksession.signalEvent(tag.eventType(), Component.getInstance(tag.eventData()));
-            } else {
-               ksession.signalEvent(tag.eventType(), null);
-            }
-         }
-      } 
-      return true;
-   }
-   
-   private Object afterInvocation(InvocationContext invocation, Object result)
-   {
-      return result;
-   }
-}

Added: branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/FlowProcess.java
===================================================================
--- branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/FlowProcess.java	                        (rev 0)
+++ branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/FlowProcess.java	2009-09-16 05:06:41 UTC (rev 11492)
@@ -0,0 +1,34 @@
+package org.jboss.seam.drools;
+
+import static org.jboss.seam.annotations.Install.BUILT_IN;
+
+import java.io.Serializable;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.core.AbstractMutable;
+
+/**
+ * Holds the process ids for the current conversation,
+ * and provides programmatic control over the flow process.
+ * 
+ * @author Tihomir Surdilovic
+ *
+ */
+
+ at Scope(ScopeType.CONVERSATION)
+ at Name("org.jboss.seam.drools.flowProcess")
+ at BypassInterceptors
+ at Install(precedence=BUILT_IN)
+
+public class FlowProcess extends AbstractMutable implements Serializable
+{
+   private Long processId;
+   
+   
+   
+   
+}

Copied: branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/FlowProcessInterceptor.java (from rev 11446, branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/FlowProcessInterceptor.java)
===================================================================
--- branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/FlowProcessInterceptor.java	                        (rev 0)
+++ branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/FlowProcessInterceptor.java	2009-09-16 05:06:41 UTC (rev 11492)
@@ -0,0 +1,100 @@
+package org.jboss.seam.drools;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.drools.runtime.process.ProcessInstance;
+import org.jboss.seam.Component;
+import org.jboss.seam.annotations.drools.AbortProcess;
+import org.jboss.seam.annotations.drools.SignalEvent;
+import org.jboss.seam.annotations.drools.StartProcess;
+import org.jboss.seam.annotations.intercept.AroundInvoke;
+import org.jboss.seam.annotations.intercept.Interceptor;
+import org.jboss.seam.core.BijectionInterceptor;
+import org.jboss.seam.intercept.InvocationContext;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+
+/**
+ * Implements annotation-based flow process demarcation.
+ *
+ * @author Tihomir Surdilovic
+ */
+ at Interceptor(stateless=true, around=BijectionInterceptor.class)
+public class FlowProcessInterceptor
+{
+   private static final LogProvider log = Logging.getLogProvider( FlowProcessInterceptor.class );
+
+   @AroundInvoke
+   public Object aroundInvoke(InvocationContext invocation) throws Exception
+   {
+      if ( !beforeInvocation(invocation) )
+      {
+         return null;
+      }
+      else
+      {
+         return afterInvocation( invocation, invocation.proceed() );
+      }
+   }
+   
+   private boolean beforeInvocation(InvocationContext invocationContext) 
+   {
+      Method method = invocationContext.getMethod();
+      if ( method.isAnnotationPresent(StartProcess.class) ) 
+      {
+         log.info( "encountered @StartProcess" );
+         StartProcess tag = method.getAnnotation(StartProcess.class);   
+         org.drools.runtime.StatefulKnowledgeSession ksession = 
+            (org.drools.runtime.StatefulKnowledgeSession) Component.getInstance(tag.ksession(), true);
+         
+         if(tag.processData() != "") {
+            ksession.startProcess(tag.processName(), (Map<String, Object>) Component.getInstance(tag.processData()));
+         } else {
+            ksession.startProcess(tag.processName());
+         }
+      } 
+      else if ( method.isAnnotationPresent(AbortProcess.class) ) {
+         log.info( "encountered @AbortProcess" );
+         AbortProcess tag = method.getAnnotation(AbortProcess.class);
+         org.drools.runtime.StatefulKnowledgeSession ksession = 
+            (org.drools.runtime.StatefulKnowledgeSession) Component.getInstance(tag.ksession(), true);
+         ksession.getProcessInstances();
+         for(ProcessInstance processInstance: ksession.getProcessInstances()) {
+            if(processInstance.getProcessName().equals(tag.processName())) {
+               ksession.abortProcessInstance(processInstance.getId());
+            }
+         }
+      } 
+      else if ( method.isAnnotationPresent(SignalEvent.class) ) {
+         log.info( "encountered @SignalEvent" );
+         SignalEvent tag = method.getAnnotation(SignalEvent.class);
+         org.drools.runtime.StatefulKnowledgeSession ksession = 
+            (org.drools.runtime.StatefulKnowledgeSession) Component.getInstance(tag.ksession(), true);
+         
+         if(tag.processName() != "") {
+            for(ProcessInstance processInstance: ksession.getProcessInstances()) {
+               if(processInstance.getProcessName().equals(tag.processName())) {
+                  if (tag.eventData() != "") {
+                     processInstance.signalEvent(tag.eventType(), Component.getInstance(tag.eventData()));
+                  } else {
+                     processInstance.signalEvent(tag.eventType(), null);
+                  }
+               }
+            }
+         } else {
+            if (tag.eventData() != "") {
+               ksession.signalEvent(tag.eventType(), Component.getInstance(tag.eventData()));
+            } else {
+               ksession.signalEvent(tag.eventType(), null);
+            }
+         }
+      } 
+      return true;
+   }
+   
+   private Object afterInvocation(InvocationContext invocation, Object result)
+   {
+      return result;
+   }
+}



More information about the seam-commits mailing list