JBoss JBPM SVN: r6278 - jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-04-23 20:18:37 -0400 (Fri, 23 Apr 2010)
New Revision: 6278
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailServer.java
Log:
JBPM-2426: move away from default mail session as it is "potentially available to all code executing in the same vm"; cache new session in mail server instead
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java 2010-04-23 19:27:29 UTC (rev 6277)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java 2010-04-24 00:18:37 UTC (rev 6278)
@@ -144,7 +144,7 @@
}
private String[] tokenizeActors(String recipients, Execution execution) {
- String[] actors = evaluateExpression(recipients).split("[,;|\\s]+");
+ String[] actors = evaluateExpression(recipients).split("[,;\\s]+");
if (actors.length == 0) throw new JbpmException("recipient list is empty: " + recipients);
return actors;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailServer.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailServer.java 2010-04-23 19:27:29 UTC (rev 6277)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailServer.java 2010-04-24 00:18:37 UTC (rev 6278)
@@ -15,6 +15,7 @@
private AddressFilter addressFilter;
private Properties sessionProperties;
private Authenticator authenticator;
+ private Session mailSession;
public AddressFilter getAddressFilter() {
return addressFilter;
@@ -41,6 +42,9 @@
}
public Session getMailSession() {
- return Session.getDefaultInstance(sessionProperties, authenticator);
+ if (mailSession == null) {
+ mailSession = Session.getInstance(sessionProperties, authenticator);
+ }
+ return mailSession;
}
}
14 years
JBoss JBPM SVN: r6277 - projects/exception_framework/trunk.
by do-not-reply@jboss.org
Author: eschabell
Date: 2010-04-23 15:27:29 -0400 (Fri, 23 Apr 2010)
New Revision: 6277
Modified:
projects/exception_framework/trunk/readme.txt
Log:
Added maven info to readme.txt file.
Modified: projects/exception_framework/trunk/readme.txt
===================================================================
--- projects/exception_framework/trunk/readme.txt 2010-04-23 19:22:41 UTC (rev 6276)
+++ projects/exception_framework/trunk/readme.txt 2010-04-23 19:27:29 UTC (rev 6277)
@@ -6,10 +6,11 @@
to a Human Task for processing the error. In our test we end this task to continue
processing and go back to the originating process.
-
This project is maven enabled, which means you can check this out as a java project in eclipse and just run:
maven eclipse:eclipse
+
+Note: 'maven build' and 'maven install' should run too.
My thanks to Maurice de Chateau for his contributions.
14 years
JBoss JBPM SVN: r6276 - in projects/exception_framework/trunk: src/test/java/org/jboss/test and 1 other directory.
by do-not-reply@jboss.org
Author: eschabell
Date: 2010-04-23 15:22:41 -0400 (Fri, 23 Apr 2010)
New Revision: 6276
Added:
projects/exception_framework/trunk/src/test/java/org/jboss/test/TestForStateExceptionHandling.java
Modified:
projects/exception_framework/trunk/readme.txt
Log:
Added state node test for exception handling and updated readme.
Modified: projects/exception_framework/trunk/readme.txt
===================================================================
--- projects/exception_framework/trunk/readme.txt 2010-04-23 19:21:17 UTC (rev 6275)
+++ projects/exception_framework/trunk/readme.txt 2010-04-23 19:22:41 UTC (rev 6276)
@@ -1,16 +1,17 @@
Project space to put together the results of a generic exception framework
example based on jBPM version 3.2.8 (see pom.xml for dependencies).
-Currently only running a test to show simple node failing, then passing exception and
+Contains tests to show simple node and state node failing, then passing exception and
all process context over to the Exception Framework. This framework defaults currently
to a Human Task for processing the error. In our test we end this task to continue
processing and go back to the originating process.
-This project is maven enabled.
-TODO: State node failure example via unit test class.
+This project is maven enabled, which means you can check this out as a java project in eclipse and just run:
+
+maven eclipse:eclipse
-With my thanks to Maurice de Chateau for his contributions.
+My thanks to Maurice de Chateau for his contributions.
Regards,
Eric D. Schabell
Added: projects/exception_framework/trunk/src/test/java/org/jboss/test/TestForStateExceptionHandling.java
===================================================================
--- projects/exception_framework/trunk/src/test/java/org/jboss/test/TestForStateExceptionHandling.java (rev 0)
+++ projects/exception_framework/trunk/src/test/java/org/jboss/test/TestForStateExceptionHandling.java 2010-04-23 19:22:41 UTC (rev 6276)
@@ -0,0 +1,241 @@
+package org.jboss.test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.log4j.Appender;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jboss.util.ProcessDefinitionReference;
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmContext;
+import org.jbpm.db.GraphSession;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.taskmgmt.exe.TaskInstance;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Tests for the Abstract Action Handler.
+ */
+public class TestForStateExceptionHandling {
+
+ /** The global jBPM configuration. */
+ private static JbpmConfiguration jbpmConf = JbpmConfiguration.getInstance();
+
+ /** Variables for Tasks. */
+ private static final String ACTOR_ID = "EXPERT";
+ private static final String TASK_NAME = "Technical dropout";
+ private static final Set<String> POOLED_ACTORS = null;
+ private static final String SWIMLANE = null;
+
+ public static final String ORIGINATING_PROCESS_NAME = "Originator Process";
+ public static final String EXCEPTION_FRAMEWORK_PROCESS_NAME = "Exception Framework";
+
+ /**
+ * Fix the standard logging setup to work better within the IDE console,
+ * just comment out to use and COMMENT OUT BEFORE CHECKIN.
+ */
+ @BeforeClass
+ public static final void oneTimeSetupExceptionFrameworkTesting() {
+ // Turn on for logging in console to be within my IDE window size.
+ //((PatternLayout) ((Appender) Logger.getRootLogger().getAllAppenders().nextElement()).getLayout()).setConversionPattern("%r [%t] %p %c %x -%n%n %m%n%n");
+
+
+ // Start the JobExecutor for async continuations within the test environment.
+ jbpmConf.startJobExecutor();
+
+ // Initialize logging.
+ BasicConfigurator.configure();
+ // - Remove the superfluous appender.
+ Logger.getRootLogger().removeAppender((Appender) Logger.getRootLogger().getAllAppenders().nextElement());
+ // Adjust levels:
+ Logger.getRootLogger().setLevel(Level.ERROR);
+ Logger.getLogger("org.jboss").setLevel(Level.DEBUG);
+ Logger.getLogger("org.jbpm.graph").setLevel(Level.DEBUG);
+
+ // Deploy my exception framework too.
+ try {
+ deployExceptionFramework();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Called once after all test runs, stops the JobExecutor.
+ *
+ * @throws Exception When something unexpected goes wrong.
+ */
+ @AfterClass
+ public static final void oneTimeTearDown() throws Exception {
+ // End the JobExecutor thread.
+ jbpmConf.getJobExecutor().stop();
+ }
+
+ /**
+ * The main test we want to run here to throw an exception in the Node of our
+ * test process and handle it through our Exception Framework.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testForStateExceptionHandling() throws Exception {
+ // deploy process first.
+ JbpmContext jbpmCtx = jbpmConf.createJbpmContext();
+ try {
+ // Create an instance of the jBPM process.
+ ProcessDefinition procDef = getTestProcess().parseAndDeployProcess();
+ ProcessInstance procInst = new ProcessInstance(procDef);
+ jbpmCtx.save(procInst);
+ } finally {
+ // Close the transaction.
+ jbpmCtx.close();
+ }
+
+ // signal process to start.
+ jbpmCtx = jbpmConf.createJbpmContext();
+ try {
+ long processInstanceId = getProcessId(ORIGINATING_PROCESS_NAME);
+ ProcessInstance procInst = jbpmCtx.getProcessInstance(processInstanceId);
+ assertThat("No exception process instance returned.", procInst, is(not(nullValue())));
+ procInst.signal();
+ } finally {
+ jbpmCtx.close();
+ }
+
+ Thread.sleep(5000);
+
+ // In Human Task and need to end which will cause the flow to signal back
+ // to the originating process.
+ endTask();
+
+ // Test that originating process is in end state.
+ jbpmCtx = jbpmConf.createJbpmContext();
+ try {
+ long processInstanceId = getProcessId(ORIGINATING_PROCESS_NAME);
+ ProcessInstance procInst = jbpmCtx.getProcessInstance(processInstanceId);
+ assertThat("No exception process instance returned.", procInst, is(not(nullValue())));
+ assertThat("Exception process not ended.", procInst.hasEnded(), is(true));
+ } finally {
+ jbpmCtx.close();
+ }
+
+ // Test that it is in end state now for exception framework.
+ jbpmCtx = jbpmConf.createJbpmContext();
+ try {
+ long processInstanceId = getProcessId(EXCEPTION_FRAMEWORK_PROCESS_NAME);
+ ProcessInstance procInst = jbpmCtx.getProcessInstance(processInstanceId);
+ assertThat("No exception process instance returned.", procInst, is(not(nullValue())));
+ assertThat("Exception process in unexpected state.", procInst.hasEnded(), is(true));
+ } finally {
+ jbpmCtx.close();
+ }
+ }
+
+ /**
+ * Gives you the test process definition.
+ */
+ protected ProcessDefinitionReference getTestProcess() throws Exception {
+ String testProcDef = "<process-definition xmlns=\"urn:jbpm.org:jpdl-3.1\" name=\"" + ORIGINATING_PROCESS_NAME + "\">"
+ + "<start-state name=\"start\">"
+ + "<transition to=\"state1\" />"
+ + "</start-state>"
+ + "<state name=\"state1\">"
+ + "<event type=\"node-enter\">"
+ + "<action class=\"org.jboss.handler.ExceptionThrowingHandler\" />"
+ + "</event>"
+ + "<transition to=\"end\" name=\"state_to_end\" />"
+ + "</state>"
+ + "<end-state name=\"end\" />"
+ + "</process-definition>";
+ return new ProcessDefinitionReference(testProcDef);
+ }
+
+ private static void deployExceptionFramework() throws Exception {
+ // Open the transaction.
+ JbpmContext jbpmCtx = jbpmConf.createJbpmContext();
+ try {
+ // Create an instance of the jBPM exception framework process.
+ String frameworkXml = "process/processdefinition.xml";
+ ProcessDefinition procDef = ProcessDefinition.parseXmlResource(frameworkXml);
+ jbpmCtx.deployProcessDefinition(procDef);
+ } finally {
+ // Close the transaction.
+ jbpmCtx.close();
+ }
+ }
+
+ private void endTask() {
+ // Open the transaction.
+ JbpmContext jbpmCtx = jbpmConf.createJbpmContext();
+ try {
+ long processInstanceId = getProcessId(EXCEPTION_FRAMEWORK_PROCESS_NAME);
+ ProcessInstance procInst = jbpmCtx.getProcessInstance(processInstanceId);
+ assertThat("No exception process instance returned.", procInst, is(not(nullValue())));
+
+ Collection<TaskInstance> taskInsts = procInst.getTaskMgmtInstance().getUnfinishedTasks(procInst.getRootToken());
+ assertThat("No task instances found.", taskInsts, is(not(nullValue())));
+
+ TaskInstance taskInst = getIndicatedTaskInstance(taskInsts, ACTOR_ID, TASK_NAME, POOLED_ACTORS, SWIMLANE);
+ if (taskInst != null) {
+ // End the task instance.
+ taskInst.end();
+ }
+ } finally {
+ // Tear down the pojo persistence context.
+ jbpmCtx.close();
+ }
+ }
+
+
+ private long getProcessId (String processName) {
+ long procId;
+
+ // Open the transaction.
+ JbpmContext jbpmCtx = jbpmConf.createJbpmContext();
+ try {
+ // Get our process instance back.
+ GraphSession graphSession = jbpmCtx.getGraphSession();
+ ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition(processName);
+ assertThat("No process definition found.", processDefinition, is(not(nullValue())));
+
+ // Now, we search for all process instances of this process definition.
+ List processInstances = graphSession.findProcessInstances(processDefinition.getId());
+ ProcessInstance procInst = (ProcessInstance) processInstances.get(0);
+ procId = procInst.getId();
+ } finally {
+ // Tear down the pojo persistence context.
+ jbpmCtx.close();
+ }
+
+ return procId;
+ }
+
+ private TaskInstance getIndicatedTaskInstance(Collection<TaskInstance> taskInsts, final String actorId, final String taskName,
+ final Set<String> pooledActors, final String swimlane) {
+ TaskInstance indicated = null;
+ for (TaskInstance taskInst : taskInsts) {
+ if ((actorId == null || actorId.equals(taskInst.getActorId()))
+ && (taskName == null || taskName.equals(taskInst.getTask().getName()))
+ && (pooledActors == null || CollectionUtils.isSubCollection(pooledActors, taskInst.getPooledActors()))
+ && (swimlane == null || swimlane.equals(taskInst.getSwimlaneInstance().getName()))) {
+ indicated = taskInst;
+ break;
+ }
+ }
+ return indicated;
+ }
+
+}
14 years
JBoss JBPM SVN: r6275 - projects/exception_framework/trunk/src/test/java/org/jboss/test.
by do-not-reply@jboss.org
Author: eschabell
Date: 2010-04-23 15:21:17 -0400 (Fri, 23 Apr 2010)
New Revision: 6275
Modified:
projects/exception_framework/trunk/src/test/java/org/jboss/test/TestForNodeExceptionHandling.java
Log:
Renamed the actual test in Node test.
Modified: projects/exception_framework/trunk/src/test/java/org/jboss/test/TestForNodeExceptionHandling.java
===================================================================
--- projects/exception_framework/trunk/src/test/java/org/jboss/test/TestForNodeExceptionHandling.java 2010-04-23 07:13:49 UTC (rev 6274)
+++ projects/exception_framework/trunk/src/test/java/org/jboss/test/TestForNodeExceptionHandling.java 2010-04-23 19:21:17 UTC (rev 6275)
@@ -91,7 +91,7 @@
* @throws Exception
*/
@Test
- public void testRun() throws Exception {
+ public void testForNodeExceptionHandling() throws Exception {
// deploy process first.
JbpmContext jbpmCtx = jbpmConf.createJbpmContext();
try {
14 years
JBoss JBPM SVN: r6274 - in jbpm3/branches/jbpm-3.2-soa/modules: core/src/main/java/org/jbpm/calendar and 27 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-04-23 03:13:49 -0400 (Fri, 23 Apr 2010)
New Revision: 6274
Added:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2852/
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2852/JBPM2852Test.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/gpd.xml
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/jbpm.cfg.xml
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/mail.templates.xml
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/processdefinition.xml
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jpdl/xml/.gpd.testSimpleSchemaReference.xml
jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/gpd.xml
jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/jbpm.cfg.xml
jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/processdefinition.xml
jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/processimage.jpg
Removed:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/context/exe/CustomSessionFactoryFactory.java
jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/mail.properties
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/BeanInfo.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/CharacterInfo.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/ConstructorInfo.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/DoubleInfo.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/FieldInfo.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/FloatInfo.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/IntegerInfo.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/JbpmContextInfo.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/JbpmTypeObjectInfo.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/LongInfo.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/ObjectFactoryImpl.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/ObjectFactoryParser.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/PropertyInfo.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/RefInfo.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/context/exe/Converter.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/context/exe/JbpmType.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/Converters.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/file/def/FileDefinition.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/action/ActionTypes.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/action/MailAction.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/ExceptionHandler.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/ProcessDefinition.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/MailNode.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/NodeTypes.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/FieldInstantiator.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/par/ProcessArchive.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/xml/JpdlParser.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlReader.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/mail/Mail.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/security/authentication/SubjectAuthenticationService.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/XmlUtil.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/jbpm.cfg.xml
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/jbpm.mail.templates.xml
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/jpdl/xml/jpdl-3.2.xsd
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/SerializabilityTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1707/JBPM1707Test.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mail/MailTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mail/TaskMailTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/mail/test.mail.properties
jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/java/org/jbpm/examples/mail/MailTest.java
Log:
JBPM-2852: support cc recipients in mail node, action and template
make static caches aware of the cached resource (e.g. business calendar)
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -237,6 +237,7 @@
public class JbpmConfiguration implements Serializable {
private static final long serialVersionUID = 1L;
+ private static final String DEFAULT_RESOURCE = "jbpm.cfg.xml";
private static ObjectFactory defaultObjectFactory;
private static final Map instances = new HashMap();
@@ -276,9 +277,7 @@
}
public static JbpmConfiguration getInstance(String resource) {
- if (resource == null) {
- resource = "jbpm.cfg.xml";
- }
+ if (resource == null) resource = DEFAULT_RESOURCE;
JbpmConfiguration instance;
synchronized (instances) {
@@ -298,7 +297,7 @@
* otherwise, users who want to load custom stuff will not receive any feedback when
* their resource cannot be found
*/
- if (jbpmCfgXmlStream == null && !"jbpm.cfg.xml".equals(resource)) {
+ if (jbpmCfgXmlStream == null && !DEFAULT_RESOURCE.equals(resource)) {
log.warn("configuration resource not found: " + resource);
}
ObjectFactory objectFactory = parseObjectFactory(jbpmCfgXmlStream);
@@ -312,7 +311,7 @@
}
public static boolean hasInstance(String resource) {
- return instances.containsKey(resource != null ? resource : "jbpm.cfg.xml");
+ return instances.containsKey(resource != null ? resource : DEFAULT_RESOURCE);
}
protected static ObjectFactory parseObjectFactory(InputStream inputStream) {
@@ -389,10 +388,6 @@
return jbpmContext;
}
- private void ensureOpen() {
- if (isClosed) throw new JbpmException("jbpm configuration is closed");
- }
-
public ServiceFactory getServiceFactory(String serviceName) {
return getServiceFactory(serviceName, JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
}
@@ -407,6 +402,10 @@
}
}
+ private DbPersistenceServiceFactory getPersistenceServiceFactory(String jbpmContextName) {
+ return (DbPersistenceServiceFactory) getServiceFactory(Services.SERVICENAME_PERSISTENCE, jbpmContextName);
+ }
+
public static ClassLoader getProcessClassLoader(ProcessDefinition processDefinition) {
ProcessClassLoaderFactory factory;
if (Configs.hasObject("process.class.loader.factory")) {
@@ -492,8 +491,8 @@
getPersistenceServiceFactory(jbpmContextName).dropSchema();
}
- private DbPersistenceServiceFactory getPersistenceServiceFactory(String jbpmContextName) {
- return (DbPersistenceServiceFactory) getServiceFactory(Services.SERVICENAME_PERSISTENCE, jbpmContextName);
+ private void ensureOpen() {
+ if (isClosed) throw new JbpmException(this + " is closed");
}
public boolean isClosed() {
@@ -602,12 +601,8 @@
public JbpmContext getCurrentJbpmContext() {
ensureOpen();
- JbpmContext currentJbpmContext = null;
List stack = getJbpmContextStack();
- if (!stack.isEmpty()) {
- currentJbpmContext = (JbpmContext) stack.get(stack.size() - 1);
- }
- return currentJbpmContext;
+ return stack.isEmpty() ? null : (JbpmContext) stack.get(stack.size() - 1);
}
private List getJbpmContextStack() {
@@ -656,5 +651,5 @@
: '@' + Integer.toHexString(hashCode()));
}
- private static Log log = LogFactory.getLog(JbpmConfiguration.class);
+ private static final Log log = LogFactory.getLog(JbpmConfiguration.class);
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -25,8 +25,10 @@
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import org.jbpm.JbpmConfiguration;
@@ -39,17 +41,22 @@
public class BusinessCalendar implements Serializable {
private static final long serialVersionUID = 1L;
- private static Properties businessCalendarProperties;
private Day[] weekDays;
private List holidays;
- public static synchronized Properties getBusinessCalendarProperties() {
- if (businessCalendarProperties == null) {
- String resource = JbpmConfiguration.Configs.getString("resource.business.calendar");
- businessCalendarProperties = ClassLoaderUtil.getProperties(resource);
+ private static final Map propertiesByResource = new HashMap();
+
+ public static Properties getBusinessCalendarProperties() {
+ String resource = JbpmConfiguration.Configs.getString("resource.business.calendar");
+ synchronized (propertiesByResource) {
+ Properties properties = (Properties) propertiesByResource.get(resource);
+ if (properties == null) {
+ properties = ClassLoaderUtil.getProperties(resource);
+ propertiesByResource.put(resource, properties);
+ }
+ return properties;
}
- return businessCalendarProperties;
}
public BusinessCalendar() {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/BeanInfo.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/BeanInfo.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/BeanInfo.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -34,9 +34,9 @@
private static final long serialVersionUID = 1L;
- String className = null;
- ConstructorInfo constructorInfo = null;
- PropertyInfo[] propertyInfos = null;
+ private String className;
+ private ConstructorInfo constructorInfo;
+ private PropertyInfo[] propertyInfos;
public BeanInfo() {
}
@@ -47,29 +47,27 @@
// parse constructor or factory
Element constructorElement = XmlUtil.element(beanElement, "constructor");
if (constructorElement != null) {
+ if (beanElement.hasAttribute("class") && !constructorElement.hasAttribute("class")) {
+ constructorElement.setAttribute("class", beanElement.getAttribute("class"));
+ }
constructorInfo = new ConstructorInfo(constructorElement, objectFactoryParser);
- constructorInfo.beanInfo = this;
}
-
- if (beanElement.hasAttribute("class")) {
+ else if (beanElement.hasAttribute("class")) {
className = beanElement.getAttribute("class");
}
- else if ((constructorInfo.factoryRefName == null) && (constructorInfo.factoryClassName == null)) {
- throw new JbpmException("bean element must have a class attribute: "
- + XmlUtil.toString(beanElement));
+ else {
+ throw new JbpmException("missing class attribute or constructor subelement in bean");
}
// parse fields
List propertyInfoList = new ArrayList();
- Iterator iter = XmlUtil.elementIterator(beanElement, "field");
- while (iter.hasNext()) {
+ for (Iterator iter = XmlUtil.elementIterator(beanElement, "field"); iter.hasNext();) {
Element fieldElement = (Element) iter.next();
propertyInfoList.add(new FieldInfo(fieldElement, objectFactoryParser));
}
// parse properties
- iter = XmlUtil.elementIterator(beanElement, "property");
- while (iter.hasNext()) {
+ for (Iterator iter = XmlUtil.elementIterator(beanElement, "property"); iter.hasNext();) {
Element propertyElement = (Element) iter.next();
propertyInfoList.add(new PropertyInfo(propertyElement, objectFactoryParser));
}
@@ -78,30 +76,36 @@
}
public Object createObject(ObjectFactoryImpl objectFactory) {
- Object object = null;
+ Object object;
if (constructorInfo == null) {
- if (className == null)
- throw new JbpmException("bean '"
- + getName()
- + "' doesn't have a class or constructor specified");
+ if (className == null) {
+ throw new JbpmException("bean '" + getName()
+ + "' does not specify a class or constructor");
+ }
try {
Class clazz = objectFactory.classForName(className);
- object = clazz.newInstance();
+ try {
+ object = clazz.newInstance();
+ }
+ catch (InstantiationException e) {
+ throw new JbpmException("failed to instantiate " + clazz, e);
+ }
+ catch (IllegalAccessException e) {
+ throw new JbpmException(getClass() + " has no access to " + clazz, e);
+ }
}
- catch (Exception e) {
- throw new JbpmException("couldn't instantiate bean '"
- + getName()
- + "' of type '"
- + className
- + "'", e);
+ catch (ClassNotFoundException e) {
+ throw new JbpmException("bean '" + getName() + "' specifies a missing class", e);
}
}
else {
object = constructorInfo.createObject(objectFactory);
}
- if (className == null) className = object.getClass().getName();
+ if (className == null) {
+ className = object.getClass().getName();
+ }
if (propertyInfos != null) {
for (int i = 0; i < propertyInfos.length; i++) {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/CharacterInfo.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/CharacterInfo.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/CharacterInfo.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -21,33 +21,27 @@
*/
package org.jbpm.configuration;
-import org.jbpm.JbpmException;
-import org.jbpm.util.XmlUtil;
import org.w3c.dom.Element;
+import org.jbpm.JbpmException;
+
public class CharacterInfo extends AbstractObjectInfo {
private static final long serialVersionUID = 1L;
- Character c = null;
-
+ private Character value;
+
public CharacterInfo(Element charElement, ObjectFactoryParser configParser) {
super(charElement, configParser);
-
- String s = getValueString(charElement);
- if (s!=null) {
- s = s.trim();
- if (s.length()==1) {
- c = new Character(s.charAt(0));
- }
+ String valueString = getValueString(charElement);
+ if (valueString == null) {
+ throw new JbpmException("missing character value");
}
- if (c==null) {
- throw new JbpmException("improper character format '"+XmlUtil.toString(charElement));
- }
+ value = new Character(valueString.charAt(0));
}
public Object createObject(ObjectFactoryImpl objectFactory) {
- return c;
+ return value;
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/ConstructorInfo.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/ConstructorInfo.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/ConstructorInfo.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -23,12 +23,14 @@
import java.io.Serializable;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import org.w3c.dom.Element;
import org.jbpm.JbpmException;
+import org.jbpm.util.ArrayUtil;
import org.jbpm.util.ClassLoaderUtil;
import org.jbpm.util.XmlUtil;
@@ -36,123 +38,133 @@
private static final long serialVersionUID = 1L;
- BeanInfo beanInfo = null;
- String className = null;
- String factoryRefName = null;
- String factoryClassName = null;
- String factoryMethodName = null;
- String[] parameterClassNames = null;
- ObjectInfo[] parameterInfos = null;
+ private String className;
+ private String factoryRefName;
+ private String factoryClassName;
+ private String factoryMethodName;
+ private final String[] parameterClassNames;
+ private final ObjectInfo[] parameterInfos;
public ConstructorInfo(Element constructorElement, ObjectFactoryParser configParser) {
- // beanInfo is set by the beanInfo itself
-
- // className
- if (constructorElement.hasAttribute("class")) {
- className = constructorElement.getAttribute("class");
- }
-
- // factoryInfo
+ // factory
if (constructorElement.hasAttribute("factory")) {
factoryRefName = constructorElement.getAttribute("factory");
if (!constructorElement.hasAttribute("method")) {
- throw new JbpmException(
- "factory element in constructor requires method attribute in constructor: "
- + XmlUtil.toString(constructorElement));
+ throw new JbpmException("missing method attribute in constructor");
}
factoryMethodName = constructorElement.getAttribute("method");
-
}
+ // factory-class
else if (constructorElement.hasAttribute("factory-class")) {
factoryClassName = constructorElement.getAttribute("factory-class");
if (!constructorElement.hasAttribute("method")) {
- throw new JbpmException(
- "factory-class element in constructor requires method attribute in constructor: "
- + XmlUtil.toString(constructorElement));
+ throw new JbpmException("missing method attribute in constructor");
}
factoryMethodName = constructorElement.getAttribute("method");
-
}
else {
if (constructorElement.hasAttribute("method")) {
- throw new JbpmException(
- "'method' element in constructor requires 'factory' of 'factory-class' attribute in constructor: "
- + XmlUtil.toString(constructorElement));
+ throw new JbpmException("missing factory or factory-class attribute in constructor");
}
+ // class
+ if (constructorElement.hasAttribute("class")) {
+ className = constructorElement.getAttribute("class");
+ }
+ else {
+ throw new JbpmException("missing class, factory or factory-class attribute in constructor");
+ }
}
- // parameterTypesNames and parameterInfos
+ // parameterTypesNames and parameterInfos
List parameterElements = XmlUtil.elements(constructorElement, "parameter");
parameterClassNames = new String[parameterElements.size()];
parameterInfos = new ObjectInfo[parameterElements.size()];
for (int i = 0; i < parameterElements.size(); i++) {
Element parameterElement = (Element) parameterElements.get(i);
if (!parameterElement.hasAttribute("class")) {
- throw new JbpmException("parameter element must have a class attribute: "
- + XmlUtil.toString(parameterElement));
+ throw new JbpmException("missing class attribute in constructor parameter");
}
parameterClassNames[i] = parameterElement.getAttribute("class");
+
Element parameterInfoElement = XmlUtil.element(parameterElement);
if (parameterInfoElement == null) {
- throw new JbpmException("parameter element must have exactly 1 child element: "
- + XmlUtil.toString(parameterElement));
+ throw new JbpmException("missing subelement in constructor parameter");
}
parameterInfos[i] = configParser.parse(parameterInfoElement);
}
}
public Object createObject(ObjectFactoryImpl objectFactory) {
- Object newObject = null;
-
Object[] args = getArgs(objectFactory);
Class[] parameterTypes = getParameterTypes(objectFactory);
- if ((factoryRefName != null) || (factoryClassName != null)) {
- Object factory = null;
- Class factoryClass = null;
+ if (factoryRefName != null || factoryClassName != null) {
+ Object factory;
+ Class factoryClass;
if (factoryRefName != null) {
factory = objectFactory.getObject(factoryRefName);
factoryClass = factory.getClass();
}
else {
- factoryClass = ClassLoaderUtil.classForName(factoryClassName);
+ factory = null;
+ try {
+ factoryClass = ClassLoaderUtil.classForName(factoryClassName);
+ }
+ catch (ClassNotFoundException e) {
+ throw new JbpmException("factory class not found: " + factoryClassName, e);
+ }
}
+ Method factoryMethod = findMethod(factoryClass, parameterTypes);
try {
- Method factoryMethod = findMethod(factoryClass, parameterTypes);
- newObject = factoryMethod.invoke(factory, args);
+ return factoryMethod.invoke(factory, args);
}
- catch (Exception e) {
- throw new JbpmException("couldn't create new bean with factory method '"
- + factoryClass.getName()
- + "."
- + factoryMethodName, e);
+ catch (IllegalAccessException e) {
+ throw new JbpmException(getClass() + " has no access to " + factoryMethod, e);
}
-
+ catch (InvocationTargetException e) {
+ throw new JbpmException(factoryMethod + " threw exception", e.getCause());
+ }
}
else {
- String className = (this.className != null ? this.className : beanInfo.getClassName());
- Class clazz = objectFactory.classForName(className);
-
try {
+ Class clazz = objectFactory.classForName(className);
Constructor constructor = clazz.getDeclaredConstructor(parameterTypes);
- newObject = constructor.newInstance(args);
+ try {
+ return constructor.newInstance(args);
+ }
+ catch (InstantiationException e) {
+ throw new JbpmException("failed to instantiate " + clazz, e);
+ }
+ catch (IllegalAccessException e) {
+ throw new JbpmException(getClass() + " has no access to " + constructor, e);
+ }
+ catch (InvocationTargetException e) {
+ throw new JbpmException(constructor + " threw exception", e.getCause());
+ }
}
- catch (Exception e) {
- throw new JbpmException("couldn't instantiate new '" + className + "' with constructor", e);
+ catch (ClassNotFoundException e) {
+ throw new JbpmException("class not found: " + className, e);
}
-
+ catch (NoSuchMethodException e) {
+ throw new JbpmException("constructor not found: " + className
+ + ArrayUtil.toString(parameterTypes), e);
+ }
}
-
- return newObject;
}
protected Class[] getParameterTypes(ObjectFactoryImpl objectFactory) {
- int nbrOfParameters = (parameterClassNames != null ? parameterClassNames.length : 0);
+ int nbrOfParameters = parameterClassNames != null ? parameterClassNames.length : 0;
Class[] parameterTypes = new Class[nbrOfParameters];
for (int i = 0; i < nbrOfParameters; i++) {
- parameterTypes[i] = objectFactory.classForName(parameterClassNames[i]);
+ String parameterClassName = parameterClassNames[i];
+ try {
+ parameterTypes[i] = objectFactory.classForName(parameterClassName);
+ }
+ catch (ClassNotFoundException e) {
+ throw new JbpmException("class not found: " + parameterClassName, e);
+ }
}
return parameterTypes;
}
@@ -167,26 +179,22 @@
}
public Method findMethod(Class clazz, Class[] parameterTypes) {
- Method method = null;
-
- Class candidateClass = clazz;
- while ((candidateClass != null) && (method == null)) {
- try {
- method = clazz.getDeclaredMethod(factoryMethodName, parameterTypes);
- }
- catch (NoSuchMethodException e1) {
- candidateClass = candidateClass.getSuperclass();
- }
+ try {
+ // look for public method
+ return clazz.getMethod(factoryMethodName, parameterTypes);
}
-
- if (method == null) {
- throw new JbpmException("couldn't find factory method '"
- + factoryMethodName
- + "' in class '"
- + clazz.getName()
- + "'");
+ catch (NoSuchMethodException e) {
+ // look for any method up the class hierarchy
+ do {
+ try {
+ return clazz.getDeclaredMethod(factoryMethodName, parameterTypes);
+ }
+ catch (NoSuchMethodException e2) {
+ clazz = clazz.getSuperclass();
+ }
+ } while (clazz != null);
+ // give up
+ throw new JbpmException("no such method: " + factoryMethodName, e);
}
-
- return method;
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/DoubleInfo.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/DoubleInfo.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/DoubleInfo.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -21,29 +21,21 @@
*/
package org.jbpm.configuration;
-import org.jbpm.JbpmException;
-import org.jbpm.util.XmlUtil;
import org.w3c.dom.Element;
public class DoubleInfo extends AbstractObjectInfo {
private static final long serialVersionUID = 1L;
- Double d = null;
-
+ private Double value;
+
public DoubleInfo(Element doubleElement, ObjectFactoryParser configParser) {
super(doubleElement, configParser);
-
- String contentText = getValueString(doubleElement);
- try {
- d = (new Double(contentText));
- } catch (Exception e) {
- throw new JbpmException("content of "+XmlUtil.toString(doubleElement)+" could not be parsed as a double", e);
- }
+ value = new Double(getValueString(doubleElement));
}
public Object createObject(ObjectFactoryImpl objectFactory) {
- return d;
+ return value;
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/FieldInfo.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/FieldInfo.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/FieldInfo.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -23,11 +23,10 @@
import java.lang.reflect.Field;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jbpm.JbpmException;
import org.w3c.dom.Element;
+import org.jbpm.JbpmException;
+
public class FieldInfo extends PropertyInfo {
private static final long serialVersionUID = 1L;
@@ -37,40 +36,29 @@
}
public void injectProperty(Object object, ObjectFactoryImpl objectFactory) {
-
- Object propertyValue = objectFactory.getObject(propertyValueInfo);
- Field propertyField = findField(object.getClass());
- propertyField.setAccessible(true);
+ Field field = findField(object.getClass());
+ field.setAccessible(true);
+ Object value = objectFactory.getObject(getPropertyValueInfo());
try {
- propertyField.set(object, propertyValue);
- } catch (Exception e) {
- throw new JbpmException("couldn't set field '"+propertyName+"' on class '"+object.getClass()+"' to value '"+propertyValue+"'", e);
+ field.set(object, value);
}
+ catch (IllegalAccessException e) {
+ throw new JbpmException(getClass() + " has no access to " + field, e);
+ }
}
- Field findField(Class clazz) {
- Field field = null;
-
- Class candidateClass = clazz;
- while ( (candidateClass!=null)
- && (field==null)
- ) {
+ private Field findField(Class clazz) {
+ String fieldName = getPropertyName();
+ for (Class currentClass = clazz; currentClass != Object.class; currentClass = currentClass.getSuperclass()) {
try {
- field = candidateClass.getDeclaredField(propertyName);
- } catch (Exception e) {
- candidateClass = candidateClass.getSuperclass();
+ return clazz.getDeclaredField(fieldName);
}
+ catch (NoSuchFieldException e) {
+ clazz = clazz.getSuperclass();
+ }
}
- if (field==null) {
- JbpmException e = new JbpmException("couldn't find field '"+propertyName+"' in class '"+clazz.getName()+"'");
- log.error(e);
- throw e;
- }
-
- return field;
+ throw new JbpmException("missing field '" + "' in " + clazz);
}
-
- private static Log log = LogFactory.getLog(FieldInfo.class);
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/FloatInfo.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/FloatInfo.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/FloatInfo.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -21,29 +21,21 @@
*/
package org.jbpm.configuration;
-import org.jbpm.JbpmException;
-import org.jbpm.util.XmlUtil;
import org.w3c.dom.Element;
public class FloatInfo extends AbstractObjectInfo {
private static final long serialVersionUID = 1L;
-
- Float f = null;
+ private Float value;
+
public FloatInfo(Element floatElement, ObjectFactoryParser configParser) {
super(floatElement, configParser);
-
- String contentText = getValueString(floatElement);
- try {
- f = (new Float(contentText));
- } catch (Exception e) {
- throw new JbpmException("content of "+XmlUtil.toString(floatElement)+" could not be parsed as a float", e);
- }
+ value = new Float(getValueString(floatElement));
}
public Object createObject(ObjectFactoryImpl objectFactory) {
- return f;
+ return value;
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/IntegerInfo.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/IntegerInfo.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/IntegerInfo.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -21,29 +21,21 @@
*/
package org.jbpm.configuration;
-import org.jbpm.JbpmException;
-import org.jbpm.util.XmlUtil;
import org.w3c.dom.Element;
public class IntegerInfo extends AbstractObjectInfo {
-
+
private static final long serialVersionUID = 1L;
-
- Integer i = null;
+ private Integer value;
+
public IntegerInfo(Element integerElement, ObjectFactoryParser configParser) {
super(integerElement, configParser);
-
- String contentText = getValueString(integerElement);
- try {
- i = new Integer(contentText);
- } catch (Exception e) {
- throw new JbpmException("content of "+XmlUtil.toString(integerElement)+" could not be parsed as a integer", e);
- }
+ value = new Integer(getValueString(integerElement));
}
public Object createObject(ObjectFactoryImpl objectFactory) {
- return i;
+ return value;
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/JbpmContextInfo.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/JbpmContextInfo.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/JbpmContextInfo.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -46,8 +46,7 @@
public JbpmContextInfo(Element jbpmContextElement, ObjectFactoryParser objectFactoryParser) {
super(verifyDefaultName(jbpmContextElement), objectFactoryParser);
if (jbpmContextElement.hasAttribute("singleton")) {
- throw new ConfigurationException(
- "attribute 'singleton' is not allowed in element 'jbpm-context'");
+ throw new ConfigurationException("attribute 'singleton' is not allowed in element 'jbpm-context'");
}
// parse the services
@@ -56,8 +55,7 @@
for (Iterator iter = XmlUtil.elementIterator(jbpmContextElement, "service"); iter.hasNext();) {
Element serviceElement = (Element) iter.next();
if (!serviceElement.hasAttribute("name")) {
- throw new ConfigurationException("name is required in service element "
- + XmlUtil.toString(serviceElement));
+ throw new ConfigurationException("service has no name");
}
String serviceName = serviceElement.getAttribute("name");
serviceNames.add(serviceName);
@@ -66,8 +64,7 @@
if (factoryElement != null) {
Element factoryBeanElement = XmlUtil.element(factoryElement);
if (factoryBeanElement == null) {
- throw new ConfigurationException(
- "element 'factory' requires either a bean or ref element");
+ throw new ConfigurationException("element 'factory' requires either a bean or ref element");
}
serviceFactoryObjectInfo = objectFactoryParser.parse(factoryBeanElement);
}
@@ -78,8 +75,7 @@
serviceFactoryObjectInfo = beanInfo;
}
else {
- throw new ConfigurationException(
- "element 'service' requires either a factory attribute or a factory element");
+ throw new ConfigurationException("element 'service' requires either a factory attribute or a factory element");
}
serviceFactoryObjectInfos.put(serviceName, serviceFactoryObjectInfo);
@@ -102,8 +98,7 @@
else {
Element saveOperationBeanElement = XmlUtil.element(saveOperationElement);
if (saveOperationBeanElement == null) {
- throw new ConfigurationException(
- "element 'save-operation' requires either a class attribute or an element of type 'bean' or 'ref'");
+ throw new ConfigurationException("element 'save-operation' requires either a class attribute or an element of type 'bean' or 'ref'");
}
saveOperationObjectInfos[i] = objectFactoryParser.parse(saveOperationBeanElement);
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/JbpmTypeObjectInfo.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/JbpmTypeObjectInfo.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/JbpmTypeObjectInfo.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -37,59 +37,49 @@
private static final long serialVersionUID = 1L;
- ObjectInfo typeMatcherObjectInfo;
- Converter converter;
- Class variableInstanceClass;
+ private ObjectInfo typeMatcherObjectInfo;
+ private Converter converter;
+ private Class variableInstanceClass;
public JbpmTypeObjectInfo(Element jbpmTypeElement, ObjectFactoryParser objectFactoryParser) {
super(jbpmTypeElement, objectFactoryParser);
- try {
- Element typeMatcherElement = XmlUtil.element(jbpmTypeElement, "matcher");
- if (typeMatcherElement == null) {
- throw new ConfigurationException("matcher is a required element in a jbpm-type: "
- + XmlUtil.toString(jbpmTypeElement));
- }
- Element typeMatcherBeanElement = XmlUtil.element(typeMatcherElement);
- typeMatcherObjectInfo = objectFactoryParser.parse(typeMatcherBeanElement);
+ Element typeMatcherElement = XmlUtil.element(jbpmTypeElement, "matcher");
+ if (typeMatcherElement == null) {
+ throw new ConfigurationException("missing matcher element in jbpm-type");
+ }
+ Element typeMatcherBeanElement = XmlUtil.element(typeMatcherElement);
+ typeMatcherObjectInfo = objectFactoryParser.parse(typeMatcherBeanElement);
- Element converterElement = XmlUtil.element(jbpmTypeElement, "converter");
- if (converterElement != null) {
- if (!converterElement.hasAttribute("class")) {
- throw new ConfigurationException(
- "class attribute is required in a converter element: "
- + XmlUtil.toString(jbpmTypeElement));
- }
- String converterClassName = converterElement.getAttribute("class");
- converter = Converters.getConverterByClassName(converterClassName);
+ Element converterElement = XmlUtil.element(jbpmTypeElement, "converter");
+ if (converterElement != null) {
+ if (!converterElement.hasAttribute("class")) {
+ throw new ConfigurationException("missing class attribute in converter");
}
+ String converterClassName = converterElement.getAttribute("class");
+ converter = Converters.getConverterByClassName(converterClassName);
+ }
- Element variableInstanceElement = XmlUtil.element(jbpmTypeElement, "variable-instance");
- if (!variableInstanceElement.hasAttribute("class")) {
- throw new ConfigurationException(
- "class is a required attribute in element variable-instance: "
- + XmlUtil.toString(jbpmTypeElement));
- }
- String variableInstanceClassName = variableInstanceElement.getAttribute("class");
+ Element variableInstanceElement = XmlUtil.element(jbpmTypeElement, "variable-instance");
+ if (!variableInstanceElement.hasAttribute("class")) {
+ throw new ConfigurationException("missing class attribute in variable-instance");
+ }
+
+ String variableInstanceClassName = variableInstanceElement.getAttribute("class");
+ try {
variableInstanceClass = ClassLoaderUtil.classForName(variableInstanceClassName);
if (!VariableInstance.class.isAssignableFrom(variableInstanceClass)) {
- throw new ConfigurationException("variable instance class '"
- + variableInstanceClassName + "' is not a VariableInstance");
+ throw new ConfigurationException(variableInstanceClassName
+ + " is not a variable instance");
}
}
- catch (ConfigurationException e) {
- throw e;
- }
- catch (Exception e) {
- // NOTE that Error's are not caught because that might halt the JVM
- // and mask the original Error
- // Probably the user does not need support for this type and does not have a required
- // library in the path. So let's log and ignore
+ catch (ClassNotFoundException e) {
+ // the library that provides this class might be absent because
+ // the user does need this type; just log and ignore
if (log.isDebugEnabled()) {
- log.debug("jbpm variables type " + XmlUtil.toString(jbpmTypeElement)
- + " could not be instantiated", e);
+ log.debug("variable instance class not found: " + variableInstanceClassName);
}
- // make sure this JbpmType is ignored by always returning false in the JbpmTypeMatcher
+ // make sure this type is ignored by always returning false in the JbpmTypeMatcher
typeMatcherObjectInfo = new ObjectInfo() {
private static final long serialVersionUID = 1L;
@@ -107,7 +97,6 @@
public Object createObject(ObjectFactoryImpl objectFactory) {
return new JbpmTypeMatcher() {
-
private static final long serialVersionUID = 1L;
public boolean matches(Object value) {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/LongInfo.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/LongInfo.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/LongInfo.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -21,29 +21,21 @@
*/
package org.jbpm.configuration;
-import org.jbpm.JbpmException;
-import org.jbpm.util.XmlUtil;
import org.w3c.dom.Element;
public class LongInfo extends AbstractObjectInfo {
private static final long serialVersionUID = 1L;
-
- Long l = null;
+ private Long value;
+
public LongInfo(Element longElement, ObjectFactoryParser configParser) {
super(longElement, configParser);
-
- String contentText = getValueString(longElement);
- try {
- l = new Long(contentText);
- } catch (Exception e) {
- throw new JbpmException("content of "+XmlUtil.toString(longElement)+" could not be parsed as a long", e);
- }
+ value = new Long(getValueString(longElement));
}
public Object createObject(ObjectFactoryImpl objectFactory) {
- return l;
+ return value;
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/ObjectFactoryImpl.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/ObjectFactoryImpl.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/ObjectFactoryImpl.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -38,12 +38,12 @@
private static final long serialVersionUID = 1L;
- ClassLoader classLoader;
- final List objectInfos;
- final Map namedObjectInfos;
- final Map singletons = new HashMap();
- final Map objects = new HashMap();
- final Collection objectsUnderConstruction = new HashSet();
+ private final List objectInfos;
+ private final Map namedObjectInfos;
+ private final Map singletons = new HashMap();
+ private final Map objects = new HashMap();
+ private final Collection objectsUnderConstruction = new HashSet();
+ private ClassLoader classLoader;
public ObjectFactoryImpl() {
objectInfos = new ArrayList();
@@ -158,19 +158,14 @@
return object;
}
- Class classForName(String className) {
+ Class classForName(String className) throws ClassNotFoundException {
if (classLoader == null) {
classLoader = ClassLoaderUtil.getClassLoader();
}
- try {
- return Class.forName(className, false, classLoader);
- }
- catch (ClassNotFoundException e) {
- throw new JbpmException("couldn't load class '" + className + "'", e);
- }
+ return Class.forName(className, false, classLoader);
}
- Object getRegistryKey(ObjectInfo objectInfo) {
+ private Object getRegistryKey(ObjectInfo objectInfo) {
Object key = null;
if (objectInfo.hasName()) {
key = objectInfo.getName();
@@ -178,12 +173,12 @@
return key;
}
- boolean isInRegistry(Object registryKey) {
+ private boolean isInRegistry(Object registryKey) {
return registryKey != null
&& (objects.containsKey(registryKey) || singletons.containsKey(registryKey));
}
- void putInRegistry(ObjectInfo objectInfo, Object object, Object registryKey) {
+ private void putInRegistry(ObjectInfo objectInfo, Object object, Object registryKey) {
if (objectInfo.isSingleton()) {
singletons.put(registryKey, object);
}
@@ -192,7 +187,7 @@
}
}
- Object findInRegistry(Object registryKey) {
+ private Object findInRegistry(Object registryKey) {
Object object = null;
if (registryKey != null) {
object = objects.get(registryKey);
@@ -201,5 +196,5 @@
return object;
}
- private static Log log = LogFactory.getLog(ObjectFactoryImpl.class);
+ private static final Log log = LogFactory.getLog(ObjectFactoryImpl.class);
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/ObjectFactoryParser.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/ObjectFactoryParser.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/ObjectFactoryParser.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -24,6 +24,7 @@
import java.io.InputStream;
import java.io.Serializable;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -65,7 +66,7 @@
return defaultMappings;
}
- private static final Class[] constructorParameterTypes = new Class[] {
+ private static final Class[] constructorParameterTypes = {
Element.class, ObjectFactoryParser.class
};
@@ -74,7 +75,7 @@
Constructor constructor = objectInfoClass.getDeclaredConstructor(constructorParameterTypes);
mappings.put(elementTagName, constructor);
}
- catch (Exception e) {
+ catch (NoSuchMethodException e) {
throw new JbpmException("couldn't add mapping for element '" + elementTagName
+ "': constructor(" + Element.class.getName() + ","
+ ObjectFactoryParser.class.getName() + ") was missing for class '"
@@ -139,22 +140,23 @@
}
public ObjectInfo parse(Element element) {
- ObjectInfo objectInfo;
String tagName = element.getTagName().toLowerCase();
Constructor constructor = (Constructor) mappings.get(tagName);
if (constructor == null) {
throw new JbpmException("no ObjectInfo class specified for element: " + tagName);
}
try {
- objectInfo = (ObjectInfo) constructor.newInstance(new Object[] {
- element, this
- });
+ return (ObjectInfo) constructor.newInstance(new Object[] { element, this });
}
- catch (Exception e) {
- throw new JbpmException("couldn't parse '" + tagName + "' into a '"
- + constructor.getDeclaringClass().getName() + "': " + XmlUtil.toString(element), e);
+ catch (InstantiationException e) {
+ throw new JbpmException("failed to instantiate " + constructor.getDeclaringClass(), e);
}
- return objectInfo;
+ catch (IllegalAccessException e) {
+ throw new JbpmException(getClass() + " has no access to " + constructor, e);
+ }
+ catch (InvocationTargetException e) {
+ throw new JbpmException(constructor + " threw exception", e);
+ }
}
public void addNamedObjectInfo(String name, ObjectInfo objectInfo) {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/PropertyInfo.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/PropertyInfo.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/PropertyInfo.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -22,6 +22,7 @@
package org.jbpm.configuration;
import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.jbpm.JbpmException;
@@ -31,77 +32,74 @@
public class PropertyInfo implements Serializable {
private static final long serialVersionUID = 1L;
-
- String propertyName = null;
- String setterMethodName = null;
- ObjectInfo propertyValueInfo = null;
+ private String propertyName;
+ private String setterMethodName;
+ private ObjectInfo propertyValueInfo;
+
public PropertyInfo(Element propertyElement, ObjectFactoryParser configParser) {
- // propertyName or setterMethodName
+ // property
if (propertyElement.hasAttribute("name")) {
- propertyName = propertyElement.getAttribute("name");
- } else if (propertyElement.hasAttribute("setter")) {
- setterMethodName = propertyElement.getAttribute("setter");
- } else {
- throw new JbpmException("property must have a 'name' or 'setter' attribute: "+XmlUtil.toString(propertyElement));
+ propertyName = propertyElement.getAttribute("name");
}
-
+ // setter method
+ else if (propertyElement.hasAttribute("setter")) {
+ setterMethodName = propertyElement.getAttribute("setter");
+ }
+ else {
+ throw new JbpmException("missing name or setter attribute in property");
+ }
+
// propertyValueInfo
Element propertyValueElement = XmlUtil.element(propertyElement);
propertyValueInfo = configParser.parse(propertyValueElement);
}
public void injectProperty(Object object, ObjectFactoryImpl objectFactory) {
- Object propertyValue = objectFactory.getObject(propertyValueInfo);
Method setterMethod = findSetter(object.getClass());
setterMethod.setAccessible(true);
+ Object value = objectFactory.getObject(propertyValueInfo);
try {
- setterMethod.invoke(object, new Object[]{propertyValue});
- } catch (Exception e) {
- throw new JbpmException("couldn't set property '"+propertyName+"' on class '"+object.getClass()+"' to value '"+propertyValue+"'", e);
+ setterMethod.invoke(object, new Object[] { value });
}
+ catch (IllegalAccessException e) {
+ throw new JbpmException(getClass() + " has no access to " + setterMethod, e);
+ }
+ catch (InvocationTargetException e) {
+ throw new JbpmException(setterMethod + " threw exception", e.getCause());
+ }
}
public Method findSetter(Class clazz) {
- Method method = null;
-
- if (setterMethodName==null) {
- if ( (propertyName.startsWith("is"))
- && (propertyName.length()>3)
- && (Character.isUpperCase(propertyName.charAt(2)))
- ) {
- setterMethodName = "set"+propertyName.substring(2);
- } else {
- setterMethodName = "set"+propertyName.substring(0,1).toUpperCase()+propertyName.substring(1);
+ if (setterMethodName == null) {
+ if (propertyName.startsWith("is") && propertyName.length() > 3
+ && Character.isUpperCase(propertyName.charAt(2))) {
+ setterMethodName = "set" + propertyName.substring(2);
}
+ else {
+ setterMethodName = "set" + Character.toUpperCase(propertyName.charAt(0))
+ + propertyName.substring(1);
+ }
}
-
- Class candidateClass = clazz;
- while ( (candidateClass!=null)
- && (method==null)
- ) {
+ for (Class candidateClass = clazz; candidateClass != Object.class; candidateClass = candidateClass.getSuperclass()) {
Method[] methods = candidateClass.getDeclaredMethods();
- if (methods!=null) {
- for (int i=0; ( (i<methods.length) && (method==null) ); i++) {
- if ( (methods[i].getName().equals(setterMethodName))
- && (methods[i].getParameterTypes()!=null)
- && (methods[i].getParameterTypes().length==1)
- ) {
- method = methods[i];
- }
+ for (int i = 0; i < methods.length; i++) {
+ Method method = methods[i];
+ if (method.getName().equals(setterMethodName) && method.getParameterTypes().length == 1) {
+ return method;
}
}
-
- if (method==null) {
- candidateClass = candidateClass.getSuperclass();
- }
}
- if (method==null) {
- throw new JbpmException("couldn't find setter '"+setterMethodName+"' in class '"+clazz.getName()+"'");
- }
-
- return method;
+ throw new JbpmException("missing setter '" + setterMethodName + "' in " + clazz);
}
+
+ String getPropertyName() {
+ return propertyName;
+ }
+
+ ObjectInfo getPropertyValueInfo() {
+ return propertyValueInfo;
+ }
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/RefInfo.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/RefInfo.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/configuration/RefInfo.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -21,24 +21,23 @@
*/
package org.jbpm.configuration;
-import org.jbpm.JbpmException;
-import org.jbpm.util.XmlUtil;
import org.w3c.dom.Element;
+import org.jbpm.JbpmException;
+
public class RefInfo extends AbstractObjectInfo {
private static final long serialVersionUID = 1L;
-
- String bean = null;
-
+
+ private String bean;
+
public RefInfo(Element refElement, ObjectFactoryParser configParser) {
super(refElement, configParser);
- if (refElement.hasAttribute("bean")) {
- bean = refElement.getAttribute("bean");
- } else {
- throw new JbpmException("element ref must have a 'bean' attribute : "+XmlUtil.toString(refElement));
+ if (!refElement.hasAttribute("bean")) {
+ throw new JbpmException("missing bean attribute in ref");
}
+ bean = refElement.getAttribute("bean");
}
public Object createObject(ObjectFactoryImpl objectFactory) {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/context/exe/Converter.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/context/exe/Converter.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/context/exe/Converter.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -21,7 +21,7 @@
*/
package org.jbpm.context.exe;
-import java.io.*;
+import java.io.Serializable;
/**
* converts plain objects to objects that are
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/context/exe/JbpmType.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/context/exe/JbpmType.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/context/exe/JbpmType.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -33,58 +33,56 @@
import org.jbpm.util.ClassLoaderUtil;
/**
- * specifies for one java-type how jbpm is able to persist objects of that type in the database.
+ * specifies how jbpm is able to persist objects of a given type in the database.
*/
public class JbpmType {
-
- static Map jbpmTypesCache = new HashMap();
-
- JbpmTypeMatcher jbpmTypeMatcher = null;
- Converter converter = null;
- Class variableInstanceClass = null;
- public JbpmType(JbpmTypeMatcher jbpmTypeMatcher, Converter converter, Class variableInstanceClass) {
+ private static Map typesByResource = new HashMap();
+
+ private JbpmTypeMatcher jbpmTypeMatcher;
+ private Converter converter;
+ private Class variableInstanceClass;
+
+ public JbpmType(JbpmTypeMatcher jbpmTypeMatcher, Converter converter,
+ Class variableInstanceClass) {
this.jbpmTypeMatcher = jbpmTypeMatcher;
this.converter = converter;
this.variableInstanceClass = variableInstanceClass;
}
-
+
public boolean matches(Object value) {
return jbpmTypeMatcher.matches(value);
}
-
+
public VariableInstance newVariableInstance() {
- VariableInstance variableInstance = null;
try {
- variableInstance = (VariableInstance) variableInstanceClass.newInstance();
+ VariableInstance variableInstance = (VariableInstance) variableInstanceClass.newInstance();
variableInstance.converter = converter;
- } catch (Exception e) {
- throw new JbpmException("couldn't instantiate variable instance class '"+variableInstanceClass.getName()+"'");
+ return variableInstance;
}
- return variableInstance;
+ catch (InstantiationException e) {
+ throw new JbpmException("failed to instantiate " + variableInstanceClass, e);
+ }
+ catch (IllegalAccessException e) {
+ throw new JbpmException(getClass() + " has no access to " + variableInstanceClass, e);
+ }
}
public static List getJbpmTypes() {
- List jbpmTypes = null;
- synchronized(jbpmTypesCache) {
- ObjectFactory objectFactory = JbpmConfiguration.Configs.getObjectFactory();
- jbpmTypes = (List) jbpmTypesCache.get(objectFactory);
- if (jbpmTypes==null) {
- if (JbpmConfiguration.Configs.hasObject("jbpm.types")) {
- jbpmTypes = (List) JbpmConfiguration.Configs.getObject("jbpm.types");
- } else {
- jbpmTypes = getDefaultJbpmTypes();
- }
- jbpmTypesCache.put(objectFactory, jbpmTypes);
- }
+ if (JbpmConfiguration.Configs.hasObject("jbpm.types")) {
+ return (List) JbpmConfiguration.Configs.getObject("jbpm.types");
}
- return jbpmTypes;
- }
- private static List getDefaultJbpmTypes() {
String resource = JbpmConfiguration.Configs.getString("resource.varmapping");
- InputStream is = ClassLoaderUtil.getStream(resource);
- ObjectFactory objectFactory = ObjectFactoryParser.parseInputStream(is);
- return (List) objectFactory.createObject("jbpm.types");
+ synchronized (typesByResource) {
+ List types = (List) typesByResource.get(resource);
+ if (types == null) {
+ InputStream resourceStream = ClassLoaderUtil.getStream(resource);
+ ObjectFactory objectFactory = ObjectFactoryParser.parseInputStream(resourceStream);
+ types = (List) objectFactory.createObject("jbpm.types");
+ typesByResource.put(resource, types);
+ }
+ return types;
+ }
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/Converters.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/Converters.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/hibernate/Converters.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -31,7 +31,6 @@
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmException;
-import org.jbpm.configuration.ObjectFactory;
import org.jbpm.context.exe.Converter;
import org.jbpm.util.ClassLoaderUtil;
@@ -40,12 +39,8 @@
*/
public class Converters {
- private static final int CONVERTERS_BY_CLASS_NAMES = 0;
- private static final int CONVERTERS_BY_DATABASE_ID = 1;
- private static final int CONVERTERS_IDS = 2;
+ private static final Map convertersByResource = new HashMap();
- private static Map converterMapsMap = new HashMap();
-
private Converters() {
// prevent instantiation
}
@@ -53,102 +48,70 @@
// public methods
public static Converter getConverterByClassName(String className) {
- Converter converter = (Converter) getConvertersByClassNames().get(className);
- if (converter == null) {
- throw new JbpmException("converter '" + className
- + "' is not declared in jbpm.converter.properties");
+ for (Iterator iter = getConverters().values().iterator(); iter.hasNext();) {
+ Converter converter = (Converter) iter.next();
+ if (className.equals(converter.getClass().getName())) return converter;
}
- return converter;
+ throw new JbpmException(className + " is not registered as a converter");
}
- public static Converter getConverterByDatabaseId(String converterDatabaseId) {
- return (Converter) getConvertersByDatabaseId().get(converterDatabaseId);
+ public static Converter getConverterByDatabaseId(String converterId) {
+ return (Converter) getConverters().get(converterId);
}
public static String getConverterId(Converter converter) {
- return (String) getConvertersIds().get(converter);
+ for (Iterator iter = getConverters().entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (converter == entry.getValue()) return (String) entry.getKey();
+ }
+ return null;
}
- // maps class names to unique converter objects
- private static Map getConvertersByClassNames() {
- return getConverterMaps()[CONVERTERS_BY_CLASS_NAMES];
- }
-
- // maps converter database-id-strings to unique converter objects
- private static Map getConvertersByDatabaseId() {
- return getConverterMaps()[CONVERTERS_BY_DATABASE_ID];
- }
-
- // maps unique converter objects to their database-id-string
- private static Map getConvertersIds() {
- return getConverterMaps()[CONVERTERS_IDS];
- }
-
- private static Map[] getConverterMaps() {
- Map[] converterMaps = null;
- synchronized (converterMapsMap) {
- ObjectFactory objectFactory = JbpmConfiguration.Configs.getObjectFactory();
- converterMaps = (Map[]) converterMapsMap.get(objectFactory);
- if (converterMaps == null) {
- converterMaps = createConverterMaps(objectFactory);
- converterMapsMap.put(objectFactory, converterMaps);
+ private static Map getConverters() {
+ String resource = JbpmConfiguration.Configs.getString("resource.converter");
+ synchronized (convertersByResource) {
+ Map converters = (Map) convertersByResource.get(resource);
+ if (converters == null) {
+ Properties properties = ClassLoaderUtil.getProperties(resource);
+ converters = createConverters(properties);
+ convertersByResource.put(resource, converters);
}
+ return converters;
}
- return converterMaps;
}
- private static Map[] createConverterMaps(ObjectFactory objectFactory) {
- Map[] converterMaps = new Map[3];
- converterMaps[CONVERTERS_BY_CLASS_NAMES] = new HashMap();
- converterMaps[CONVERTERS_BY_DATABASE_ID] = new HashMap();
- converterMaps[CONVERTERS_IDS] = new HashMap();
-
- Map convertersByClassNames = converterMaps[CONVERTERS_BY_CLASS_NAMES];
- Map convertersByDatabaseId = converterMaps[CONVERTERS_BY_DATABASE_ID];
- Map convertersIds = converterMaps[CONVERTERS_IDS];
-
- Properties converterProperties = null;
- if (objectFactory.hasObject("resource.converter")) {
- String resource = (String) objectFactory.createObject("resource.converter");
- converterProperties = ClassLoaderUtil.getProperties(resource);
- }
- else {
- converterProperties = new Properties();
- }
-
+ private static Map createConverters(Properties properties) {
+ Map converters = new HashMap();
boolean debug = log.isDebugEnabled();
- for (Iterator iter = converterProperties.keySet().iterator(); iter.hasNext();) {
- String converterId = (String) iter.next();
+ for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ // validate converter id
+ String converterId = (String) entry.getKey();
if (converterId.length() != 1) {
throw new JbpmException("converter-id must be a single char");
}
- if (convertersByDatabaseId.containsKey(converterId)) {
- throw new JbpmException("duplicate converter-id: " + converterId);
- }
-
- String converterClassName = converterProperties.getProperty(converterId);
+ // load converter class
+ String converterClassName = (String) entry.getValue();
try {
Class converterClass = ClassLoaderUtil.classForName(converterClassName);
+ // instantiate converter
try {
Converter converter = (Converter) converterClass.newInstance();
- convertersByClassNames.put(converterClassName, converter);
- convertersByDatabaseId.put(converterId, converter);
- convertersIds.put(converter, converterId);
- if (debug) log.debug("registered converter: " + converterClassName);
+ converters.put(converterId, converter);
+ if (debug) log.debug("registered " + converterClassName);
}
catch (InstantiationException e) {
- if (debug) log.debug("failed to instantiate: " + converterClass, e);
+ if (debug) log.debug("failed to instantiate " + converterClass, e);
}
catch (IllegalAccessException e) {
if (debug) log.debug(Converters.class + " has no access to " + converterClass, e);
}
}
- catch (JbpmException e) {
+ catch (ClassNotFoundException e) {
if (debug) log.debug("converter class not found: " + converterClassName, e);
}
}
-
- return converterMaps;
+ return converters;
}
private static final Log log = LogFactory.getLog(Converters.class);
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/file/def/FileDefinition.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/file/def/FileDefinition.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/file/def/FileDefinition.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -46,16 +46,15 @@
private static final long serialVersionUID = 1L;
- static String getRootDir() {
- String rootDir = null;
+ private static String getRootDir() {
if (JbpmConfiguration.Configs.hasObject("jbpm.files.dir")) {
- rootDir = JbpmConfiguration.Configs.getString("jbpm.files.dir");
+ return JbpmConfiguration.Configs.getString("jbpm.files.dir");
}
- return rootDir;
+ return null;
}
- String dir;
- Map processFiles;
+ private String dir;
+ private Map processFiles;
public ModuleInstance createInstance() {
return null;
@@ -81,7 +80,7 @@
}
}
- void storeFileInFileSystem(String name, byte[] bytes) throws IOException {
+ private void storeFileInFileSystem(String name, byte[] bytes) throws IOException {
File filePath = getFilePath(name);
log.trace("storing '" + name + "' to file '" + filePath + "'");
@@ -90,7 +89,7 @@
fos.close();
}
- void storeFileInDb(String name, byte[] bytes) {
+ private void storeFileInDb(String name, byte[] bytes) {
if (processFiles == null) {
processFiles = new HashMap();
}
@@ -116,7 +115,7 @@
}
}
- void storeFileInFileSystem(String name, InputStream is) throws IOException {
+ private void storeFileInFileSystem(String name, InputStream is) throws IOException {
File filePath = getFilePath(name);
log.trace("storing '" + name + "' to file '" + filePath + "'");
@@ -125,7 +124,7 @@
fos.close();
}
- void storeFileInDb(String name, InputStream is) throws IOException {
+ private void storeFileInDb(String name, InputStream is) throws IOException {
if (processFiles == null) {
processFiles = new HashMap();
}
@@ -182,8 +181,9 @@
private InputStream getInputStreamFromFileSystem(String name) {
try {
File filePath = getFilePath(name);
- if (log.isTraceEnabled())
- log.trace("loading '" + name + "' from file '" + filePath + "'");
+ if (log.isDebugEnabled()) {
+ log.debug("loading '" + name + "' from file '" + filePath + "'");
+ }
return filePath.canRead() ? new FileInputStream(filePath) : null;
}
catch (FileNotFoundException e) {
@@ -192,7 +192,7 @@
}
private InputStream getInputStreamFromDb(String name) {
- if (log.isTraceEnabled()) log.trace("loading '" + name + "' from database");
+ if (log.isDebugEnabled()) log.debug("loading '" + name + "' from database");
byte[] bytes = getBytesFromDb(name);
return bytes != null ? new ByteArrayInputStream(bytes) : null;
}
@@ -212,7 +212,7 @@
return bytes;
}
- byte[] getBytesFromFileSystem(String name) {
+ private byte[] getBytesFromFileSystem(String name) {
InputStream in = getInputStreamFromFileSystem(name);
if (in == null) return null;
@@ -232,7 +232,7 @@
}
}
- byte[] getBytesFromDb(String name) {
+ private byte[] getBytesFromDb(String name) {
if (processFiles != null) {
ByteArray byteArray = (ByteArray) processFiles.get(name);
if (byteArray != null) return byteArray.getBytes();
@@ -240,7 +240,7 @@
return null;
}
- boolean isStoredOnFileSystem() {
+ private boolean isStoredOnFileSystem() {
String rootDir = getRootDir();
boolean isStoredOnFileSystem = (rootDir != null);
// if files should be stored on the file system
@@ -253,7 +253,7 @@
return isStoredOnFileSystem;
}
- String findNewDirName() {
+ private String findNewDirName() {
String dirName = "files-1";
File parentFile = new File(getRootDir());
@@ -274,12 +274,8 @@
return dirName;
}
- File getFilePath(String name) {
- File filePath = new File(getRootDir()
- + File.separatorChar
- + dir
- + File.separatorChar
- + name);
+ private File getFilePath(String name) {
+ File filePath = new File(getRootDir(), dir + File.separatorChar + name);
filePath.getParentFile().mkdirs();
return filePath;
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/action/ActionTypes.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/action/ActionTypes.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/action/ActionTypes.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -22,6 +22,7 @@
package org.jbpm.graph.action;
import java.io.InputStream;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -32,41 +33,53 @@
import org.w3c.dom.Element;
import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmException;
-import org.jbpm.graph.node.NodeTypes;
import org.jbpm.util.ClassLoaderUtil;
import org.jbpm.util.XmlUtil;
public class ActionTypes {
- public static Set getActionTypes() {
- return actionNames.keySet();
+ private static Map typesByResource = new HashMap();
+ private static final Log log = LogFactory.getLog(ActionTypes.class);
+
+ public static Collection getActionTypes() {
+ return getTypes().values();
}
public static Set getActionNames() {
- return actionTypes.keySet();
+ return getTypes().keySet();
}
public static Class getActionType(String name) {
- return (Class) actionTypes.get(name);
+ return (Class) getTypes().get(name);
}
public static String getActionName(Class type) {
- return (String) actionNames.get(type);
+ for (Iterator iter = getTypes().entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (type == entry.getValue()) return (String) entry.getKey();
+ }
+ return null;
}
public static boolean hasActionName(String name) {
- return actionTypes.containsKey(name);
+ return getTypes().containsKey(name);
}
- private static final Log log = LogFactory.getLog(ActionTypes.class);
- private static Map actionTypes = initialiseActionTypes();
- private static Map actionNames = NodeTypes.createInverseMapping(actionTypes);
+ private static Map getTypes() {
+ String resource = JbpmConfiguration.Configs.getString("resource.action.types");
+ synchronized (typesByResource) {
+ Map types = (Map) typesByResource.get(resource);
+ if (types == null) {
+ types = initialiseActionTypes(resource);
+ typesByResource.put(resource, types);
+ }
+ return types;
+ }
+ }
- private static Map initialiseActionTypes() {
+ private static Map initialiseActionTypes(String resource) {
Map types = new HashMap();
- String resource = JbpmConfiguration.Configs.getString("resource.action.types");
InputStream actionTypesStream = ClassLoaderUtil.getStream(resource);
Element actionTypesElement = XmlUtil.parseXmlInputStream(actionTypesStream)
.getDocumentElement();
@@ -80,7 +93,7 @@
Class actionClass = ClassLoaderUtil.classForName(className);
types.put(elementTag, actionClass);
}
- catch (JbpmException e) {
+ catch (ClassNotFoundException e) {
if (log.isDebugEnabled()) {
log.debug("action '" + elementTag + "' will not be available, class not found: "
+ className);
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/action/MailAction.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/action/MailAction.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/action/MailAction.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -9,12 +9,7 @@
private static final long serialVersionUID = 1L;
public void read(Element element, JpdlXmlReader jpdlReader) {
- String template = element.attributeValue("template");
- String actors = element.attributeValue("actors");
- String to = element.attributeValue("to");
- String subject = jpdlReader.getProperty("subject", element);
- String text = jpdlReader.getProperty("text", element);
- actionDelegation = jpdlReader.createMailDelegation(template, actors, to, subject, text);
+ actionDelegation = jpdlReader.readMailDelegation(element);
}
public String toString() {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/ExceptionHandler.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/ExceptionHandler.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/ExceptionHandler.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -26,6 +26,7 @@
import java.util.Iterator;
import java.util.List;
+import org.jbpm.JbpmException;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.util.ClassLoaderUtil;
@@ -34,26 +35,33 @@
private static final long serialVersionUID = 1L;
long id = 0;
- protected String exceptionClassName = null;
- protected GraphElement graphElement = null;
- protected List actions = null;
+ protected String exceptionClassName;
+ protected GraphElement graphElement;
+ protected List actions;
+ private transient Class exceptionClass;
+
public ExceptionHandler() {
}
public boolean matches(Throwable exception) {
- boolean matches = true;
- if (exceptionClassName != null) {
- Class clazz = ClassLoaderUtil.classForName(exceptionClassName);
- if (!clazz.isAssignableFrom(exception.getClass())) {
- matches = false;
+ return exceptionClassName != null ? getExceptionClass().isInstance(exception) : true;
+ }
+
+ private Class getExceptionClass() {
+ if (exceptionClass == null) {
+ try {
+ exceptionClass = ClassLoaderUtil.classForName(exceptionClassName);
}
+ catch (ClassNotFoundException e) {
+ throw new JbpmException("exception class not found: " + exceptionClassName, e);
+ }
}
- return matches;
+ return exceptionClass;
}
public void handleException(GraphElement graphElement, ExecutionContext executionContext)
- throws Exception {
+ throws Exception {
if (actions != null) {
for (Iterator iter = actions.iterator(); iter.hasNext();) {
Action action = (Action) iter.next();
@@ -63,7 +71,7 @@
}
// actions
- /////////////////////////////////////////////////////////////////////////////
+ // ///////////////////////////////////////////////////////////////////////////
public List getActions() {
return actions;
}
@@ -74,19 +82,15 @@
}
public void removeAction(Action action) {
- if (actions != null) {
- actions.remove(action);
- }
+ if (actions != null) actions.remove(action);
}
public void reorderAction(int oldIndex, int newIndex) {
- if (actions != null) {
- actions.add(newIndex, actions.remove(oldIndex));
- }
+ if (actions != null) actions.add(newIndex, actions.remove(oldIndex));
}
// getters and setters
- /////////////////////////////////////////////////////////////////////////////
+ // ///////////////////////////////////////////////////////////////////////////
public String getExceptionClassName() {
return exceptionClassName;
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/ProcessDefinition.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/ProcessDefinition.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/ProcessDefinition.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -34,6 +34,8 @@
import java.util.Properties;
import java.util.zip.ZipInputStream;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.xml.sax.InputSource;
import org.jbpm.JbpmConfiguration;
@@ -58,24 +60,36 @@
protected boolean isTerminationImplicit;
protected Node startState;
protected List nodes;
- transient Map nodesMap;
+ private transient Map nodesMap;
protected Map actions;
protected Map definitions;
+ private static final Map moduleClassesByResource = new HashMap();
+
// event types //////////////////////////////////////////////////////////////
private static final String[] EVENT_TYPES = {
- Event.EVENTTYPE_PROCESS_START, Event.EVENTTYPE_PROCESS_END, Event.EVENTTYPE_NODE_ENTER,
- Event.EVENTTYPE_NODE_LEAVE, Event.EVENTTYPE_TASK_CREATE, Event.EVENTTYPE_TASK_ASSIGN,
- Event.EVENTTYPE_TASK_START, Event.EVENTTYPE_TASK_END, Event.EVENTTYPE_TRANSITION,
- Event.EVENTTYPE_BEFORE_SIGNAL, Event.EVENTTYPE_AFTER_SIGNAL,
- Event.EVENTTYPE_SUPERSTATE_ENTER, Event.EVENTTYPE_SUPERSTATE_LEAVE,
- Event.EVENTTYPE_SUBPROCESS_CREATED, Event.EVENTTYPE_SUBPROCESS_END, Event.EVENTTYPE_TIMER
+ Event.EVENTTYPE_PROCESS_START,
+ Event.EVENTTYPE_PROCESS_END,
+ Event.EVENTTYPE_NODE_ENTER,
+ Event.EVENTTYPE_NODE_LEAVE,
+ Event.EVENTTYPE_TASK_CREATE,
+ Event.EVENTTYPE_TASK_ASSIGN,
+ Event.EVENTTYPE_TASK_START,
+ Event.EVENTTYPE_TASK_END,
+ Event.EVENTTYPE_TRANSITION,
+ Event.EVENTTYPE_BEFORE_SIGNAL,
+ Event.EVENTTYPE_AFTER_SIGNAL,
+ Event.EVENTTYPE_SUPERSTATE_ENTER,
+ Event.EVENTTYPE_SUPERSTATE_LEAVE,
+ Event.EVENTTYPE_SUBPROCESS_CREATED,
+ Event.EVENTTYPE_SUBPROCESS_END,
+ Event.EVENTTYPE_TIMER
};
/**
- * @deprecated arrays are mutable and thus vulnerable to external
- * manipulation. use {@link #getSupportedEventTypes()} instead
+ * @deprecated arrays are mutable and thus vulnerable to external manipulation. use
+ * {@link #getSupportedEventTypes()} instead
*/
public static final String[] supportedEventTypes = (String[]) EVENT_TYPES.clone();
@@ -92,12 +106,10 @@
public static ProcessDefinition createNewProcessDefinition() {
ProcessDefinition processDefinition = new ProcessDefinition();
- // add all default modules from file jbpm.default.modules
- String resource = JbpmConfiguration.Configs.getString("resource.default.modules");
- Properties defaultModulesProperties = ClassLoaderUtil.getProperties(resource);
- for (Iterator iter = defaultModulesProperties.keySet().iterator(); iter.hasNext();) {
- String moduleClassName = (String) iter.next();
- Class moduleClass = ClassLoaderUtil.classForName(moduleClassName);
+ // instantiate default modules
+ List moduleClasses = getModuleClasses();
+ for (Iterator iter = moduleClasses.iterator(); iter.hasNext();) {
+ Class moduleClass = (Class) iter.next();
try {
ModuleDefinition moduleDefinition = (ModuleDefinition) moduleClass.newInstance();
processDefinition.addDefinition(moduleDefinition);
@@ -109,9 +121,43 @@
throw new JbpmException(ProcessDefinition.class + " has no access to " + moduleClass, e);
}
}
+
return processDefinition;
}
+ private static List getModuleClasses() {
+ String resource = JbpmConfiguration.Configs.getString("resource.default.modules");
+ synchronized (moduleClassesByResource) {
+ List moduleClasses = (List) moduleClassesByResource.get(resource);
+ if (moduleClasses == null) {
+ moduleClasses = loadModuleClasses(resource);
+ moduleClassesByResource.put(resource, moduleClasses);
+ }
+ return moduleClasses;
+ }
+ }
+
+ private static List loadModuleClasses(String resource) {
+ Properties properties = ClassLoaderUtil.getProperties(resource);
+ List moduleClasses = new ArrayList();
+
+ Log log = LogFactory.getLog(ProcessDefinition.class);
+ boolean debug = log.isDebugEnabled();
+
+ for (Iterator iter = properties.keySet().iterator(); iter.hasNext();) {
+ String moduleClassName = (String) iter.next();
+ try {
+ Class moduleClass = ClassLoaderUtil.classForName(moduleClassName);
+ moduleClasses.add(moduleClass);
+ if (debug) log.debug("loaded module " + moduleClassName);
+ }
+ catch (ClassNotFoundException e) {
+ if (debug) log.debug("module class not found: " + moduleClassName, e);
+ }
+ }
+ return moduleClasses;
+ }
+
public ProcessDefinition(String name) {
this();
this.name = name;
@@ -136,8 +182,7 @@
public void setProcessDefinition(ProcessDefinition processDefinition) {
if (!equals(processDefinition)) {
- throw new IllegalArgumentException(
- "process definition cannot reference another process definition");
+ throw new IllegalArgumentException("process definition cannot reference another process definition");
}
}
@@ -333,7 +378,7 @@
return name;
}
- static boolean containsName(List nodes, String name) {
+ private static boolean containsName(List nodes, String name) {
for (Iterator iter = nodes.iterator(); iter.hasNext();) {
Node node = (Node) iter.next();
if (name.equals(node.getName())) return true;
@@ -393,11 +438,9 @@
// actions //////////////////////////////////////////////////////////////////
/**
- * creates a bidirectional relation between this process definition and the
- * given action.
+ * creates a bidirectional relation between this process definition and the given action.
*
- * @throws IllegalArgumentException if action is null or if action.getName()
- * is null.
+ * @throws IllegalArgumentException if action is null or if action.getName() is null.
*/
public Action addAction(Action action) {
if (action == null) {
@@ -413,11 +456,10 @@
}
/**
- * removes the bidirectional relation between this process definition and the
- * given action.
+ * removes the bidirectional relation between this process definition and the given action.
*
- * @throws IllegalArgumentException if action is null or if the action was not
- * present in the actions of this process definition.
+ * @throws IllegalArgumentException if action is null or if the action was not present in the
+ * actions of this process definition.
*/
public void removeAction(Action action) {
if (action == null) {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/MailNode.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/MailNode.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/MailNode.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -14,12 +14,7 @@
// xml //////////////////////////////////////////////////////////////////////
public void read(Element element, JpdlXmlReader jpdlReader) {
- String template = element.attributeValue("template");
- String actors = element.attributeValue("actors");
- String to = element.attributeValue("to");
- String subject = jpdlReader.getProperty("subject", element);
- String text = jpdlReader.getProperty("text", element);
- Delegation delegation = jpdlReader.createMailDelegation(template, actors, to, subject, text);
+ Delegation delegation = jpdlReader.readMailDelegation(element);
this.action = new Action(delegation);
}
@@ -29,5 +24,4 @@
// leave the node over the default transition
leave(executionContext);
}
-
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/NodeTypes.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/NodeTypes.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/NodeTypes.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -22,6 +22,7 @@
package org.jbpm.graph.node;
import java.io.InputStream;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -32,37 +33,49 @@
import org.w3c.dom.Element;
import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmException;
import org.jbpm.util.ClassLoaderUtil;
import org.jbpm.util.XmlUtil;
public class NodeTypes {
- public static Set getNodeTypes() {
- return nodeTypes.keySet();
+ private static Map typesByResource = new HashMap();
+ private static final Log log = LogFactory.getLog(NodeTypes.class);
+
+ public static Collection getNodeTypes() {
+ return getTypes().values();
}
public static Set getNodeNames() {
- return nodeNames.keySet();
+ return getTypes().keySet();
}
public static Class getNodeType(String name) {
- return (Class) nodeTypes.get(name);
+ return (Class) getTypes().get(name);
}
public static String getNodeName(Class type) {
- return (String) nodeNames.get(type);
+ for (Iterator iter = getTypes().entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (type == entry.getValue()) return (String) entry.getKey();
+ }
+ return null;
}
- private static final Log log = LogFactory.getLog(NodeTypes.class);
+ private static Map getTypes() {
+ String resource = JbpmConfiguration.Configs.getString("resource.node.types");
+ synchronized (typesByResource) {
+ Map types = (Map) typesByResource.get(resource);
+ if (types == null) {
+ types = initialiseNodeTypes(resource);
+ typesByResource.put(resource, types);
+ }
+ return types;
+ }
+ }
- private static Map nodeTypes = initialiseNodeTypes();
- private static Map nodeNames = createInverseMapping(nodeTypes);
-
- private static Map initialiseNodeTypes() {
+ private static Map initialiseNodeTypes(String resource) {
Map types = new HashMap();
- String resource = JbpmConfiguration.Configs.getString("resource.node.types");
InputStream nodeTypesStream = ClassLoaderUtil.getStream(resource);
Element nodeTypesElement = XmlUtil.parseXmlInputStream(nodeTypesStream)
.getDocumentElement();
@@ -76,7 +89,7 @@
Class nodeClass = ClassLoaderUtil.classForName(className);
types.put(elementTag, nodeClass);
}
- catch (JbpmException e) {
+ catch (ClassNotFoundException e) {
if (log.isDebugEnabled()) {
log.debug("node '" + elementTag + "' will not be available, class not found: "
+ className);
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/FieldInstantiator.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/FieldInstantiator.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/FieldInstantiator.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -181,9 +181,13 @@
value = getMap(propertyElement, (Map) type.newInstance());
}
else if (propertyElement.isTextOnly()) {
- Constructor constructor = type.getConstructor(new Class[] { String.class });
+ Constructor constructor = type.getConstructor(new Class[] {
+ String.class
+ });
try {
- value = constructor.newInstance(new Object[] { propertyElement.getTextTrim() });
+ value = constructor.newInstance(new Object[] {
+ propertyElement.getTextTrim()
+ });
}
catch (IllegalAccessException e) {
log.error(FieldInstantiator.class + " has no access to " + constructor);
@@ -234,16 +238,20 @@
}
/**
- * Returns the <code>Class</code> associated with the value for the attribute
- * with the given name.
+ * Returns the <code>Class</code> associated with the value for the attribute with the given
+ * name.
*/
private static Class classForAttributeValue(Element element, String attributeName) {
- Class type = String.class;
- String attributeValue = element.attributeValue(attributeName);
- if (attributeValue != null) {
- type = ClassLoaderUtil.classForName(attributeValue);
+ String className = element.attributeValue(attributeName);
+ if (className != null) {
+ try {
+ return ClassLoaderUtil.classForName(className);
+ }
+ catch (ClassNotFoundException e) {
+ throw new JbpmException("no such class " + className, e);
+ }
}
- return type;
+ return String.class;
}
private static final Log log = LogFactory.getLog(FieldInstantiator.class);
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/par/ProcessArchive.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/par/ProcessArchive.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/par/ProcessArchive.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -33,11 +33,11 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
-import org.w3c.dom.Document;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Element;
import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmException;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.jpdl.JpdlException;
import org.jbpm.jpdl.xml.Problem;
@@ -50,26 +50,22 @@
private static final long serialVersionUID = 1L;
- static List processArchiveParsers = getProcessArchiveParsers();
+ private static final Map parsersByResource = new HashMap();
// fields ///////////////////////////////////////////////////////////////////
- String name = "";
+ private String name = "";
// maps entry-names (String) to byte-arrays (byte[])
- Map entries = new HashMap();
- List problems = new ArrayList();
+ private Map entries = new HashMap();
+ private List problems = new ArrayList();
// constructors /////////////////////////////////////////////////////////////
public ProcessArchive(ZipInputStream zipInputStream) throws IOException {
- ZipEntry zipEntry = zipInputStream.getNextEntry();
- while (zipEntry != null) {
+ for (ZipEntry zipEntry = zipInputStream.getNextEntry(); zipEntry != null; zipEntry = zipInputStream.getNextEntry()) {
String entryName = zipEntry.getName();
byte[] bytes = IoUtil.readBytes(zipInputStream);
- if (bytes != null) {
- entries.put(entryName, bytes);
- }
- zipEntry = zipInputStream.getNextEntry();
+ entries.put(entryName, bytes);
}
}
@@ -77,8 +73,7 @@
public ProcessDefinition parseProcessDefinition() {
ProcessDefinition processDefinition = ProcessDefinition.createNewProcessDefinition();
- Iterator iter = processArchiveParsers.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = getParsers().iterator(); iter.hasNext();) {
ProcessArchiveParser processArchiveParser = (ProcessArchiveParser) iter.next();
processDefinition = processArchiveParser.readFromArchive(this, processDefinition);
}
@@ -126,28 +121,53 @@
problems = new ArrayList();
}
- static List getProcessArchiveParsers() {
- List processArchiveParsers = new ArrayList();
- try {
- String resource = JbpmConfiguration.Configs.getString("resource.parsers");
- InputStream parsersStream = ClassLoaderUtil.getStream(resource);
- Document document = XmlUtil.parseXmlInputStream(parsersStream);
- Iterator iter = XmlUtil.elementIterator(document.getDocumentElement(), "parser");
- while (iter.hasNext()) {
- Element element = (Element) iter.next();
- String className = element.getAttribute("class");
- ProcessArchiveParser processArchiveParser = (ProcessArchiveParser) ClassLoaderUtil.classForName(className)
- .newInstance();
- if (processArchiveParser instanceof ConfigurableParser) {
- ((ConfigurableParser) processArchiveParser).configure(element);
+ private static List getParsers() {
+ String resource = JbpmConfiguration.Configs.getString("resource.parsers");
+ synchronized (parsersByResource) {
+ List parsers = (List) parsersByResource.get(resource);
+ if (parsers == null) {
+ parsers = createParsers(resource);
+ parsersByResource.put(resource, parsers);
+ }
+ return parsers;
+ }
+ }
+
+ private static List createParsers(String resource) {
+ // read parsers resource
+ InputStream resourceStream = ClassLoaderUtil.getStream(resource);
+ Element parsersElement = XmlUtil.parseXmlInputStream(resourceStream).getDocumentElement();
+ List parsers = new ArrayList();
+
+ Log log = LogFactory.getLog(ProcessArchive.class);
+ boolean debug = log.isDebugEnabled();
+
+ for (Iterator iter = XmlUtil.elementIterator(parsersElement, "parser"); iter.hasNext();) {
+ Element parserElement = (Element) iter.next();
+ String parserClassName = parserElement.getAttribute("class");
+ // load parser class
+ try {
+ Class parserClass = ClassLoaderUtil.classForName(parserClassName);
+ // instantiate parser
+ try {
+ ProcessArchiveParser parser = (ProcessArchiveParser) parserClass.newInstance();
+ if (parser instanceof ConfigurableParser) {
+ ((ConfigurableParser) parser).configure(parserElement);
+ }
+ parsers.add(parser);
+ if (debug) log.debug("loaded " + parserClass);
}
- processArchiveParsers.add(processArchiveParser);
+ catch (InstantiationException e) {
+ if (debug) log.debug("failed to instantiate " + parserClass, e);
+ }
+ catch (IllegalAccessException e) {
+ if (debug) log.debug(ProcessArchive.class + " has no access to " + parserClass, e);
+ }
}
+ catch (ClassNotFoundException e) {
+ if (debug) log.debug("parser not found: " + parserClassName, e);
+ }
}
- catch (Exception e) {
- throw new JbpmException("couldn't parse process archive parsers (jbpm.parsers.xml)", e);
- }
- return processArchiveParsers;
+ return parsers;
}
-
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/xml/JpdlParser.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/xml/JpdlParser.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/xml/JpdlParser.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -57,6 +57,10 @@
private static final long serialVersionUID = 1L;
+ private static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
+ private static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
+ private static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
+
private static SAXParserFactory saxParserFactory = createSaxParserFactory();
private static Set schemaResources = getDefaultSchemaResources();
private static Object schemaSource;
@@ -94,7 +98,7 @@
}
try {
- saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
+ saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
}
catch (SAXException e) {
log.warn("failed to set schema language to xml schema", e);
@@ -102,7 +106,7 @@
Object schemaSource = getSchemaSource();
try {
- saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", schemaSource);
+ saxParser.setProperty(JAXP_SCHEMA_SOURCE, schemaSource);
}
catch (SAXException e) {
log.warn("failed to set schema source to " + schemaSource, e);
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlReader.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlReader.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlReader.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -713,9 +713,8 @@
/**
* creates the transition object and configures it by the read attributes
*
- * @return the created <code>org.jbpm.graph.def.Transition</code> object
- * (useful, if you want to override this method to read additional
- * configuration properties)
+ * @return the created <code>org.jbpm.graph.def.Transition</code> object (useful, if you want
+ * to override this method to read additional configuration properties)
*/
public Transition resolveTransitionDestination(Element transitionElement, Node node) {
Transition transition = new Transition();
@@ -802,6 +801,7 @@
// mail delegations /////////////////////////////////////////////////////////
+ /** @deprecated call {@link #readMailDelegation(Element)} instead */
public Delegation createMailDelegation(String template, String actors, String to,
String subject, String text) {
StringBuffer config = new StringBuffer();
@@ -845,6 +845,54 @@
return delegation;
}
+ public Delegation readMailDelegation(Element element) {
+ StringBuffer config = new StringBuffer();
+ // template
+ String template = element.attributeValue("template");
+ if (template != null) {
+ config.append("<template>").append(template).append("</template>");
+ }
+ // to - addresses
+ String to = element.attributeValue("to");
+ if (to != null) {
+ config.append("<to>").append(to).append("</to>");
+ }
+ // to - actors
+ String actors = element.attributeValue("actors");
+ if (actors != null) {
+ config.append("<actors>").append(actors).append("</actors>");
+ }
+ // cc - addresses
+ String cc = element.attributeValue("cc");
+ if (cc != null) {
+ config.append("<cc>").append(cc).append("</cc>");
+ }
+ // cc - actors
+ // subject
+ String subject = getProperty("subject", element);
+ if (subject != null) {
+ config.append("<subject>").append(subject).append("</subject>");
+ }
+ // text
+ String text = getProperty("text", element);
+ if (text != null) {
+ config.append("<text>").append(text).append("</text>");
+ }
+
+ String mailClassName;
+ if (JbpmConfiguration.Configs.hasObject("jbpm.mail.class.name")) {
+ mailClassName = JbpmConfiguration.Configs.getString("jbpm.mail.class.name");
+ }
+ else {
+ mailClassName = Mail.class.getName();
+ }
+
+ Delegation delegation = new Delegation(mailClassName);
+ delegation.setProcessDefinition(processDefinition);
+ delegation.setConfiguration(config.toString());
+ return delegation;
+ }
+
public String getProperty(String property, Element element) {
String value = element.attributeValue(property);
if (value == null) {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/mail/Mail.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/mail/Mail.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/mail/Mail.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -1,11 +1,10 @@
package org.jbpm.mail;
-import java.io.IOException;
-import java.io.InputStream;
import java.io.Serializable;
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;
@@ -36,8 +35,10 @@
public class Mail implements ActionHandler {
private String template;
+ private String to;
private String actors;
- private String to;
+ private String cc;
+ private String ccActors;
private String bcc;
private String bccActors;
private String subject;
@@ -45,7 +46,7 @@
private ExecutionContext executionContext;
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 2L;
public Mail() {
}
@@ -81,6 +82,13 @@
return recipients;
}
+ public List getCcRecipients() {
+ List recipients = new ArrayList();
+ if (ccActors != null) recipients.addAll(evaluateActors(ccActors));
+ if (cc != null) recipients.addAll(evaluateAddresses(cc));
+ return recipients;
+ }
+
public List getBccRecipients() {
List recipients = new ArrayList();
if (bccActors != null) recipients.addAll(evaluateActors(bccActors));
@@ -113,8 +121,7 @@
}
protected Collection resolveAddresses(List actorIds) {
- AddressResolver addressResolver = (AddressResolver) JbpmConfiguration.Configs
- .getObject("jbpm.mail.address.resolver");
+ AddressResolver addressResolver = (AddressResolver) JbpmConfiguration.Configs.getObject("jbpm.mail.address.resolver");
List addresses = new ArrayList();
for (Iterator iter = actorIds.iterator(); iter.hasNext();) {
@@ -146,20 +153,18 @@
if (value instanceof String) return tokenize((String) 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");
}
protected List tokenize(String text) {
- return text != null ? Arrays.asList(text.split("[;:]+")) : null;
+ return text != null ? Arrays.asList(text.split("[,;:]+")) : null;
}
private Object evaluate(String expression, Class expectedType) {
- VariableResolver variableResolver = new MailVariableResolver(templateVariables, JbpmExpressionEvaluator
- .getVariableResolver());
- return JbpmExpressionEvaluator
- .evaluate(expression, executionContext, expectedType, variableResolver, JbpmExpressionEvaluator
- .getFunctionMapper());
+ VariableResolver variableResolver = new MailVariableResolver(getTemplateVariables(), JbpmExpressionEvaluator.getVariableResolver());
+ return JbpmExpressionEvaluator.evaluate(expression, executionContext, expectedType, variableResolver, JbpmExpressionEvaluator.getFunctionMapper());
}
public String getSubject() {
@@ -174,76 +179,98 @@
if (JbpmConfiguration.Configs.hasObject("jbpm.mail.from.address")) {
return JbpmConfiguration.Configs.getString("jbpm.mail.from.address");
}
- return "jbpm@noreply";
+ return "no-reply(a)jbpm.org";
}
public void send() {
if (template != null) {
- Properties properties = getMailTemplateProperties(template);
+ Properties templateProperties = getTemplateProperties(template);
- if (actors == null) actors = properties.getProperty("actors");
- if (to == null) to = properties.getProperty("to");
- if (subject == null) subject = properties.getProperty("subject");
- if (text == null) text = properties.getProperty("text");
- if (bcc == null) bcc = properties.getProperty("bcc");
- if (bccActors == null) bccActors = properties.getProperty("bccActors");
+ if (actors == null) actors = templateProperties.getProperty("actors");
+ if (to == null) to = templateProperties.getProperty("to");
+ if (cc == null) cc = templateProperties.getProperty("cc");
+ if (ccActors == null) ccActors = templateProperties.getProperty("cc-actors");
+ if (bcc == null) bcc = templateProperties.getProperty("bcc");
+ if (bccActors == null) bccActors = templateProperties.getProperty("bcc-actors");
+ if (subject == null) subject = templateProperties.getProperty("subject");
+ if (text == null) text = templateProperties.getProperty("text");
}
- send(getMailServerProperties(), getFromAddress(), getRecipients(), getBccRecipients(), getSubject(), getText());
+ List recipients = getRecipients();
+ List ccRecipients = getCcRecipients();
+ List bccRecipients = getBccRecipients();
+ if (recipients.isEmpty() && ccRecipients.isEmpty() && bccRecipients.isEmpty()) 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);
+ 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--) {
+ try {
+ sendMailInternal(session, 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());
+ }
+ }
}
- public static void send(Properties mailServerProperties, String fromAddress, List recipients,
+ public static void send(Properties serverProperties, String fromAddress, List recipients,
String subject, String text) {
- send(mailServerProperties, fromAddress, recipients, null, subject, text);
+ send(serverProperties, fromAddress, recipients, Collections.EMPTY_LIST, subject, text);
}
- public static void send(Properties mailServerProperties, String fromAddress, List recipients,
+ public static void send(Properties serverProperties, String fromAddress, List recipients,
List bccRecipients, String subject, String text) {
- // if there are no recipients, skip mail sending
- if ((recipients == null || recipients.isEmpty())
- && (bccRecipients == null || bccRecipients.isEmpty())) return;
+ if (recipients.isEmpty() && bccRecipients.isEmpty()) return;
- for (int retries = 5; retries >= 0; retries--) {
+ if (log.isDebugEnabled()) {
+ StringBuffer detail = new StringBuffer("sending email to ");
+ detail.append(recipients);
+ if (bccRecipients != null) detail.append(" bcc ").append(bccRecipients);
+ if (subject != null) detail.append(" about '").append(subject).append('\'');
+ log.debug(detail.toString());
+ }
+
+ Session session = Session.getInstance(serverProperties);
+ for (int retries = 3; retries >= 0; retries--) {
try {
- sendMailInternal(mailServerProperties, fromAddress, recipients, bccRecipients, subject, text);
+ sendMailInternal(session, 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());
- try {
- Thread.sleep(1000);
- }
- catch (InterruptedException ie) {
- // reassert interruption
- Thread.currentThread().interrupt();
- throw new JbpmException("cannot send email", me);
- }
}
}
}
- private static void sendMailInternal(Properties mailServerProperties, String fromAddress,
- List recipients, List bccRecipients, String subject, String text) throws MessagingException {
- if (log.isDebugEnabled()) {
- StringBuffer message = new StringBuffer("sending email ");
- if (recipients != null) message.append(recipients);
- if (bccRecipients != null) message.append(" bcc ").append(bccRecipients);
- if (fromAddress != null) message.append(" from '").append(fromAddress).append(')');
- if (subject != null) message.append(" about '").append(subject).append(')');
- log.debug(message.toString());
- }
-
- Session session = Session.getDefaultInstance(mailServerProperties, null);
+ private static void sendMailInternal(Session session, List recipients, List ccRecipients,
+ List bccRecipients, String subject, String text) throws MessagingException {
MimeMessage message = new MimeMessage(session);
- // from
- if (fromAddress != null) message.setFrom(new InternetAddress(fromAddress));
// to
for (Iterator iter = recipients.iterator(); iter.hasNext();) {
InternetAddress recipient = new InternetAddress((String) iter.next());
message.addRecipient(Message.RecipientType.TO, recipient);
}
+ // cc
+ if (ccRecipients != null) {
+ for (Iterator iter = ccRecipients.iterator(); iter.hasNext();) {
+ InternetAddress recipient = new InternetAddress((String) iter.next());
+ message.addRecipient(Message.RecipientType.CC, recipient);
+ }
+ }
// bcc
if (bccRecipients != null) {
for (Iterator iter = bccRecipients.iterator(); iter.hasNext();) {
@@ -255,90 +282,129 @@
if (subject != null) message.setSubject(subject);
// text
if (text != null) message.setText(text);
-
+ // send the message
Transport.send(message);
}
- private Properties getMailServerProperties() {
- Properties mailServerProperties = new Properties();
+ private static final Map serverPropertiesByResource = new HashMap();
+ private Properties getServerProperties() {
+ Properties serverProperties;
+
if (JbpmConfiguration.Configs.hasObject("resource.mail.properties")) {
- String mailServerPropertiesResource = JbpmConfiguration.Configs
- .getString("resource.mail.properties");
- try {
- InputStream mailServerStream = ClassLoaderUtil.getStream(mailServerPropertiesResource);
- mailServerProperties.load(mailServerStream);
+ String resource = JbpmConfiguration.Configs.getString("resource.mail.properties");
+ synchronized (serverPropertiesByResource) {
+ serverProperties = (Properties) serverPropertiesByResource.get(resource);
+ if (serverProperties == null) {
+ // load mail properties
+ serverProperties = ClassLoaderUtil.getProperties(resource);
+ serverPropertiesByResource.put(resource, serverProperties);
+ }
}
- catch (IOException e) {
- throw new JbpmException("could not load mail server properties from resource: "
- + mailServerPropertiesResource, e);
- }
}
- else if (JbpmConfiguration.Configs.hasObject("jbpm.mail.smtp.host")) {
- String smtpServer = JbpmConfiguration.Configs.getString("jbpm.mail.smtp.host");
- mailServerProperties.put("mail.smtp.host", smtpServer);
- }
else {
- log.error("could not get mail properties");
+ serverProperties = new Properties();
+ // host
+ if (JbpmConfiguration.Configs.hasObject("jbpm.mail.smtp.host")) {
+ String smtpHost = JbpmConfiguration.Configs.getString("jbpm.mail.smtp.host");
+ serverProperties.setProperty("mail.smtp.host", smtpHost);
+ }
+ // port
+ if (JbpmConfiguration.Configs.hasObject("jbpm.mail.smtp.port")) {
+ int port = JbpmConfiguration.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;
+ }
- return mailServerProperties;
+ private static final Map templatePropertiesByResource = new HashMap();
+ private static final Map templateVariablesByResource = new HashMap();
+
+ private static Properties getTemplateProperties(String templateName) {
+ String resource = JbpmConfiguration.Configs.getString("resource.mail.templates");
+ synchronized (templatePropertiesByResource) {
+ Map templateProperties = (Map) templatePropertiesByResource.get(resource);
+ if (templateProperties == null) {
+ loadTemplates(resource);
+ templateProperties = (Map) templatePropertiesByResource.get(resource);
+ }
+ return (Properties) templateProperties.get(templateName);
+ }
}
- private static Map templates;
- private static Map templateVariables;
+ private static Map getTemplateVariables() {
+ String resource = JbpmConfiguration.Configs.getString("resource.mail.templates");
+ synchronized (templateVariablesByResource) {
+ Map templateVariables = (Map) templateVariablesByResource.get(resource);
+ if (templateVariables == null) {
+ loadTemplates(resource);
+ templateVariables = (Map) templateVariablesByResource.get(resource);
+ }
+ return templateVariables;
+ }
+ }
- private synchronized Properties getMailTemplateProperties(String templateName) {
- if (templates == null) {
- templates = new HashMap();
- String mailTemplatesResource = JbpmConfiguration.Configs
- .getString("resource.mail.templates");
+ private static void loadTemplates(String resource) {
+ Element templatesElement = XmlUtil.parseXmlResource(resource, true).getDocumentElement();
- Element mailTemplatesElement = XmlUtil
- .parseXmlResource(mailTemplatesResource, true)
- .getDocumentElement();
- for (Iterator iter = XmlUtil.elementIterator(mailTemplatesElement, "mail-template"); iter
- .hasNext();) {
- Element mailTemplateElement = (Element) iter.next();
+ Map templatePropertiesMap = new HashMap();
+ for (Iterator iter = XmlUtil.elementIterator(templatesElement, "mail-template"); iter.hasNext();) {
+ Element templateElement = (Element) iter.next();
- Properties templateProperties = new Properties();
- addTemplateProperty(mailTemplateElement, "actors", templateProperties);
- addTemplateProperty(mailTemplateElement, "to", templateProperties);
- addTemplateProperty(mailTemplateElement, "subject", templateProperties);
- addTemplateProperty(mailTemplateElement, "text", templateProperties);
- addTemplateProperty(mailTemplateElement, "bcc", templateProperties);
- addTemplateProperty(mailTemplateElement, "bccActors", templateProperties);
-
- templates.put(mailTemplateElement.getAttribute("name"), templateProperties);
+ Properties templateProperties = new Properties();
+ addTemplateProperty(templateElement, "to", templateProperties);
+ addTemplateProperty(templateElement, "actors", templateProperties);
+ addTemplateProperty(templateElement, "subject", templateProperties);
+ addTemplateProperty(templateElement, "text", templateProperties);
+ addTemplateProperty(templateElement, "cc", templateProperties);
+ addTemplateProperty(templateElement, "cc-actors", templateProperties);
+ addTemplateProperty(templateElement, "bcc", templateProperties);
+ addTemplateProperty(templateElement, "bcc-actors", templateProperties);
+ // preserve backwards compatibility with bccActors element
+ Element bccActorsElement = XmlUtil.element(templateElement, "bccActors");
+ if (bccActorsElement != null) {
+ String bccActors = templateProperties.getProperty("bcc-actors");
+ if (bccActors != null) {
+ bccActors += ';' + XmlUtil.getContentText(bccActorsElement);
+ }
+ else {
+ bccActors = XmlUtil.getContentText(bccActorsElement);
+ }
+ templateProperties.setProperty("bcc-actors", bccActors);
}
- templateVariables = new HashMap();
- for (Iterator iter = XmlUtil.elementIterator(mailTemplatesElement, "variable"); iter
- .hasNext();) {
- Element variableElement = (Element) iter.next();
- templateVariables.put(variableElement.getAttribute("name"), variableElement
- .getAttribute("value"));
- }
+ templatePropertiesMap.put(templateElement.getAttribute("name"), templateProperties);
}
- return (Properties) templates.get(templateName);
+ templatePropertiesByResource.put(resource, templatePropertiesMap);
+
+ Map templateVariables = new HashMap();
+ for (Iterator iter = XmlUtil.elementIterator(templatesElement, "variable"); iter.hasNext();) {
+ Element variableElement = (Element) iter.next();
+ templateVariables.put(variableElement.getAttribute("name"), variableElement.getAttribute("value"));
+ }
+ templateVariablesByResource.put(resource, templateVariables);
}
- private void addTemplateProperty(Element mailTemplateElement, String property,
+ private static void addTemplateProperty(Element templateElement, String property,
Properties templateProperties) {
- Element element = XmlUtil.element(mailTemplateElement, property);
+ Element element = XmlUtil.element(templateElement, property);
if (element != null) {
- templateProperties.put(property, XmlUtil.getContentText(element));
+ templateProperties.setProperty(property, XmlUtil.getContentText(element));
}
}
- private static class MailVariableResolver implements VariableResolver, Serializable {
+ static class MailVariableResolver implements VariableResolver, Serializable {
private Map templateVariables;
private VariableResolver variableResolver;
private static final long serialVersionUID = 1L;
- public MailVariableResolver(Map templateVariables, VariableResolver variableResolver) {
+ MailVariableResolver(Map templateVariables, VariableResolver variableResolver) {
this.templateVariables = templateVariables;
this.variableResolver = variableResolver;
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/security/authentication/SubjectAuthenticationService.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/security/authentication/SubjectAuthenticationService.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/security/authentication/SubjectAuthenticationService.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -32,33 +32,32 @@
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
+import org.jbpm.JbpmException;
import org.jbpm.security.AuthenticationService;
import org.jbpm.util.ClassLoaderUtil;
/**
- * gets the authenticated actor id from the current Subject. This Authenticator is either configured
- * via the {@link SubjectAuthenticationServiceFactory} or it requires the two other configuration
- * parameter 'jbpm.authenticator.principal.classname' and
- * 'jbpm.authenticator.principal.allow.overwrite' This configuration property specifies the class
- * name of the principal that should be used from the current subject. This could be for example
- * org.jboss.security.CallerIdentity in an JBoss AS. If not actorId is set, the name of that
- * principal is used as the currently authenticated actorId. If an actorId!=null is set (via
- * setActorId) this one overwrites the principal. This behavior is configurable via the
- * 'jbpm.authenticator.principal.allow.overwrite' attribute. If this is set to false, setActorId is
- * simply ignored.
+ * gets the authenticated actor id from the current Subject. This Authenticator is either
+ * configured via the {@link SubjectAuthenticationServiceFactory} or it requires the two other
+ * configuration parameter 'jbpm.authenticator.principal.classname' and
+ * 'jbpm.authenticator.principal.allow.overwrite' This configuration property specifies the
+ * class name of the principal that should be used from the current subject. This could be for
+ * example org.jboss.security.CallerIdentity in an JBoss AS. If not actorId is set, the name of
+ * that principal is used as the currently authenticated actorId. If an actorId!=null is set
+ * (via setActorId) this one overwrites the principal. This behavior is configurable via the
+ * 'jbpm.authenticator.principal.allow.overwrite' attribute. If this is set to false, setActorId
+ * is simply ignored.
*/
public class SubjectAuthenticationService implements AuthenticationService {
private static final long serialVersionUID = 1L;
- private static Log log = LogFactory.getLog(JbpmContext.class);
+ private static final Log log = LogFactory.getLog(JbpmContext.class);
private Class principalClass;
-
+ private String actorId;
private boolean allowActorIdOverwrite;
- private String actorId;
-
public SubjectAuthenticationService(String principalClassName, Boolean allowActorIdOverwrite) {
if (principalClassName != null) {
initPrincipalClass(principalClassName);
@@ -80,20 +79,24 @@
}
protected void initPrincipalClass(String principalClassName) {
- this.principalClass = ClassLoaderUtil.classForName(principalClassName);
+ try {
+ principalClass = ClassLoaderUtil.classForName(principalClassName);
+ }
+ catch (ClassNotFoundException e) {
+ throw new JbpmException("principal class not found: " + principalClassName, e);
+ }
}
public String getActorId() {
if (actorId == null) {
-
Subject subject = Subject.getSubject(AccessController.getContext());
if (subject == null) {
- log.warn("no javax.security.auth.Subject exists! Cannot set jbpm actorId");
+ log.warn("no subject exists! cannot get actorId");
return null;
}
Set principals = subject.getPrincipals(principalClass);
- if ((principals != null) && (!principals.isEmpty())) {
+ if (principals != null && !principals.isEmpty()) {
// always use the first one (so be patient what Principal classes are used)
Principal principal = (Principal) principals.iterator().next();
actorId = principal.getName();
@@ -110,5 +113,4 @@
public void close() {
}
-
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/ClassLoaderUtil.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -29,6 +29,7 @@
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmException;
+import org.jbpm.configuration.ObjectFactory;
/**
* provides centralized classloader lookup.
@@ -54,16 +55,12 @@
}
}
- public static Class classForName(String className) {
- try {
- return Class.forName(className, false, getClassLoader());
- }
- catch (ClassNotFoundException e) {
- throw new JbpmException("class not found: " + className, e);
- }
+ public static Class classForName(String className) throws ClassNotFoundException {
+ return Class.forName(className, false, getClassLoader());
}
- public static Class classForName(String className, boolean useConfiguredLoader) {
+ public static Class classForName(String className, boolean useConfiguredLoader)
+ throws ClassNotFoundException {
if (useConfiguredLoader) return classForName(className);
// try context class loader first, so that applications can override provided classes
@@ -72,13 +69,7 @@
}
catch (ClassNotFoundException e) {
// try the class loader of the current class
- try {
- return Class.forName(className, false, ClassLoaderUtil.class.getClassLoader());
- }
- catch (ClassNotFoundException e2) {
- // give up
- throw new JbpmException("class not found: " + className, e2);
- }
+ return Class.forName(className, false, ClassLoaderUtil.class.getClassLoader());
}
}
@@ -97,25 +88,22 @@
* </ul>
*/
public static ClassLoader getClassLoader() {
- if (JbpmConfiguration.Configs.hasObject("jbpm.class.loader")) {
- String jbpmClassLoader = JbpmConfiguration.Configs.getString("jbpm.class.loader");
-
- if (jbpmClassLoader.equals("jbpm")) {
+ ObjectFactory objectFactory = JbpmConfiguration.Configs.getObjectFactory();
+ if (objectFactory.hasObject("jbpm.class.loader")) {
+ String classLoader = (String) objectFactory.createObject("jbpm.class.loader");
+
+ if ("jbpm".equals(classLoader)) {
// use class loader that loaded the jbpm classes
return ClassLoaderUtil.class.getClassLoader();
}
-
- if (jbpmClassLoader.equals("context")) {
+
+ if (classLoader.equals("context")) {
// use the context class loader
return Thread.currentThread().getContextClassLoader();
}
-
+
// interpret value as a reference to a class loader bean
- Object bean = JbpmConfiguration.Configs.getObject(jbpmClassLoader);
- if (!(bean instanceof ClassLoader)) {
- throw new JbpmException("bean '" + jbpmClassLoader + "' is not a class loader");
- }
- return (ClassLoader) bean;
+ return (ClassLoader) objectFactory.createObject(classLoader);
}
else {
// behave like before JBPM-1148
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/XmlUtil.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/XmlUtil.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/util/XmlUtil.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -42,6 +42,7 @@
import org.apache.commons.collections.IteratorUtils;
import org.apache.commons.collections.Predicate;
+import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -101,6 +102,11 @@
return factory.newDocumentBuilder();
}
+ public static String attribute(Element element, String attrName) {
+ Attr attr = element.getAttributeNode(attrName);
+ return attr != null ? attr.getValue() : null;
+ }
+
public static Iterator elementIterator(Element element, final String tagName) {
return IteratorUtils.filteredIterator(new NodeIterator(element), new Predicate() {
public boolean evaluate(Object arg) {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/jbpm.cfg.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/jbpm.cfg.xml 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/jbpm.cfg.xml 2010-04-23 07:13:49 UTC (rev 6274)
@@ -1,9 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
<jbpm-configuration>
-
<!--
The default configurations can be found in org/jbpm/default.jbpm.cfg.xml
Those configurations can be overwritten by putting this file called
jbpm.cfg.xml on the root of the classpath and put in the customized values.
-->
-
</jbpm-configuration>
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/jbpm.mail.templates.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/jbpm.mail.templates.xml 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/jbpm.mail.templates.xml 2010-04-23 07:13:49 UTC (rev 6274)
@@ -1,5 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
<mail-templates>
-
<variable name="BaseTaskListURL" value="http://localhost:8080/jbpm/home?taskId=" />
<mail-template name='task-assign'>
@@ -20,5 +20,4 @@
Get going !
---powered by JBoss jBPM---]]></text>
</mail-template>
-
</mail-templates>
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml 2010-04-23 07:13:49 UTC (rev 6274)
@@ -1,5 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
<jbpm-configuration>
-
<!--
This file provides the default jBPM configuration. All available services
are enabled. Objects described in custom configuration files add to the
@@ -69,9 +69,11 @@
<bean name="jbpm.date.generator" class="org.example.DateGeneratorImpl" />
-->
- <!-- email sending properties -->
+ <!-- outgoing mail properties
<string name="jbpm.mail.smtp.host" value="localhost" />
- <string name="jbpm.mail.from.address" value="jbpm@noreply" />
+ <int name="jbpm.mail.smtp.port" value="25" />
+ <string name="jbpm.mail.from.address" value="no-reply(a)jbpm.org" />
+ -->
<bean name="jbpm.mail.address.resolver" class="org.jbpm.identity.mail.IdentityAddressResolver"
singleton="true" />
@@ -106,5 +108,4 @@
<int value="60000" />
</property>
</bean>
-
</jbpm-configuration>
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/jpdl/xml/jpdl-3.2.xsd
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/jpdl/xml/jpdl-3.2.xsd 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/resources/org/jbpm/jpdl/xml/jpdl-3.2.xsd 2010-04-23 07:13:49 UTC (rev 6274)
@@ -186,8 +186,12 @@
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="async" type="asyncType" default="false" />
<xs:attribute name="template" type="xs:string" />
+ <xs:attribute name="to" type="xs:string" />
<xs:attribute name="actors" type="xs:string" />
- <xs:attribute name="to" type="xs:string" />
+ <xs:attribute name="cc" type="xs:string"></xs:attribute>
+ <xs:attribute name="cc-actors" type="xs:string"></xs:attribute>
+ <xs:attribute name="bcc" type="xs:string"></xs:attribute>
+ <xs:attribute name="bcc-actors" type="xs:string"></xs:attribute>
<xs:attribute name="subject" type="xs:string" />
<xs:attribute name="text" type="xs:string" />
</xs:complexType>
@@ -270,11 +274,15 @@
<xs:element ref="subject" />
<xs:element ref="text" />
</xs:choice>
- <xs:attribute name="name" type="xs:string" use="required" />
+ <xs:attribute name="name" type="xs:string" />
<xs:attribute name="async" type="asyncType" default="false" />
<xs:attribute name="template" type="xs:string" />
+ <xs:attribute name="to" type="xs:string" />
<xs:attribute name="actors" type="xs:string" />
- <xs:attribute name="to" type="xs:string" />
+ <xs:attribute name="cc" type="xs:string"></xs:attribute>
+ <xs:attribute name="cc-actors" type="xs:string"></xs:attribute>
+ <xs:attribute name="bcc" type="xs:string"></xs:attribute>
+ <xs:attribute name="bcc-actors" type="xs:string"></xs:attribute>
<xs:attribute name="subject" type="xs:string" />
<xs:attribute name="text" type="xs:string" />
<xs:attribute name="accept-propagated-events" type="booleanType" default="true" />
@@ -400,11 +408,8 @@
<!-- MAIL -->
<!-- #### -->
- <xs:element name="to" type="xs:string" />
- <xs:element name="recipients" type="xs:string" />
<xs:element name="subject" type="xs:string" />
<xs:element name="text" type="xs:string" />
- <xs:element name="template" type="xs:string" />
<!-- TYPES AND GROUPS -->
<!-- ################ -->
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/SerializabilityTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/SerializabilityTest.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/SerializabilityTest.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -107,20 +107,24 @@
}
else if (fileName.endsWith(".class")) {
String className = packageName + '.' + fileName.substring(0, fileName.length() - 6);
- assertSerializabilityOfClass(className);
+ assertClassIsSerializable(className);
}
}
}
- private static void assertSerializabilityOfClass(String className) {
- Class clazz = ClassLoaderUtil.classForName(className);
+ private static void assertClassIsSerializable(String className) {
+ try {
+ Class clazz = Class.forName(className);
- if (!(Serializable.class.isAssignableFrom(clazz)
- || Modifier.isAbstract(clazz.getModifiers())
- || isAnonymous(clazz)
- || isUtility(clazz) || isExcused(className))) {
- fail(className + " is NOT Serializable");
+ if (!Serializable.class.isAssignableFrom(clazz)
+ && !Modifier.isAbstract(clazz.getModifiers()) && !isAnonymous(clazz)
+ && !isUtility(clazz) && !isExcused(className)) {
+ fail(className + " is NOT Serializable");
+ }
}
+ catch (ClassNotFoundException e) {
+ fail("no such class: " + className);
+ }
}
private static boolean isAnonymous(Class clazz) {
@@ -128,8 +132,8 @@
}
/**
- * Tells whether the given class consists exclusively of static methods and
- * has no public constructors.
+ * Tells whether the given class consists exclusively of static methods and has no public
+ * constructors.
*/
private static boolean isUtility(Class clazz) {
Method[] methods = clazz.getMethods();
Deleted: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/context/exe/CustomSessionFactoryFactory.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/context/exe/CustomSessionFactoryFactory.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/context/exe/CustomSessionFactoryFactory.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -1,40 +0,0 @@
-/*
- * 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.context.exe;
-
-import org.hibernate.SessionFactory;
-import org.hibernate.cfg.Configuration;
-
-import org.jbpm.db.hibernate.HibernateHelper;
-import org.jbpm.util.ClassLoaderUtil;
-
-public abstract class CustomSessionFactoryFactory {
-
- String extraClassMapping = null;
-
- public static SessionFactory createSessionFactory(String extraClassMapping) {
- Configuration configuration = HibernateHelper.createConfiguration(null, null);
- Class clazz = ClassLoaderUtil.classForName(extraClassMapping);
- configuration.addClass(clazz);
- return HibernateHelper.createSessionFactory(configuration, false);
- }
-}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1707/JBPM1707Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1707/JBPM1707Test.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1707/JBPM1707Test.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -32,8 +32,7 @@
/**
* Pageflow parsing is slow.
*
- * https://jira.jboss.org/jira/browse/JBPM-1707
- *
+ * @see <a href="https://jira.jboss.org/jira/browse/JBPM-1707">JBPM-1707</a>
* @author Alejandro Guizar
*/
public class JBPM1707Test extends AbstractJbpmTestCase {
Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2852/JBPM2852Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2852/JBPM2852Test.java (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2852/JBPM2852Test.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -0,0 +1,90 @@
+/*
+ * 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.jbpm2852;
+
+import org.jbpm.AbstractJbpmTestCase;
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmContext;
+import org.jbpm.context.exe.ContextInstance;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.mail.MailTest;
+
+import com.dumbster.smtp.SimpleSmtpServer;
+import com.dumbster.smtp.SmtpMessage;
+
+/**
+ * CC support in mail nodes and mail templates.
+ *
+ * @author Alejandro Guizar
+ */
+public class JBPM2852Test extends AbstractJbpmTestCase {
+
+ private JbpmContext jbpmContext;
+ private SimpleSmtpServer smtpServer;
+ private ProcessInstance processInstance;
+
+ private static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseResource("org/jbpm/jbpm2852/jbpm.cfg.xml");
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ jbpmContext = jbpmConfiguration.createJbpmContext();
+
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource("org/jbpm/jbpm2852/processdefinition.xml");
+ processInstance = new ProcessInstance(processDefinition);
+
+ ContextInstance contextInstance = processInstance.getContextInstance();
+ contextInstance.setVariable("technician", "technician(a)example.com");
+ contextInstance.setVariable("supervisor", "supervisor(a)example.com");
+ processInstance.signal();
+
+ smtpServer = MailTest.startSmtpServer(2525);
+ }
+
+ protected void tearDown() throws Exception {
+ smtpServer.stop();
+ jbpmContext.close();
+ super.tearDown();
+ }
+
+ public void testMailNodeInlineCC() {
+ processInstance.signal("high");
+ assertEquals("alert", processInstance.getRootToken().getNode().getName());
+
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ SmtpMessage message = (SmtpMessage) smtpServer.getReceivedEmail().next();
+ assertEquals("Reactor temperature exceeded threshold", message.getHeaderValue("Subject"));
+ assertEquals("technician(a)example.com", message.getHeaderValue("To"));
+ assertEquals("supervisor(a)example.com", message.getHeaderValue("Cc"));
+ }
+
+ public void testMailActionTemplateCC() {
+ processInstance.signal("normal");
+ assertEquals("ok", processInstance.getRootToken().getNode().getName());
+
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ SmtpMessage message = (SmtpMessage) smtpServer.getReceivedEmail().next();
+ assertEquals("Reactor temperature normal", message.getHeaderValue("Subject"));
+ assertEquals("technician(a)example.com", message.getHeaderValue("To"));
+ assertEquals("supervisor(a)example.com", message.getHeaderValue("Cc"));
+ }
+}
Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2852/JBPM2852Test.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mail/MailTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mail/MailTest.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mail/MailTest.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -3,12 +3,9 @@
import java.util.Arrays;
import java.util.Iterator;
-import junit.extensions.TestSetup;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
+import org.jbpm.AbstractJbpmTestCase;
import org.jbpm.JbpmConfiguration;
-import org.jbpm.db.AbstractDbTestCase;
+import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.taskmgmt.def.Swimlane;
@@ -17,32 +14,29 @@
import com.dumbster.smtp.SimpleSmtpServer;
import com.dumbster.smtp.SmtpMessage;
-public class MailTest extends AbstractDbTestCase {
+public class MailTest extends AbstractJbpmTestCase {
- static SimpleSmtpServer server;
-
+ private SimpleSmtpServer smtpServer;
+ private JbpmContext jbpmContext;
private static final String XML_DECL = "<?xml version='1.0'?>";
- public static Test suite() {
- return new TestSetup(new TestSuite(MailTest.class)) {
- protected void setUp() throws Exception {
- server = startSmtpServer(23583);
- }
+ private static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(XML_DECL
+ + "<jbpm-configuration>"
+ + " <jbpm-context />"
+ + " <string name='resource.mail.properties' value='org/jbpm/mail/test.mail.properties' />"
+ + " <bean name='jbpm.mail.address.resolver' class='"
+ + TestAddressResolver.class.getName()
+ + "' singleton='true' />"
+ + "</jbpm-configuration>");
- protected void tearDown() throws Exception {
- server.stop();
- }
- };
- }
-
- static SimpleSmtpServer startSmtpServer(int port) {
+ public static SimpleSmtpServer startSmtpServer(int port) {
/*
- * SimpleSmtpServer.start(int) blocks the calling thread until the server socket is created. If
- * the socket is created too quickly (seems to happen on Linux and Mac) then the notification is
- * sent too early and the calling thread blocks forever.
+ * SimpleSmtpServer.start(int) blocks the calling thread until the server socket is created.
+ * If the socket is created too quickly (seems to happen on Linux and Mac) then the
+ * notification is sent too early and the calling thread blocks forever.
*
- * The code below corresponds to SimpleSmtpServer.start(int) except that the thread is started
- * inside of the synchronized block.
+ * The code below corresponds to SimpleSmtpServer.start(int) except that the thread is
+ * started inside of the synchronized block.
*/
SimpleSmtpServer server = new SimpleSmtpServer(port);
Thread serverThread = new Thread(server);
@@ -60,20 +54,18 @@
return server;
}
- protected JbpmConfiguration getJbpmConfiguration() {
- if (jbpmConfiguration == null) {
- jbpmConfiguration = JbpmConfiguration.parseXmlString(XML_DECL +
- "<jbpm-configuration>" +
- " <jbpm-context />" +
- " <string name='resource.mail.properties' value='org/jbpm/mail/test.mail.properties' />" +
- " <bean name='jbpm.mail.address.resolver' class='" +
- TestAddressResolver.class.getName() +
- "' singleton='true' />" +
- "</jbpm-configuration>");
- }
- return jbpmConfiguration;
+ protected void setUp() throws Exception {
+ super.setUp();
+ jbpmContext = jbpmConfiguration.createJbpmContext();
+ smtpServer = startSmtpServer(2525);
}
+ protected void tearDown() throws Exception {
+ smtpServer.stop();
+ jbpmContext.close();
+ super.tearDown();
+ }
+
public void testWithoutAddressResolving() {
String to = "sample.shipper(a)example.domain";
String subject = "latest news";
@@ -82,11 +74,10 @@
Mail mail = new Mail(null, null, to, subject, text);
mail.send();
- assertEquals(1, server.getReceivedEmailSize());
- Iterator emailIter = server.getReceivedEmail();
- SmtpMessage email = (SmtpMessage) emailIter.next();
- emailIter.remove();
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ Iterator emailIter = smtpServer.getReceivedEmail();
+ SmtpMessage email = (SmtpMessage) emailIter.next();
assertEquals("latest news", email.getHeaderValue("Subject"));
assertEquals("roy is assurancetourix", email.getBody());
assertEquals("sample.shipper(a)example.domain", email.getHeaderValue("To"));
@@ -100,11 +91,10 @@
Mail mail = new Mail(null, actors, null, subject, text);
mail.send();
- assertEquals(1, server.getReceivedEmailSize());
- Iterator emailIter = server.getReceivedEmail();
- SmtpMessage email = (SmtpMessage) emailIter.next();
- emailIter.remove();
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ Iterator emailIter = smtpServer.getReceivedEmail();
+ SmtpMessage email = (SmtpMessage) emailIter.next();
assertEquals("latest news", email.getHeaderValue("Subject"));
assertEquals("roy is assurancetourix", email.getBody());
assertEquals("manager(a)example.domain", email.getHeaderValue("To"));
@@ -118,177 +108,173 @@
Mail mail = new Mail(null, null, null, null, bcc, subject, text);
mail.send();
- assertEquals(1, server.getReceivedEmailSize());
- Iterator emailIter = server.getReceivedEmail();
- SmtpMessage email = (SmtpMessage) emailIter.next();
- emailIter.remove();
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ Iterator emailIter = smtpServer.getReceivedEmail();
+ SmtpMessage email = (SmtpMessage) emailIter.next();
assertEquals("latest news", email.getHeaderValue("Subject"));
assertEquals("roy is assurancetourix", email.getBody());
assertNull(email.getHeaderValue("To"));
}
public void testMailNodeAttributes() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL +
- "<process-definition>" +
- " <start-state>" +
- " <transition to='send email' />" +
- " </start-state>" +
- " <mail-node name='send email' actors='george' subject='readmylips' text='nomoretaxes'>" +
- " <transition to='end' />" +
- " </mail-node>" +
- " <end-state name='end' />" +
- "</process-definition>");
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL
+ + "<process-definition>"
+ + " <start-state>"
+ + " <transition to='send email' />"
+ + " </start-state>"
+ + " <mail-node name='send email' actors='george' subject='readmylips' text='nomoretaxes'>"
+ + " <transition to='end' />"
+ + " </mail-node>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
- assertEquals(1, server.getReceivedEmailSize());
- Iterator emailIter = server.getReceivedEmail();
- SmtpMessage email = (SmtpMessage) emailIter.next();
- emailIter.remove();
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ Iterator emailIter = smtpServer.getReceivedEmail();
+ SmtpMessage email = (SmtpMessage) emailIter.next();
assertEquals("readmylips", email.getHeaderValue("Subject"));
assertEquals("nomoretaxes", email.getBody());
assertEquals("george(a)example.domain", email.getHeaderValue("To"));
}
public void testMailNodeElements() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL +
- "<process-definition>" +
- " <start-state>" +
- " <transition to='send email' />" +
- " </start-state>" +
- " <mail-node name='send email' actors='george'>" +
- " <subject>readmylips</subject>" +
- " <text>nomoretaxes</text>" +
- " <transition to='end' />" +
- " </mail-node>" +
- " <end-state name='end' />" +
- "</process-definition>");
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL
+ + "<process-definition>"
+ + " <start-state>"
+ + " <transition to='send email' />"
+ + " </start-state>"
+ + " <mail-node name='send email' actors='george'>"
+ + " <subject>readmylips</subject>"
+ + " <text>nomoretaxes</text>"
+ + " <transition to='end' />"
+ + " </mail-node>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
- assertEquals(1, server.getReceivedEmailSize());
- Iterator emailIter = server.getReceivedEmail();
- SmtpMessage email = (SmtpMessage) emailIter.next();
- emailIter.remove();
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ Iterator emailIter = smtpServer.getReceivedEmail();
+ SmtpMessage email = (SmtpMessage) emailIter.next();
assertEquals("readmylips", email.getHeaderValue("Subject"));
assertEquals("nomoretaxes", email.getBody());
assertEquals("george(a)example.domain", email.getHeaderValue("To"));
}
public void testMailActionAttributes() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL +
- "<process-definition>" +
- " <start-state>" +
- " <transition to='end'>" +
- " <mail name='send email' actors='george' subject='readmylips' text='nomoretaxes' />" +
- " </transition>" +
- " </start-state>" +
- " <end-state name='end' />" +
- "</process-definition>");
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL
+ + "<process-definition>"
+ + " <start-state>"
+ + " <transition to='end'>"
+ + " <mail name='send email' actors='george' subject='readmylips' text='nomoretaxes' />"
+ + " </transition>"
+ + " </start-state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
- assertEquals(1, server.getReceivedEmailSize());
- Iterator emailIter = server.getReceivedEmail();
- SmtpMessage email = (SmtpMessage) emailIter.next();
- emailIter.remove();
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ Iterator emailIter = smtpServer.getReceivedEmail();
+ SmtpMessage email = (SmtpMessage) emailIter.next();
assertEquals("readmylips", email.getHeaderValue("Subject"));
assertEquals("nomoretaxes", email.getBody());
assertEquals("george(a)example.domain", email.getHeaderValue("To"));
}
public void testMailActionElements() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL +
- "<process-definition>" +
- " <start-state>" +
- " <transition to='end'>" +
- " <mail actors='george'>" +
- " <subject>readmylips</subject>" +
- " <text>nomoretaxes</text>" +
- " </mail>" +
- " <transition to='end' />" +
- " </transition>" +
- " </start-state>" +
- " <end-state name='end' />" +
- "</process-definition>");
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL
+ + "<process-definition>"
+ + " <start-state>"
+ + " <transition to='end'>"
+ + " <mail actors='george'>"
+ + " <subject>readmylips</subject>"
+ + " <text>nomoretaxes</text>"
+ + " </mail>"
+ + " <transition to='end' />"
+ + " </transition>"
+ + " </start-state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
- assertEquals(1, server.getReceivedEmailSize());
- Iterator emailIter = server.getReceivedEmail();
- SmtpMessage email = (SmtpMessage) emailIter.next();
- emailIter.remove();
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ Iterator emailIter = smtpServer.getReceivedEmail();
+ SmtpMessage email = (SmtpMessage) emailIter.next();
assertEquals("readmylips", email.getHeaderValue("Subject"));
assertEquals("nomoretaxes", email.getBody());
assertEquals("george(a)example.domain", email.getHeaderValue("To"));
}
public void testMultipleRecipients() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL +
- "<process-definition>" +
- " <start-state>" +
- " <transition to='end'>" +
- " <mail name='send email' actors='george; barbara; suzy'" +
- " subject='readmylips' text='nomoretaxes' />" +
- " </transition>" +
- " </start-state>" +
- " <end-state name='end' />" +
- "</process-definition>");
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL
+ + "<process-definition>"
+ + " <start-state>"
+ + " <transition to='end'>"
+ + " <mail name='send email' actors='george; barbara; suzy'"
+ + " subject='readmylips' text='nomoretaxes' />"
+ + " </transition>"
+ + " </start-state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
- assertEquals(1, server.getReceivedEmailSize());
- Iterator emailIter = server.getReceivedEmail();
- SmtpMessage email = (SmtpMessage) emailIter.next();
- emailIter.remove();
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ Iterator emailIter = smtpServer.getReceivedEmail();
+ SmtpMessage email = (SmtpMessage) emailIter.next();
assertEquals("readmylips", email.getHeaderValue("Subject"));
assertEquals("nomoretaxes", email.getBody());
- String[] expectedTo = { "george(a)example.domain", "barbara(a)example.domain",
- "suzy(a)example.domain" };
+ String[] expectedTo = {
+ "george(a)example.domain", "barbara(a)example.domain", "suzy(a)example.domain"
+ };
String[] to = email.getHeaderValues("To");
assert Arrays.equals(expectedTo, to) : Arrays.asList(to);
}
public void testMailWithoutAddressResolving() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL +
- "<process-definition>" +
- " <start-state>" +
- " <transition to='end'>" +
- " <mail name='send email' to='george(a)humpydumpy.gov: spiderman(a)hollywood.ca.us'" +
- " subject='readmylips' text='nomoretaxes' />" +
- " </transition>" +
- " </start-state>" +
- " <end-state name='end' />" +
- "</process-definition>");
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL
+ + "<process-definition>"
+ + " <start-state>"
+ + " <transition to='end'>"
+ + " <mail name='send email' to='george(a)humpydumpy.gov: spiderman(a)hollywood.ca.us'"
+ + " subject='readmylips' text='nomoretaxes' />"
+ + " </transition>"
+ + " </start-state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
- assertEquals(1, server.getReceivedEmailSize());
- Iterator emailIter = server.getReceivedEmail();
- SmtpMessage email = (SmtpMessage) emailIter.next();
- emailIter.remove();
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ Iterator emailIter = smtpServer.getReceivedEmail();
- String[] expectedTo = { "george(a)humpydumpy.gov", "spiderman(a)hollywood.ca.us" };
+ SmtpMessage email = (SmtpMessage) emailIter.next();
+ String[] expectedTo = {
+ "george(a)humpydumpy.gov", "spiderman(a)hollywood.ca.us"
+ };
String[] to = email.getHeaderValues("To");
assert Arrays.equals(expectedTo, to) : Arrays.asList(to);
}
public void testToVariableExpression() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL +
- "<process-definition>" +
- " <start-state>" +
- " <transition to='end'>" +
- " <mail name='send email' to='#{user.email}' subject='s' text='t' />" +
- " </transition>" +
- " </start-state>" +
- " <end-state name='end' />" +
- "</process-definition>");
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL
+ + "<process-definition>"
+ + " <start-state>"
+ + " <transition to='end'>"
+ + " <mail name='send email' to='#{user.email}' subject='s' text='t' />"
+ + " </transition>"
+ + " </start-state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
User mrNobody = new User("hucklebuck(a)example.domain");
@@ -296,24 +282,23 @@
processInstance.getContextInstance().setVariable("user", mrNobody);
processInstance.signal();
- assertEquals(1, server.getReceivedEmailSize());
- Iterator emailIter = server.getReceivedEmail();
- SmtpMessage email = (SmtpMessage) emailIter.next();
- emailIter.remove();
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ Iterator emailIter = smtpServer.getReceivedEmail();
+ SmtpMessage email = (SmtpMessage) emailIter.next();
assertEquals("hucklebuck(a)example.domain", email.getHeaderValue("To"));
}
public void testToSwimlaneExpression() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL +
- "<process-definition>" +
- " <start-state>" +
- " <transition to='end'>" +
- " <mail name='send email' actors='#{initiator}' subject='s' text='t' />" +
- " </transition>" +
- " </start-state>" +
- " <end-state name='end' />" +
- "</process-definition>");
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL
+ + "<process-definition>"
+ + " <start-state>"
+ + " <transition to='end'>"
+ + " <mail name='send email' actors='#{initiator}' subject='s' text='t' />"
+ + " </transition>"
+ + " </start-state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Swimlane initiator = new Swimlane("initiator");
@@ -322,57 +307,54 @@
processInstance.getTaskMgmtInstance().addSwimlaneInstance(initiatorInstance);
processInstance.signal();
- assertEquals(1, server.getReceivedEmailSize());
- Iterator emailIter = server.getReceivedEmail();
- SmtpMessage email = (SmtpMessage) emailIter.next();
- emailIter.remove();
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ Iterator emailIter = smtpServer.getReceivedEmail();
+ SmtpMessage email = (SmtpMessage) emailIter.next();
assertEquals("huckelberry(a)example.domain", email.getHeaderValue("To"));
}
public void testSubjectExpression() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL +
- "<process-definition>" +
- " <start-state>" +
- " <transition to='end'>" +
- " <mail name='send email' actors='me' subject='your ${item} order' text='t' />" +
- " </transition>" +
- " </start-state>" +
- " <end-state name='end' />" +
- "</process-definition>");
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL
+ + "<process-definition>"
+ + " <start-state>"
+ + " <transition to='end'>"
+ + " <mail name='send email' actors='me' subject='your ${item} order' text='t' />"
+ + " </transition>"
+ + " </start-state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("item", "cookies");
processInstance.signal();
- assertEquals(1, server.getReceivedEmailSize());
- Iterator emailIter = server.getReceivedEmail();
- SmtpMessage email = (SmtpMessage) emailIter.next();
- emailIter.remove();
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ Iterator emailIter = smtpServer.getReceivedEmail();
+ SmtpMessage email = (SmtpMessage) emailIter.next();
assertEquals("your cookies order", email.getHeaderValue("Subject"));
}
public void testTextExpression() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL +
- "<process-definition>" +
- " <start-state>" +
- " <transition to='end'>" +
- " <mail name='send email' actors='me' text='your ${item} order' />" +
- " </transition>" +
- " </start-state>" +
- " <end-state name='end' />" +
- "</process-definition>");
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL
+ + "<process-definition>"
+ + " <start-state>"
+ + " <transition to='end'>"
+ + " <mail name='send email' actors='me' text='your ${item} order' />"
+ + " </transition>"
+ + " </start-state>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("item", "cookies");
processInstance.signal();
- assertEquals(1, server.getReceivedEmailSize());
- Iterator emailIter = server.getReceivedEmail();
- SmtpMessage email = (SmtpMessage) emailIter.next();
- emailIter.remove();
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ Iterator emailIter = smtpServer.getReceivedEmail();
+ SmtpMessage email = (SmtpMessage) emailIter.next();
assertEquals("your cookies order", email.getBody());
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mail/TaskMailTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mail/TaskMailTest.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mail/TaskMailTest.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -4,10 +4,6 @@
import java.util.Iterator;
import java.util.List;
-import junit.extensions.TestSetup;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.jbpm.AbstractJbpmTestCase;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
@@ -20,6 +16,7 @@
import org.jbpm.scheduler.SchedulerService;
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;
@@ -29,40 +26,35 @@
import com.dumbster.smtp.SmtpMessage;
public class TaskMailTest extends AbstractJbpmTestCase {
- private static final int SMTP_PORT = 23583;
- static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
+ private JbpmContext jbpmContext;
+ private SimpleSmtpServer smtpServer;
+
+ private static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
+ " <jbpm-context>"
- + " <service name='scheduler' factory='org.jbpm.mail.TaskMailTest$TestSchedulerService' />"
+ + " <service name='scheduler' factory='"
+ + TestSchedulerService.class.getName()
+ + "' />"
+ " </jbpm-context>"
+ " <string name='resource.mail.properties' value='org/jbpm/mail/test.mail.properties' />"
- + " <bean name='jbpm.mail.address.resolver' class='org.jbpm.mail.MailTest$TestAddressResolver' singleton='true' />"
+ + " <bean name='jbpm.mail.address.resolver' class='"
+ + MailTest.TestAddressResolver.class.getName()
+ + "' singleton='true' />"
+ "</jbpm-configuration>");
- static SimpleSmtpServer server;
- private JbpmContext jbpmContext;
-
- public static Test suite() {
- return new TestSetup(new TestSuite(TaskMailTest.class)) {
- protected void setUp() throws Exception {
- server = MailTest.startSmtpServer(SMTP_PORT);
- }
-
- protected void tearDown() throws Exception {
- server.stop();
- }
- };
- }
-
protected void setUp() throws Exception {
super.setUp();
- TestSchedulerService testSchedulerService = (TestSchedulerService) jbpmConfiguration.getServiceFactory("scheduler");
- testSchedulerService.reset();
jbpmContext = jbpmConfiguration.createJbpmContext();
+ smtpServer = MailTest.startSmtpServer(2525);
}
protected void tearDown() throws Exception {
+ smtpServer.stop();
+
+ TestSchedulerService testSchedulerService = (TestSchedulerService) jbpmContext.getServiceFactory(Services.SERVICENAME_SCHEDULER);
+ testSchedulerService.reset();
jbpmContext.close();
+
super.tearDown();
}
@@ -82,7 +74,9 @@
+ " </start-state>"
+ " <task-node name='a'>"
+ " <task name='laundry' notify='yes'>"
- + " <assignment class='org.jbpm.mail.TaskMailTest$RoundRobinAssigner' />"
+ + " <assignment class='"
+ + RoundRobinAssigner.class.getName()
+ + "' />"
+ " </task>"
+ " <transition to='b' />"
+ " </task-node>"
@@ -91,31 +85,27 @@
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
- assertTrue(server.getReceivedEmailSize() == 1);
- Iterator emailIter = server.getReceivedEmail();
+ assertTrue(smtpServer.getReceivedEmailSize() == 1);
+ Iterator emailIter = smtpServer.getReceivedEmail();
SmtpMessage email = (SmtpMessage) emailIter.next();
emailIter.remove();
assertEquals("you(a)example.domain", email.getHeaderValue("To"));
assertEquals("Task 'laundry'", email.getHeaderValue("Subject"));
- assertEquals(-1, email.getBody().indexOf("#{")); // just to make sure that
- // all expressions were
- // resolved
+ // just to make sure that all expressions were resolved
+ assertEquals(-1, email.getBody().indexOf("#{"));
assertTrue(-1 != email.getBody().indexOf("http://localhost:8080/jbpm/home?taskId=0"));
}
public static class TestSchedulerService implements SchedulerService, ServiceFactory {
private static final long serialVersionUID = 1L;
- List createdTimers = null;
- List cancelledTimers = null;
- public TestSchedulerService() {
- reset();
- }
+ List createdTimers = new ArrayList();
+ List cancelledTimers = new ArrayList();
public void reset() {
- createdTimers = new ArrayList();
- cancelledTimers = new ArrayList();
+ createdTimers.clear();
+ cancelledTimers.clear();
}
public void createTimer(Timer timer) {
@@ -148,7 +138,9 @@
+ " </start-state>"
+ " <task-node name='a'>"
+ " <task name='laundry'>"
- + " <assignment class='org.jbpm.mail.TaskMailTest$RoundRobinAssigner' />"
+ + " <assignment class='"
+ + RoundRobinAssigner.class.getName()
+ + "' />"
+ " <reminder duedate='0 seconds' repeat='60 seconds' />"
+ " </task>"
+ " <transition to='b' />"
@@ -158,7 +150,7 @@
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
- assertTrue(server.getReceivedEmailSize() == 0);
+ assertTrue(smtpServer.getReceivedEmailSize() == 0);
TestSchedulerService testSchedulerService = (TestSchedulerService) jbpmContext.getServices()
.getService("scheduler");
@@ -170,16 +162,15 @@
createdTimer.execute(jbpmContext);
- assertTrue(server.getReceivedEmailSize() == 1);
- Iterator emailIter = server.getReceivedEmail();
+ assertTrue(smtpServer.getReceivedEmailSize() == 1);
+ Iterator emailIter = smtpServer.getReceivedEmail();
SmtpMessage email = (SmtpMessage) emailIter.next();
emailIter.remove();
assertEquals("you(a)example.domain", email.getHeaderValue("To"));
assertEquals("Task 'laundry' !", email.getHeaderValue("Subject"));
- assertEquals(-1, email.getBody().indexOf("#{")); // just to make sure that
- // all expressions were
- // resolved
+ // just to make sure that all expressions were resolved
+ assertEquals(-1, email.getBody().indexOf("#{"));
assertTrue(-1 != email.getBody().indexOf("http://localhost:8080/jbpm/home?taskId=0"));
TaskMgmtInstance taskMgmtInstance = processInstance.getTaskMgmtInstance();
@@ -207,7 +198,9 @@
+ " </start-state>"
+ " <task-node name='a'>"
+ " <task name='laundry' notify='true'>"
- + " <assignment class='org.jbpm.mail.TaskMailTest$GhostAssigner' />"
+ + " <assignment class='"
+ + GhostAssigner.class.getName()
+ + "' />"
+ " </task>"
+ " <transition to='b' />"
+ " </task-node>"
@@ -216,7 +209,7 @@
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
- assertEquals(0, server.getReceivedEmailSize());
+ assertEquals(0, smtpServer.getReceivedEmailSize());
TaskMgmtInstance taskMgmtInstance = processInstance.getTaskMgmtInstance();
TaskInstance taskInstance = (TaskInstance) taskMgmtInstance.getTaskInstances()
@@ -228,6 +221,6 @@
assertEquals("ghost", taskInstance.getActorId());
taskInstance.end();
- assertEquals(0, server.getReceivedEmailSize());
+ assertEquals(0, smtpServer.getReceivedEmailSize());
}
}
Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/gpd.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/gpd.xml (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/gpd.xml 2010-04-23 07:13:49 UTC (rev 6274)
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root-container name="jbpm2852" width="788" height="568">
+ <node name="start" x="36" y="36" width="121" height="37">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="read sensor" x="36" y="120" width="121" height="37">
+ <edge>
+ <label x="-12" y="-22"/>
+ </edge>
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="contact technician" x="216" y="120" width="133" height="37">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="ok" x="36" y="204" width="121" height="37"/>
+ <node name="alert" x="216" y="204" width="133" height="37"/>
+ <deployment serverName="" serverPort="" serverDeployer="">
+ <classesAndResources/>
+ <filesAndFolders>
+ <element value="/jbpm-jpdl/src/test/resources/org/jbpm/jbpm2852/gpd.xml"/>
+ <element value="/jbpm-jpdl/src/test/resources/org/jbpm/jbpm2852/processdefinition.xml"/>
+ </filesAndFolders>
+ </deployment>
+</root-container>
Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/gpd.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/jbpm.cfg.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/jbpm.cfg.xml (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/jbpm.cfg.xml 2010-04-23 07:13:49 UTC (rev 6274)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jbpm-configuration>
+ <jbpm-context />
+ <string name="resource.mail.templates" value="org/jbpm/jbpm2852/mail.templates.xml" />
+ <int name="jbpm.mail.smtp.port" value="2525" />
+</jbpm-configuration>
Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/jbpm.cfg.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/mail.templates.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/mail.templates.xml (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/mail.templates.xml 2010-04-23 07:13:49 UTC (rev 6274)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mail-templates>
+ <mail-template name='a-ok'>
+ <to>${technician}</to>
+ <cc>${supervisor}</cc>
+ <subject>Reactor temperature normal</subject>
+ <text><![CDATA[Keep up the good work!]]></text>
+ </mail-template>
+</mail-templates>
Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/mail.templates.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/processdefinition.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/processdefinition.xml (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/processdefinition.xml 2010-04-23 07:13:49 UTC (rev 6274)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process-definition xmlns="urn:jbpm.org:jpdl-3.2" name="jbpm2852">
+
+ <start-state name="start">
+ <transition to="read sensor" />
+ </start-state>
+
+ <state name="read sensor">
+ <transition to="contact technician" name="high" />
+ <transition to="ok" name="normal">
+ <mail name="reassure supervisor" template="a-ok" />
+ </transition>
+ </state>
+
+ <mail-node name="contact technician" to="${technician}" cc="${supervisor}">
+ <subject>Reactor temperature exceeded threshold</subject>
+ <text>Act fast! We do not want another Chernobyl.</text>
+ <transition to="alert" />
+ </mail-node>
+
+ <end-state name="ok" />
+
+ <end-state name="alert" />
+
+</process-definition>
\ No newline at end of file
Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jbpm2852/processdefinition.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jpdl/xml/.gpd.testSimpleSchemaReference.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jpdl/xml/.gpd.testSimpleSchemaReference.xml (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jpdl/xml/.gpd.testSimpleSchemaReference.xml 2010-04-23 07:13:49 UTC (rev 6274)
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root-container/>
\ No newline at end of file
Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/jpdl/xml/.gpd.testSimpleSchemaReference.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/mail/test.mail.properties
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/mail/test.mail.properties 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/resources/org/jbpm/mail/test.mail.properties 2010-04-23 07:13:49 UTC (rev 6274)
@@ -1,2 +1,2 @@
mail.smtp.host = localhost
-mail.smtp.port = 23583
\ No newline at end of file
+mail.smtp.port = 2525
\ No newline at end of file
Modified: jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/java/org/jbpm/examples/mail/MailTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/java/org/jbpm/examples/mail/MailTest.java 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/java/org/jbpm/examples/mail/MailTest.java 2010-04-23 07:13:49 UTC (rev 6274)
@@ -21,10 +21,6 @@
*/
package org.jbpm.examples.mail;
-import junit.extensions.TestSetup;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.jbpm.AbstractJbpmTestCase;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
@@ -33,68 +29,45 @@
import org.jbpm.mail.AddressResolver;
import com.dumbster.smtp.SimpleSmtpServer;
+import com.dumbster.smtp.SmtpMessage;
public class MailTest extends AbstractJbpmTestCase {
- static SimpleSmtpServer server;
- private static final String XML_DECL = "<?xml version='1.0'?>";
+ private JbpmContext jbpmContext;
+ private SimpleSmtpServer smtpServer;
- public static Test suite() {
- return new TestSetup(new TestSuite(MailTest.class)) {
- protected void setUp() throws Exception {
- server = startSmtpServer(23583);
- }
+ private static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseResource("mail/jbpm.cfg.xml");
- protected void tearDown() throws Exception {
- server.stop();
- }
- };
+ protected void setUp() throws Exception {
+ super.setUp();
+ jbpmContext = jbpmConfiguration.createJbpmContext();
+ smtpServer = startSmtpServer(2525);
}
+ protected void tearDown() throws Exception {
+ smtpServer.stop();
+ jbpmContext.close();
+ super.tearDown();
+ }
+
public void testSimpleProcess() throws Exception {
- JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(XML_DECL +
- "<jbpm-configuration>" +
- " <jbpm-context />" +
- " <string name='resource.mail.properties' value='mail/mail.properties' />" +
- " <bean name='jbpm.mail.address.resolver' class='" +
- MyAddressResolver.class.getName() +
- "' singleton='true' />" +
- "</jbpm-configuration>");
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource("mail/processdefinition.xml");
+ ProcessInstance processInstance = new ProcessInstance(processDefinition);
+ processInstance.signal();
- JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(XML_DECL +
- "<process-definition name='mailtest'>" +
- " <start-state name='start'>" +
- " <transition to='start toothpick line' />" +
- " </start-state>" +
- " <task-node name='start toothpick line'>" +
- " <task notify='yes'>" +
- " <assignment actor-id='grandma' />" +
- " </task>" +
- " <transition to='end' />" +
- " </task-node>" +
- " <end-state name='end' />" +
- "</process-definition>");
- ProcessInstance processInstance = new ProcessInstance(processDefinition);
- processInstance.signal();
- jbpmContext.save(processInstance);
- }
- finally {
- jbpmContext.close();
- }
-
- assertEquals(1, server.getReceivedEmailSize());
+ assertEquals(1, smtpServer.getReceivedEmailSize());
+ SmtpMessage smtpMessage = (SmtpMessage) smtpServer.getReceivedEmail().next();
+ assertEquals("grandma(a)dalton.com", smtpMessage.getHeaderValue("To"));
}
static SimpleSmtpServer startSmtpServer(int port) {
/*
- * SimpleSmtpServer.start(int) blocks the calling thread until the server socket is created. If
- * the socket is created too quickly (happens on Linux and Mac) then the notification is sent
- * too early and the calling thread blocks forever.
+ * SimpleSmtpServer.start(int) blocks the calling thread until the server socket is created.
+ * If the socket is created too quickly (happens on Linux and Mac) then the notification is
+ * sent too early and the calling thread blocks forever.
*
- * The code below corresponds to SimpleSmtpServer.start(int) except that the thread is started
- * inside of the synchronized block.
+ * The code below corresponds to SimpleSmtpServer.start(int) except that the thread is
+ * started inside of the synchronized block.
*/
SimpleSmtpServer server = new SimpleSmtpServer(port);
Thread serverThread = new Thread(server);
Added: jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/gpd.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/gpd.xml (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/gpd.xml 2010-04-23 07:13:49 UTC (rev 6274)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root-container name="mail" width="788" height="568">
+ <node name="start" x="36" y="24" width="133" height="37">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="start toothpick line" x="36" y="96" width="133" height="37">
+ <edge>
+ <label x="5" y="-10"/>
+ </edge>
+ </node>
+ <node name="end" x="36" y="168" width="133" height="37"/>
+ <deployment serverName="" serverPort="" serverDeployer="">
+ <classesAndResources/>
+ <filesAndFolders>
+ <element value="/jbpm-examples/src/test/resources/mail/gpd.xml"/>
+ <element value="/jbpm-examples/src/test/resources/mail/mail.properties"/>
+ <element value="/jbpm-examples/src/test/resources/mail/processdefinition.xml"/>
+ </filesAndFolders>
+ </deployment>
+</root-container>
Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/gpd.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/jbpm.cfg.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/jbpm.cfg.xml (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/jbpm.cfg.xml 2010-04-23 07:13:49 UTC (rev 6274)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jbpm-configuration>
+ <jbpm-context />
+ <int name="jbpm.mail.smtp.port" value="2525" />
+ <bean name="jbpm.mail.address.resolver" class="org.jbpm.examples.mail.MailTest$MyAddressResolver"
+ singleton="true" />
+</jbpm-configuration>
\ No newline at end of file
Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/jbpm.cfg.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Deleted: jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/mail.properties
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/mail.properties 2010-04-21 19:12:33 UTC (rev 6273)
+++ jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/mail.properties 2010-04-23 07:13:49 UTC (rev 6274)
@@ -1,2 +0,0 @@
-mail.smtp.host localhost
-mail.smtp.port 23583
\ No newline at end of file
Added: jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/processdefinition.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/processdefinition.xml (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/processdefinition.xml 2010-04-23 07:13:49 UTC (rev 6274)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process-definition name='mail'>
+ <start-state name='start'>
+ <transition to='start toothpick line' />
+ </start-state>
+ <task-node name='start toothpick line'>
+ <task notify='yes'>
+ <assignment actor-id='grandma' />
+ </task>
+ <transition to='end' />
+ </task-node>
+ <end-state name='end' />
+</process-definition>
Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/processdefinition.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/processimage.jpg
===================================================================
(Binary files differ)
Property changes on: jbpm3/branches/jbpm-3.2-soa/modules/examples/src/test/resources/mail/processimage.jpg
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
14 years
JBoss JBPM SVN: r6273 - projects/exception_framework/trunk.
by do-not-reply@jboss.org
Author: eschabell
Date: 2010-04-21 15:12:33 -0400 (Wed, 21 Apr 2010)
New Revision: 6273
Modified:
projects/exception_framework/trunk/pom.xml
Log:
Fixed maven pom.xml to create resource dirs for config and jpdl.
Modified: projects/exception_framework/trunk/pom.xml
===================================================================
--- projects/exception_framework/trunk/pom.xml 2010-04-21 16:51:07 UTC (rev 6272)
+++ projects/exception_framework/trunk/pom.xml 2010-04-21 19:12:33 UTC (rev 6273)
@@ -8,9 +8,33 @@
<build>
<plugins>
<plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>surefire-report-maven-plugin</artifactId>
- <version>2.0-beta-1</version>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.5</version>
+ <executions>
+ <execution>
+ <id>add-resource</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>add-resource</goal>
+ </goals>
+ <configuration>
+ <resources>
+ <resource>
+ <directory>src/main/config</directory>
+ </resource>
+ <resource>
+ <directory>src/main/jpdl</directory>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.5</version>
</plugin>
</plugins>
</build>
14 years
JBoss JBPM SVN: r6272 - in jbpm4/trunk/modules: examples/src/test/java/org/jbpm/examples/mail/template and 9 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-04-21 12:51:07 -0400 (Wed, 21 Apr 2010)
New Revision: 6272
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/AttachmentTest.java
jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/activity/
jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/activity/mail/
jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/activity/mail/strip.gif
Modified:
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/inline/InlineMailTest.java
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/template/TemplateMailTest.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ScriptActivity.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AttachmentTemplate.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java
jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml
Log:
JBPM-2426: code and document mail attachment example
Modified: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/inline/InlineMailTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/inline/InlineMailTest.java 2010-04-21 15:28:50 UTC (rev 6271)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/inline/InlineMailTest.java 2010-04-21 16:51:07 UTC (rev 6272)
@@ -44,48 +44,44 @@
*/
public class InlineMailTest extends JbpmTestCase {
- Wiser wiser = null;
-
- String groupId1;
-
- String groupId2;
+ private Wiser wiser = new Wiser();
protected void setUp() throws Exception {
super.setUp();
// deploy process
String deploymentId = repositoryService.createDeployment()
- .addResourceFromClasspath("org/jbpm/examples/mail/inline/process.jpdl.xml")
- .deploy();
+ .addResourceFromClasspath("org/jbpm/examples/mail/inline/process.jpdl.xml")
+ .deploy();
registerDeployment(deploymentId);
// create actors
identityService.createUser("bb", "Big Brother", null, "bb@oceania");
identityService.createUser("obrien", null, "O'Brien", "obrien@miniluv");
identityService.createUser("charr", null, "Charrington", "charr@miniluv");
- groupId1 = identityService.createGroup("thinkpol");
- groupId2 = identityService.createGroup("innerparty");
- identityService.createMembership("obrien", groupId2);
- identityService.createMembership("charr", groupId1);
- identityService.createMembership("obrien", groupId1);
-
+ identityService.createGroup("thinkpol");
+ identityService.createGroup("innerparty");
+ identityService.createMembership("obrien", "innerparty");
+ identityService.createMembership("charr", "thinkpol");
+ identityService.createMembership("obrien", "thinkpol");
+
// start mail server
- wiser = new Wiser();
wiser.setPort(2525);
wiser.start();
}
protected void tearDown() throws Exception {
+ // stop mail server
wiser.stop();
// delete actors
identityService.deleteUser("bb");
identityService.deleteUser("obrien");
identityService.deleteUser("charr");
-
- identityService.deleteGroup(groupId1);
- identityService.deleteGroup(groupId2);
-
+
+ identityService.deleteGroup("thinkpol");
+ identityService.deleteGroup("innerparty");
+
super.tearDown();
}
@@ -117,13 +113,13 @@
// to
Address[] expectedTo = InternetAddress.parse("winston@minitrue");
Address[] to = message.getRecipients(RecipientType.TO);
- assert Arrays.equals(expectedTo, to) : Arrays.asList(to);
+ assert Arrays.equals(expectedTo, to) : Arrays.toString(to);
// cc
Address[] expectedCc = InternetAddress.parse("bb@oceania, obrien@miniluv");
System.out.println(Arrays.toString(expectedCc));
Address[] cc = message.getRecipients(RecipientType.CC);
System.out.println(Arrays.toString(cc));
- assert Arrays.equals(expectedCc, cc) : Arrays.asList(cc);
+ assert Arrays.equals(expectedCc, cc) : Arrays.toString(cc);
// bcc - recipients undisclosed
assertNull(message.getRecipients(RecipientType.BCC));
// subject
Modified: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/template/TemplateMailTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/template/TemplateMailTest.java 2010-04-21 15:28:50 UTC (rev 6271)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/template/TemplateMailTest.java 2010-04-21 16:51:07 UTC (rev 6272)
@@ -44,7 +44,7 @@
*/
public class TemplateMailTest extends JbpmTestCase {
- private Wiser wiser;
+ private Wiser wiser = new Wiser();
protected void setUp() throws Exception {
super.setUp();
@@ -66,12 +66,12 @@
identityService.createMembership("obrien", "thinkpol");
// start mail server
- wiser = new Wiser();
wiser.setPort(2525);
wiser.start();
}
protected void tearDown() throws Exception {
+ // stop mail server
wiser.stop();
// delete actors
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ScriptActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ScriptActivity.java 2010-04-21 15:28:50 UTC (rev 6271)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ScriptActivity.java 2010-04-21 16:51:07 UTC (rev 6272)
@@ -23,10 +23,8 @@
import org.jbpm.api.model.OpenExecution;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.script.ScriptManager;
-
/**
* @author Tom Baeyens
*/
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AttachmentTemplate.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AttachmentTemplate.java 2010-04-21 15:28:50 UTC (rev 6271)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AttachmentTemplate.java 2010-04-21 16:51:07 UTC (rev 6272)
@@ -32,6 +32,10 @@
private String name;
private String description;
+
+ private String expression;
+ private String mimeType;
+
private String url;
private String resource;
private String file;
@@ -39,7 +43,6 @@
public String getName() {
return name;
}
-
public void setName(String name) {
this.name = name;
}
@@ -47,15 +50,27 @@
public String getDescription() {
return description;
}
-
public void setDescription(String description) {
this.description = description;
}
+ public String getExpression() {
+ return expression;
+ }
+ public void setExpression(String expression) {
+ this.expression = expression;
+ }
+
+ public String getMimeType() {
+ return mimeType;
+ }
+ public void setMimeType(String mimeType) {
+ this.mimeType = mimeType;
+ }
+
public String getUrl() {
return url;
}
-
public void setUrl(String url) {
this.url = url;
}
@@ -63,7 +78,6 @@
public String getResource() {
return resource;
}
-
public void setResource(String resource) {
this.resource = resource;
}
@@ -71,9 +85,7 @@
public String getFile() {
return file;
}
-
public void setFile(String file) {
this.file = file;
}
-
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java 2010-04-21 15:28:50 UTC (rev 6271)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java 2010-04-21 16:51:07 UTC (rev 6272)
@@ -30,7 +30,9 @@
import java.util.List;
import javax.activation.DataHandler;
+import javax.activation.DataSource;
import javax.activation.FileDataSource;
+import javax.activation.URLDataSource;
import javax.mail.Address;
import javax.mail.BodyPart;
import javax.mail.Message;
@@ -105,7 +107,7 @@
// resolve and parse addresses
String addresses = fromTemplate.getAddresses();
if (addresses != null) {
- addresses = evaluateExpression(addresses, execution);
+ addresses = evaluateExpression(addresses);
email.addFrom(InternetAddress.parse(addresses));
}
@@ -131,20 +133,18 @@
}
}
- private String evaluateExpression(String expression, Execution execution) {
- ScriptManager scriptManager = EnvironmentImpl.getFromCurrent(ScriptManager.class);
+ private String evaluateExpression(String expression) {
+ return evaluateExpression(expression, String.class);
+ }
+
+ private <T> T evaluateExpression(String expression, Class<T> type) {
+ ScriptManager scriptManager = ScriptManager.getScriptManager();
Object value = scriptManager.evaluateExpression(expression, template.getLanguage());
- if (!(value instanceof String)) {
- throw new JbpmException("expected expression '"
- + expression
- + "' to return string, but was: "
- + value);
- }
- return (String) value;
+ return type.cast(value);
}
private String[] tokenizeActors(String recipients, Execution execution) {
- String[] actors = evaluateExpression(recipients, execution).split("[,;|\\s]+");
+ String[] actors = evaluateExpression(recipients).split("[,;|\\s]+");
if (actors.length == 0) throw new JbpmException("recipient list is empty: " + recipients);
return actors;
}
@@ -178,7 +178,7 @@
// resolve and parse addresses
String addresses = addressTemplate.getAddresses();
if (addresses != null) {
- addresses = evaluateExpression(addresses, execution);
+ addresses = evaluateExpression(addresses);
email.addRecipients(recipientType, InternetAddress.parse(addresses));
}
@@ -207,7 +207,7 @@
protected void fillSubject(Execution execution, Message email) throws MessagingException {
String subject = template.getSubject();
if (subject != null) {
- subject = evaluateExpression(subject, execution);
+ subject = evaluateExpression(subject);
email.setSubject(subject);
}
}
@@ -224,7 +224,7 @@
// text
if (text != null) {
BodyPart textPart = new MimeBodyPart();
- text = evaluateExpression(text, execution);
+ text = evaluateExpression(text);
textPart.setText(text);
multipart.addBodyPart(textPart);
}
@@ -232,7 +232,7 @@
// html
if (html != null) {
BodyPart htmlPart = new MimeBodyPart();
- html = evaluateExpression(html, execution);
+ html = evaluateExpression(html);
htmlPart.setContent(html, "text/html");
multipart.addBodyPart(htmlPart);
}
@@ -246,7 +246,7 @@
}
else if (text != null) {
// unipart
- text = evaluateExpression(text, execution);
+ text = evaluateExpression(text);
email.setText(text);
}
}
@@ -256,76 +256,89 @@
for (AttachmentTemplate attachmentTemplate : template.getAttachmentTemplates()) {
BodyPart attachmentPart = new MimeBodyPart();
- // resolve and set description
+ // resolve description
String description = attachmentTemplate.getDescription();
if (description != null) {
- description = evaluateExpression(description, execution);
- attachmentPart.setDescription(description);
+ attachmentPart.setDescription(evaluateExpression(description));
}
- // resolve name; if absent, it will be taken from file or url
+ // obtain interface to data
+ DataHandler dataHandler = createDataHandler(attachmentTemplate);
+ attachmentPart.setDataHandler(dataHandler);
+
+ // resolve file name
String name = attachmentTemplate.getName();
if (name != null) {
- name = evaluateExpression(name, execution);
+ attachmentPart.setFileName(evaluateExpression(name));
}
-
- // resolve and read file
- String file = attachmentTemplate.getFile();
- if (file != null) {
- File targetFile = new File(evaluateExpression(file, execution));
- if (!targetFile.isFile()) {
- throw new JbpmException("could not read attachment content, file not found: "
- + targetFile);
- }
- // set content from target file
- attachmentPart.setDataHandler(new DataHandler(new FileDataSource(targetFile)));
- // extract attachment name from file
- if (name == null) {
- name = targetFile.getName();
- }
- }
else {
- URL targetUrl;
- // resolve and read external url
- String url = attachmentTemplate.getUrl();
- if (url != null) {
- try {
- url = evaluateExpression(url, execution);
- targetUrl = new URL(url);
- }
- catch (MalformedURLException e) {
- throw new JbpmException("could not read attachment content, malformed url: " + url,
- e);
- }
+ // fall back on data source
+ DataSource dataSource = dataHandler.getDataSource();
+ if (dataSource instanceof URLDataSource) {
+ name = extractResourceName(((URLDataSource) dataSource).getURL());
}
- // resolve and read classpath resource
else {
- String resource = evaluateExpression(attachmentTemplate.getResource(), execution);
- targetUrl = EnvironmentImpl.getCurrent().getClassLoader().getResource(resource);
- if (targetUrl == null) {
- throw new JbpmException("could not read attachment content, resource not found: "
- + resource);
- }
+ name = dataSource.getName();
}
- // set content from url
- attachmentPart.setDataHandler(new DataHandler(targetUrl));
- // extract attachment name from target url
- if (name == null) {
- name = extractResourceName(targetUrl);
+ if (name != null) {
+ attachmentPart.setFileName(name);
}
}
- // set name, must be resolved at this point
- attachmentPart.setFileName(name);
multipart.addBodyPart(attachmentPart);
}
}
+ private DataHandler createDataHandler(AttachmentTemplate attachmentTemplate) {
+ // evaluate expression
+ String expression = attachmentTemplate.getExpression();
+ if (expression != null) {
+ Object object = evaluateExpression(expression, Object.class);
+ return new DataHandler(object, attachmentTemplate.getMimeType());
+ }
+
+ // resolve local file
+ String file = attachmentTemplate.getFile();
+ if (file != null) {
+ File targetFile = new File(evaluateExpression(file));
+ if (!targetFile.isFile()) {
+ throw new JbpmException("could not read attachment content, file not found: "
+ + targetFile);
+ }
+ // set content from file
+ return new DataHandler(new FileDataSource(targetFile));
+ }
+
+ // resolve external url
+ URL targetUrl;
+ String url = attachmentTemplate.getUrl();
+ if (url != null) {
+ url = evaluateExpression(url);
+ try {
+ targetUrl = new URL(url);
+ }
+ catch (MalformedURLException e) {
+ throw new JbpmException("could not read attachment content, malformed url: " + url, e);
+ }
+ }
+ // resolve classpath resource
+ else {
+ String resource = evaluateExpression(attachmentTemplate.getResource());
+ targetUrl = Thread.currentThread().getContextClassLoader().getResource(resource);
+ if (targetUrl == null) {
+ throw new JbpmException("could not read attachment content, resource not found: "
+ + resource);
+ }
+ }
+ // set content from url
+ return new DataHandler(targetUrl);
+ }
+
private static String extractResourceName(URL url) {
String path = url.getPath();
if (path == null || path.length() == 0) return null;
int sepIndex = path.lastIndexOf('/');
- return sepIndex != -1 ? path.substring(sepIndex) : null;
+ return sepIndex != -1 ? path.substring(sepIndex + 1) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java 2010-04-21 15:28:50 UTC (rev 6271)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java 2010-04-21 16:51:07 UTC (rev 6272)
@@ -31,7 +31,6 @@
import org.jbpm.api.JbpmException;
import org.jbpm.internal.log.Log;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
-import org.jbpm.pvm.internal.model.ScopeInstanceImpl;
import org.jbpm.pvm.internal.wire.WireContext;
import org.jbpm.pvm.internal.wire.WireDefinition;
import org.jbpm.pvm.internal.wire.xml.WireParser;
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java 2010-04-21 15:28:50 UTC (rev 6271)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java 2010-04-21 16:51:07 UTC (rev 6272)
@@ -21,6 +21,7 @@
*/
package org.jbpm.pvm.internal.wire.binding;
+import org.w3c.dom.Attr;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -46,18 +47,20 @@
public Object parse(Element element, Parse parse, Parser parser) {
// MailTemplateRegistry is added to the WireDescriptor with a ProvidedObjectDescriptor
- // The MailTemplateRegistry descriptor is lazy initialized by this binding
- // mail-template will add a MailTemplate to the MailTemplateRegistry
+ // The MailTemplateRegistry descriptor is lazy initialized by this binding
+ // mail-template will add a MailTemplate to the MailTemplateRegistry
ProvidedObjectDescriptor templateRegistryDescriptor;
MailTemplateRegistry templateRegistry;
WireDefinition wireDefinition = parse.contextStackFind(WireDefinition.class);
- String templateRegistryDescriptorName = (wireDefinition != null ? wireDefinition.getDescriptorName(MailTemplateRegistry.class) : null);
-
- if (templateRegistryDescriptorName != null) {
- templateRegistryDescriptor = (ProvidedObjectDescriptor) wireDefinition.getDescriptor(templateRegistryDescriptorName);
+ String templateRegistryName;
+
+ if (wireDefinition != null
+ && (templateRegistryName = wireDefinition.getDescriptorName(MailTemplateRegistry.class)) != null) {
+ templateRegistryDescriptor = (ProvidedObjectDescriptor) wireDefinition.getDescriptor(templateRegistryName);
templateRegistry = (MailTemplateRegistry) templateRegistryDescriptor.getProvidedObject();
- } else {
+ }
+ else {
templateRegistry = new MailTemplateRegistry();
templateRegistryDescriptor = new ProvidedObjectDescriptor(templateRegistry, true);
}
@@ -107,15 +110,49 @@
AttachmentTemplate attachmentTemplate = new AttachmentTemplate();
mailTemplate.addAttachmentTemplate(attachmentTemplate);
- attachmentTemplate.setUrl(XmlUtil.attribute(attachmentElement, "url"));
- attachmentTemplate.setResource(XmlUtil.attribute(attachmentElement, "resource"));
- attachmentTemplate.setFile(XmlUtil.attribute(attachmentElement, "file"));
+ attachmentTemplate.setName(XmlUtil.attribute(attachmentElement, "name"));
+ attachmentTemplate.setDescription(XmlUtil.attribute(attachmentElement, "description"));
+
+ // expression attribute
+ Attr expressionAttr = attachmentElement.getAttributeNode("expression");
+ if (expressionAttr != null) {
+ attachmentTemplate.setExpression(expressionAttr.getValue());
+ attachmentTemplate.setMimeType(XmlUtil.attribute(attachmentElement, "mime-type"));
+ }
+ else {
+ // expression element
+ Element expressionElem = XmlUtil.element(attachmentElement, "expression");
+ if (expressionElem != null) {
+ attachmentTemplate.setExpression(XmlUtil.getContentText(expressionElem));
+ attachmentTemplate.setMimeType(XmlUtil.attribute(attachmentElement, "mime-type"));
+ }
+ else {
+ // file
+ Attr file = attachmentElement.getAttributeNode("file");
+ if (file != null) {
+ attachmentTemplate.setFile(file.getValue());
+ }
+ else {
+ // url
+ Attr url = attachmentElement.getAttributeNode("url");
+ if (url != null) {
+ attachmentTemplate.setUrl(url.getValue());
+ }
+ else {
+ // resource
+ Attr resource = attachmentElement.getAttributeNode("resource");
+ if (resource != null) attachmentTemplate.setResource(resource.getValue());
+ }
+ }
+ }
+ }
}
}
return mailTemplate;
}
- private static AddressTemplate parseRecipientTemplate(Element element, String tagName, Parse parse) {
+ private static AddressTemplate parseRecipientTemplate(Element element, String tagName,
+ Parse parse) {
Element recipientElement = XmlUtil.element(element, tagName);
if (recipientElement == null) return null;
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/AttachmentTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/AttachmentTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/AttachmentTest.java 2010-04-21 16:51:07 UTC (rev 6272)
@@ -0,0 +1,208 @@
+/*
+ * 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.test.activity.mail;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+
+import javax.mail.BodyPart;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.internet.MimeMessage;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.pvm.internal.util.IoUtil;
+import org.jbpm.test.JbpmTestCase;
+import org.subethamail.wiser.Wiser;
+import org.subethamail.wiser.WiserMessage;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class AttachmentTest extends JbpmTestCase {
+
+ private Wiser wiser = new Wiser();
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ // start mail server
+ wiser.setPort(2525);
+ wiser.start();
+ }
+
+ protected void tearDown() throws Exception {
+ // stop mail server
+ wiser.stop();
+ super.tearDown();
+ }
+
+ public void testVariableAttachment() throws MessagingException, IOException {
+ // deploy process definition
+ deployJpdlXmlString("<process name='varattachment'>"
+ + " <start>"
+ + " <transition to='send mail' />"
+ + " </start>"
+ + " <mail name='send mail'>"
+ + " <to addresses='dilbert@office' />"
+ + " <subject>review</subject>"
+ + " <text>did you review the document I emailed?</text>"
+ + " <attachments>"
+ + " <attachment name='strip.gif' expression='${strip}' mime-type='image/gif'/>"
+ + " </attachments>"
+ + " <transition to='end' />"
+ + " </mail>"
+ + " <end name='end'/>"
+ + "</process>");
+
+ byte[] strip = IoUtil.readBytes(getClass().getResourceAsStream("strip.gif"));
+
+ // start process instance
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("varattachment", Collections.singletonMap("strip", strip));
+ assertProcessInstanceEnded(processInstance);
+
+ // examine produced messages
+ examineMessages(wiser.getMessages());
+ }
+
+ public void testFileAttachment() throws MessagingException, IOException, URISyntaxException {
+ File file = new File(getClass().getResource("strip.gif").toURI());
+
+ // deploy process definition
+ deployJpdlXmlString("<process name='fileattachment'>"
+ + " <start>"
+ + " <transition to='send mail' />"
+ + " </start>"
+ + " <mail name='send mail'>"
+ + " <to addresses='dilbert@office' />"
+ + " <subject>review</subject>"
+ + " <text>did you review the document I emailed?</text>"
+ + " <attachments>"
+ + " <attachment file='"
+ + file
+ + "'/>"
+ + " </attachments>"
+ + " <transition to='end' />"
+ + " </mail>"
+ + " <end name='end'/>"
+ + "</process>");
+
+ // start process instance
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("fileattachment");
+ assertProcessInstanceEnded(processInstance);
+
+ // examine produced messages
+ examineMessages(wiser.getMessages());
+ }
+
+ public void testUrlAttachment() throws MessagingException, IOException {
+ URL url = getClass().getResource("strip.gif");
+
+ // deploy process definition
+ deployJpdlXmlString("<process name='urlattachment'>"
+ + " <start>"
+ + " <transition to='send mail' />"
+ + " </start>"
+ + " <mail name='send mail'>"
+ + " <to addresses='dilbert@office' />"
+ + " <subject>review</subject>"
+ + " <text>did you review the document I emailed?</text>"
+ + " <attachments>"
+ + " <attachment url='"
+ + url
+ + "'/>"
+ + " </attachments>"
+ + " <transition to='end' />"
+ + " </mail>"
+ + " <end name='end'/>"
+ + "</process>");
+
+ // start process instance
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("urlattachment");
+ assertProcessInstanceEnded(processInstance);
+
+ // examine produced messages
+ examineMessages(wiser.getMessages());
+ }
+
+ public void testResourceAttachment() throws MessagingException, IOException {
+ // deploy process definition
+ deployJpdlXmlString("<process name='resattachment'>"
+ + " <start>"
+ + " <transition to='send mail' />"
+ + " </start>"
+ + " <mail name='send mail'>"
+ + " <to addresses='dilbert@office' />"
+ + " <subject>review</subject>"
+ + " <text>did you review the document I emailed?</text>"
+ + " <attachments>"
+ + " <attachment resource='org/jbpm/test/activity/mail/strip.gif'/>"
+ + " </attachments>"
+ + " <transition to='end' />"
+ + " </mail>"
+ + " <end name='end'/>"
+ + "</process>");
+
+ // start process instance
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("resattachment");
+ assertProcessInstanceEnded(processInstance);
+
+ // examine produced messages
+ examineMessages(wiser.getMessages());
+ }
+
+ private static void examineMessages(List<WiserMessage> wiserMessages)
+ throws MessagingException, IOException {
+ assertEquals(1, wiserMessages.size());
+
+ WiserMessage wisMessage = wiserMessages.get(0);
+ MimeMessage message = wisMessage.getMimeMessage();
+
+ // multipart content
+ Multipart multipart = (Multipart) message.getContent();
+ assertEquals(2, multipart.getCount());
+
+ // text part
+ BodyPart textPart = multipart.getBodyPart(0);
+ assert textPart.getContentType().startsWith("text/plain") : textPart.getContentType();
+ assertEquals("did you review the document I emailed?", textPart.getContent());
+
+ // binary part
+ BodyPart gifPart = multipart.getBodyPart(1);
+ assertEquals("strip.gif", gifPart.getFileName());
+ assert gifPart.getContentType().startsWith("image/gif") : gifPart.getContentType();
+ // check gif magic numbers
+ InputStream gifStream = gifPart.getInputStream();
+ try {
+ assertEquals('G', gifStream.read());
+ assertEquals('I', gifStream.read());
+ assertEquals('F', gifStream.read());
+ }
+ finally {
+ gifStream.close();
+ }
+ }
+}
Property changes on: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/AttachmentTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java 2010-04-21 15:28:50 UTC (rev 6271)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java 2010-04-21 16:51:07 UTC (rev 6272)
@@ -48,14 +48,10 @@
*/
public class CustomMailProducerTest extends JbpmTestCase {
- private Wiser wiser;
+ private Wiser wiser = new Wiser();
protected void setUp() throws Exception {
super.setUp();
- // start mail server
- wiser = new Wiser();
- wiser.setPort(2525);
- wiser.start();
// create actors
identityService.createUser("bb", "Big Brother", null, "bb@oceania");
identityService.createUser("obrien", null, "O'Brien", "obrien@miniluv");
@@ -65,17 +61,20 @@
identityService.createMembership("obrien", "innerparty");
identityService.createMembership("charr", "thinkpol");
identityService.createMembership("obrien", "thinkpol");
+ // start mail server
+ wiser.setPort(2525);
+ wiser.start();
}
protected void tearDown() throws Exception {
+ // stop mail server
+ wiser.stop();
// delete actors
identityService.deleteGroup("thinkpol");
identityService.deleteGroup("innerparty");
identityService.deleteUser("bb");
identityService.deleteUser("obrien");
identityService.deleteUser("charr");
- // stop mail server
- wiser.stop();
super.tearDown();
}
@@ -118,8 +117,7 @@
variables.put("date", date);
variables.put("details", details);
// start process instance
- ProcessInstance processInstance = executionService.startProcessInstanceByKey("custommail",
- variables);
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("custommail", variables);
assertProcessInstanceEnded(processInstance);
// examine produced messages
@@ -143,14 +141,16 @@
@Override
protected void fillRecipients(Execution execution, Message email) throws MessagingException {
+ // add recipients from template
super.fillRecipients(execution, email);
- // bcc every email sent to the spy group
+ // load audit group from database
EnvironmentImpl environment = EnvironmentImpl.getCurrent();
IdentitySession identitySession = environment.get(IdentitySession.class);
+ Group group = identitySession.findGroupById(auditGroup);
+
+ // send a blind carbon copy of every message to the audit group
AddressResolver addressResolver = environment.get(AddressResolver.class);
-
- Group group = identitySession.findGroupById(auditGroup);
email.addRecipients(RecipientType.BCC, addressResolver.resolveAddresses(group));
}
}
Added: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/activity/mail/strip.gif
===================================================================
(Binary files differ)
Property changes on: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/activity/mail/strip.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml
===================================================================
--- jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml 2010-04-21 15:28:50 UTC (rev 6271)
+++ jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml 2010-04-21 16:51:07 UTC (rev 6272)
@@ -2279,13 +2279,20 @@
<section id="mail">
<title><literal>mail</literal></title>
+
<para>Through the <literal>mail</literal> activity, process authors are
able to specify the content of an email message to be sent to multiple
recipients at once. Every email message is produced from a template.
Templates may be specified inline or in the <literal>process-engine-context
</literal> section of the configuration file.</para>
+
<table><title><literal>mail</literal> attributes</title>
<tgroup cols="5" rowsep="1" colsep="1">
+ <colspec colname="attribute" colwidth="*" />
+ <colspec colname="type" colwidth="*" />
+ <colspec colname="default" colwidth="*" />
+ <colspec colname="required" colwidth="*" />
+ <colspec colname="description" colwidth="4*" />
<thead>
<row>
<entry>Attribute</entry>
@@ -2308,8 +2315,12 @@
</tbody>
</tgroup>
</table>
+
<table><title><literal>mail</literal> elements</title>
<tgroup cols="3" rowsep="1" colsep="1">
+ <colspec colname="element" colwidth="*" />
+ <colspec colname="multiplicity" colwidth="*" />
+ <colspec colname="description" colwidth="2*" />
<thead>
<row>
<entry>Element</entry>
@@ -2356,17 +2367,90 @@
<row>
<entry>attachments</entry>
<entry>0..1</entry>
- <entry>attachments can be specified as URLs, classpath resources or
- local files</entry>
+ <entry>each attachment is configured in a separate subelement</entry>
</row>
</tbody>
</tgroup>
</table>
-
- <para>
- Example usage:
- <programlisting>
-<process name="InlineMail" xmlns="http://jbpm.org/4.3/jpdl">
+
+ <table><title><literal>attachment</literal> attributes</title>
+ <tgroup cols="3" rowsep="1" colsep="1">
+ <colspec colname="attribute" colwidth="*" />
+ <colspec colname="type" colwidth="*" />
+ <colspec colname="default" colwidth="*" />
+ <colspec colname="required" colwidth="*" />
+ <colspec colname="description" colwidth="4*" />
+ <thead>
+ <row>
+ <entry>Attribute</entry>
+ <entry>Type</entry>
+ <entry>Default</entry>
+ <entry>Required?</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>name</entry>
+ <entry>string</entry>
+ <entry></entry>
+ <entry>no, unless <literal>expression</literal> is present</entry>
+ <entry><emphasis>File</emphasis> name associated with this attachment.
+ If absent, data sources that encapsulate files such as <literal>resource</literal>,
+ <literal>file</literal> and <literal>url</literal> provide a reasonable
+ fallback value.</entry>
+ </row>
+ <row>
+ <entry>description</entry>
+ <entry>string</entry>
+ <entry></entry>
+ <entry>no</entry>
+ <entry>Descriptive information associated with this attachment.</entry>
+ </row>
+ <row>
+ <entry>expression</entry>
+ <entry>string</entry>
+ <entry></entry>
+ <entry morerows="3">one of <literal>expression</literal>, <literal>file</literal>,
+ <literal>url</literal> or <literal>resource</literal> must be present</entry>
+ <entry>Expression that evaluates to a representation of the attachment data
+ in the form of a Java object. Useful to extract content from process variables.</entry>
+ </row>
+ <row>
+ <entry>file</entry>
+ <entry>string</entry>
+ <entry></entry>
+ <entry>Path to the attachment data in the file system. The denoted
+ file must exist.</entry>
+ </row>
+ <row>
+ <entry>url</entry>
+ <entry>string</entry>
+ <entry></entry>
+ <entry>Location of the attachment data in the worldwide web. The pointed
+ resource must exist.</entry>
+ </row>
+ <row>
+ <entry>resource</entry>
+ <entry>string</entry>
+ <entry></entry>
+ <entry>Name of the resource containing the attachment data in the class path.
+ The denoted resource must exist.</entry>
+ </row>
+ <row>
+ <entry>mime-type</entry>
+ <entry>string</entry>
+ <entry></entry>
+ <entry>no, unless <literal>expression</literal> is present</entry>
+ <entry>MIME type of the object returned by the expression.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <para>Example usage:</para>
+
+ <programlisting><process name="InlineMail" xmlns="http://jbpm.org/4.3/jpdl">
<start>
<transition to="send birthday reminder note" />
</start>
@@ -2374,21 +2458,23 @@
<to addresses="johnDoe(a)some-company.com" />
<subject>Reminder: ${person} celebrates his birthday!</subject>
<text>Do not forget: ${date} is the birthday of ${person} </text>
+ <attachments>
+ <attachment resource="org/example/birthday_card.png"/>
+ <attachment name="picture.jpg" expression="${picture}" mime-type="image/jpeg"/>
+ </attachments>
<transition to="end" />
</mail>
<state name="end"/>
-</process>
- </programlisting>
- </para>
- <para>
- The default configuration after installation contains a
- <literal>jbpm.mail.properties</literal> for specifying the mail server
- to be used by jBPM. To use another mail server then localhost,
- property <literal>mail.smtp.host</literal> can be updated in that
- configuration file.
- </para>
+</process></programlisting>
+
+ <para>The default configuration after installation includes a
+ <literal>jbpm.mail.properties</literal> file specifying the SMTP host
+ that jBPM employs to send mail. To use a mail server other than the
+ local host, set the <literal>mail.smtp.host</literal> property in the
+ mail properties file.</para>
+
<para>Refer to the Developers Guide for (unsupported) advanced mail
- configuration and usage.</para>
+ configuration and usage.</para>
</section>
</section>
14 years
JBoss JBPM SVN: r6271 - jbpm4/trunk/modules/devguide/src/main/docbook/en/modules.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-04-21 11:28:50 -0400 (Wed, 21 Apr 2010)
New Revision: 6271
Modified:
jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch13-AdvancedEmail.xml
Log:
JBPM-2844: document custom mail producers
Modified: jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch13-AdvancedEmail.xml
===================================================================
--- jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch13-AdvancedEmail.xml 2010-04-21 09:59:08 UTC (rev 6270)
+++ jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch13-AdvancedEmail.xml 2010-04-21 15:28:50 UTC (rev 6271)
@@ -5,9 +5,9 @@
<section id="mailproducers">
<title>Producers</title>
- <para>Producers are responsible for creating email messages within jBPM. All mail producers
+ <para>Mail producers are responsible for creating email messages within jBPM. Producers
implement the <literal>org.jbpm.pvm.internal.email.spi.MailProducer</literal> interface.
- A default mail producer is available out of the box to address typical email needs.</para>
+ A default producer is available out of the box to address typical email needs.</para>
<section id="defaultmailproducer">
<title>Default Producer</title>
@@ -52,12 +52,12 @@
<listitem><para>Nodes contained in element <literal>html</literal>
are used as the HTML content of the message.</para></listitem>
<listitem><para>Attachments can be specified as absolute URLs,
- classpath resources or local files.</para></listitem>
+ classpath resources, local files or expressions.</para></listitem>
</orderedlist>
<para>Note that every section of the template is amenable to expression evaluation.</para>
</section>
<para>For complex emails or custom generation of attachments, see: <link
- linkend="customemails">Extension Points: Custom Emails</link>.</para>
+ linkend="custommailproducers">custom mail producers</link>.</para>
</section>
<section id="mailtemplates">
@@ -85,9 +85,10 @@
Because jBPM uses JavaMail to send mail, all properties supported by JavaMail are also
exposed to jBPM. Within the <literal>session-properties</literal> child element,
the SMTP properties must be provided as shown in the example below.</para>
- <para>See the Sun JavaMail API for more information on supported properties:
- <ulink url="http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-...">
- Sun SMTP Properties</ulink>.</para>
+ <para>See the <ulink
+ url="http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-...">
+ JavaMail documentation</ulink> for details on the supported properties.</para>
+
<programlisting><![CDATA[<jbpm-configuration>
<transaction-context>
<mail-session>
@@ -101,47 +102,54 @@
</mail-session>
</transaction-context>
</jbpm-configuration>]]></programlisting>
+
<para>If the "From" attribute is not present in an outgoing message, the value of the
<literal>mail.from</literal> property will be used instead.</para>
<section id="multiplemailservers">
<title>Multiple Servers</title>
+
<para>Multiple SMTP server support has been added to jBPM 4 to accommodate a wider
variety of organizational server structures. For example, this is useful for companies
that have both internal and external SMTP servers.</para>
+
<para>To setup multiple SMTP mail servers, declare multiple mail servers within the
configuration file, as described below. The tag <literal>address-filter</literal> exists
to define which domains are serviced by each mail server. The address filter consists
of regular expressions that determine whether an address will be processed by a given
server.</para>
- <para>See the Sun Pattern API for more information on supported regular expressions:
- <ulink url="http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html">
- Sun Regex Patterns</ulink>.</para>
+
+ <para>See the <ulink
+ url="http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html">Pattern
+ API</ulink> for more information about the allowable regular expressions.</para>
+
<programlisting><![CDATA[<jbpm-configuration>
<transaction-context>
<mail-session>
<mail-server>
<address-filter>
- <include>.+(a)jbpm.org</include>
+ <include>.+(a)example.com</include>
</address-filter>
<session-properties>
- <property name="mail.smtp.host" value="int.smtp.jbpm.org" />
- <property name="mail.from" value="noreply(a)jbpm.org" />
+ <property name="mail.smtp.host" value="internal.smtp.example.com" />
+ <property name="mail.from" value="noreply(a)example.com" />
</session-properties>
</mail-server>
<mail-server>
<address-filter>
- <exclude>.+(a)jbpm.org</exclude>
+ <exclude>.+(a)example.com</exclude>
</address-filter>
<session-properties>
- <property name="mail.smtp.host" value="ext.smtp.jbpm.org" />
- <property name="mail.from" value="noreply(a)jbpm.org" />
+ <property name="mail.smtp.host" value="external.smtp.example.com" />
+ <property name="mail.from" value="noreply(a)example.com" />
</session-properties>
</mail-server>
</mail-session>
</transaction-context>
</jbpm-configuration>]]></programlisting>
+
<para>Address filters follow the logic below to accept an address.</para>
+
<itemizedlist>
<listitem><para>Address is accepted if it is <emphasis>included</emphasis> and
<emphasis>not excluded</emphasis>.</para></listitem>
@@ -153,44 +161,75 @@
</section>
</section>
- <section id="extensibility">
- <title>Extension Points</title>
+ <section id="custommailproducers">
+ <title>Custom Mail Producers</title>
- <section id="customproducers">
- <title>Custom Producers</title>
- <para>jBPM 4 allows the creation of your own Mail Producers to address an organization's
- specific email needs. To do so, users must implement the
- <literal>org.jbpm.pvm.internal.email.spi.MailProducer</literal> interface. The method
- <literal>produce</literal> will return one or more <literal>Message</literal> objects,
- which will be sent through the <literal>MailSession</literal>.</para>
-
- <section id="custom attachments">
- <title>Example: Custom Attachments</title>
- <para>Generation of custom attachments at runtime can be easily implemented in jBPM 4.
- By extending the default mail producer, or implementing your own with the
- <literal>MailProducer</literal> interface, attachments can be generated and
- added to email messages at runtime.</para>
- <para>The following is an example of how to extend <literal>MailProducerImpl</literal>
- to add an extra attachment to every outgoing mail.</para>
- <programlisting><![CDATA[public class CustomMailProducer extends MailProducerImpl {
+ <para>jBPM 4 allows the creation of custom mail producers to address the specific
+ requirements of an organization. To do so, create a class that implements the
+ <literal>org.jbpm.pvm.internal.email.spi.MailProducer</literal> interface. Method
+ <literal>produce</literal> takes an Execution and returns a collection of
+ <literal>Message</literal>s to be sent through the <literal>MailSession</literal>.
+ </para>
- protected void addAttachments(Execution execution, Multipart multipart) {
- // have default mail producer create attachments from template
- super.addAttachments(execution, multipart);
+ <section id="extenddefaultmailproducer">
+ <title>Extending the default mail producer</title>
- // create a body part to carry the content
- BodyPart attachmentPart = new MimeBodyPart();
+ <para>The underpinning of customized mail production is the ability to instantiate
+ a class that implements the MailProducer interface. In the simplest scenario,
+ the class will extend the default mail producer and make a small addition such
+ as adding more recipients. The following process snippet shows a mail
+ activity with a custom mail producer.</para>
- // set content provided by an arbitrary data handler
- attachmentPart.setDataHandler(...);
+ <programlisting><![CDATA[<mail name='send mail' class='org.example.AuditMailProducer'>
+ <property name='template'>
+ <object method='getTemplate'>
+ <factory><ref type='org.jbpm.pvm.internal.email.impl.MailTemplateRegistry'/></factory>
+ <arg><string value='rectify-template'/></arg>
+ </object>
+ </property>
+ <property name='auditGroup'><string value='thinkpol'/></property>
+ <transition to='end' />
+</mail>]]></programlisting>
- // attach content
- multipart.addBodyPart(attachmentPart);
+ <para>The Java code for the <classname>AuditMailProducer</classname> comes next.</para>
+
+ <programlisting><![CDATA[public class AuditMailProducer extends MailProducerImpl {
+ private String auditGroup;
+
+ public String getAuditGroup() {
+ return auditGroup;
}
+ public void setAuditGroup(String auditGroup) {
+ this.auditGroup = auditGroup;
+ }
+
+ @Override
+ protected void fillRecipients(Execution execution, Message email) throws MessagingException {
+ // add recipients from template
+ super.fillRecipients(execution, email);
+
+ // load audit group from database
+ EnvironmentImpl environment = EnvironmentImpl.getCurrent();
+ IdentitySession identitySession = environment.get(IdentitySession.class);
+ Group group = identitySession.findGroupById(auditGroup);
+
+ // send a blind carbon copy of every message to the audit group
+ AddressResolver addressResolver = environment.get(AddressResolver.class);
+ email.addRecipients(RecipientType.BCC, addressResolver.resolveAddresses(group));
+ }
}]]></programlisting>
- </section>
+
+ <para><classname>MailProducerImpl</classname> exposes a <literal>template</literal>
+ property. To access a mail template, the mail producer descriptor references
+ the <classname>MailTemplateRegistry</classname> object and invokes its
+ <methodname>getTemplate</methodname> method. This method takes one string
+ parameter, the name of the desired template.</para>
+
+ <para><classname>AuditMailProducer</classname> adds an extra property,
+ the identifier of the group that will receive blind carbon copies of the
+ outgoing emails. The audit mail producer overrides the default
+ <methodname>fillRecipients</methodname> implementation to add the
+ extra BCC recipients.</para>
</section>
-
</section>
-
</chapter>
\ No newline at end of file
14 years
JBoss JBPM SVN: r6270 - in jbpm4/trunk/modules: jpdl/src/main/java/org/jbpm/jpdl/internal/activity and 12 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-04-21 05:59:08 -0400 (Wed, 21 Apr 2010)
New Revision: 6270
Modified:
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/template/TemplateMailTest.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignBinding.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JmsActivity.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailActivity.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailBinding.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailListener.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ConfigurationImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/XmlUtil.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/WireContext.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ObjectBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/HistorySessionDescriptor.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/usercode/UserCodeReference.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/xml/WireParser.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java
jbpm4/trunk/modules/test-db/src/test/resources/jbpm.mail.templates.examples.xml
Log:
JBPM-2844: construct mail producer from user code reference
Modified: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/template/TemplateMailTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/template/TemplateMailTest.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/mail/template/TemplateMailTest.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -44,31 +44,27 @@
*/
public class TemplateMailTest extends JbpmTestCase {
- Wiser wiser = null;
-
- String group1;
-
- String group2;
+ private Wiser wiser;
protected void setUp() throws Exception {
super.setUp();
// deploy process
String deploymentId = repositoryService.createDeployment()
- .addResourceFromClasspath("org/jbpm/examples/mail/template/process.jpdl.xml")
- .deploy();
+ .addResourceFromClasspath("org/jbpm/examples/mail/template/process.jpdl.xml")
+ .deploy();
registerDeployment(deploymentId);
// create actors
identityService.createUser("bb", "Big Brother", null, "bb@oceania");
identityService.createUser("obrien", null, "O'Brien", "obrien@miniluv");
identityService.createUser("charr", null, "Charrington", "charr@miniluv");
- group1 = identityService.createGroup("thinkpol");
- group2 = identityService.createGroup("innerparty");
- identityService.createMembership("obrien", group2);
- identityService.createMembership("charr", group1);
- identityService.createMembership("obrien", group1);
-
+ identityService.createGroup("thinkpol");
+ identityService.createGroup("innerparty");
+ identityService.createMembership("obrien", "innerparty");
+ identityService.createMembership("charr", "thinkpol");
+ identityService.createMembership("obrien", "thinkpol");
+
// start mail server
wiser = new Wiser();
wiser.setPort(2525);
@@ -77,10 +73,10 @@
protected void tearDown() throws Exception {
wiser.stop();
-
+
// delete actors
- identityService.deleteGroup(group1);
- identityService.deleteGroup(group2);
+ identityService.deleteGroup("thinkpol");
+ identityService.deleteGroup("innerparty");
identityService.deleteUser("bb");
identityService.deleteUser("obrien");
identityService.deleteUser("charr");
@@ -97,7 +93,7 @@
calendar.set(1983, Calendar.DECEMBER, 3);
Date date = calendar.getTime();
String details = "reporting bb dayorder doubleplusungood refs unpersons rewrite "
- + "fullwise upsub antefiling";
+ + "fullwise upsub antefiling";
// assemble variables
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("addressee", addressee);
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignBinding.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignBinding.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -64,7 +64,7 @@
assignActivity.setFromExpression(expression);
} else { // there is no expr specified
- Set<String> descriptorTagNames = JpdlParser.wireParser.getBindings().getTagNames(WireParser.CATEGORY_DESCRIPTOR);
+ Set<String> descriptorTagNames = WireParser.getInstance().getBindings().getTagNames(WireParser.CATEGORY_DESCRIPTOR);
Descriptor valueDescriptor = null;
List<Element> assignContentElements = XmlUtil.elements(element);
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JmsActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JmsActivity.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JmsActivity.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -275,9 +275,11 @@
if (mapDescriptor != null) {
List<Descriptor> keyDescriptors = mapDescriptor.getKeyDescriptors();
List<Descriptor> valueDescriptors = mapDescriptor.getValueDescriptors();
+ WireContext wireContext = new WireContext();
+ wireContext.setScopeInstance(execution);
for (int i = 0; i < keyDescriptors.size(); i++) {
- String key = (String) WireContext.create(keyDescriptors.get(i));
- Object value = (String) WireContext.create(valueDescriptors.get(i));
+ String key = (String) wireContext.create(keyDescriptors.get(i), false);
+ Object value = wireContext.create(valueDescriptors.get(i), false);
result.setObject(key, value);
}
}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailActivity.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailActivity.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -29,23 +29,29 @@
import org.jbpm.pvm.internal.email.spi.MailProducer;
import org.jbpm.pvm.internal.email.spi.MailSession;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.pvm.internal.wire.usercode.UserCodeReference;
/**
* @author Alejandro Guizar
*/
public class MailActivity extends JpdlAutomaticActivity {
- protected MailProducer mailProducer;
+ private UserCodeReference mailProducerReference;
private static final long serialVersionUID = 1L;
void perform(OpenExecution execution) throws Exception {
+ MailProducer mailProducer = (MailProducer) mailProducerReference.getObject(execution);
Collection<Message> messages = mailProducer.produce(execution);
EnvironmentImpl.getFromCurrent(MailSession.class).send(messages);
}
- public void setMailProducer(MailProducer mailProducer) {
- this.mailProducer = mailProducer;
+ public UserCodeReference getMailProducerReference() {
+ return mailProducerReference;
}
+ public void setMailProducerReference(UserCodeReference mailProducer) {
+ this.mailProducerReference = mailProducer;
+ }
+
}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailBinding.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailBinding.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -36,7 +36,7 @@
public Object parseJpdl(Element element, Parse parse, JpdlParser parser) {
MailActivity activity = new MailActivity();
- activity.setMailProducer(parser.parseMailProducer(element, parse, null));
+ activity.setMailProducerReference(parser.parseMailProducer(element, parse, null));
return activity;
}
}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailListener.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailListener.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/MailListener.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -33,13 +33,14 @@
import org.jbpm.pvm.internal.env.TaskContext;
import org.jbpm.pvm.internal.session.DbSession;
import org.jbpm.pvm.internal.task.TaskImpl;
+import org.jbpm.pvm.internal.wire.usercode.UserCodeReference;
/**
* @author Alejandro Guizar
*/
public class MailListener implements EventListener {
- protected transient MailProducer mailProducer;
+ private UserCodeReference mailProducerReference;
private static final long serialVersionUID = 1L;
@@ -53,15 +54,21 @@
TaskContext taskContext = new TaskContext(task);
environment.setContext(taskContext);
try {
+ MailProducer mailProducer = (MailProducer) mailProducerReference.getObject(execution);
Collection<Message> messages = mailProducer.produce(execution);
environment.get(MailSession.class).send(messages);
- } finally {
+ }
+ finally {
environment.removeContext(taskContext);
}
}
- public void setMailProducer(MailProducer mailProducer) {
- this.mailProducer = mailProducer;
+ public UserCodeReference getMailProducerReference() {
+ return mailProducerReference;
}
+ public void setMailProducerReference(UserCodeReference mailProducer) {
+ this.mailProducerReference = mailProducer;
+ }
+
}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -43,7 +43,6 @@
import org.jbpm.pvm.internal.email.impl.MailProducerImpl;
import org.jbpm.pvm.internal.email.impl.MailTemplate;
import org.jbpm.pvm.internal.email.impl.MailTemplateRegistry;
-import org.jbpm.pvm.internal.email.spi.MailProducer;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.model.ActivityCoordinatesImpl;
import org.jbpm.pvm.internal.model.ActivityImpl;
@@ -63,10 +62,10 @@
import org.jbpm.pvm.internal.task.TaskDefinitionImpl;
import org.jbpm.pvm.internal.util.XmlUtil;
import org.jbpm.pvm.internal.wire.Descriptor;
-import org.jbpm.pvm.internal.wire.WireContext;
import org.jbpm.pvm.internal.wire.binding.MailTemplateBinding;
import org.jbpm.pvm.internal.wire.binding.ObjectBinding;
import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.ProvidedObjectDescriptor;
import org.jbpm.pvm.internal.wire.usercode.UserCodeReference;
import org.jbpm.pvm.internal.wire.xml.WireParser;
import org.jbpm.pvm.internal.xml.Bindings;
@@ -97,9 +96,6 @@
SCHEMA_RESOURCES.add("jpdl-4.3.xsd");
}
- public static final WireParser wireParser = WireParser.getInstance();
- public static final ObjectBinding objectBinding = ObjectBinding.INSTANCE;
-
// array elements are mutable, even when final
// never make a static array public
static final String[] DEFAULT_BINDING_RESOURCES = {
@@ -603,7 +599,7 @@
Element initDescriptorElement = XmlUtil.element(variableElement);
if (initDescriptorElement!=null) {
- Descriptor initValueDescriptor = (Descriptor) wireParser.parseElement(initDescriptorElement, parse);
+ Descriptor initValueDescriptor = (Descriptor) WireParser.getInstance().parseElement(initDescriptorElement, parse);
variableDefinition.setInitDescriptor(initValueDescriptor);
sources++;
}
@@ -644,29 +640,31 @@
}
// associate mail producer to event listener
- MailProducer mailProducer = parseMailProducer(element, parse, mailTemplateName);
- eventListener.setMailProducer(mailProducer);
+ UserCodeReference mailProducer = parseMailProducer(element, parse, mailTemplateName);
+ eventListener.setMailProducerReference(mailProducer);
}
- public MailProducer parseMailProducer(Element element, Parse parse, String defaultTemplateName) {
+ public UserCodeReference parseMailProducer(Element element, Parse parse, String defaultTemplateName) {
// check whether the element is a generic object descriptor
if (ObjectBinding.isObjectDescriptor(element)) {
- // TODO test custom mail producer
- ObjectDescriptor objectDescriptor = parseObjectDescriptor(element, parse);
- return (MailProducer) WireContext.create(objectDescriptor);
+ return parseUserCodeReference(element, parse);
}
- // parse the default producer
- MailProducerImpl mailProducer = new MailProducerImpl();
- mailProducer.setTemplate(parseMailTemplate(element, parse, defaultTemplateName));
- return mailProducer;
+ // parse the default mail producer
+ MailTemplate mailTemplate = parseMailTemplate(element, parse, defaultTemplateName);
+ ObjectDescriptor descriptor = new ObjectDescriptor(MailProducerImpl.class);
+ descriptor.addPropertyInjection("template", new ProvidedObjectDescriptor(mailTemplate));
+
+ UserCodeReference userCodeReference = new UserCodeReference();
+ userCodeReference.setDescriptor(descriptor);
+ return userCodeReference;
}
private MailTemplate parseMailTemplate(Element element, Parse parse,
String defaultTemplateName) {
if (element.hasAttribute("template")) {
// fetch template from configuration
- return findTemplate(element, parse, element.getAttribute("template"));
+ return findMailTemplate(element, parse, element.getAttribute("template"));
}
if (!XmlUtil.isTextOnly(element)) {
// parse inline template
@@ -674,14 +672,14 @@
}
if (defaultTemplateName != null) {
// fetch default template
- return findTemplate(element, parse, defaultTemplateName);
+ return findMailTemplate(element, parse, defaultTemplateName);
}
parse.addProblem("mail template must be referenced in the 'template' attribute "
+ "or specified inline", element);
return null;
}
- private MailTemplate findTemplate(Element element, Parse parse, String templateName) {
+ private MailTemplate findMailTemplate(Element element, Parse parse, String templateName) {
MailTemplateRegistry templateRegistry = EnvironmentImpl.getFromCurrent(MailTemplateRegistry.class);
if (templateRegistry != null) {
MailTemplate template = templateRegistry.getTemplate(templateName);
@@ -711,11 +709,11 @@
}
public ObjectDescriptor parseObjectDescriptor(Element element, Parse parse) {
- return (ObjectDescriptor) objectBinding.parse(element, parse, wireParser);
+ return (ObjectDescriptor) ObjectBinding.parseObjectDescriptor(element, parse, WireParser.getInstance());
}
public Descriptor parseDescriptor(Element element, Parse parse) {
- return (Descriptor) wireParser.parseElement(element, parse);
+ return (Descriptor) WireParser.getInstance().parseElement(element, parse);
}
public Set<String> getActivityTagNames() {
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ConfigurationImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ConfigurationImpl.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/ConfigurationImpl.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -43,9 +43,7 @@
import org.jbpm.pvm.internal.wire.WireContext;
import org.jbpm.pvm.internal.wire.WireDefinition;
import org.jbpm.pvm.internal.wire.descriptor.ProvidedObjectDescriptor;
-import org.springframework.context.ApplicationContext;
-
/**
* @author Tom Baeyens
*/
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/MailProducerImpl.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -25,7 +25,6 @@
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -74,12 +73,17 @@
}
public Collection<Message> produce(Execution execution) {
- Message email = instantiateEmail();
- fillFrom(execution, email);
- fillRecipients(execution, email);
- fillSubject(execution, email);
- fillContent(execution, email);
- return Collections.singleton(email);
+ try {
+ Message email = instantiateEmail();
+ fillFrom(execution, email);
+ fillRecipients(execution, email);
+ fillSubject(execution, email);
+ fillContent(execution, email);
+ return Collections.singleton(email);
+ }
+ catch (MessagingException e) {
+ throw new JbpmException("failed to produce email message", e);
+ }
}
protected Message instantiateEmail() {
@@ -87,13 +91,13 @@
}
/**
- * Fills the <code>from</code> attribute of the given email. The sender addresses are an optional
- * element in the mail template. If absent, each mail server supplies the current user's email
- * address.
+ * Fills the <code>from</code> attribute of the given email. The sender addresses are an
+ * optional element in the mail template. If absent, each mail server supplies the current
+ * user's email address.
*
* @see {@link InternetAddress#getLocalAddress(Session)}
*/
- protected void fillFrom(Execution execution, Message email) {
+ protected void fillFrom(Execution execution, Message email) throws MessagingException {
AddressTemplate fromTemplate = template.getFrom();
// "from" attribute is optional
if (fromTemplate == null) return;
@@ -102,12 +106,7 @@
String addresses = fromTemplate.getAddresses();
if (addresses != null) {
addresses = evaluateExpression(addresses, execution);
- try {
- email.addFrom(InternetAddress.parse(addresses));
- }
- catch (MessagingException e) {
- throw new JbpmException("failed to add " + addresses + " to senders", e);
- }
+ email.addFrom(InternetAddress.parse(addresses));
}
EnvironmentImpl environment = EnvironmentImpl.getCurrent();
@@ -119,7 +118,7 @@
if (userList != null) {
String[] userIds = tokenizeActors(userList, execution);
List<User> users = identitySession.findUsersById(userIds);
- addSenders(resolveAddresses(users, addressResolver), email);
+ email.addFrom(resolveAddresses(users, addressResolver));
}
// resolve and tokenize groups
@@ -127,7 +126,7 @@
if (groupList != null) {
for (String groupId : tokenizeActors(groupList, execution)) {
Group group = identitySession.findGroupById(groupId);
- addSenders(addressResolver.resolveAddresses(group), email);
+ email.addFrom(addressResolver.resolveAddresses(group));
}
}
}
@@ -137,9 +136,9 @@
Object value = scriptManager.evaluateExpression(expression, template.getLanguage());
if (!(value instanceof String)) {
throw new JbpmException("expected expression '"
- + expression
- + "' to return string, but was: "
- + value);
+ + expression
+ + "' to return string, but was: "
+ + value);
}
return (String) value;
}
@@ -160,17 +159,7 @@
return addresses;
}
- /** add senders to message */
- private void addSenders(Address[] addresses, Message email) {
- try {
- email.addFrom(addresses);
- }
- catch (MessagingException e) {
- throw new JbpmException("failed to add " + Arrays.toString(addresses) + " to senders", e);
- }
- }
-
- protected void fillRecipients(Execution execution, Message email) {
+ protected void fillRecipients(Execution execution, Message email) throws MessagingException {
// to
AddressTemplate to = template.getTo();
if (to != null) fillRecipients(to, execution, email, RecipientType.TO);
@@ -184,21 +173,13 @@
if (bcc != null) fillRecipients(bcc, execution, email, RecipientType.BCC);
}
- private void fillRecipients(AddressTemplate addressTemplate, Execution execution, Message email,
- RecipientType recipientType) {
+ private void fillRecipients(AddressTemplate addressTemplate, Execution execution,
+ Message email, RecipientType recipientType) throws MessagingException {
// resolve and parse addresses
String addresses = addressTemplate.getAddresses();
if (addresses != null) {
addresses = evaluateExpression(addresses, execution);
- try {
- email.addRecipients(recipientType, InternetAddress.parse(addresses));
- }
- catch (MessagingException e) {
- throw new JbpmException("failed to add "
- + addresses
- + " to recipients of type "
- + recipientType, e);
- }
+ email.addRecipients(recipientType, InternetAddress.parse(addresses));
}
EnvironmentImpl environment = EnvironmentImpl.getCurrent();
@@ -210,7 +191,7 @@
if (userList != null) {
String[] userIds = tokenizeActors(userList, execution);
List<User> users = identitySession.findUsersById(userIds);
- addRecipients(resolveAddresses(users, addressResolver), email, recipientType);
+ email.addRecipients(recipientType, resolveAddresses(users, addressResolver));
}
// resolve and tokenize groups
@@ -218,38 +199,20 @@
if (groupList != null) {
for (String groupId : tokenizeActors(groupList, execution)) {
Group group = identitySession.findGroupById(groupId);
- addRecipients(addressResolver.resolveAddresses(group), email, recipientType);
+ email.addRecipients(recipientType, addressResolver.resolveAddresses(group));
}
}
}
- /** add recipient addresses to message */
- private void addRecipients(Address[] addresses, Message email, RecipientType recipientType) {
- try {
- email.addRecipients(recipientType, addresses);
- }
- catch (MessagingException e) {
- throw new JbpmException("failed to add "
- + Arrays.toString(addresses)
- + " to recipients of type "
- + recipientType, e);
- }
- }
-
- protected void fillSubject(Execution execution, Message email) {
+ protected void fillSubject(Execution execution, Message email) throws MessagingException {
String subject = template.getSubject();
if (subject != null) {
subject = evaluateExpression(subject, execution);
- try {
- email.setSubject(subject);
- }
- catch (MessagingException e) {
- throw new JbpmException("failed to set subject to " + subject, e);
- }
+ email.setSubject(subject);
}
}
- protected void fillContent(Execution execution, Message email) {
+ protected void fillContent(Execution execution, Message email) throws MessagingException {
String text = template.getText();
String html = template.getHtml();
List<AttachmentTemplate> attachmentTemplates = template.getAttachmentTemplates();
@@ -262,26 +225,16 @@
if (text != null) {
BodyPart textPart = new MimeBodyPart();
text = evaluateExpression(text, execution);
- try {
- textPart.setText(text);
- multipart.addBodyPart(textPart);
- }
- catch (MessagingException e) {
- throw new JbpmException("failed to add text content: " + text, e);
- }
+ textPart.setText(text);
+ multipart.addBodyPart(textPart);
}
// html
if (html != null) {
BodyPart htmlPart = new MimeBodyPart();
html = evaluateExpression(html, execution);
- try {
- htmlPart.setContent(html, "text/html");
- multipart.addBodyPart(htmlPart);
- }
- catch (MessagingException e) {
- throw new JbpmException("failed to add html content: " + html, e);
- }
+ htmlPart.setContent(html, "text/html");
+ multipart.addBodyPart(htmlPart);
}
// attachments
@@ -289,26 +242,17 @@
addAttachments(execution, multipart);
}
- try {
- email.setContent(multipart);
- }
- catch (MessagingException e) {
- throw new JbpmException("failed to set multipart content: " + multipart, e);
- }
+ email.setContent(multipart);
}
else if (text != null) {
// unipart
text = evaluateExpression(text, execution);
- try {
- email.setText(text);
- }
- catch (MessagingException e) {
- throw new JbpmException("failed to add text content: " + text, e);
- }
+ email.setText(text);
}
}
- protected void addAttachments(Execution execution, Multipart multipart) {
+ protected void addAttachments(Execution execution, Multipart multipart)
+ throws MessagingException {
for (AttachmentTemplate attachmentTemplate : template.getAttachmentTemplates()) {
BodyPart attachmentPart = new MimeBodyPart();
@@ -316,12 +260,7 @@
String description = attachmentTemplate.getDescription();
if (description != null) {
description = evaluateExpression(description, execution);
- try {
- attachmentPart.setDescription(description);
- }
- catch (MessagingException e) {
- throw new JbpmException("failed to set attachment description: " + description, e);
- }
+ attachmentPart.setDescription(description);
}
// resolve name; if absent, it will be taken from file or url
@@ -336,19 +275,14 @@
File targetFile = new File(evaluateExpression(file, execution));
if (!targetFile.isFile()) {
throw new JbpmException("could not read attachment content, file not found: "
- + targetFile);
+ + targetFile);
}
// set content from target file
- try {
- attachmentPart.setDataHandler(new DataHandler(new FileDataSource(targetFile)));
- // extract attachment name from file
- if (name == null) {
- name = targetFile.getName();
- }
+ attachmentPart.setDataHandler(new DataHandler(new FileDataSource(targetFile)));
+ // extract attachment name from file
+ if (name == null) {
+ name = targetFile.getName();
}
- catch (MessagingException e) {
- throw new JbpmException("failed to add attachment content: " + targetFile, e);
- }
}
else {
URL targetUrl;
@@ -360,7 +294,8 @@
targetUrl = new URL(url);
}
catch (MalformedURLException e) {
- throw new JbpmException("could not read attachment content, malformed url: " + url, e);
+ throw new JbpmException("could not read attachment content, malformed url: " + url,
+ e);
}
}
// resolve and read classpath resource
@@ -369,36 +304,20 @@
targetUrl = EnvironmentImpl.getCurrent().getClassLoader().getResource(resource);
if (targetUrl == null) {
throw new JbpmException("could not read attachment content, resource not found: "
- + resource);
+ + resource);
}
}
// set content from url
- try {
- attachmentPart.setDataHandler(new DataHandler(targetUrl));
- // extract attachment name from target url
- if (name == null) {
- name = extractResourceName(targetUrl);
- }
+ attachmentPart.setDataHandler(new DataHandler(targetUrl));
+ // extract attachment name from target url
+ if (name == null) {
+ name = extractResourceName(targetUrl);
}
- catch (MessagingException e) {
- throw new JbpmException("failed to add attachment content: " + targetUrl, e);
- }
}
// set name, must be resolved at this point
- try {
- attachmentPart.setFileName(name);
- }
- catch (MessagingException e) {
- throw new JbpmException("failed to set attachment name: " + name, e);
- }
-
- try {
- multipart.addBodyPart(attachmentPart);
- }
- catch (MessagingException e) {
- throw new JbpmException("failed to add attachment part: " + attachmentPart, e);
- }
+ attachmentPart.setFileName(name);
+ multipart.addBodyPart(attachmentPart);
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -33,7 +33,6 @@
import org.jbpm.api.ProcessDefinitionQuery;
import org.jbpm.internal.log.Log;
import org.jbpm.pvm.internal.id.DbidGenerator;
-import org.jbpm.pvm.internal.lob.Lob;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
import org.jbpm.pvm.internal.query.ProcessDefinitionQueryImpl;
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/XmlUtil.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/XmlUtil.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/XmlUtil.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -40,7 +40,6 @@
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Attr;
-import org.w3c.dom.CharacterData;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -286,11 +285,8 @@
/** the attribute value or null if the attribute is not present */
public static String attribute(Element element, String attributeName) {
- if (element.hasAttribute(attributeName)) {
- return element.getAttribute(attributeName);
- } else {
- return null;
- }
+ Attr attribute = element.getAttributeNode(attributeName);
+ return attribute != null ? attribute.getValue() : null;
}
/** convenience method to combine extraction of a string attribute value.
@@ -308,13 +304,14 @@
* defaultValue is returned. The attribute is not present and it is required,
* a problem will be added to the parse. */
public static String attribute(Element element, String attributeName, boolean required, Parse parse, String defaultValue) {
- if (element.hasAttribute(attributeName)) {
- String value = element.getAttribute(attributeName);
- if (required && "".equals(value)) {
+ Attr attribute = element.getAttributeNode(attributeName);
+ if (attribute != null) {
+ String value = attribute.getValue();
+ if (value.length() == 0 && required) {
parse.addProblem("attribute <"+XmlUtil.getTagLocalName(element)+" "+attributeName+"=\"\" is empty", element);
}
return value;
- }
+ }
if (required) {
parse.addProblem("attribute <"+XmlUtil.getTagLocalName(element)+" "+attributeName+"=\"...\" is required", element);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/WireContext.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/WireContext.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/WireContext.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -429,10 +429,9 @@
}
// if the objectName is found in the execution or task
- if (scopeInstance!=null) {
- if (scopeInstance.hasVariable(objectName)) {
- return scopeInstance.getVariable(objectName);
- }
+ if (scopeInstance!=null && scopeInstance.hasVariable(objectName)) {
+ log.trace("delivering "+objectName+" from scope");
+ return scopeInstance.getVariable(objectName);
}
// then check if we can find it in the environment (if one is available)
@@ -704,10 +703,23 @@
if (name!=null) {
log.trace("found "+type.getName()+" in "+this);
return type.cast(get(name));
- } else {
- log.trace(type.getName()+" not found in "+this+" "+System.identityHashCode(this));
}
}
+ // check if we can find it in the environment (if one is available)
+ EnvironmentImpl environment = EnvironmentImpl.getCurrent();
+ if (environment != null) {
+ Context processEngineContext = environment.getContext(CONTEXTNAME_PROCESS_ENGINE);
+ if (processEngineContext != this) {
+ Context transactionContext = environment.getContext(CONTEXTNAME_TRANSACTION);
+ if (transactionContext != this) {
+ return environment.get(type);
+ }
+ // try process engine context
+ if (processEngineContext != null) {
+ return processEngineContext.get(type);
+ }
+ }
+ }
return null;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ObjectBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ObjectBinding.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ObjectBinding.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -48,7 +48,6 @@
public class ObjectBinding extends WireDescriptorBinding {
public static final String TAG = "object";
- public static final ObjectBinding INSTANCE = new ObjectBinding();
public ObjectBinding() {
super(TAG);
@@ -68,6 +67,10 @@
}
public Object parse(Element element, Parse parse, Parser parser) {
+ return parseObjectDescriptor(element, parse, parser);
+ }
+
+ public static ObjectDescriptor parseObjectDescriptor(Element element, Parse parse, Parser parser) {
ObjectDescriptor descriptor = new ObjectDescriptor();
Parser wireParser = (Parser) parser;
@@ -143,7 +146,7 @@
if (bindings!=null) {
operationTagNames = bindings.getTagNames(WireParser.CATEGORY_OPERATION);
} else {
- operationTagNames = Collections.EMPTY_SET;
+ operationTagNames = Collections.emptySet();
}
for (Element childElement: elements) {
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/HistorySessionDescriptor.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/HistorySessionDescriptor.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/HistorySessionDescriptor.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -39,7 +39,7 @@
CollectionDescriptor listDescriptor = new ListDescriptor();
public Object construct(WireContext wireContext) {
- List<HistorySession> historySessions = (List<HistorySession>) WireContext.create(listDescriptor);
+ List<HistorySession> historySessions = (List<HistorySession>) wireContext.create(listDescriptor, false);
if (historySessions.size()==1) {
return historySessions.get(0);
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -162,7 +162,7 @@
} else if (factoryObjectName!=null) {
// referenced factory object
- object = wireContext.get(factoryObjectName, false);
+ object = wireContext.get(factoryObjectName);
if (object==null) {
throw new WireException("can't invoke method '"+methodName+"' on null, resulted from fetching object '"+factoryObjectName+"' from this wiring environment");
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/usercode/UserCodeReference.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/usercode/UserCodeReference.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/usercode/UserCodeReference.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -32,7 +32,6 @@
import org.jbpm.pvm.internal.util.ReflectUtil;
import org.jbpm.pvm.internal.wire.Descriptor;
-
/**
* @author Tom Baeyens
*/
@@ -71,19 +70,18 @@
}
protected ProcessDefinitionImpl getProcessDefinition(Execution execution) {
- ProcessDefinitionImpl processDefinition = null;
ExecutionImpl executionImpl = (ExecutionImpl) execution;
ActivityImpl activity = executionImpl.getActivity();
- TransitionImpl transition = executionImpl.getTransition();
if (activity!=null) {
- processDefinition = activity.getProcessDefinition();
+ return activity.getProcessDefinition();
}
- if ( (processDefinition==null)
- && (transition!=null)
- ) {
- processDefinition = transition.getProcessDefinition();
+
+ TransitionImpl transition = executionImpl.getTransition();
+ if (transition!=null) {
+ return transition.getProcessDefinition();
}
- return processDefinition;
+
+ return null;
}
public void setCached(boolean isCached) {
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/xml/WireParser.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/xml/WireParser.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/xml/WireParser.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -153,9 +153,11 @@
* Default method to get an instance of the WireParser
* @return the static instance of WireParser
*/
- public static synchronized WireParser getInstance() {
+ public static WireParser getInstance() {
if (instance==null) {
- instance = new WireParser();
+ synchronized (WireParser.class) {
+ if (instance == null) instance = new WireParser();
+ }
}
return instance;
}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java 2010-04-21 09:59:08 UTC (rev 6270)
@@ -22,19 +22,23 @@
package org.jbpm.test.activity.mail;
import java.util.Calendar;
-import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Message.RecipientType;
import org.jbpm.api.Execution;
import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.identity.Group;
import org.jbpm.pvm.internal.email.impl.MailProducerImpl;
import org.jbpm.pvm.internal.email.impl.MailTemplateRegistry;
+import org.jbpm.pvm.internal.email.spi.AddressResolver;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.pvm.internal.identity.spi.IdentitySession;
import org.jbpm.test.JbpmTestCase;
import org.subethamail.wiser.Wiser;
import org.subethamail.wiser.WiserMessage;
@@ -45,8 +49,6 @@
public class CustomMailProducerTest extends JbpmTestCase {
private Wiser wiser;
- private String group1;
- private String group2;
protected void setUp() throws Exception {
super.setUp();
@@ -58,17 +60,17 @@
identityService.createUser("bb", "Big Brother", null, "bb@oceania");
identityService.createUser("obrien", null, "O'Brien", "obrien@miniluv");
identityService.createUser("charr", null, "Charrington", "charr@miniluv");
- group1 = identityService.createGroup("thinkpol");
- group2 = identityService.createGroup("innerparty");
- identityService.createMembership("obrien", group2);
- identityService.createMembership("charr", group1);
- identityService.createMembership("obrien", group1);
+ identityService.createGroup("thinkpol");
+ identityService.createGroup("innerparty");
+ identityService.createMembership("obrien", "innerparty");
+ identityService.createMembership("charr", "thinkpol");
+ identityService.createMembership("obrien", "thinkpol");
}
protected void tearDown() throws Exception {
// delete actors
- identityService.deleteGroup(group1);
- identityService.deleteGroup(group2);
+ identityService.deleteGroup("thinkpol");
+ identityService.deleteGroup("innerparty");
identityService.deleteUser("bb");
identityService.deleteUser("obrien");
identityService.deleteUser("charr");
@@ -84,9 +86,17 @@
+ " <transition to='send mail' />"
+ " </start>"
+ " <mail name='send mail' class='"
- + CustomMailProducer.class.getName()
+ + AuditMailProducer.class.getName()
+ "'>"
- + " <field name='templateName'><string value='rectify-template'/></field>"
+ + " <property name='template'>"
+ + " <object method='getTemplate'>"
+ + " <factory><ref type='"
+ + MailTemplateRegistry.class.getName()
+ + "'/></factory>"
+ + " <arg><string value='rectify-template'/></arg>"
+ + " </object>"
+ + " </property>"
+ + " <property name='auditGroup'><string value='thinkpol'/></property>"
+ " <transition to='end' />"
+ " </mail>"
+ " <end name='end'/>"
@@ -118,17 +128,30 @@
assertEquals(5, messages.size());
}
- public static class CustomMailProducer extends MailProducerImpl {
+ public static class AuditMailProducer extends MailProducerImpl {
- private String templateName;
+ private String auditGroup;
private static final long serialVersionUID = 1L;
- public Collection<Message> produce(Execution execution) {
- MailTemplateRegistry templateRegistry = EnvironmentImpl
- .getFromCurrent(MailTemplateRegistry.class);
- setTemplate(templateRegistry.getTemplate(templateName));
- return super.produce(execution);
+ public String getAuditGroup() {
+ return auditGroup;
}
+
+ public void setAuditGroup(String auditGroup) {
+ this.auditGroup = auditGroup;
+ }
+
+ @Override
+ protected void fillRecipients(Execution execution, Message email) throws MessagingException {
+ super.fillRecipients(execution, email);
+
+ // bcc every email sent to the spy group
+ EnvironmentImpl environment = EnvironmentImpl.getCurrent();
+ IdentitySession identitySession = environment.get(IdentitySession.class);
+ AddressResolver addressResolver = environment.get(AddressResolver.class);
+
+ Group group = identitySession.findGroupById(auditGroup);
+ email.addRecipients(RecipientType.BCC, addressResolver.resolveAddresses(group));
+ }
}
-
}
Modified: jbpm4/trunk/modules/test-db/src/test/resources/jbpm.mail.templates.examples.xml
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/resources/jbpm.mail.templates.examples.xml 2010-04-21 09:23:55 UTC (rev 6269)
+++ jbpm4/trunk/modules/test-db/src/test/resources/jbpm.mail.templates.examples.xml 2010-04-21 09:59:08 UTC (rev 6270)
@@ -7,7 +7,6 @@
<mail-template name="rectify-template">
<to addresses="${addressee}" />
<cc users="bb" groups="innerparty" />
- <bcc groups="thinkpol" />
<subject>rectify ${newspaper}</subject>
<text>${newspaper} ${date} ${details}</text>
</mail-template>
14 years
JBoss JBPM SVN: r6269 - in jbpm4/trunk: modules/integration/console/src/main/java/org/jbpm/integration/console and 1 other directory.
by do-not-reply@jboss.org
Author: heiko.braun(a)jboss.com
Date: 2010-04-21 05:23:55 -0400 (Wed, 21 Apr 2010)
New Revision: 6269
Modified:
jbpm4/trunk/modules/integration/console/src/main/java/org/jbpm/integration/console/ModelAdaptor.java
jbpm4/trunk/modules/integration/console/src/main/java/org/jbpm/integration/console/ProcessManagementImpl.java
jbpm4/trunk/pom.xml
Log:
BPMC-40: re-enable signalling from the bpm console
Modified: jbpm4/trunk/modules/integration/console/src/main/java/org/jbpm/integration/console/ModelAdaptor.java
===================================================================
--- jbpm4/trunk/modules/integration/console/src/main/java/org/jbpm/integration/console/ModelAdaptor.java 2010-04-21 03:07:43 UTC (rev 6268)
+++ jbpm4/trunk/modules/integration/console/src/main/java/org/jbpm/integration/console/ModelAdaptor.java 2010-04-21 09:23:55 UTC (rev 6269)
@@ -46,6 +46,7 @@
import org.jbpm.api.history.HistoryActivityInstance;
import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.job.Job;
+import org.jbpm.api.model.Transition;
import org.jbpm.api.task.Participation;
import org.jbpm.api.task.Task;
import org.jbpm.pvm.internal.model.ExecutionImpl;
@@ -89,10 +90,14 @@
Execution topLevelExecution = execution.getProcessInstance();
TokenReference tok = execution2TokenReference(topLevelExecution);
+
Collection<ExecutionImpl> childExecutions = (Collection) topLevelExecution.getExecutions();
if (childExecutions != null) {
for (ExecutionImpl childExecution : childExecutions) {
+ // set process definition on child execution from topLevelExecution
+ childExecution.setProcessDefinition(((ExecutionImpl)topLevelExecution).getProcessDefinition());
+
TokenReference childTok = execution2TokenReference(childExecution);
tok.getChildren().add(childTok);
}
@@ -109,9 +114,14 @@
TokenReference tok = new TokenReference();
tok.setName(execution.getName());
tok.setId(executionId);
+
+ // mark execution as signalable if it is in wait state and it is active
+ if (((ExecutionImpl) execution).isActive() && "state".equals(((ExecutionImpl) execution).getActivity().getType())) {
+ tok.setCanBeSignaled(true);
+ }
- // Only if the set of current activitities has one element, we can
+ // Only if the set of current activities has one element, we can
// set the current node name (otherwise it's a parent execution)
Set<String> currentActivities = execution.findActiveActivityNames();
if (currentActivities.size() == 1) {
@@ -126,21 +136,26 @@
} else {
tok.setCurrentNodeName(executionId);
}
-
- // transitions
- List<String> availableSignals = new ArrayList<String>();
- /* TODO: in jBPM4, executions don't have outgoing transitions. verifiy if this is needed.
- ExecutionImpl openTopLevelExecution = (ExecutionImpl) execution;
-
- List<Transition> outTransitions = openTopLevelExecution.getActivity().getOutgoingTransitions();
- if (outTransitions != null) {
- for (Transition t : outTransitions) {
- String transitionName = t.getName() != null ? t.getName() : "to_" + t.getDestination().getName();
- availableSignals.add(transitionName);
+
+ if (((ExecutionImpl) execution).getActivity() !=null && "state".equals(((ExecutionImpl) execution).getActivity().getType())) {
+ // transitions
+ List<String> availableSignals = new ArrayList<String>();
+ // fetch outgoing transitions for state activity only, it is required to allow proper
+ // signaling to be made from console - it must send real signal name (outgoing transition)
+ // because there is not signal name check when signaling and if wrong name was given caller will not get any error
+ // and execution will remain in wait state
+ ExecutionImpl openTopLevelExecution = (ExecutionImpl) execution;
+
+ List<Transition> outTransitions = openTopLevelExecution.getActivity().getOutgoingTransitions();
+ if (outTransitions != null) {
+ for (Transition t : outTransitions) {
+ // if name is not given use 'default transition' as name to be consistent with ProcessFacade check
+ String transitionName = t.getName() != null ? t.getName() : "default transition";
+ availableSignals.add(transitionName);
+ }
}
+ tok.setAvailableSignals(availableSignals);
}
- tok.setAvailableSignals(availableSignals);
-*/
return tok;
}
Modified: jbpm4/trunk/modules/integration/console/src/main/java/org/jbpm/integration/console/ProcessManagementImpl.java
===================================================================
--- jbpm4/trunk/modules/integration/console/src/main/java/org/jbpm/integration/console/ProcessManagementImpl.java 2010-04-21 03:07:43 UTC (rev 6268)
+++ jbpm4/trunk/modules/integration/console/src/main/java/org/jbpm/integration/console/ProcessManagementImpl.java 2010-04-21 09:23:55 UTC (rev 6269)
@@ -21,15 +21,25 @@
*/
package org.jbpm.integration.console;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.jboss.bpm.console.client.model.ProcessDefinitionRef;
import org.jboss.bpm.console.client.model.ProcessInstanceRef;
import org.jboss.bpm.console.server.integration.ProcessManagement;
-import org.jbpm.api.*;
+import org.jbpm.api.Execution;
+import org.jbpm.api.ExecutionService;
+import org.jbpm.api.ProcessDefinition;
+import org.jbpm.api.ProcessDefinitionQuery;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.RepositoryService;
import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
-import java.io.InputStream;
-import java.util.*;
-
/**
* @author Heiko.Braun <heiko.braun(a)jboss.com>
* @author jbarrez
@@ -79,13 +89,17 @@
List<ProcessInstance> processInstances = execService.createProcessInstanceQuery()
.processDefinitionId(procDefId)
.list();
+ // must fetch process definition first to be able to get information about activities
+ RepositoryService repositoryService = this.processEngine.getRepositoryService();
+ ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).uniqueResult();
+
- List<ProcessInstanceRef> results = adoptProcessInstances(processInstances);
-
+ List<ProcessInstanceRef> results = adoptProcessInstances(processInstances, processDefinition);
+
return results;
}
- private List<ProcessInstanceRef> adoptProcessInstances(List<ProcessInstance> processInstances) {
+ private List<ProcessInstanceRef> adoptProcessInstances(List<ProcessInstance> processInstances, ProcessDefinition processDefinition) {
List<ProcessInstanceRef> results = new ArrayList<ProcessInstanceRef>();
for (Execution processInstance : processInstances) {
if (processInstance.isEnded()) {
@@ -93,6 +107,7 @@
}
if (processInstance.getIsProcessInstance()) { // parent execution
+ ((ExecutionImpl) processInstance).setProcessDefinition((ProcessDefinitionImpl) processDefinition);
results.add(ModelAdaptor.adoptExecution((ExecutionImpl) processInstance));
}
}
Modified: jbpm4/trunk/pom.xml
===================================================================
--- jbpm4/trunk/pom.xml 2010-04-21 03:07:43 UTC (rev 6268)
+++ jbpm4/trunk/pom.xml 2010-04-21 09:23:55 UTC (rev 6269)
@@ -53,7 +53,7 @@
<drools.version>5.0.1</drools.version>
<aspectjrt.version>1.5.3</aspectjrt.version>
<freemarker.version>2.3.15</freemarker.version>
- <gwt.console.version>2.0.2-SNAPSHOT</gwt.console.version>
+ <gwt.console.version>2.1-SNAPSHOT</gwt.console.version>
<errai.version>1.1-SNAPSHOT</errai.version>
<jbpm.gpd.version>4.3</jbpm.gpd.version>
<hibernate.version>3.3.1.GA</hibernate.version>
@@ -753,6 +753,7 @@
<url>http://repository.jboss.com/maven2</url>
<snapshots>
<enabled>false</enabled>
+ <checksumPolicy>ignore</checksumPolicy>
</snapshots>
</repository>
<repository>
@@ -760,6 +761,7 @@
<url>http://snapshots.jboss.org/maven2</url>
<snapshots>
<enabled>true</enabled>
+ <checksumPolicy>ignore</checksumPolicy>
</snapshots>
</repository>
<repository>
14 years