[jbpm-commits] JBoss JBPM SVN: r6880 - in jbpm3/branches/jbpm-3.2-soa: core/src/main/java/org/jbpm/context/exe and 17 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Jan 10 23:58:24 EST 2011


Author: alex.guizar at jboss.com
Date: 2011-01-10 23:58:23 -0500 (Mon, 10 Jan 2011)
New Revision: 6880

Modified:
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/JbpmType.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/JbpmSessionFactory.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/hibernate/Converters.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/action/ActionTypes.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/ProcessDefinition.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/node/NodeTypes.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/UserCodeInterceptorConfig.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/job/Job.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/el/impl/JbpmVariableResolver.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/par/ProcessArchive.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/mail/Mail.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/db/DbPersistenceServiceFactory.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/security/authentication/SubjectAuthenticationService.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java
   jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/mail/MailTest.java
   jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/mail/TaskMailTest.java
   jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/mail/test.mail.properties
   jbpm3/branches/jbpm-3.2-soa/simulation/src/main/java/org/jbpm/sim/def/JbpmSimulationModel.java
Log:
SOA-2416 restore ability to combine external mail properties and property jbpm.mail.from.address

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -29,7 +29,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
 
 /**
  * is used by {@link org.jbpm.bytes.ByteArray} to chop a byte arrays into a list of chunks and
@@ -46,7 +46,7 @@
   public static List chopItUp(byte[] byteArray) {
     List bytes = null;
     if (byteArray != null) {
-      int blockSize = JbpmConfiguration.Configs.getInt("jbpm.byte.block.size");
+      int blockSize = Configs.getInt("jbpm.byte.block.size");
       int byteCount = byteArray.length;
       if (byteCount > blockSize) {
         if (log.isTraceEnabled()) log.trace("chopping up " + byteCount + " bytes");
@@ -85,7 +85,7 @@
         if (log.isTraceEnabled()) log.trace("no need to glue " + byteArray.length + " bytes");
         break;
       default:
-        int blockSize = JbpmConfiguration.Configs.getInt("jbpm.byte.block.size");
+        int blockSize = Configs.getInt("jbpm.byte.block.size");
         byte[] lastBlock = (byte[]) byteBlocks.get(blockCount - 1);
         int byteCount = blockSize * (blockCount - 1) + lastBlock.length;
         if (log.isTraceEnabled()) log.trace("gluing " + byteCount + " bytes back together");

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/JbpmType.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/JbpmType.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/JbpmType.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -26,14 +26,14 @@
 import java.util.List;
 import java.util.Map;
 
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
 import org.jbpm.JbpmException;
 import org.jbpm.configuration.ObjectFactory;
 import org.jbpm.configuration.ObjectFactoryParser;
 import org.jbpm.util.ClassLoaderUtil;
 
 /**
- * specifies how jbpm is able to persist objects of a given type in the database.
+ * specifies how jbpm can persist objects of a given type in the database.
  */
 public class JbpmType {
 
@@ -69,11 +69,11 @@
   }
 
   public static List getJbpmTypes() {
-    if (JbpmConfiguration.Configs.hasObject("jbpm.types")) {
-      return (List) JbpmConfiguration.Configs.getObject("jbpm.types");
+    if (Configs.hasObject("jbpm.types")) {
+      return (List) Configs.getObject("jbpm.types");
     }
 
-    String resource = JbpmConfiguration.Configs.getString("resource.varmapping");
+    String resource = Configs.getString("resource.varmapping");
     synchronized (typesByResource) {
       List types = (List) typesByResource.get(resource);
       if (types == null) {

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/JbpmSessionFactory.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/JbpmSessionFactory.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/JbpmSessionFactory.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -39,7 +39,7 @@
 import org.hibernate.type.LongType;
 import org.hibernate.type.StringType;
 
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
 import org.jbpm.JbpmException;
 import org.jbpm.util.ClassLoaderUtil;
 import org.jbpm.util.JndiUtil;
@@ -63,8 +63,8 @@
   private static String jndiName = getJndiName();
 
   private static String getJndiName() {
-    if (JbpmConfiguration.Configs.hasObject("jbpm.session.factory.jndi.name")) {
-      return JbpmConfiguration.Configs.getString("jbpm.session.factory.jndi.name");
+    if (Configs.hasObject("jbpm.session.factory.jndi.name")) {
+      return Configs.getString("jbpm.session.factory.jndi.name");
     }
     return null;
   }
@@ -122,7 +122,7 @@
   }
 
   private static String getConfigResource() {
-    return JbpmConfiguration.Configs.getString("resource.hibernate.cfg.xml");
+    return Configs.getString("resource.hibernate.cfg.xml");
   }
 
   public static Configuration createConfiguration() {
@@ -141,8 +141,8 @@
 
     // check if the properties in the hibernate.cfg.xml need to be overwritten by a separate
     // properties file.
-    if (JbpmConfiguration.Configs.hasObject("resource.hibernate.properties")) {
-      String propertiesResource = JbpmConfiguration.Configs.getString("resource.hibernate.properties");
+    if (Configs.hasObject("resource.hibernate.properties")) {
+      String propertiesResource = Configs.getString("resource.hibernate.properties");
       if (log.isDebugEnabled()) {
         log.debug("loading hibernate properties from resource: " + propertiesResource);
       }

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/hibernate/Converters.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/hibernate/Converters.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/db/hibernate/Converters.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -29,7 +29,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
 import org.jbpm.JbpmException;
 import org.jbpm.context.exe.Converter;
 import org.jbpm.util.ClassLoaderUtil;
@@ -68,7 +68,7 @@
   }
 
   private static Map getConverters() {
-    String resource = JbpmConfiguration.Configs.getString("resource.converter");
+    String resource = Configs.getString("resource.converter");
     synchronized (convertersByResource) {
       Map converters = (Map) convertersByResource.get(resource);
       if (converters == null) {

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/action/ActionTypes.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/action/ActionTypes.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/action/ActionTypes.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -32,7 +32,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Element;
 
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
 import org.jbpm.util.ClassLoaderUtil;
 import org.jbpm.util.XmlUtil;
 
@@ -66,7 +66,7 @@
   }
 
   private static Map getTypes() {
-    String resource = JbpmConfiguration.Configs.getString("resource.action.types");
+    String resource = Configs.getString("resource.action.types");
     synchronized (typesByResource) {
       Map types = (Map) typesByResource.get(resource);
       if (types == null) {

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/ProcessDefinition.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/ProcessDefinition.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/ProcessDefinition.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -38,7 +38,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.xml.sax.InputSource;
 
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
 import org.jbpm.JbpmContext;
 import org.jbpm.JbpmException;
 import org.jbpm.context.def.ContextDefinition;
@@ -127,7 +127,7 @@
   }
 
   private static List getModuleClasses() {
-    String resource = JbpmConfiguration.Configs.getString("resource.default.modules");
+    String resource = Configs.getString("resource.default.modules");
     synchronized (moduleClassesByResource) {
       List moduleClasses = (List) moduleClassesByResource.get(resource);
       if (moduleClasses == null) {

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/node/NodeTypes.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/node/NodeTypes.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/node/NodeTypes.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -32,7 +32,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Element;
 
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
 import org.jbpm.util.ClassLoaderUtil;
 import org.jbpm.util.XmlUtil;
 
@@ -62,7 +62,7 @@
   }
 
   private static Map getTypes() {
-    String resource = JbpmConfiguration.Configs.getString("resource.node.types");
+    String resource = Configs.getString("resource.node.types");
     synchronized (typesByResource) {
       Map types = (Map) typesByResource.get(resource);
       if (types == null) {

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/UserCodeInterceptorConfig.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/UserCodeInterceptorConfig.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/UserCodeInterceptorConfig.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -1,6 +1,6 @@
 package org.jbpm.instantiation;
 
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
 
 public class UserCodeInterceptorConfig {
 
@@ -12,9 +12,8 @@
 
   public static UserCodeInterceptor getUserCodeInterceptor() {
     return userCodeInterceptor != null ? userCodeInterceptor
-        : JbpmConfiguration.Configs.hasObject("jbpm.user.code.interceptor") ?
-            (UserCodeInterceptor) JbpmConfiguration.Configs.getObject("jbpm.user.code.interceptor")
-            : null;
+      : Configs.hasObject("jbpm.user.code.interceptor") ?
+        (UserCodeInterceptor) Configs.getObject("jbpm.user.code.interceptor") : null;
   }
 
   /** @deprecated Use the configuration entry <code>jbpm.user.code.interceptor</code> instead */

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/job/Job.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/job/Job.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/job/Job.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -3,7 +3,7 @@
 import java.io.Serializable;
 import java.util.Date;
 
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
 import org.jbpm.JbpmContext;
 import org.jbpm.graph.exe.ProcessInstance;
 import org.jbpm.graph.exe.Token;
@@ -29,7 +29,7 @@
   private Date lockTime;
 
   private String exception;
-  private int retries = JbpmConfiguration.Configs.getInt("jbpm.job.retries");
+  private int retries = Configs.getInt("jbpm.job.retries");
 
   private String configuration;
 

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/el/impl/JbpmVariableResolver.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/el/impl/JbpmVariableResolver.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/el/impl/JbpmVariableResolver.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -1,6 +1,6 @@
 package org.jbpm.jpdl.el.impl;
 
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
 import org.jbpm.context.exe.ContextInstance;
 import org.jbpm.graph.exe.ExecutionContext;
 import org.jbpm.graph.exe.Token;
@@ -47,10 +47,6 @@
       if (swimlaneInstance != null) return swimlaneInstance.getActorId();
     }
 
-    if (JbpmConfiguration.Configs.hasObject(name)) {
-      return JbpmConfiguration.Configs.getObject(name);
-    }
-
-    return null;
+    return Configs.hasObject(name) ? Configs.getObject(name) : null;
   }
 }

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/par/ProcessArchive.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/par/ProcessArchive.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/par/ProcessArchive.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -37,7 +37,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Element;
 
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
 import org.jbpm.graph.def.ProcessDefinition;
 import org.jbpm.jpdl.JpdlException;
 import org.jbpm.jpdl.xml.Problem;
@@ -122,7 +122,7 @@
   }
 
   private static List getParsers() {
-    String resource = JbpmConfiguration.Configs.getString("resource.parsers");
+    String resource = Configs.getString("resource.parsers");
     synchronized (parsersByResource) {
       List parsers = (List) parsersByResource.get(resource);
       if (parsers == null) {

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/mail/Mail.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/mail/Mail.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/mail/Mail.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -4,7 +4,6 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -44,7 +43,7 @@
   private String subject;
   private String text;
 
-  private ExecutionContext executionContext;
+  private transient ExecutionContext executionContext;
 
   private static final long serialVersionUID = 2L;
 
@@ -75,55 +74,61 @@
     send();
   }
 
-  public List getRecipients() {
-    List recipients = new ArrayList();
-    if (actors != null) recipients.addAll(evaluateActors(actors));
-    if (to != null) recipients.addAll(evaluateAddresses(to));
-    return recipients;
+  public Collection getRecipients() {
+    return collectRecipients(actors, to);
   }
 
-  public List getCcRecipients() {
-    List recipients = new ArrayList();
-    if (ccActors != null) recipients.addAll(evaluateActors(ccActors));
-    if (cc != null) recipients.addAll(evaluateAddresses(cc));
-    return recipients;
+  public Collection getCcRecipients() {
+    return collectRecipients(ccActors, cc);
   }
 
-  public List getBccRecipients() {
-    List recipients = new ArrayList();
-    if (bccActors != null) recipients.addAll(evaluateActors(bccActors));
-    if (bcc != null) recipients.addAll(evaluateAddresses(bcc));
+  public Collection getBccRecipients() {
+    Collection recipients = collectRecipients(bccActors, bcc);
     if (Configs.hasObject("jbpm.mail.bcc.address")) {
+      if (!(recipients instanceof ArrayList)) recipients = new ArrayList(recipients);
       recipients.addAll(tokenize(Configs.getString("jbpm.mail.bcc.address")));
     }
     return recipients;
   }
 
+  private Collection collectRecipients(String actors, String addresses) {
+    if (actors != null) {
+      if (addresses != null) {
+        Collection recipients = new ArrayList(evaluateActors(actors));
+        recipients.addAll(evaluateAddresses(addresses));
+        return recipients;
+      }
+      return evaluateActors(actors);
+    }
+    else if (addresses != null) {
+      return evaluateAddresses(addresses);
+    }
+    return null;
+  }
+
   private Collection evaluateActors(String expression) {
     Object value = evaluate(expression, Object.class);
-    List actors;
+    Collection actorIds;
     if (value instanceof String) {
-      actors = tokenize((String) value);
+      actorIds = tokenize((String) value);
     }
+    else if (value instanceof Collection) {
+      actorIds = (Collection) value;
+    }
     else if (value instanceof String[]) {
-      actors = Arrays.asList((String[]) value);
+      actorIds = Arrays.asList((String[]) value);
     }
-    else if (value instanceof List) {
-      actors = (List) value;
-    }
-    else if (value instanceof Collection) {
-      actors = new ArrayList((Collection) value);
-    }
     else {
-      throw new JbpmException("could not resolve actors from expression: " + expression);
+      throw new JbpmException(expression + " returned " + value
+        + " instead of comma-separated string, string array or collection");
     }
-    return resolveAddresses(actors);
+    return resolveAddresses(actorIds);
   }
 
-  protected Collection resolveAddresses(List actorIds) {
+  protected Collection resolveAddresses(Collection actorIds) {
     AddressResolver addressResolver = (AddressResolver) Configs.getObject("jbpm.mail.address.resolver");
 
-    List addresses = new ArrayList();
+    Collection addresses = new ArrayList();
     for (Iterator iter = actorIds.iterator(); iter.hasNext();) {
       String actorId = (String) iter.next();
       Object result = addressResolver.resolveAddress(actorId);
@@ -151,8 +156,8 @@
   private Collection evaluateAddresses(String expression) {
     Object value = evaluate(expression, Object.class);
     if (value instanceof String) return tokenize((String) value);
+    if (value instanceof Collection) return (Collection) value;
     if (value instanceof String[]) return Arrays.asList((String[]) value);
-    if (value instanceof Collection) return (Collection) value;
     // give up
     throw new JbpmException(expression + " returned " + value
       + " instead of comma-separated string, string array or collection");
@@ -176,7 +181,8 @@
   }
 
   public String getFromAddress() {
-    return Configs.getString("jbpm.mail.from.address");
+    return Configs.hasObject("jbpm.mail.from.address") ?
+      Configs.getString("jbpm.mail.from.address") : null;
   }
 
   public void send() {
@@ -193,44 +199,46 @@
       if (text == null) text = templateProperties.getProperty("text");
     }
 
-    List recipients = getRecipients();
-    List ccRecipients = getCcRecipients();
-    List bccRecipients = getBccRecipients();
-    if (recipients.isEmpty() && ccRecipients.isEmpty() && bccRecipients.isEmpty()) return;
+    String sender = getFromAddress();
+    Collection recipients = getRecipients();
+    Collection ccRecipients = getCcRecipients();
+    Collection bccRecipients = getBccRecipients();
+    if (nullOrEmpty(recipients) && nullOrEmpty(ccRecipients) && nullOrEmpty(bccRecipients))
+      return;
 
     String subject = getSubject();
     String text = getText();
 
     if (log.isDebugEnabled()) {
-      StringBuffer detail = new StringBuffer("sending email to ");
-      detail.append(recipients);
-      if (!ccRecipients.isEmpty()) detail.append(" cc ").append(ccRecipients);
-      if (!bccRecipients.isEmpty()) detail.append(" bcc ").append(bccRecipients);
+      StringBuffer detail = new StringBuffer("sending email");
+      if (!nullOrEmpty(recipients)) detail.append(" to ").append(recipients);
+      if (!nullOrEmpty(ccRecipients)) detail.append(" cc ").append(ccRecipients);
+      if (!nullOrEmpty(bccRecipients)) detail.append(" bcc ").append(bccRecipients);
       if (subject != null) detail.append(" about '").append(subject).append('\'');
       log.debug(detail.toString());
     }
 
     Session session = Session.getInstance(getServerProperties());
-    for (int retries = 3; retries >= 0; retries--) {
+    for (int retries = 4; retries >= 0; retries--) {
       try {
-        sendMailInternal(session, recipients, ccRecipients, bccRecipients, subject, text);
+        sendInternal(session, sender, recipients, ccRecipients, bccRecipients, subject, text);
         break;
       }
       catch (MessagingException me) {
-        if (retries == 0) throw new JbpmException("cannot send email", me);
-        log.warn("cannot send mail (" + retries + " retries left): " + me.getMessage());
+        if (retries == 0) throw new JbpmException("failed to send email", me);
+        log.warn("failed to send email (" + retries + " retries left): " + me.getMessage());
       }
     }
   }
 
-  public static void send(Properties serverProperties, String fromAddress, List recipients,
+  public static void send(Properties serverProperties, String sender, Collection recipients,
     String subject, String text) {
-    send(serverProperties, fromAddress, recipients, Collections.EMPTY_LIST, subject, text);
+    send(serverProperties, sender, recipients, null, subject, text);
   }
 
-  public static void send(Properties serverProperties, String fromAddress, List recipients,
-    List bccRecipients, String subject, String text) {
-    if (recipients.isEmpty() && bccRecipients.isEmpty()) return;
+  public static void send(Properties serverProperties, String sender, Collection recipients,
+    Collection bccRecipients, String subject, String text) {
+    if (nullOrEmpty(recipients) && nullOrEmpty(bccRecipients)) return;
 
     if (log.isDebugEnabled()) {
       StringBuffer detail = new StringBuffer("sending email to ");
@@ -241,27 +249,40 @@
     }
 
     Session session = Session.getInstance(serverProperties);
-    for (int retries = 3; retries >= 0; retries--) {
+    for (int retries = 4; retries >= 0; retries--) {
       try {
-        sendMailInternal(session, recipients, null, bccRecipients, subject, text);
+        sendInternal(session, null, recipients, null, bccRecipients, subject, text);
         break;
       }
       catch (MessagingException me) {
-        if (retries == 0) throw new JbpmException("cannot send email", me);
-        log.warn("cannot send mail (" + retries + " retries left): " + me.getMessage());
+        if (retries == 0) throw new JbpmException("failed to send email", me);
+        log.warn("failed to send email (" + retries + " retries left): " + me.getMessage());
       }
     }
   }
 
-  private static void sendMailInternal(Session session, List recipients, List ccRecipients,
-    List bccRecipients, String subject, String text) throws MessagingException {
+  private static boolean nullOrEmpty(Collection col) {
+    return col == null || col.isEmpty();
+  }
+
+  private static void sendInternal(Session session, String sender, Collection recipients,
+    Collection ccRecipients, Collection bccRecipients, String subject, String text)
+    throws MessagingException {
     MimeMessage message = new MimeMessage(session);
-    // from - specified in the "mail.from" property
-    message.setFrom();
+    // from
+    if (sender != null) {
+      message.setFrom(new InternetAddress(sender));
+    }
+    else {
+      // read sender from session property "mail.from"
+      message.setFrom();
+    }
     // to
-    for (Iterator iter = recipients.iterator(); iter.hasNext();) {
-      InternetAddress recipient = new InternetAddress((String) iter.next());
-      message.addRecipient(Message.RecipientType.TO, recipient);
+    if (recipients != null) {
+      for (Iterator iter = recipients.iterator(); iter.hasNext();) {
+        InternetAddress recipient = new InternetAddress((String) iter.next());
+        message.addRecipient(Message.RecipientType.TO, recipient);
+      }
     }
     // cc
     if (ccRecipients != null) {
@@ -293,9 +314,10 @@
     if (Configs.hasObject("resource.mail.properties")) {
       String resource = Configs.getString("resource.mail.properties");
       synchronized (serverPropertiesByResource) {
+        // look in server properties cache
         serverProperties = (Properties) serverPropertiesByResource.get(resource);
         if (serverProperties == null) {
-          // load mail properties
+          // load server properties and put them in the cache
           serverProperties = ClassLoaderUtil.getProperties(resource);
           serverPropertiesByResource.put(resource, serverProperties);
         }
@@ -313,9 +335,6 @@
         int port = Configs.getInt("jbpm.mail.smtp.port");
         serverProperties.setProperty("mail.smtp.port", Integer.toString(port));
       }
-      // from
-      String from = getFromAddress();
-      serverProperties.setProperty("mail.from", from);
     }
     return serverProperties;
   }

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/db/DbPersistenceServiceFactory.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/db/DbPersistenceServiceFactory.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/db/DbPersistenceServiceFactory.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -29,7 +29,8 @@
 import org.hibernate.cfg.Configuration;
 import org.hibernate.cfg.Environment;
 import org.hibernate.tool.hbm2ddl.SchemaExport;
-import org.jbpm.JbpmConfiguration;
+
+import org.jbpm.JbpmConfiguration.Configs;
 import org.jbpm.db.JbpmSchema;
 import org.jbpm.db.hibernate.HibernateHelper;
 import org.jbpm.svc.Service;
@@ -64,12 +65,12 @@
   public synchronized Configuration getConfiguration() {
     if (configuration == null) {
       String hibernateCfgXmlResource = null;
-      if (JbpmConfiguration.Configs.hasObject("resource.hibernate.cfg.xml")) {
-        hibernateCfgXmlResource = JbpmConfiguration.Configs.getString("resource.hibernate.cfg.xml");
+      if (Configs.hasObject("resource.hibernate.cfg.xml")) {
+        hibernateCfgXmlResource = Configs.getString("resource.hibernate.cfg.xml");
       }
       String hibernatePropertiesResource = null;
-      if (JbpmConfiguration.Configs.hasObject("resource.hibernate.properties")) {
-        hibernatePropertiesResource = JbpmConfiguration.Configs.getString("resource.hibernate.properties");
+      if (Configs.hasObject("resource.hibernate.properties")) {
+        hibernatePropertiesResource = Configs.getString("resource.hibernate.properties");
       }
       configuration = HibernateHelper.createConfiguration(hibernateCfgXmlResource, hibernatePropertiesResource);
     }

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/security/authentication/SubjectAuthenticationService.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/security/authentication/SubjectAuthenticationService.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/security/authentication/SubjectAuthenticationService.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -30,7 +30,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
 import org.jbpm.JbpmContext;
 import org.jbpm.JbpmException;
 import org.jbpm.security.AuthenticationService;
@@ -63,19 +63,19 @@
       initPrincipalClass(principalClassName);
     }
     else {
-      initPrincipalClass(JbpmConfiguration.Configs.getString("jbpm.authenticator.principal.classname"));
+      initPrincipalClass(Configs.getString("jbpm.authenticator.principal.classname"));
     }
     if (allowActorIdOverwrite != null) {
       this.allowActorIdOverwrite = allowActorIdOverwrite.booleanValue();
     }
     else {
-      this.allowActorIdOverwrite = JbpmConfiguration.Configs.getBoolean("jbpm.authenticator.principal.allow.overwrite");
+      this.allowActorIdOverwrite = Configs.getBoolean("jbpm.authenticator.principal.allow.overwrite");
     }
   }
 
   public SubjectAuthenticationService() {
-    initPrincipalClass(JbpmConfiguration.Configs.getString("jbpm.authenticator.principal.classname"));
-    allowActorIdOverwrite = JbpmConfiguration.Configs.getBoolean("jbpm.authenticator.principal.allow.overwrite");
+    initPrincipalClass(Configs.getString("jbpm.authenticator.principal.classname"));
+    allowActorIdOverwrite = Configs.getBoolean("jbpm.authenticator.principal.allow.overwrite");
   }
 
   protected void initPrincipalClass(String principalClassName) {

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -335,8 +335,8 @@
 
   private TaskInstance instantiateNewTaskInstance(ExecutionContext executionContext) {
     if (Configs.hasObject("jbpm.task.instance.factory")) {
-      TaskInstanceFactory factory = (TaskInstanceFactory) Configs
-        .getObject("jbpm.task.instance.factory");
+      TaskInstanceFactory factory =
+        (TaskInstanceFactory) Configs.getObject("jbpm.task.instance.factory");
       return factory.createTaskInstance(executionContext);
     }
     return new TaskInstance();

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -28,7 +28,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
 import org.jbpm.JbpmException;
 import org.jbpm.configuration.ObjectFactory;
 
@@ -89,7 +89,7 @@
    * </ul>
    */
   public static ClassLoader getClassLoader() {
-    ObjectFactory objectFactory = JbpmConfiguration.Configs.getObjectFactory();
+    ObjectFactory objectFactory = Configs.getObjectFactory();
     if (objectFactory.hasObject("jbpm.class.loader")) {
       String classLoader = (String) objectFactory.createObject("jbpm.class.loader");
 

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/mail/MailTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/mail/MailTest.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/mail/MailTest.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -33,6 +33,7 @@
     + "<jbpm-configuration>"
     + "  <jbpm-context />"
     + "  <string name='resource.mail.properties' value='org/jbpm/mail/test.mail.properties' />"
+    + "  <string name='jbpm.mail.from.address' value='workflow at redhat.com' /> "
     + "  <bean name='jbpm.mail.address.resolver' class='"
     + TestAddressResolver.class.getName()
     + "' singleton='true' />"
@@ -400,9 +401,7 @@
     private static final long serialVersionUID = 1L;
 
     public Object resolveAddress(String actorId) {
-      if ("ghost".equals(actorId)) {
-        return null;
-      }
+      if ("ghost".equals(actorId)) return null;
       return actorId + "@example.domain";
     }
   }

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/mail/TaskMailTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/mail/TaskMailTest.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/mail/TaskMailTest.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -5,21 +5,17 @@
 import java.util.Arrays;
 import java.util.List;
 
-import javax.mail.MessagingException;
 import javax.mail.Message.RecipientType;
+import javax.mail.MessagingException;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
 
 import junit.framework.Test;
 
-import org.subethamail.wiser.Wiser;
-import org.subethamail.wiser.WiserMessage;
-
 import org.jbpm.AbstractJbpmTestCase;
 import org.jbpm.JbpmConfiguration;
 import org.jbpm.JbpmContext;
 import org.jbpm.graph.def.ProcessDefinition;
-import org.jbpm.graph.exe.ExecutionContext;
 import org.jbpm.graph.exe.ProcessInstance;
 import org.jbpm.graph.exe.Token;
 import org.jbpm.instantiation.Delegation;
@@ -28,10 +24,10 @@
 import org.jbpm.svc.Service;
 import org.jbpm.svc.ServiceFactory;
 import org.jbpm.svc.Services;
-import org.jbpm.taskmgmt.def.AssignmentHandler;
-import org.jbpm.taskmgmt.exe.Assignable;
 import org.jbpm.taskmgmt.exe.TaskInstance;
 import org.jbpm.taskmgmt.exe.TaskMgmtInstance;
+import org.subethamail.wiser.Wiser;
+import org.subethamail.wiser.WiserMessage;
 
 public class TaskMailTest extends AbstractJbpmTestCase {
 
@@ -189,15 +185,6 @@
     assertEquals(1, testSchedulerService.cancelledTimers.size());
   }
 
-  public static class GhostAssigner implements AssignmentHandler {
-    private static final long serialVersionUID = 1L;
-
-    public void assign(Assignable assignable, ExecutionContext executionContext)
-      throws Exception {
-      assignable.setActorId("ghost");
-    }
-  }
-
   public void testUnexistingUser() throws Exception {
     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
       + "  <start-state>"
@@ -205,9 +192,7 @@
       + "  </start-state>"
       + "  <task-node name='a'>"
       + "    <task name='laundry' notify='true'>"
-      + "      <assignment class='"
-      + GhostAssigner.class.getName()
-      + "' />"
+      + "      <assignment actor-id='ghost' />"
       + "    </task>"
       + "    <transition to='b' />"
       + "  </task-node>"

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/mail/test.mail.properties
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/mail/test.mail.properties	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/mail/test.mail.properties	2011-01-11 04:58:23 UTC (rev 6880)
@@ -1,3 +1,2 @@
 mail.smtp.host = localhost
 mail.smtp.port = 2525
-mail.from = workflow at redhat.com
\ No newline at end of file

Modified: jbpm3/branches/jbpm-3.2-soa/simulation/src/main/java/org/jbpm/sim/def/JbpmSimulationModel.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/simulation/src/main/java/org/jbpm/sim/def/JbpmSimulationModel.java	2010-12-23 02:29:52 UTC (rev 6879)
+++ jbpm3/branches/jbpm-3.2-soa/simulation/src/main/java/org/jbpm/sim/def/JbpmSimulationModel.java	2011-01-11 04:58:23 UTC (rev 6880)
@@ -11,7 +11,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
 import org.jbpm.graph.def.Node;
 import org.jbpm.graph.def.ProcessDefinition;
 import org.jbpm.graph.def.Transition;
@@ -162,7 +162,7 @@
     // set the jBPM-Clock and register it to be controlled by the real simulation clock
     // TODO: Only do that, if the clock isn't already created, e.g. by JbpmExperiment
     JbpmSimulationClock jbpmClock =
-      (JbpmSimulationClock) JbpmConfiguration.Configs.getObject("jbpm.date.generator");
+      (JbpmSimulationClock) Configs.getObject("jbpm.date.generator");
     getExperiment().getSimClock().addObserver(jbpmClock);
   }
   



More information about the jbpm-commits mailing list