[jboss-cvs] jboss-seam/src/main/org/jboss/seam/jbpm ...
Gavin King
gavin.king at jboss.com
Fri Jun 15 21:43:42 EDT 2007
User: gavin
Date: 07/06/15 21:43:42
Modified: src/main/org/jboss/seam/jbpm SeamUserCodeInterceptor.java
Log:
JBSEAM-1085, JBSEAM-506
Revision Changes Path
1.2 +104 -10 jboss-seam/src/main/org/jboss/seam/jbpm/SeamUserCodeInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SeamUserCodeInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/jbpm/SeamUserCodeInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- SeamUserCodeInterceptor.java 16 Jun 2007 00:46:33 -0000 1.1
+++ SeamUserCodeInterceptor.java 16 Jun 2007 01:43:42 -0000 1.2
@@ -1,5 +1,8 @@
package org.jboss.seam.jbpm;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.contexts.Lifecycle;
+import org.jboss.seam.core.BusinessProcess;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.def.Action;
import org.jbpm.graph.exe.ExecutionContext;
@@ -12,28 +15,119 @@
public class SeamUserCodeInterceptor implements UserCodeInterceptor
{
+ abstract static class ContextualCall
+ {
+ abstract void process() throws Exception;
+
+ void run() throws Exception
+ {
+ if ( Contexts.isEventContextActive() || Contexts.isApplicationContextActive() ) //not sure about the second bit (only needed at init time!)
+ {
+ process();
+ }
+ else
+ {
+ Lifecycle.beginCall();
+ try
+ {
+ process();
+ }
+ finally
+ {
+ Lifecycle.endCall();
+ }
+ }
+ }
+
+ void runAndWrap()
+ {
+ try
+ {
+ run();
+ }
+ catch (RuntimeException re)
+ {
+ throw re;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ }
- public void executeAction(Action action, ExecutionContext context) throws Exception
+ public void executeAction(final Action action, final ExecutionContext context) throws Exception
+ {
+ new ContextualCall()
+ {
+ @Override
+ void process() throws Exception
{
+ initProcessAndTask(context);
action.execute(context);
}
+ }.run();
+ }
- public void executeAssignment(AssignmentHandler handler, Assignable task, ExecutionContext context)
+ public void executeAssignment(final AssignmentHandler handler, final Assignable assignable,
+ final ExecutionContext context)
throws Exception
{
- handler.assign(task, context);
+ new ContextualCall()
+ {
+ @Override
+ void process() throws Exception
+ {
+ initProcessAndTask(context);
+ handler.assign(assignable, context);
+ }
+ }.run();
}
- public void executeTaskControllerInitialization(TaskControllerHandler handler, TaskInstance task,
- ContextInstance context, Token token)
+ public void executeTaskControllerInitialization(final TaskControllerHandler handler, final TaskInstance task,
+ final ContextInstance context, final Token token)
+ {
+ new ContextualCall()
+ {
+ @Override
+ void process() throws Exception
{
+ initProcessAndTask(task);
handler.initializeTaskVariables(task, context, token);
}
+ }.runAndWrap();
+ }
- public void executeTaskControllerSubmission(TaskControllerHandler handler, TaskInstance task,
- ContextInstance context, Token token)
+ public void executeTaskControllerSubmission(final TaskControllerHandler handler, final TaskInstance task,
+ final ContextInstance context, final Token token)
+ {
+ new ContextualCall()
{
+ @Override
+ void process() throws Exception
+ {
+ initProcessAndTask(task);
handler.submitTaskVariables(task, context, token);
}
+ }.runAndWrap();
+ }
+
+ private static void initProcessAndTask(ExecutionContext context)
+ {
+ BusinessProcess businessProcess = BusinessProcess.instance();
+ businessProcess.setProcessId( context.getProcessInstance().getId() );
+ TaskInstance taskInstance = context.getTaskInstance();
+ if (taskInstance!=null)
+ {
+ businessProcess.setTaskId( taskInstance.getId() );
+ }
+ }
+
+ private static void initProcessAndTask(TaskInstance task)
+ {
+ BusinessProcess businessProcess = BusinessProcess.instance();
+ businessProcess.setProcessId( task.getProcessInstance().getId() );
+ businessProcess.setTaskId( task.getId() );
+ }
}
More information about the jboss-cvs-commits
mailing list