[jbpm-commits] JBoss JBPM SVN: r6118 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src: main/java/org/jbpm/graph/node and 5 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Jan 22 05:39:47 EST 2010
Author: alex.guizar at jboss.com
Date: 2010-01-22 05:39:47 -0500 (Fri, 22 Jan 2010)
New Revision: 6118
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Action.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/DbSubProcessResolver.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/Delegation.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/JpdlException.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/jpdl/xml/Problem.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/scheduler/def/CancelTimerAction.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/scheduler/def/CreateTimerAction.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/scheduler/exe/SchedulerTest.java
Log:
JBPM-2678: clean up parse error reporting
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Action.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Action.java 2010-01-22 10:38:03 UTC (rev 6117)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Action.java 2010-01-22 10:39:47 UTC (rev 6118)
@@ -85,8 +85,8 @@
actionDelegation.read(actionElement, jpdlReader);
}
else {
- jpdlReader.addWarning("action does not have class nor ref-name attribute "
- + actionElement.asXML());
+ jpdlReader.addWarning("action does not have class nor ref-name attribute: "
+ + actionElement.getPath());
}
String acceptPropagatedEvents = actionElement.attributeValue("accept-propagated-events");
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/DbSubProcessResolver.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/DbSubProcessResolver.java 2010-01-22 10:38:03 UTC (rev 6117)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/DbSubProcessResolver.java 2010-01-22 10:39:47 UTC (rev 6118)
@@ -2,6 +2,7 @@
import org.dom4j.Element;
import org.jbpm.JbpmContext;
+import org.jbpm.db.GraphSession;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.jpdl.JpdlException;
@@ -10,43 +11,41 @@
private static final long serialVersionUID = 1L;
public ProcessDefinition findSubProcess(Element subProcessElement) {
- ProcessDefinition subProcessDefinition = null;
- String subProcessName = subProcessElement.attributeValue("name");
- String subProcessVersion = subProcessElement.attributeValue("version");
-
- // if this parsing is done in the context of a process deployment, there is
- // a database connection to look up the subprocess.
- // when there is no jbpmSession, the definition will be left null... the
- // testcase can set it as appropriate.
+ // if this parsing is done in the context of a process deployment,
+ // there is a database connection to look up the subprocess.
+ // when there is no jbpmSession, the definition will be left null...
+ // the test case can set it as appropriate.
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
if (jbpmContext != null) {
-
+ GraphSession graphSession = jbpmContext.getGraphSession();
+
// now, we must be able to find the sub-process
- if (subProcessName != null) {
-
- // if the name and the version are specified
- if (subProcessVersion != null) {
-
- try {
- int version = Integer.parseInt(subProcessVersion);
- // select that exact process definition as the subprocess definition
- subProcessDefinition = jbpmContext.getGraphSession().findProcessDefinition(subProcessName, version);
+ String subProcessName = subProcessElement.attributeValue("name");
+ if (subProcessName == null) {
+ throw new JpdlException("subprocess name is not specified: "
+ + subProcessElement.getPath());
+ }
- } catch (NumberFormatException e) {
- throw new JpdlException("version in process-state was not a number: " + subProcessElement.asXML());
- }
-
- } else { // if only the name is specified
- // select the latest version of that process as the subprocess
- // definition
- subProcessDefinition = jbpmContext.getGraphSession().findLatestProcessDefinition(subProcessName);
- }
- } else {
- throw new JpdlException("no sub-process name specfied in process-state: " + subProcessElement.asXML());
+ // if only the name is specified,
+ String subProcessVersion = subProcessElement.attributeValue("version");
+ if (subProcessVersion == null) {
+ // select the latest version of the subprocess definition
+ return graphSession.findLatestProcessDefinition(subProcessName);
}
+
+ // if the name and the version are specified
+ try {
+ // select the exact version of the subprocess definition
+ int version = Integer.parseInt(subProcessVersion);
+ return graphSession.findProcessDefinition(subProcessName, version);
+ }
+ catch (NumberFormatException e) {
+ throw new JpdlException("subprocess version is invalid: "
+ + subProcessElement.getPath());
+ }
}
- return subProcessDefinition;
+ return null;
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/Delegation.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/Delegation.java 2010-01-22 10:38:03 UTC (rev 6117)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/Delegation.java 2010-01-22 10:39:47 UTC (rev 6118)
@@ -83,7 +83,8 @@
processDefinition = jpdlReader.getProcessDefinition();
className = delegateElement.attributeValue("class");
if (className == null) {
- jpdlReader.addWarning("no class specified in " + delegateElement.asXML());
+ jpdlReader.addWarning("no class specified in delegation: "
+ + delegateElement.getPath());
}
configType = delegateElement.attributeValue("config-type");
@@ -92,8 +93,8 @@
StringWriter stringWriter = new StringWriter();
// when parsing, it could be to store the config in the database,
// so we want to make the configuration compact
- XMLWriter xmlWriter = new XMLWriter(stringWriter,
- OutputFormat.createCompactFormat());
+ XMLWriter xmlWriter =
+ new XMLWriter(stringWriter, OutputFormat.createCompactFormat());
for (Iterator iter = delegateElement.content().iterator(); iter.hasNext();) {
Object node = iter.next();
xmlWriter.write(node);
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/JpdlException.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/JpdlException.java 2010-01-22 10:38:03 UTC (rev 6117)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/JpdlException.java 2010-01-22 10:39:47 UTC (rev 6118)
@@ -21,26 +21,30 @@
*/
package org.jbpm.jpdl;
-import java.util.*;
+import java.util.Collections;
+import java.util.List;
import org.jbpm.jpdl.xml.Problem;
public class JpdlException extends RuntimeException {
private static final long serialVersionUID = 1L;
-
- protected List problems = null;
-
+
+ protected List problems;
+
public JpdlException(List problems) {
super(problems.toString());
this.problems = problems;
}
+
public JpdlException(String msg) {
this(Collections.singletonList(new Problem(Problem.LEVEL_ERROR, msg)));
}
- public JpdlException(String msg, Throwable e ) {
+
+ public JpdlException(String msg, Throwable e) {
this(Collections.singletonList(new Problem(Problem.LEVEL_ERROR, msg, e)));
}
+
public List getProblems() {
return problems;
}
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-01-22 10:38:03 UTC (rev 6117)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/xml/JpdlParser.java 2010-01-22 10:39:47 UTC (rev 6118)
@@ -29,12 +29,14 @@
import java.util.List;
import java.util.Set;
+import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
+import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
@@ -56,52 +58,71 @@
private static final long serialVersionUID = 1L;
- static SAXParserFactory saxParserFactory = createSaxParserFactory();
+ private static SAXParserFactory saxParserFactory = createSaxParserFactory();
private static Set schemaResources = getDefaultSchemaResources();
private static Object schemaSource;
- public static Document parse(InputSource inputSource, ProblemListener problemListener) throws Exception {
- Document document = null;
- SAXReader saxReader = createSaxReader(problemListener);
- document = saxReader.read(inputSource);
- return document;
+ public static Document parse(InputSource inputSource,
+ ProblemListener problemListener) throws DocumentException {
+ try {
+ SAXReader saxReader = createSaxReader(problemListener);
+ return saxReader.read(inputSource);
+ }
+ catch (SAXException e) {
+ throw new DocumentException("failed to create sax reader", e);
+ }
}
- public static SAXReader createSaxReader(ProblemListener problemListener) throws Exception {
+ public static SAXReader createSaxReader(ProblemListener problemListener)
+ throws SAXException {
XMLReader xmlReader = createXmlReader();
SAXReader saxReader = new SAXReader(xmlReader);
saxReader.setErrorHandler(new JpdlErrorHandler(problemListener));
return saxReader;
}
-
- public static XMLReader createXmlReader() throws Exception {
- SAXParser saxParser = saxParserFactory.newSAXParser();
- XMLReader xmlReader = saxParser.getXMLReader();
-
+
+ public static XMLReader createXmlReader() throws SAXException {
+ SAXParser saxParser;
try {
- saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
- } catch (SAXException e){
- log.warn("couldn't set schema language property", e);
+ saxParser = saxParserFactory.newSAXParser();
}
+ catch (ParserConfigurationException e) {
+ // validating, namespace-aware sax parsr should be available
+ throw new AssertionError(e);
+ }
try {
- saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", getSchemaSource());
- } catch (SAXException e){
- log.warn("couldn't set schema source property", e);
+ saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
+ "http://www.w3.org/2001/XMLSchema");
}
+ catch (SAXException e) {
+ log.warn("failed to set schema language to xml schema", e);
+ }
+ Object schemaSource = getSchemaSource();
try {
- xmlReader.setFeature("http://apache.org/xml/features/validation/dynamic", true);
- } catch (SAXException e){
- log.warn("couldn't set dynamic validation feature", e);
+ saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",
+ schemaSource);
}
+ catch (SAXException e) {
+ log.warn("failed to set schema source to " + schemaSource, e);
+ }
+
+ XMLReader xmlReader = saxParser.getXMLReader();
+ try {
+ xmlReader.setFeature("http://apache.org/xml/features/validation/dynamic",
+ true);
+ }
+ catch (SAXException e) {
+ log.warn("failed to enable dynamic validation", e);
+ }
return xmlReader;
}
- private static Object getSchemaSource() {
+ private synchronized static Object getSchemaSource() {
if (schemaSource == null) {
ClassLoader classLoader = ClassLoaderUtil.getClassLoader();
- List schemaLocations = new ArrayList(schemaResources.size());
+ List schemaLocations = new ArrayList(schemaResources.size());
for (Iterator i = schemaResources.iterator(); i.hasNext();) {
String schemaResource = (String) i.next();
URL schemaURL = classLoader.getResource(schemaResource);
@@ -111,7 +132,8 @@
schemaLocations.add(schemaLocation);
}
}
- schemaSource = schemaLocations.toArray(new String[schemaLocations.size()]);
+ schemaSource =
+ schemaLocations.toArray(new String[schemaLocations.size()]);
}
return schemaSource;
}
@@ -146,8 +168,8 @@
problemListener.addProblem(problem);
}
}
-
- public static void addSchemaResource(String resource) {
+
+ public synchronized static void addSchemaResource(String resource) {
schemaResources.add(resource);
schemaSource = null;
}
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-01-22 10:38:03 UTC (rev 6117)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlReader.java 2010-01-22 10:39:47 UTC (rev 6118)
@@ -28,13 +28,16 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.StringTokenizer;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
+import org.dom4j.DocumentException;
import org.dom4j.Element;
+import org.xml.sax.InputSource;
+
import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmException;
import org.jbpm.context.def.VariableAccess;
import org.jbpm.graph.action.ActionTypes;
import org.jbpm.graph.def.Action;
@@ -57,22 +60,21 @@
import org.jbpm.taskmgmt.def.Task;
import org.jbpm.taskmgmt.def.TaskController;
import org.jbpm.taskmgmt.def.TaskMgmtDefinition;
-import org.xml.sax.InputSource;
public class JpdlXmlReader implements ProblemListener {
-
+
private static final long serialVersionUID = 1L;
- protected InputSource inputSource = null;
+ protected InputSource inputSource;
protected List problems = new ArrayList();
- protected ProblemListener problemListener = null;
- protected ProcessDefinition processDefinition = null;
- protected String initialNodeName = null;
- protected Collection unresolvedTransitionDestinations = null;
- protected Collection unresolvedActionReferences = null;
+ protected ProblemListener problemListener;
+ protected ProcessDefinition processDefinition;
+ protected String initialNodeName;
+ protected Collection unresolvedTransitionDestinations = new ArrayList();
+ protected Collection unresolvedActionReferences = new ArrayList();
/**
- * the parsed process definition as DOM tree (available after readProcessDefinition)
+ * process definition as DOM tree, available after readProcessDefinition
*/
protected Document document;
@@ -82,24 +84,23 @@
public JpdlXmlReader(InputSource inputSource) {
this.inputSource = inputSource;
}
-
+
public JpdlXmlReader(InputSource inputSource, ProblemListener problemListener) {
this.inputSource = inputSource;
this.problemListener = problemListener;
}
-
+
public JpdlXmlReader(Reader reader) {
this(new InputSource(reader));
}
public void close() throws IOException {
InputStream byteStream = inputSource.getByteStream();
- if (byteStream != null)
+ if (byteStream != null)
byteStream.close();
else {
Reader charStream = inputSource.getCharacterStream();
- if (charStream != null)
- charStream.close();
+ if (charStream != null) charStream.close();
}
document = null;
}
@@ -110,21 +111,18 @@
public void addProblem(Problem problem) {
problems.add(problem);
- if (problemListener!=null) problemListener.addProblem(problem);
+ if (problemListener != null) problemListener.addProblem(problem);
}
-
+
public void addError(String description) {
- log.error("invalid process xml: "+description);
addProblem(new Problem(Problem.LEVEL_ERROR, description));
}
public void addError(String description, Throwable exception) {
- log.error("invalid process xml: "+description, exception);
addProblem(new Problem(Problem.LEVEL_ERROR, description, exception));
}
public void addWarning(String description) {
- log.warn("process xml warning: "+description);
addProblem(new Problem(Problem.LEVEL_WARNING, description));
}
@@ -133,23 +131,21 @@
processDefinition = ProcessDefinition.createNewProcessDefinition();
// initialize lists
- problems = new ArrayList();
- unresolvedTransitionDestinations = new ArrayList();
- unresolvedActionReferences = new ArrayList();
-
+ problems.clear();
+ unresolvedTransitionDestinations.clear();
+ unresolvedActionReferences.clear();
+
try {
// parse the document into a dom tree
document = JpdlParser.parse(inputSource, this);
Element root = document.getRootElement();
-
+
// read the process name
parseProcessDefinitionAttributes(root);
-
- // get the process description
+
+ // get the process description
String description = root.elementTextTrim("description");
- if (description!=null) {
- processDefinition.setDescription(description);
- }
+ if (description != null) processDefinition.setDescription(description);
// first pass: read most content
readSwimlanes(root);
@@ -164,23 +160,14 @@
resolveActionReferences();
verifySwimlaneAssignments();
- } catch (Exception e) {
- log.error("couldn't parse process definition", e);
- addProblem(new Problem(Problem.LEVEL_ERROR, "couldn't parse process definition", e));
- }
-
- if (Problem.containsProblemsOfLevel(problems, Problem.LEVEL_ERROR)) {
- throw new JpdlException(problems);
- }
-
- if (problems!=null) {
- Iterator iter = problems.iterator();
- while (iter.hasNext()) {
- Problem problem = (Problem) iter.next();
- log.warn("process parse warning: "+problem.getDescription());
+ if (Problem.containsProblemsOfLevel(problems, Problem.LEVEL_ERROR)) {
+ throw new JpdlException(problems);
}
}
-
+ catch (DocumentException e) {
+ throw new JpdlException("failed to parse process document", e);
+ }
+
return processDefinition;
}
@@ -188,37 +175,37 @@
processDefinition.setName(root.attributeValue("name"));
initialNodeName = root.attributeValue("initial");
}
-
+
protected void readSwimlanes(Element processDefinitionElement) {
- Iterator iter = processDefinitionElement.elementIterator("swimlane");
- TaskMgmtDefinition taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
- while (iter.hasNext()) {
+ TaskMgmtDefinition taskMgmtDefinition =
+ processDefinition.getTaskMgmtDefinition();
+ for (Iterator iter = processDefinitionElement.elementIterator("swimlane"); iter.hasNext();) {
Element swimlaneElement = (Element) iter.next();
String swimlaneName = swimlaneElement.attributeValue("name");
- if (swimlaneName==null) {
+ if (swimlaneName == null) {
addWarning("there's a swimlane without a name");
- } else {
+ }
+ else {
Swimlane swimlane = new Swimlane(swimlaneName);
Element assignmentElement = swimlaneElement.element("assignment");
- if (assignmentElement!=null) {
-
- if ( (assignmentElement.attribute("actor-id")!=null)
- || (assignmentElement.attribute("pooled-actors")!=null)
- ) {
+ if (assignmentElement != null) {
+ if (assignmentElement.attribute("actor-id") != null
+ || assignmentElement.attribute("pooled-actors") != null) {
swimlane.setActorIdExpression(assignmentElement.attributeValue("actor-id"));
swimlane.setPooledActorsExpression(assignmentElement.attributeValue("pooled-actors"));
-
- } else {
- Delegation assignmentDelegation = readAssignmentDelegation(assignmentElement);
+ }
+ else {
+ Delegation assignmentDelegation =
+ readAssignmentDelegation(assignmentElement);
swimlane.setAssignmentDelegation(assignmentDelegation);
}
- } else {
+ }
+ else {
Task startTask = taskMgmtDefinition.getStartTask();
- if ( (startTask==null)
- || (startTask.getSwimlane()!=swimlane)
- ) {
- addWarning("swimlane '"+swimlaneName+"' does not have an assignment");
+ if (startTask == null || startTask.getSwimlane() != swimlane) {
+ addWarning("swimlane '" + swimlaneName
+ + "' does not have an assignment");
}
}
taskMgmtDefinition.addSwimlane(swimlane);
@@ -227,178 +214,175 @@
}
public void readNodes(Element element, NodeCollection nodeCollection) {
- Iterator nodeElementIter = element.elementIterator();
- while (nodeElementIter.hasNext()) {
- Element nodeElement = (Element) nodeElementIter.next();
+ for (Iterator iter = element.elementIterator(); iter.hasNext();) {
+ Element nodeElement = (Element) iter.next();
String nodeName = nodeElement.getName();
// get the node type
Class nodeType = NodeTypes.getNodeType(nodeName);
- if (nodeType!=null) {
-
- Node node = null;
+ if (nodeType != null) {
try {
- // create a new instance
- node = (Node) nodeType.newInstance();
- } catch (Exception e) {
- log.error("couldn't instantiate node '"+nodeName+"', of type '"+nodeType.getName()+"'", e);
+ // instantiate the node
+ Node node = (Node) nodeType.newInstance();
+ node.setProcessDefinition(processDefinition);
+
+ // check for duplicate start-states
+ if (node instanceof StartState
+ && processDefinition.getStartState() != null) {
+ addError("max one start-state allowed in a process");
+ }
+ else {
+ // read the common node parts of the element
+ readNode(nodeElement, node, nodeCollection);
+
+ // let node parse its special configuration
+ node.read(nodeElement, this);
+ }
}
-
- node.setProcessDefinition(processDefinition);
-
- // check for duplicate start-states
- if ( (node instanceof StartState)
- && (processDefinition.getStartState()!=null)
- ) {
- addError("max one start-state allowed in a process");
-
- } else {
- // read the common node parts of the element
- readNode(nodeElement, node, nodeCollection);
-
- // if the node is parsable
- // (meaning: if the node has special configuration to parse, other then the
- // common node data)
- node.read(nodeElement, this);
+ catch (InstantiationException e) {
+ throw new JbpmException("could not instantiate " + nodeType, e);
}
+ catch (IllegalAccessException e) {
+ throw new JbpmException("illegal access to " + nodeType, e);
+ }
}
}
}
public void readTasks(Element element, TaskNode taskNode) {
List elements = element.elements("task");
- TaskMgmtDefinition tmd = (TaskMgmtDefinition) processDefinition.getDefinition(TaskMgmtDefinition.class);
- if (elements.size()>0) {
- if (tmd==null) {
+ TaskMgmtDefinition tmd =
+ (TaskMgmtDefinition) processDefinition.getDefinition(TaskMgmtDefinition.class);
+ if (elements.size() > 0) {
+ if (tmd == null) {
tmd = new TaskMgmtDefinition();
}
processDefinition.addDefinition(tmd);
-
- Iterator iter = elements.iterator();
- while (iter.hasNext()) {
+
+ for (Iterator iter = elements.iterator(); iter.hasNext();) {
Element taskElement = (Element) iter.next();
readTask(taskElement, tmd, taskNode);
}
}
}
- public Task readTask(Element taskElement, TaskMgmtDefinition taskMgmtDefinition, TaskNode taskNode) {
+ public Task readTask(Element taskElement,
+ TaskMgmtDefinition taskMgmtDefinition, TaskNode taskNode) {
Task task = new Task();
task.setProcessDefinition(processDefinition);
-
+
// get the task name
String name = taskElement.attributeValue("name");
- if (name!=null) {
+ if (name != null) {
task.setName(name);
taskMgmtDefinition.addTask(task);
- } else if (taskNode!=null) {
+ }
+ else if (taskNode != null) {
task.setName(taskNode.getName());
taskMgmtDefinition.addTask(task);
}
-
- // get the task description
+
+ // get the task description
String description = taskElement.elementTextTrim("description");
- if (description!=null) {
+ if (description != null) {
task.setDescription(description);
- } else {
+ }
+ else {
task.setDescription(taskElement.attributeValue("description"));
}
-
- // get the condition
+
+ // get the condition
String condition = taskElement.elementTextTrim("condition");
- if (condition!=null) {
+ if (condition != null) {
task.setCondition(condition);
- } else {
+ }
+ else {
task.setCondition(taskElement.attributeValue("condition"));
}
-
+
// parse common subelements
readTaskTimers(taskElement, task);
readEvents(taskElement, task);
readExceptionHandlers(taskElement, task);
- // duedate and priority
+ // duedate
String duedateText = taskElement.attributeValue("duedate");
- if (duedateText==null) {
+ if (duedateText == null) {
duedateText = taskElement.attributeValue("dueDate");
}
task.setDueDate(duedateText);
+ // priority
String priorityText = taskElement.attributeValue("priority");
- if (priorityText!=null) {
+ if (priorityText != null) {
task.setPriority(Task.parsePriority(priorityText));
}
-
+
// if this task is in the context of a taskNode, associate them
- if (taskNode!=null) {
- taskNode.addTask(task);
- }
+ if (taskNode != null) taskNode.addTask(task);
// blocking
String blockingText = taskElement.attributeValue("blocking");
- if (blockingText!=null) {
- if ( ("true".equalsIgnoreCase(blockingText))
- || ("yes".equalsIgnoreCase(blockingText))
- || ("on".equalsIgnoreCase(blockingText)) ) {
- task.setBlocking(true);
- }
+ if (blockingText != null
+ && ("true".equalsIgnoreCase(blockingText)
+ || "yes".equalsIgnoreCase(blockingText) || "on".equalsIgnoreCase(blockingText))) {
+ task.setBlocking(true);
}
-
+
// signalling
String signallingText = taskElement.attributeValue("signalling");
- if (signallingText!=null) {
- if ( ("false".equalsIgnoreCase(signallingText))
- || ("no".equalsIgnoreCase(signallingText))
- || ("off".equalsIgnoreCase(signallingText)) ) {
- task.setSignalling(false);
- }
+ if (signallingText != null
+ && ("false".equalsIgnoreCase(signallingText)
+ || "no".equalsIgnoreCase(signallingText) || "off".equalsIgnoreCase(signallingText))) {
+ task.setSignalling(false);
}
-
+
// assignment
String swimlaneName = taskElement.attributeValue("swimlane");
Element assignmentElement = taskElement.element("assignment");
// if there is a swimlane attribute specified
- if (swimlaneName!=null) {
+ if (swimlaneName != null) {
Swimlane swimlane = taskMgmtDefinition.getSwimlane(swimlaneName);
- if (swimlane==null) {
- addWarning("task references unknown swimlane '"+swimlaneName+"':"+taskElement.asXML());
- } else {
+ if (swimlane == null) {
+ addWarning("task references unknown swimlane: "
+ + taskElement.getPath());
+ }
+ else {
task.setSwimlane(swimlane);
}
-
+ }
// else if there is a direct assignment specified
- } else if (assignmentElement!=null) {
- if ( (assignmentElement.attribute("actor-id")!=null)
- || (assignmentElement.attribute("pooled-actors")!=null)
- ) {
+ else if (assignmentElement != null) {
+ if (assignmentElement.attribute("actor-id") != null
+ || assignmentElement.attribute("pooled-actors") != null) {
task.setActorIdExpression(assignmentElement.attributeValue("actor-id"));
task.setPooledActorsExpression(assignmentElement.attributeValue("pooled-actors"));
-
- } else {
- Delegation assignmentDelegation = readAssignmentDelegation(assignmentElement);
+ }
+ else {
+ Delegation assignmentDelegation =
+ readAssignmentDelegation(assignmentElement);
task.setAssignmentDelegation(assignmentDelegation);
}
-
+ }
// if no assignment or swimlane is specified
- } else {
- // the user has to manage assignment manually, so we better inform him/her.
- log.info("process xml information: no swimlane or assignment specified for task '"+taskElement.asXML()+"'");
+ else {
+ // user has to manage assignment manually, so better inform him/her
+ addProblem(new Problem(Problem.LEVEL_INFO,
+ "no assignment specified for task: " + taskElement.getPath()));
}
// notify
String notificationsText = taskElement.attributeValue("notify");
- if ( notificationsText!=null
- && ("true".equalsIgnoreCase(notificationsText)
- || "on".equalsIgnoreCase(notificationsText)
- || "yes".equalsIgnoreCase(notificationsText)
- )
- ) {
+ if (notificationsText != null
+ && ("true".equalsIgnoreCase(notificationsText)
+ || "on".equalsIgnoreCase(notificationsText) || "yes".equalsIgnoreCase(notificationsText))) {
String notificationEvent = Event.EVENTTYPE_TASK_ASSIGN;
Event event = task.getEvent(notificationEvent);
- if (event==null) {
+ if (event == null) {
event = new Event(notificationEvent);
task.addEvent(event);
}
- Delegation delegation = createMailDelegation(notificationEvent, null, null, null, null);
+ Delegation delegation =
+ createMailDelegation(notificationEvent, null, null, null, null);
Action action = new Action(delegation);
action.setProcessDefinition(processDefinition);
action.setName(task.getName());
@@ -407,10 +391,10 @@
// task controller
Element taskControllerElement = taskElement.element("controller");
- if (taskControllerElement!=null) {
+ if (taskControllerElement != null) {
task.setTaskController(readTaskController(taskControllerElement));
}
-
+
return task;
}
@@ -419,107 +403,109 @@
String expression = assignmentElement.attributeValue("expression");
String actorId = assignmentElement.attributeValue("actor-id");
String pooledActors = assignmentElement.attributeValue("pooled-actors");
-
- if (expression!=null){
+
+ if (expression != null) {
assignmentDelegation.setProcessDefinition(processDefinition);
assignmentDelegation.setClassName("org.jbpm.identity.assignment.ExpressionAssignmentHandler");
- assignmentDelegation.setConfiguration("<expression>"+expression+"</expression>");
-
- } else if ( (actorId!=null)
- || (pooledActors!=null)
- ) {
+ assignmentDelegation.setConfiguration("<expression>" + expression
+ + "</expression>");
+ }
+ else if (actorId != null || pooledActors != null) {
assignmentDelegation.setProcessDefinition(processDefinition);
assignmentDelegation.setClassName("org.jbpm.taskmgmt.assignment.ActorAssignmentHandler");
String configuration = "";
- if (actorId!=null) {
- configuration += "<actorId>"+actorId+"</actorId>";
+ if (actorId != null) {
+ configuration += "<actorId>" + actorId + "</actorId>";
}
- if (pooledActors!=null) {
- configuration += "<pooledActors>"+pooledActors+"</pooledActors>";
+ if (pooledActors != null) {
+ configuration += "<pooledActors>" + pooledActors + "</pooledActors>";
}
assignmentDelegation.setConfiguration(configuration);
-
- } else {
+ }
+ else {
assignmentDelegation = new Delegation();
assignmentDelegation.read(assignmentElement, this);
}
-
+
return assignmentDelegation;
}
protected TaskController readTaskController(Element taskControllerElement) {
TaskController taskController = new TaskController();
- if (taskControllerElement.attributeValue("class")!=null) {
+ if (taskControllerElement.attributeValue("class") != null) {
Delegation taskControllerDelegation = new Delegation();
taskControllerDelegation.read(taskControllerElement, this);
taskController.setTaskControllerDelegation(taskControllerDelegation);
- } else {
+ }
+ else {
List variableAccesses = readVariableAccesses(taskControllerElement);
taskController.setVariableAccesses(variableAccesses);
}
return taskController;
}
-
+
public List readVariableAccesses(Element element) {
List variableAccesses = new ArrayList();
- Iterator iter = element.elementIterator("variable");
- while (iter.hasNext()) {
+ for (Iterator iter = element.elementIterator("variable"); iter.hasNext();) {
Element variableElement = (Element) iter.next();
-
+
String variableName = variableElement.attributeValue("name");
- if (variableName==null) {
- addProblem(new Problem(Problem.LEVEL_WARNING, "the name attribute of a variable element is required: "+variableElement.asXML()));
+ if (variableName == null) {
+ addWarning("variable name not specified: "
+ + variableElement.getPath());
}
String access = variableElement.attributeValue("access", "read,write");
String mappedName = variableElement.attributeValue("mapped-name");
-
+
variableAccesses.add(new VariableAccess(variableName, access, mappedName));
}
return variableAccesses;
}
public void readStartStateTask(Element startTaskElement, StartState startState) {
- TaskMgmtDefinition taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
+ TaskMgmtDefinition taskMgmtDefinition =
+ processDefinition.getTaskMgmtDefinition();
Task startTask = readTask(startTaskElement, taskMgmtDefinition, null);
startTask.setStartState(startState);
- if (startTask.getName()==null) {
+ if (startTask.getName() == null) {
startTask.setName(startState.getName());
}
taskMgmtDefinition.setStartTask(startTask);
}
- public void readNode(Element nodeElement, Node node, NodeCollection nodeCollection) {
+ public void readNode(Element nodeElement, Node node,
+ NodeCollection nodeCollection) {
- // first put the node in its collection. this is done so that the
- // setName later on will be able to differentiate between nodes contained in
+ // first put the node in its collection. this is done so that the
+ // setName later on will be able to differentiate between nodes contained in
// processDefinitions and nodes contained in superstates
nodeCollection.addNode(node);
// get the node name
String name = nodeElement.attributeValue("name");
- if (name!=null) {
+ if (name != null) {
node.setName(name);
// check if this is the initial node
- if ( (initialNodeName!=null)
- && (initialNodeName.equals(node.getFullyQualifiedName()))
- ) {
+ if (initialNodeName != null
+ && initialNodeName.equals(node.getFullyQualifiedName())) {
processDefinition.setStartState(node);
}
}
- // get the node description
+ // get the node description
String description = nodeElement.elementTextTrim("description");
- if (description!=null) {
+ if (description != null) {
node.setDescription(description);
}
String asyncText = nodeElement.attributeValue("async");
if ("true".equalsIgnoreCase(asyncText)) {
node.setAsync(true);
- } else if ("exclusive".equalsIgnoreCase(asyncText)) {
+ }
+ else if ("exclusive".equalsIgnoreCase(asyncText)) {
node.setAsync(true);
node.setAsyncExclusive(true);
}
@@ -534,8 +520,7 @@
}
protected void readNodeTimers(Element nodeElement, Node node) {
- Iterator iter = nodeElement.elementIterator("timer");
- while (iter.hasNext()) {
+ for (Iterator iter = nodeElement.elementIterator("timer"); iter.hasNext();) {
Element timerElement = (Element) iter.next();
readNodeTimer(timerElement, node);
}
@@ -544,29 +529,27 @@
protected void readNodeTimer(Element timerElement, Node node) {
String name = timerElement.attributeValue("name", node.getName());
if (name == null) name = generateTimerName();
-
+
CreateTimerAction createTimerAction = new CreateTimerAction();
createTimerAction.read(timerElement, this);
createTimerAction.setTimerName(name);
createTimerAction.setTimerAction(readSingleAction(timerElement));
addAction(node, Event.EVENTTYPE_NODE_ENTER, createTimerAction);
-
+
CancelTimerAction cancelTimerAction = new CancelTimerAction();
cancelTimerAction.setTimerName(name);
addAction(node, Event.EVENTTYPE_NODE_LEAVE, cancelTimerAction);
}
private String generateTimerName() {
- return "timer-" + (timerNumber++);
+ return "timer-" + (timerNumber++);
}
protected void readTaskTimers(Element taskElement, Task task) {
- Iterator iter = taskElement.elementIterator();
- while (iter.hasNext()) {
+ for (Iterator iter = taskElement.elementIterator(); iter.hasNext();) {
Element element = (Element) iter.next();
- if ( ("timer".equals(element.getName()))
- || ("reminder".equals(element.getName()))
- ) {
+ String elementName = element.getName();
+ if ("timer".equals(elementName) || "reminder".equals(elementName)) {
readTaskTimer(element, task);
}
}
@@ -574,7 +557,7 @@
protected void readTaskTimer(Element timerElement, Task task) {
String name = timerElement.attributeValue("name", task.getName());
- if (name==null) name = generateTimerName();
+ if (name == null) name = generateTimerName();
CreateTimerAction createTimerAction = new CreateTimerAction();
createTimerAction.read(timerElement, this);
@@ -582,8 +565,10 @@
Action action = null;
if ("timer".equals(timerElement.getName())) {
action = readSingleAction(timerElement);
- } else {
- Delegation delegation = createMailDelegation("task-reminder", null, null, null, null);
+ }
+ else {
+ Delegation delegation =
+ createMailDelegation("task-reminder", null, null, null, null);
action = new Action(delegation);
}
createTimerAction.setTimerAction(action);
@@ -593,29 +578,28 @@
Collection cancelEventTypes = new ArrayList();
String cancelEventTypeText = timerElement.attributeValue("cancel-event");
- if (cancelEventTypeText!=null) {
+ if (cancelEventTypeText != null) {
// cancel-event is a comma separated list of events
StringTokenizer tokenizer = new StringTokenizer(cancelEventTypeText, ",");
while (tokenizer.hasMoreTokens()) {
cancelEventTypes.add(tokenizer.nextToken().trim());
}
- } else {
+ }
+ else {
// set the default
cancelEventTypes.add(Event.EVENTTYPE_TASK_END);
}
-
- Iterator iter = cancelEventTypes.iterator();
- while (iter.hasNext()) {
+
+ for (Iterator iter = cancelEventTypes.iterator(); iter.hasNext();) {
String cancelEventType = (String) iter.next();
CancelTimerAction cancelTimerAction = new CancelTimerAction();
cancelTimerAction.setTimerName(name);
addAction(task, cancelEventType, cancelTimerAction);
}
}
-
+
protected void readEvents(Element parentElement, GraphElement graphElement) {
- Iterator iter = parentElement.elementIterator("event");
- while (iter.hasNext()) {
+ for (Iterator iter = parentElement.elementIterator("event"); iter.hasNext();) {
Element eventElement = (Element) iter.next();
String eventType = eventElement.attributeValue("type");
if (!graphElement.hasEvent(eventType)) {
@@ -625,17 +609,15 @@
}
}
- public void readActions(Element eventElement, GraphElement graphElement, String eventType) {
+ public void readActions(Element eventElement, GraphElement graphElement,
+ String eventType) {
// for all the elements in the event element
- Iterator nodeElementIter = eventElement.elementIterator();
- while (nodeElementIter.hasNext()) {
- Element actionElement = (Element) nodeElementIter.next();
+ for (Iterator iter = eventElement.elementIterator(); iter.hasNext();) {
+ Element actionElement = (Element) iter.next();
String actionName = actionElement.getName();
if (ActionTypes.hasActionName(actionName)) {
Action action = createAction(actionElement);
- if ( (graphElement!=null)
- && (eventType!=null)
- ) {
+ if (graphElement != null && eventType != null) {
// add the action to the event
addAction(graphElement, eventType, action);
}
@@ -643,69 +625,69 @@
}
}
- protected void addAction(GraphElement graphElement, String eventType, Action action) {
+ protected void addAction(GraphElement graphElement, String eventType,
+ Action action) {
Event event = graphElement.getEvent(eventType);
- if (event==null) {
- event = new Event(eventType);
+ if (event == null) {
+ event = new Event(eventType);
graphElement.addEvent(event);
}
event.addAction(action);
}
-
+
public Action readSingleAction(Element nodeElement) {
- Action action = null;
// search for the first action element in the node
- Iterator iter = nodeElement.elementIterator();
- while (iter.hasNext() && (action==null)) {
+ for (Iterator iter = nodeElement.elementIterator(); iter.hasNext();) {
Element candidate = (Element) iter.next();
if (ActionTypes.hasActionName(candidate.getName())) {
// parse the action and assign it to this node
- action = createAction(candidate);
+ return createAction(candidate);
}
}
- return action;
+ return null;
}
public Action createAction(Element actionElement) {
- // create a new instance of the action
- Action action = null;
String actionName = actionElement.getName();
Class actionType = ActionTypes.getActionType(actionName);
try {
- action = (Action) actionType.newInstance();
- } catch (Exception e) {
- log.error("couldn't instantiate action '"+actionName+"', of type '"+actionType.getName()+"'", e);
+ // instantiate action
+ Action action = (Action) actionType.newInstance();
+ // read the common node parts of the action
+ readAction(actionElement, action);
+ return action;
}
-
- // read the common node parts of the action
- readAction(actionElement, action);
-
- return action;
+ catch (InstantiationException e) {
+ throw new JbpmException("failed to instantiate " + actionType, e);
+ }
+ catch (IllegalAccessException e) {
+ throw new JbpmException("illegal access to " + actionType, e);
+ }
}
public void readAction(Element element, Action action) {
// if a name is specified for this action
String actionName = element.attributeValue("name");
- if (actionName!=null) {
+ if (actionName != null) {
action.setName(actionName);
- // add the action to the named process action repository
+ // add the action to the named process action repository
processDefinition.addAction(action);
}
- // if the action is parsable
- // (meaning: if the action has special configuration to parse, other then the common node data)
+ // let action parse its special configuration
action.read(element, this);
}
- protected void readExceptionHandlers(Element graphElementElement, GraphElement graphElement) {
- Iterator iter = graphElementElement.elementIterator("exception-handler");
- while (iter.hasNext()) {
+ protected void readExceptionHandlers(Element graphDomElement,
+ GraphElement graphElement) {
+ for (Iterator iter = graphDomElement.elementIterator("exception-handler"); iter.hasNext();) {
Element exceptionHandlerElement = (Element) iter.next();
readExceptionHandler(exceptionHandlerElement, graphElement);
}
}
- protected void readExceptionHandler(Element exceptionHandlerElement, GraphElement graphElement) {
+ protected void readExceptionHandler(Element exceptionHandlerElement,
+ GraphElement graphElement) {
// create the exception handler
ExceptionHandler exceptionHandler = new ExceptionHandler();
exceptionHandler.setExceptionClassName(exceptionHandlerElement.attributeValue("exception-class"));
@@ -713,8 +695,7 @@
graphElement.addExceptionHandler(exceptionHandler);
// read the actions in the body of the exception-handler element
- Iterator iter = exceptionHandlerElement.elementIterator();
- while (iter.hasNext()) {
+ for (Iterator iter = exceptionHandlerElement.elementIterator(); iter.hasNext();) {
Element childElement = (Element) iter.next();
if (ActionTypes.hasActionName(childElement.getName())) {
Action action = createAction(childElement);
@@ -724,14 +705,13 @@
}
// transition destinations are parsed in a second pass //////////////////////
-
+
public void addUnresolvedTransitionDestination(Element nodeElement, Node node) {
- unresolvedTransitionDestinations.add(new Object[]{nodeElement, node});
+ unresolvedTransitionDestinations.add(new Object[] { nodeElement, node });
}
public void resolveTransitionDestinations() {
- Iterator iter = unresolvedTransitionDestinations.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = unresolvedTransitionDestinations.iterator(); iter.hasNext();) {
Object[] unresolvedTransition = (Object[]) iter.next();
Element nodeElement = (Element) unresolvedTransition[0];
Node node = (Node) unresolvedTransition[1];
@@ -740,8 +720,7 @@
}
public void resolveTransitionDestinations(List transitionElements, Node node) {
- Iterator iter = transitionElements.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = transitionElements.iterator(); iter.hasNext();) {
Element transitionElement = (Element) iter.next();
resolveTransitionDestination(transitionElement, node);
}
@@ -749,11 +728,13 @@
/**
* 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)
+ * (useful, if you want to override this method to read additional
+ * configuration properties)
*/
- public Transition resolveTransitionDestination(Element transitionElement, Node node) {
+ public Transition resolveTransitionDestination(Element transitionElement,
+ Node node) {
Transition transition = new Transition();
transition.setProcessDefinition(processDefinition);
@@ -761,14 +742,12 @@
transition.setDescription(transitionElement.elementTextTrim("description"));
String condition = transitionElement.attributeValue("condition");
- if (condition==null) {
+ if (condition == null) {
Element conditionElement = transitionElement.element("condition");
- if (conditionElement!=null) {
+ if (conditionElement != null) {
condition = conditionElement.getTextTrim();
// for backwards compatibility
- if ( (condition==null)
- || (condition.length()==0)
- ) {
+ if (condition == null || condition.length() == 0) {
condition = conditionElement.attributeValue("expression");
}
}
@@ -780,41 +759,44 @@
// set destinationNode of the transition
String toName = transitionElement.attributeValue("to");
- if (toName==null) {
- addWarning("node '"+node.getFullyQualifiedName()+"' has a transition without a 'to'-attribute to specify its destinationNode");
- } else {
- Node to = ((NodeCollection)node.getParent()).findNode(toName);
- if (to==null) {
- addWarning("transition to='"+toName+"' on node '"+node.getFullyQualifiedName()+"' cannot be resolved");
- } else {
+ if (toName == null) {
+ addWarning("node '" + node.getFullyQualifiedName()
+ + "' has a transition without a 'to'-attribute");
+ }
+ else {
+ Node to = ((NodeCollection) node.getParent()).findNode(toName);
+ if (to == null) {
+ addWarning("transition to='" + toName + "' on node '"
+ + node.getFullyQualifiedName() + "' cannot be resolved");
+ }
+ else {
to.addArrivingTransition(transition);
}
}
-
+
// read the actions
readActions(transitionElement, transition, Event.EVENTTYPE_TRANSITION);
-
readExceptionHandlers(transitionElement, transition);
-
return transition;
}
-
+
// action references are parsed in a second pass ////////////////////////////
public void addUnresolvedActionReference(Element actionElement, Action action) {
- unresolvedActionReferences.add(new Object[]{actionElement, action});
+ unresolvedActionReferences.add(new Object[] { actionElement, action });
}
public void resolveActionReferences() {
- Iterator iter = unresolvedActionReferences.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = unresolvedActionReferences.iterator(); iter.hasNext();) {
Object[] unresolvedActionReference = (Object[]) iter.next();
Element actionElement = (Element) unresolvedActionReference[0];
Action action = (Action) unresolvedActionReference[1];
String referencedActionName = actionElement.attributeValue("ref-name");
- Action referencedAction = processDefinition.getAction(referencedActionName);
- if (referencedAction==null) {
- addWarning("couldn't resolve action reference in "+actionElement.asXML());
+ Action referencedAction =
+ processDefinition.getAction(referencedActionName);
+ if (referencedAction == null) {
+ addWarning("referenced action not found: "
+ + actionElement.getPath());
}
action.setReferencedAction(referencedAction);
}
@@ -822,21 +804,22 @@
// verify swimlane assignments in second pass ///////////////////////////////
public void verifySwimlaneAssignments() {
- TaskMgmtDefinition taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
- if ( (taskMgmtDefinition!=null)
- && (taskMgmtDefinition.getSwimlanes()!=null)
- ) {
- Iterator iter = taskMgmtDefinition.getSwimlanes().values().iterator();
- while (iter.hasNext()) {
+ TaskMgmtDefinition taskMgmtDefinition =
+ processDefinition.getTaskMgmtDefinition();
+ Map swimlanes;
+ if (taskMgmtDefinition != null
+ && (swimlanes = taskMgmtDefinition.getSwimlanes()) != null) {
+ for (Iterator iter = swimlanes.values().iterator(); iter.hasNext();) {
Swimlane swimlane = (Swimlane) iter.next();
-
+
Task startTask = taskMgmtDefinition.getStartTask();
- Swimlane startTaskSwimlane = (startTask!=null ? startTask.getSwimlane() : null);
-
- if ( (swimlane.getAssignmentDelegation()==null)
- && (swimlane!=startTaskSwimlane)
- ) {
- addWarning("swimlane '"+swimlane.getName()+"' does not have an assignment");
+ Swimlane startTaskSwimlane =
+ startTask != null ? startTask.getSwimlane() : null;
+
+ if (swimlane.getAssignmentDelegation() == null
+ && swimlane != startTaskSwimlane) {
+ addWarning("swimlane '" + swimlane.getName()
+ + "' does not have an assignment");
}
}
}
@@ -844,33 +827,30 @@
// mail delegations /////////////////////////////////////////////////////////
- public Delegation createMailDelegation(String template,
- String actors,
- String to,
- String subject,
- String text) {
+ public Delegation createMailDelegation(String template, String actors,
+ String to, String subject, String text) {
StringBuffer config = new StringBuffer();
- if (template!=null) {
+ if (template != null) {
config.append("<template>");
config.append(template);
config.append("</template>");
}
- if (actors!=null) {
+ if (actors != null) {
config.append("<actors>");
config.append(actors);
config.append("</actors>");
}
- if (to!=null) {
+ if (to != null) {
config.append("<to>");
config.append(to);
config.append("</to>");
}
- if (subject!=null) {
+ if (subject != null) {
config.append("<subject>");
config.append(subject);
config.append("</subject>");
}
- if (text!=null) {
+ if (text != null) {
config.append("<text>");
config.append(text);
config.append("</text>");
@@ -878,8 +858,10 @@
String mailClassName = Mail.class.getName();
if (JbpmConfiguration.Configs.hasObject("jbpm.mail.class.name")) {
- mailClassName = JbpmConfiguration.Configs.getString("jbpm.mail.class.name");
- } else if (JbpmConfiguration.Configs.hasObject("mail.class.name")) {
+ mailClassName =
+ JbpmConfiguration.Configs.getString("jbpm.mail.class.name");
+ }
+ else if (JbpmConfiguration.Configs.hasObject("mail.class.name")) {
mailClassName = JbpmConfiguration.Configs.getString("mail.class.name");
}
@@ -891,14 +873,12 @@
public String getProperty(String property, Element element) {
String value = element.attributeValue(property);
- if (value==null) {
+ if (value == null) {
Element propertyElement = element.element(property);
- if (propertyElement!=null) {
+ if (propertyElement != null) {
value = propertyElement.getText();
}
}
return value;
}
-
- private static final Log log = LogFactory.getLog(JpdlXmlReader.class);
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/xml/Problem.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/xml/Problem.java 2010-01-22 10:38:03 UTC (rev 6117)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/xml/Problem.java 2010-01-22 10:39:47 UTC (rev 6118)
@@ -26,19 +26,25 @@
import java.util.Iterator;
public class Problem implements Serializable {
-
+
private static final long serialVersionUID = 1L;
-
+
public static final int LEVEL_FATAL = 1;
public static final int LEVEL_ERROR = 2;
public static final int LEVEL_WARNING = 3;
public static final int LEVEL_INFO = 4;
static String getTypeDescription(int level) {
- if (level==LEVEL_FATAL) return "FATAL";
- if (level==LEVEL_ERROR) return "ERROR";
- if (level==LEVEL_WARNING) return "WARNING";
- if (level==LEVEL_INFO) return "INFO";
+ switch (level) {
+ case LEVEL_FATAL:
+ return "FATAL";
+ case LEVEL_ERROR:
+ return "ERROR";
+ case LEVEL_WARNING:
+ return "WARNING";
+ case LEVEL_INFO:
+ return "INFO";
+ }
return null;
}
@@ -48,7 +54,7 @@
protected String folder;
protected Integer line;
protected Throwable exception;
-
+
public Problem(int level, String description) {
this.level = level;
this.description = description;
@@ -59,24 +65,23 @@
this.description = description;
this.exception = exception;
}
-
+
public String toString() {
StringBuffer buffer = new StringBuffer();
- buffer.append("["+getTypeDescription(level)+"]");
- if (description!=null) buffer.append(" "+description);
- if (resource!=null) buffer.append(" at "+resource);
- if (line!=null) buffer.append(" line "+line);
- if (folder!=null) buffer.append(" in "+folder);
+ buffer.append('[').append(getTypeDescription(level)).append(']');
+ if (description != null) buffer.append(' ').append(description);
+ if (resource != null) {
+ buffer.append(" (").append(resource);
+ if (line != null) buffer.append(':').append(line);
+ buffer.append(')');
+ }
return buffer.toString();
}
-
+
public static boolean containsProblemsOfLevel(Collection c, int level) {
- Iterator iter = c.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = c.iterator(); iter.hasNext();) {
Problem problem = (Problem) iter.next();
- if (problem.level <= level) {
- return true;
- }
+ if (problem.level <= level) return true;
}
return false;
}
@@ -84,33 +89,43 @@
public String getDescription() {
return description;
}
+
public void setDescription(String description) {
this.description = description;
}
+
public Throwable getException() {
return exception;
}
+
public void setException(Throwable exception) {
this.exception = exception;
}
+
public String getFolder() {
return folder;
}
+
public void setFolder(String folder) {
this.folder = folder;
}
+
public Integer getLine() {
return line;
}
+
public void setLine(Integer line) {
this.line = line;
}
+
public String getResource() {
return resource;
}
+
public void setResource(String resource) {
this.resource = resource;
}
+
public int getLevel() {
return level;
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/scheduler/def/CancelTimerAction.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/scheduler/def/CancelTimerAction.java 2010-01-22 10:38:03 UTC (rev 6117)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/scheduler/def/CancelTimerAction.java 2010-01-22 10:39:47 UTC (rev 6118)
@@ -22,33 +22,36 @@
package org.jbpm.scheduler.def;
import org.dom4j.Element;
+
import org.jbpm.graph.def.Action;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.jpdl.xml.JpdlXmlReader;
import org.jbpm.scheduler.SchedulerService;
-import org.jbpm.svc.Services;
public class CancelTimerAction extends Action {
private static final long serialVersionUID = 1L;
-
- String timerName = null;
-
+
+ String timerName;
+
public void read(Element actionElement, JpdlXmlReader jpdlReader) {
timerName = actionElement.attributeValue("name");
- if (timerName==null) {
- jpdlReader.addWarning("no 'name' specified in CancelTimerAction '"+actionElement.asXML()+"'");
+ if (timerName == null) {
+ jpdlReader.addWarning("timer name not specified on cancel timer: "
+ + actionElement.getPath());
}
}
public void execute(ExecutionContext executionContext) throws Exception {
- SchedulerService schedulerService = (SchedulerService) Services.getCurrentService(Services.SERVICENAME_SCHEDULER);
+ SchedulerService schedulerService =
+ executionContext.getJbpmContext().getServices().getSchedulerService();
schedulerService.deleteTimersByName(timerName, executionContext.getToken());
}
-
+
public String getTimerName() {
return timerName;
}
+
public void setTimerName(String timerName) {
this.timerName = timerName;
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/scheduler/def/CreateTimerAction.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/scheduler/def/CreateTimerAction.java 2010-01-22 10:38:03 UTC (rev 6117)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/scheduler/def/CreateTimerAction.java 2010-01-22 10:39:47 UTC (rev 6118)
@@ -25,6 +25,7 @@
import java.util.Date;
import org.dom4j.Element;
+
import org.jbpm.JbpmException;
import org.jbpm.calendar.BusinessCalendar;
import org.jbpm.calendar.Duration;
@@ -35,15 +36,13 @@
import org.jbpm.job.Timer;
import org.jbpm.jpdl.el.impl.JbpmExpressionEvaluator;
import org.jbpm.jpdl.xml.JpdlXmlReader;
-import org.jbpm.jpdl.xml.Problem;
import org.jbpm.scheduler.SchedulerService;
-import org.jbpm.svc.Services;
import org.jbpm.util.Clock;
public class CreateTimerAction extends Action {
private static final long serialVersionUID = 1L;
- static final BusinessCalendar businessCalendar = new BusinessCalendar();
+ static final BusinessCalendar businessCalendar = new BusinessCalendar();
String timerName;
String dueDate;
@@ -56,68 +55,78 @@
timerAction = jpdlReader.readSingleAction(actionElement);
dueDate = actionElement.attributeValue("duedate");
- if (dueDate==null) {
- jpdlReader.addWarning("no duedate specified in create timer action '"+actionElement+"'");
+ if (dueDate == null) {
+ jpdlReader.addWarning("due date not specified on create timer: "
+ + actionElement.getPath());
}
repeat = actionElement.attributeValue("repeat");
- if ( "true".equalsIgnoreCase(repeat)
- || "yes".equalsIgnoreCase(repeat) ) {
+ if ("true".equalsIgnoreCase(repeat) || "yes".equalsIgnoreCase(repeat)) {
repeat = dueDate;
}
transitionName = actionElement.attributeValue("transition");
-
- if ( (transitionName!=null)
- && (repeat!=null)
- ) {
+
+ if (transitionName != null && repeat != null) {
repeat = null;
- jpdlReader.addProblem(new Problem(Problem.LEVEL_WARNING, "ignoring repeat on timer with transition "+actionElement.asXML()));
+ jpdlReader.addWarning("ignoring repeat on create timer with transition: "
+ + actionElement.getPath());
}
}
public void execute(ExecutionContext executionContext) throws Exception {
Timer timer = createTimer(executionContext);
- SchedulerService schedulerService = (SchedulerService) Services.getCurrentService(Services.SERVICENAME_SCHEDULER);
+ SchedulerService schedulerService =
+ executionContext.getJbpmContext().getServices().getSchedulerService();
schedulerService.createTimer(timer);
}
protected Timer createTimer(ExecutionContext executionContext) {
- Date baseDate = null;
- Date dueDateDate = null;
- Duration duration;
- String durationString = null;
- String durationSeparator = null;
Timer timer = new Timer(executionContext.getToken());
timer.setName(timerName);
timer.setRepeat(repeat);
- if (dueDate!=null) {
- if (dueDate.startsWith("#")) {
- String baseDateEL = dueDate.substring(0,dueDate.indexOf("}")+1);
- Object o = JbpmExpressionEvaluator.evaluate(baseDateEL, executionContext);
- if (o instanceof Date) {
- baseDate = (Date) o;
- } else {
- if (o instanceof Calendar) {
- baseDate = ((Calendar) o).getTime();
- } else {
- throw new JbpmException("Invalid basedate type: " + baseDateEL + " is of type " + o.getClass().getName() +". Only Date and Calendar are supported");
- }
+
+ if (dueDate != null) {
+ Date dueDateDate;
+ if (dueDate.startsWith("#{")) {
+ int braceIndex = dueDate.indexOf("}");
+ if (braceIndex == -1) {
+ throw new JbpmException("invalid due date, closing brace missing: "
+ + dueDate);
}
- int endOfELIndex = dueDate.indexOf("}");
- if (endOfELIndex < (dueDate.length() -1) ) {
- durationSeparator = dueDate.substring(endOfELIndex+1).trim().substring(0,1);
- if ( !(durationSeparator.equals("+") || durationSeparator.equals("-") ) ){
- throw new JbpmException("Invalid duedate, + or - missing after EL");
+
+ String baseDateEL = dueDate.substring(0, braceIndex + 1);
+ Object result =
+ JbpmExpressionEvaluator.evaluate(baseDateEL, executionContext);
+
+ Date baseDate;
+ if (result instanceof Date) {
+ baseDate = (Date) result;
+ }
+ else if (result instanceof Calendar) {
+ baseDate = ((Calendar) result).getTime();
+ }
+ else {
+ throw new JbpmException("invalid base date type: "
+ + result.getClass().getName());
+ }
+
+ String durationString = dueDate.substring(braceIndex + 1).trim();
+ if (durationString.length() > 0) {
+ char durationSeparator = durationString.charAt(0);
+ if (durationSeparator != '+' && durationSeparator != '-') {
+ throw new JbpmException("invalid due date, + or - missing: "
+ + dueDate);
}
- durationString = dueDate.substring(endOfELIndex+1).trim();
+ durationString = dueDate.substring(braceIndex + 1).trim();
+ dueDateDate =
+ businessCalendar.add(baseDate, new Duration(durationString));
}
- } else {
- durationString = dueDate;
+ else {
+ dueDateDate = baseDate;
+ }
}
- if (baseDate != null && (durationString == null || durationString.length() == 0)) {
- dueDateDate = baseDate;
- } else {
- duration = new Duration(durationString);
- dueDateDate = businessCalendar.add( (baseDate != null) ? baseDate : Clock.getCurrentTime(), duration );
+ else {
+ dueDateDate =
+ businessCalendar.add(Clock.getCurrentTime(), new Duration(dueDate));
}
timer.setDueDate(dueDateDate);
}
@@ -125,51 +134,60 @@
timer.setTransitionName(transitionName);
timer.setGraphElement(executionContext.getEventSource());
timer.setTaskInstance(executionContext.getTaskInstance());
-
+
// if this action was executed for a graph element
- if ( (getEvent()!=null)
- && (getEvent().getGraphElement()!=null)
- ) {
- GraphElement graphElement = getEvent().getGraphElement();
+ Event event = getEvent();
+ GraphElement graphElement;
+ if (event != null && (graphElement = event.getGraphElement()) != null) {
try {
executionContext.setTimer(timer);
// fire the create timer event on the same graph element
graphElement.fireEvent(Event.EVENTTYPE_TIMER_CREATE, executionContext);
- } finally {
+ }
+ finally {
executionContext.setTimer(null);
}
}
-
+
return timer;
}
-
+
public String getDueDate() {
return dueDate;
}
+
public void setDueDate(String dueDateDuration) {
this.dueDate = dueDateDuration;
}
+
public String getRepeat() {
return repeat;
}
+
public void setRepeat(String repeatDuration) {
this.repeat = repeatDuration;
}
+
public String getTransitionName() {
return transitionName;
}
+
public void setTransitionName(String transitionName) {
this.transitionName = transitionName;
}
+
public String getTimerName() {
return timerName;
}
+
public void setTimerName(String timerName) {
this.timerName = timerName;
}
+
public Action getTimerAction() {
return timerAction;
}
+
public void setTimerAction(Action timerAction) {
this.timerAction = timerAction;
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/scheduler/exe/SchedulerTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/scheduler/exe/SchedulerTest.java 2010-01-22 10:38:03 UTC (rev 6117)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/scheduler/exe/SchedulerTest.java 2010-01-22 10:39:47 UTC (rev 6118)
@@ -655,8 +655,7 @@
processInstance.signal();
}
catch (JbpmException je) {
- assertEquals("Invalid basedate type: #{dateOfPension} is of type java.lang.String. "
- + "Only Date and Calendar are supported", je.getMessage());
+ assert je.getMessage().indexOf("invalid base date") != -1 : je;
}
finally {
jbpmContext.close();
@@ -670,8 +669,7 @@
processInstance.signal();
}
catch (JbpmException je) {
- assertEquals("Invalid basedate type: #{dateOfPension} is of type java.lang.String. "
- + "Only Date and Calendar are supported", je.getMessage());
+ assert je.getMessage().indexOf("invalid base date") != -1 : je;
}
finally {
jbpmContext.close();
More information about the jbpm-commits
mailing list