[jbpm-commits] JBoss JBPM SVN: r5266 - in jbpm4/branches/jbpm-4.0/modules: jpdl/src/main/java/org/jbpm/jpdl/internal/activity and 10 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jul 9 06:04:17 EDT 2009


Author: tom.baeyens at jboss.com
Date: 2009-07-09 06:04:17 -0400 (Thu, 09 Jul 2009)
New Revision: 5266

Added:
   jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/TaskContext.java
Modified:
   jbpm4/branches/jbpm-4.0/modules/devguide/src/main/docbook/en/modules/ch16-SpringIntegration.xml
   jbpm4/branches/jbpm-4.0/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailListener.java
   jbpm4/branches/jbpm-4.0/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/Jpdl3ConverterReaderTest.java
   jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java
   jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java
   jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/EnvironmentBindings.java
   jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java
   jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java
   jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ScriptManagerBinding.java
   jbpm4/branches/jbpm-4.0/modules/pvm/src/main/resources/jbpm.default.cfg.xml
   jbpm4/branches/jbpm-4.0/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/GroovyExpressionTest.java
   jbpm4/branches/jbpm-4.0/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/JuelExpressionTest.java
   jbpm4/branches/jbpm-4.0/modules/pvm/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml
Log:
JBPM-2395 fix mail listener task access

Modified: jbpm4/branches/jbpm-4.0/modules/devguide/src/main/docbook/en/modules/ch16-SpringIntegration.xml
===================================================================
--- jbpm4/branches/jbpm-4.0/modules/devguide/src/main/docbook/en/modules/ch16-SpringIntegration.xml	2009-07-09 10:01:33 UTC (rev 5265)
+++ jbpm4/branches/jbpm-4.0/modules/devguide/src/main/docbook/en/modules/ch16-SpringIntegration.xml	2009-07-09 10:04:17 UTC (rev 5266)
@@ -78,20 +78,6 @@
 		</programlisting>
 	</para>
 
-	<para>
-		For accessing Spring beans from withing a process, we need to register 
-		the Spring applicationContext with the scripting-manager.
-		
-		<programlisting>
-	&lt;script-manager default-expression-language=&quot;juel&quot;
-	 default-script-language=&quot;juel&quot;
-	 read-contexts=&quot;execution, environment, process-engine, <emphasis role="bold">spring</emphasis>&quot;
-	 write-context=&quot;&quot;&gt;
-	 &lt;script-language name=&quot;juel&quot;
-	 factory=&quot;org.jbpm.pvm.internal.script.JuelScriptEngineFactory&quot; /&gt;
-	 &lt;/script-manager&gt;		
-		</programlisting>	
-    </para>
   </section>
   
   <section id="spring_usage">

Modified: jbpm4/branches/jbpm-4.0/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailListener.java
===================================================================
--- jbpm4/branches/jbpm-4.0/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailListener.java	2009-07-09 10:01:33 UTC (rev 5265)
+++ jbpm4/branches/jbpm-4.0/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailListener.java	2009-07-09 10:04:17 UTC (rev 5266)
@@ -27,11 +27,12 @@
 
 import org.jbpm.api.listener.EventListener;
 import org.jbpm.api.listener.EventListenerExecution;
-import org.jbpm.api.task.Task;
 import org.jbpm.pvm.internal.email.spi.MailProducer;
 import org.jbpm.pvm.internal.email.spi.MailSession;
 import org.jbpm.pvm.internal.env.Environment;
+import org.jbpm.pvm.internal.env.TaskContext;
 import org.jbpm.pvm.internal.session.DbSession;
