Author: tsurdilovic
Date: 2009-08-28 15:45:50 -0400 (Fri, 28 Aug 2009)
New Revision: 11446
Added:
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/FlowProcessInterceptor.java
Modified:
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
Log:
Drools5 Integration.
Modified:
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 2009-08-28
13:47:56 UTC (rev 11445)
+++
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/AbortProcess.java 2009-08-28
19:45:50 UTC (rev 11446)
@@ -1,6 +1,31 @@
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 aborted.
+ *
+ * @author Tihomir Surdilovic
+ */
+
+@Target( METHOD )
+@Retention( RUNTIME )
+@Documented
public @interface AbortProcess
{
+ /**
+ * Name of the StatefulKnowledgeSession component.
+ * @return an EL expression
+ */
+ String ksession();
+ /**
+ * The process name to be aborted.
+ */
+ String processName();
}
Added:
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
(rev 0)
+++
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/FlowProcessInterceptor.java 2009-08-28
19:45:50 UTC (rev 11446)
@@ -0,0 +1,97 @@
+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
+ */
+@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;
+ }
+}
Modified:
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 2009-08-28
13:47:56 UTC (rev 11445)
+++
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/SignalEvent.java 2009-08-28
19:45:50 UTC (rev 11446)
@@ -22,24 +22,23 @@
public @interface SignalEvent
{
/**
- * An EL expression that evaluates to a StatefulKnowledgeSession.
- * @return an EL expression
+ * Name of the StatefulKnowledgeSession component.
*/
- String ksession() default "";
+ String ksession();
/**
- * The process instance id to be started.
+ * The process name.
*/
- String processInstanceId() default "";
+ String processName();
/**
* The event type.
*/
- String eventType() default "";
+ String eventType();
/**
- * An EL expression that evaluates to Event Data.
- * @return an EL expression
+ * Name of the component which unwraps itself to Object
+ * and provides event data.
*/
String eventData() default "";
Modified:
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 2009-08-28
13:47:56 UTC (rev 11445)
+++
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/annotations/drools/StartProcess.java 2009-08-28
19:45:50 UTC (rev 11446)
@@ -18,13 +18,18 @@
public @interface StartProcess
{
/**
- * An EL expression that evaluates to a StatefulKnowledgeSession.
- * @return an EL expression
+ * Name of the StatefulKnowledgeSession. component.
*/
- String ksession() default "";
+ String ksession();
/**
- * The process id to be started.
+ * The process name to be started.
*/
- String processId() default "";
+ String processName();
+
+ /**
+ * Name of the component which unwraps itself to Map<Object, String>
+ * and provides process data.
+ */
+ String processData() default "";
}
Show replies by date