+import org.jbpm.pvm.internal.task.TaskImpl;
 
 /**
  * @author Alejandro Guizar
@@ -41,24 +42,22 @@
   protected transient MailProducer mailProducer;
 
   private static final long serialVersionUID = 1L;
-  private static final String TASK_VARIABLE_NAME = "task";
 
   public void notify(EventListenerExecution execution) throws Exception {
     // find current task
     Environment environment = Environment.getCurrent();
-    Task task = environment
-        .get(DbSession.class)
-        .findTaskByExecution(execution);
-    // make task available to mail templates through execution variable
-    // TODO find a cleaner way
-    execution.setVariable(TASK_VARIABLE_NAME, task);
+    DbSession dbSession = environment.get(DbSession.class);
+    TaskImpl task = dbSession.findTaskByExecution(execution);
+
+    // make task available to mail templates through task context
+    TaskContext taskContext = new TaskContext(task);
+    environment.setContext(taskContext);
     try {
       Collection<Message> messages = mailProducer.produce(execution);
       environment.get(MailSession.class).send(messages);
+    } finally {
+      environment.removeContext(taskContext);
     }
-    finally {
-//      execution.removeVariable(TASK_VARIABLE_NAME);
-    }
   }
 
   public void setMailProducer(MailProducer mailProducer) {

Modified: jbpm4/branches/jbpm-4.0/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/Jpdl3ConverterReaderTest.java
===================================================================
--- jbpm4/branches/jbpm-4.0/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/Jpdl3ConverterReaderTest.java	2009-07-09 10:01:33 UTC (rev 5265)
+++ jbpm4/branches/jbpm-4.0/modules/migration/src/test/java/org/jbpm/jpdl/internal/convert/Jpdl3ConverterReaderTest.java	2009-07-09 10:04:17 UTC (rev 5266)
@@ -157,9 +157,7 @@
 				.parseXmlString("<jbpm-configuration>"
 						+ "  <process-engine-context>"
 						+ "    <script-manager default-expression-language='juel'"
-						+ "                    default-script-language='juel'"
-						+ "                    read-contexts='execution, environment, process-engine' "
-						+ "                    write-context='execution'>"
+						+ "                    default-script-language='juel'>"
 						+ "      <script-language name='juel' factory='com.sun.script.juel.JuelScriptEngineFactory' />"
 						+ "    </script-manager>"
 						+ "  </process-engine-context> </jbpm-configuration>");

Added: jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/TaskContext.java
===================================================================
--- jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/TaskContext.java	                        (rev 0)
+++ jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/TaskContext.java	2009-07-09 10:04:17 UTC (rev 5266)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.env;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jbpm.api.job.Job;
+import org.jbpm.pvm.internal.task.TaskImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TaskContext implements Context {
+  
+  private static final String KEY_TASK = "task";
+  
+  static final Set<String> keys = Collections.unmodifiableSet(getKeys());
+  
+  static Set<String> getKeys() {
+    Set<String> keys = new HashSet<String>();
+    keys.add(KEY_TASK);
+    return keys;
+  }
+
+  TaskImpl task;
+
+  public TaskContext(TaskImpl task) {
+    this.task = task;
+  }
+
+  public Object get(String key) {
+    if (KEY_TASK.equals(key)) {
+      return task;
+    }
+    return null;
+  }
+
+  public boolean has(String key) {
+    return KEY_TASK.equals(key);
+  }
+
+  public Set<String> keys() {
+    return keys;
+  }
+
+  public Object set(String key, Object value) {
+    task.setVariable(key, value);
+    return null;
+  }
+  
+  public <T> T get(Class<T> type) {
+    if (Job.class.isAssignableFrom(type)) {
+      return (T) task;
+    }
+    return null;
+  }
+
+  public String getName() {
+    return Context.CONTEXTNAME_TASK;
+  }
+}


Property changes on: jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/TaskContext.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java
===================================================================
--- jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java	2009-07-09 10:01:33 UTC (rev 5265)
+++ jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java	2009-07-09 10:04:17 UTC (rev 5266)
@@ -355,7 +355,7 @@
     }
   }
 
-  public Task createTask() {
+  public TaskImpl createTask() {
     TaskImpl task = newTask();
     task.setCreateTime(Clock.getCurrentTime());
     return task;
@@ -372,14 +372,14 @@
   }
 
 
-  public Task findTaskByExecution(Execution execution) {
+  public TaskImpl findTaskByExecution(Execution execution) {
     Query query = session.createQuery(
       "select task " +
       "from "+TaskImpl.class.getName()+" as task " +
       "where task.execution = :execution"
     );
     query.setEntity("execution", execution);
-    return (Task) query.uniqueResult();
+    return (TaskImpl) query.uniqueResult();
   }
   
   public JobImpl<?> findFirstAcquirableJob() {

Modified: jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java
===================================================================
--- jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java	2009-07-09 10:01:33 UTC (rev 5265)
+++ jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/JobImpl.java	2009-07-09 10:04:17 UTC (rev 5266)
@@ -34,7 +34,7 @@
   /** job state. */
   protected String state = STATE_WAITING;
 
-  /** the execution (if any) for this jobImpl */  
+  /** the execution (if any) for this job */  
   protected ExecutionImpl execution;
 
   /** the process instance */  

Modified: jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/EnvironmentBindings.java
===================================================================
--- jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/EnvironmentBindings.java	2009-07-09 10:01:33 UTC (rev 5265)
+++ jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/EnvironmentBindings.java	2009-07-09 10:04:17 UTC (rev 5266)
@@ -27,7 +27,6 @@
 
 import javax.script.Bindings;
 
-import org.jbpm.pvm.internal.env.Context;
 import org.jbpm.pvm.internal.env.Environment;
 
 
@@ -36,52 +35,22 @@
  */
 public class EnvironmentBindings implements Bindings {
   
-  protected String[] readContextNames;
-  protected String writeContextName;
-  protected Map<String, WriteBinding> writeBindings;
   protected Environment environment;
 
   public EnvironmentBindings(String[] readContextNames, String writeContextName) {
-    this.readContextNames = readContextNames;
-    this.writeContextName = writeContextName;
-    
     environment = Environment.getCurrent();
   }
 
   public Object get(Object key) {
-    Context context = getReadContext(key);
-    if (context!=null) {
-      return context.get((String) key);
-    }
-    return null;
+    return environment.get((String)key);
   }
 
-  protected Context getReadContext(Object key) {
-    for (String readContextName: readContextNames) {
-      Context readContext = environment.getContext(readContextName);
-      if ( (readContext!=null)
-           && (readContext.has((String) key))
-         ) {
-        return readContext;
-      }
-    }
-    return null;
-  }
-
   public boolean containsKey(Object key) {
-    Context context = getReadContext(key);
-    return (context!=null);
+    return (get(key)!=null);
   }
 
   public Object put(String key, Object value) {
-    if (writeContextName==null) {
-      return null;
-    }
-    Context writeContext = environment.getContext(writeContextName);
-    if (writeContext==null) {
-      return null;
-    }
-    return writeContext.set(key, value);
+    return null;
   }
 
   public void putAll(Map< ? extends String, ? extends Object> toMerge) {

Modified: jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java
===================================================================
--- jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java	2009-07-09 10:01:33 UTC (rev 5265)
+++ jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java	2009-07-09 10:04:17 UTC (rev 5266)
@@ -57,9 +57,7 @@
         .setString(
           "<objects>" +
           "  <script-manager default-expression-language='juel'" +
-          "                  default-script-language='beanshell' " +
-          "                  read-contexts='execution, environment, process-engine' " +
-          "                  write-context=''>" +
+          "                  default-script-language='beanshell'>" +
           "    <script-language name='juel' factory='org.jbpm.pvm.internal.script.JuelScriptEngineFactory' />" +
           "  </script-manager>" +
           "</objects>"

Modified: jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java
===================================================================
--- jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java	2009-07-09 10:01:33 UTC (rev 5265)
+++ jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java	2009-07-09 10:04:17 UTC (rev 5266)
@@ -25,10 +25,8 @@
 
 import org.jbpm.api.Execution;
 import org.jbpm.api.history.HistoryComment;
-import org.jbpm.api.task.Task;
 import org.jbpm.pvm.internal.client.ClientExecution;
 import org.jbpm.pvm.internal.client.ClientProcessDefinition;
-import org.jbpm.pvm.internal.history.model.HistoryProcessInstanceImpl;
 import org.jbpm.pvm.internal.job.JobImpl;
 import org.jbpm.pvm.internal.model.ExecutionImpl;
 import org.jbpm.pvm.internal.query.DeploymentQueryImpl;
@@ -37,6 +35,7 @@
 import org.jbpm.pvm.internal.query.JobQueryImpl;
 import org.jbpm.pvm.internal.query.ProcessInstanceQueryImpl;
 import org.jbpm.pvm.internal.query.TaskQueryImpl;
+import org.jbpm.pvm.internal.task.TaskImpl;
 
 
 /**
@@ -111,9 +110,9 @@
   
   // task methods /////////////////////////////////////////////////////////////
   
-  Task createTask();
+  TaskImpl createTask();
 
-  Task findTaskByExecution(Execution execution);
+  TaskImpl findTaskByExecution(Execution execution);
 
   // job methods //////////////////////////////////////////////////////////////
 

Modified: jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ScriptManagerBinding.java
===================================================================
--- jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ScriptManagerBinding.java	2009-07-09 10:01:33 UTC (rev 5265)
+++ jbpm4/branches/jbpm-4.0/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ScriptManagerBinding.java	2009-07-09 10:04:17 UTC (rev 5266)
@@ -59,24 +59,6 @@
       descriptor.addInjection("defaultScriptLanguage", new StringDescriptor(defaultLanguage));
     }
 
-    if (element.hasAttribute("read-contexts")) {
-      String readContextsText = element.getAttribute("read-contexts");
-      List<String> readContextList = XmlUtil.parseCommaSeparatedList(readContextsText);
-      String[] readContextNames = readContextList.toArray(new String[readContextList.size()]);
-      descriptor.addInjection("readContextNames", new ProvidedObjectDescriptor(readContextNames));
-      
-    } else {
-      parse.addProblem("'read-contexts' is a required attribute in element <script-manager />", element);
-    }
-
-    if (element.hasAttribute("write-context")) {
-      String writeContextName = element.getAttribute("write-context");
-      descriptor.addInjection("writeContextName", new StringDescriptor(writeContextName));
-      
-    } else {
-      parse.addProblem("'write-context' is a required attribute in element <script-manager />", element);
-    }
-    
     ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
     List<Element> scriptElements = XmlUtil.elements(element, "script-language");
     for (Element scriptElement : scriptElements) {

Modified: jbpm4/branches/jbpm-4.0/modules/pvm/src/main/resources/jbpm.default.cfg.xml
===================================================================
--- jbpm4/branches/jbpm-4.0/modules/pvm/src/main/resources/jbpm.default.cfg.xml	2009-07-09 10:01:33 UTC (rev 5265)
+++ jbpm4/branches/jbpm-4.0/modules/pvm/src/main/resources/jbpm.default.cfg.xml	2009-07-09 10:04:17 UTC (rev 5266)
@@ -19,9 +19,7 @@
     <hibernate-session-factory />
 
     <script-manager default-expression-language="juel"
-                    default-script-language="juel"
-                    read-contexts="execution, environment, process-engine"
-                    write-context="">
+                    default-script-language="juel">
       <script-language name="juel" factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" />
     </script-manager>
     

Modified: jbpm4/branches/jbpm-4.0/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/GroovyExpressionTest.java
===================================================================
--- jbpm4/branches/jbpm-4.0/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/GroovyExpressionTest.java	2009-07-09 10:01:33 UTC (rev 5265)
+++ jbpm4/branches/jbpm-4.0/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/GroovyExpressionTest.java	2009-07-09 10:04:17 UTC (rev 5266)
@@ -46,9 +46,7 @@
         "<jbpm-configuration>" +
         "  <process-engine-context>" +
         "    <script-manager default-expression-language='juel'" +
-        "                    default-script-language='juel'" +
-        "                    read-contexts='execution, environment, process-engine' " +
-        "                    write-context='execution'>" +
+        "                    default-script-language='juel'>" +
         "      <script-language name='groovy' factory='com.sun.script.groovy.GroovyScriptEngineFactory' />" +
         "    </script-manager>" +
         "  </process-engine-context>" +

Modified: jbpm4/branches/jbpm-4.0/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/JuelExpressionTest.java
===================================================================
--- jbpm4/branches/jbpm-4.0/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/JuelExpressionTest.java	2009-07-09 10:01:33 UTC (rev 5265)
+++ jbpm4/branches/jbpm-4.0/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/JuelExpressionTest.java	2009-07-09 10:04:17 UTC (rev 5266)
@@ -43,9 +43,7 @@
         "<jbpm-configuration>" +
         "  <process-engine-context>" +
         "    <script-manager default-expression-language='juel'" +
-        "                    default-script-language='juel'" +
-        "                    read-contexts='execution, environment, process-engine' " +
-        "                    write-context='execution'>" +
+        "                    default-script-language='juel'>" +
         "      <script-language name='juel' factory='com.sun.script.juel.JuelScriptEngineFactory' />" +
         "    </script-manager>" +
         "  </process-engine-context>" +

Modified: jbpm4/branches/jbpm-4.0/modules/pvm/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml
===================================================================
--- jbpm4/branches/jbpm-4.0/modules/pvm/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml	2009-07-09 10:01:33 UTC (rev 5265)
+++ jbpm4/branches/jbpm-4.0/modules/pvm/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml	2009-07-09 10:04:17 UTC (rev 5266)
@@ -23,9 +23,7 @@
 
     
     <script-manager default-expression-language="juel"
-                    default-script-language="juel"
-                    read-contexts="execution, environment, process-engine"
-                    write-context="">
+                    default-script-language="juel">
         <script-language name="juel" factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" />
     </script-manager>
     




More information about the jbpm-commits mailing list