Author: alex.guizar(a)jboss.com
Date: 2010-12-03 16:11:52 -0500 (Fri, 03 Dec 2010)
New Revision: 6861
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/JbpmContext.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/file/def/FileDefinition.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/Action.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/Delegation.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/FieldInstantiator.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlReader.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlWriter.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/module/exe/ModuleInstance.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/msg/MessageService.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/security/SecurityHelper.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/security/authentication/DefaultAuthenticationService.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/Services.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/taskmgmt/exe/SwimlaneInstance.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/util/JndiUtil.java
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/persistence/db/MockSession.java
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/taskmgmt/exe/TaskAssignmentTest.java
jbpm3/branches/jbpm-3.2-soa/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java
Log:
JBPM-2981 factor out common code from mail delegation parse methods;
avoid writing xml directly, rely on dom4j instead
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/JbpmContext.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/JbpmContext.java 2010-12-03
17:32:13 UTC (rev 6860)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/JbpmContext.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -42,6 +42,7 @@
import org.jbpm.graph.exe.Token;
import org.jbpm.persistence.PersistenceService;
import org.jbpm.persistence.db.DbPersistenceService;
+import org.jbpm.security.AuthenticationService;
import org.jbpm.svc.ServiceFactory;
import org.jbpm.svc.Services;
import org.jbpm.taskmgmt.exe.TaskInstance;
@@ -669,7 +670,8 @@
*/
public void setActorId(String actorId) {
ensureOpen();
- services.getAuthenticationService().setActorId(actorId);
+ AuthenticationService authService = services.getAuthenticationService();
+ if (authService != null) authService.setActorId(actorId);
}
public void addAutoSaveProcessInstance(ProcessInstance processInstance) {
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/file/def/FileDefinition.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/file/def/FileDefinition.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/file/def/FileDefinition.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -36,10 +36,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jbpm.JbpmContext;
+import org.jbpm.JbpmConfiguration.Configs;
import org.jbpm.JbpmException;
import org.jbpm.bytes.ByteArray;
-import org.jbpm.configuration.ObjectFactory;
import org.jbpm.module.def.ModuleDefinition;
import org.jbpm.module.exe.ModuleInstance;
import org.jbpm.util.IoUtil;
@@ -49,13 +48,7 @@
private static final long serialVersionUID = 1L;
private static String getRootDir() {
- JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
- if (jbpmContext != null) {
- ObjectFactory objectFactory = jbpmContext.getObjectFactory();
- if (objectFactory.hasObject("jbpm.files.dir"))
- return (String) objectFactory.createObject("jbpm.files.dir");
- }
- return null;
+ return Configs.hasObject("jbpm.files.dir") ?
Configs.getString("jbpm.files.dir") : null;
}
private String dir;
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/Action.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/Action.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/def/Action.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -21,7 +21,6 @@
*/
package org.jbpm.graph.def;
-import java.io.Serializable;
import java.util.Map;
import org.dom4j.Element;
@@ -33,7 +32,7 @@
import org.jbpm.jpdl.xml.JpdlXmlReader;
import org.jbpm.jpdl.xml.Parsable;
-public class Action implements ActionHandler, Parsable, Serializable {
+public class Action implements ActionHandler, Parsable {
private static final long serialVersionUID = 1L;
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/Delegation.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/Delegation.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/Delegation.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -21,10 +21,7 @@
*/
package org.jbpm.instantiation;
-import java.io.IOException;
import java.io.Serializable;
-import java.io.StringWriter;
-import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
@@ -33,15 +30,12 @@
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
-import org.dom4j.io.OutputFormat;
-import org.dom4j.io.XMLWriter;
import org.jbpm.JbpmException;
import org.jbpm.graph.def.DelegationException;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.jpdl.xml.JpdlXmlReader;
import org.jbpm.jpdl.xml.Parsable;
-import org.jbpm.jpdl.xml.Problem;
public class Delegation implements Parsable, Serializable {
@@ -87,32 +81,10 @@
configType = delegateElement.attributeValue("config-type");
if (delegateElement.hasContent()) {
- try {
- StringWriter stringWriter = new StringWriter();
- // configuration is saved to database, write in a compact format
- CompactXmlWriter xmlWriter = new CompactXmlWriter(stringWriter);
- xmlWriter.writeElementContent(delegateElement);
- xmlWriter.flush();
- configuration = stringWriter.toString();
- }
- catch (IOException e) {
- jpdlReader.addProblem(new Problem(Problem.LEVEL_WARNING,
- "failed to write configuration xml", e));
- }
+ configuration = jpdlReader.writeElementContent(delegateElement);
}
}
- private static class CompactXmlWriter extends XMLWriter {
-
- CompactXmlWriter(Writer writer) {
- super(writer, OutputFormat.createCompactFormat());
- }
-
- public void writeElementContent(Element element) throws IOException {
- super.writeElementContent(element);
- }
- }
-
public void write(Element element) {
element.addAttribute("class", className);
element.addAttribute("config-type", configType);
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/FieldInstantiator.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/FieldInstantiator.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/instantiation/FieldInstantiator.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -101,15 +101,13 @@
}
protected Element parseConfiguration(String configuration) {
- Element element = null;
try {
- element = DocumentHelper.parseText("<action>" + configuration +
"</action>")
+ return DocumentHelper.parseText("<action>" + configuration +
"</action>")
.getRootElement();
}
catch (DocumentException e) {
throw new JbpmException("failed to parse configuration", e);
}
- return element;
}
protected Object newInstance(Class clazz) {
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlReader.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlReader.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlReader.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -24,6 +24,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -32,10 +34,13 @@
import org.dom4j.Document;
import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
import org.dom4j.Element;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.XMLWriter;
import org.xml.sax.InputSource;
-import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmConfiguration.Configs;
import org.jbpm.JbpmException;
import org.jbpm.context.def.VariableAccess;
import org.jbpm.graph.action.ActionTypes;
@@ -72,14 +77,14 @@
protected Collection unresolvedTransitionDestinations = new ArrayList();
protected Collection unresolvedActionReferences = new ArrayList();
- /**
- * process definition as DOM tree, available after readProcessDefinition
- */
+ /** process document, available after {@link #readProcessDefinition()} */
protected Document document;
- /** for autonumbering anonymous timers. */
+ /** for auto-numbering anonymous timers. */
private int timerNumber;
+ private XMLWriter xmlWriter;
+
public JpdlXmlReader(InputSource inputSource) {
this.inputSource = inputSource;
}
@@ -129,7 +134,7 @@
// create a new definition
processDefinition = ProcessDefinition.createNewProcessDefinition();
- // initialize lists
+ // clear lists
problems.clear();
unresolvedTransitionDestinations.clear();
unresolvedActionReferences.clear();
@@ -137,35 +142,35 @@
try {
// parse the document into a dom tree
document = JpdlParser.parse(inputSource, this);
- Element root = document.getRootElement();
+ }
+ catch (DocumentException e) {
+ throw new JpdlException("failed to parse process document", e);
+ }
- // read the process name
- parseProcessDefinitionAttributes(root);
+ // read the process name
+ Element root = document.getRootElement();
+ parseProcessDefinitionAttributes(root);
- // get the process description
- String description = root.elementTextTrim("description");
- if (description != null) processDefinition.setDescription(description);
+ // get the process description
+ String description = root.elementTextTrim("description");
+ if (description != null) processDefinition.setDescription(description);
- // first pass: read most content
- readSwimlanes(root);
- readActions(root, null, null);
- readNodes(root, processDefinition);
- readEvents(root, processDefinition);
- readExceptionHandlers(root, processDefinition);
- readTasks(root, null);
+ // first pass: read most content
+ readSwimlanes(root);
+ readActions(root, null, null);
+ readNodes(root, processDefinition);
+ readEvents(root, processDefinition);
+ readExceptionHandlers(root, processDefinition);
+ readTasks(root, null);
- // second pass processing
- resolveTransitionDestinations();
- resolveActionReferences();
- verifySwimlaneAssignments();
+ // second pass processing
+ resolveTransitionDestinations();
+ resolveActionReferences();
+ verifySwimlaneAssignments();
- if (Problem.containsProblemsOfLevel(problems, Problem.LEVEL_ERROR)) {
- throw new JpdlException(problems);
- }
+ 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;
}
@@ -180,7 +185,7 @@
Element swimlaneElement = (Element) iter.next();
String swimlaneName = swimlaneElement.attributeValue("name");
if (swimlaneName == null) {
- addWarning("there's a swimlane without a name");
+ addWarning("unnamed swimlane detected");
}
else {
Swimlane swimlane = new Swimlane(swimlaneName);
@@ -222,13 +227,12 @@
// check for duplicate start-states
if (node instanceof StartState && processDefinition.getStartState() !=
null) {
- addError("max one start-state allowed in a process");
+ addError("only one start-state is allowed");
}
else {
// read the common node parts of the element
readNode(nodeElement, node, nodeCollection);
-
- // let node parse its special configuration
+ // let node parse its specific configuration
node.read(nodeElement, this);
}
}
@@ -244,13 +248,8 @@
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) {
- tmd = new TaskMgmtDefinition();
- }
- processDefinition.addDefinition(tmd);
-
+ TaskMgmtDefinition tmd = processDefinition.getTaskMgmtDefinition();
for (Iterator iter = elements.iterator(); iter.hasNext();) {
Element taskElement = (Element) iter.next();
readTask(taskElement, tmd, taskNode);
@@ -276,38 +275,27 @@
// get the task description
String description = taskElement.elementTextTrim("description");
- if (description != null) {
- task.setDescription(description);
- }
- else {
- task.setDescription(taskElement.attributeValue("description"));
- }
+ if (description == null) description =
taskElement.attributeValue("description");
+ task.setDescription(description);
// get the condition
String condition = taskElement.elementTextTrim("condition");
- if (condition != null) {
- task.setCondition(condition);
- }
- else {
- task.setCondition(taskElement.attributeValue("condition"));
- }
+ if (condition == null) condition =
taskElement.attributeValue("condition");
+ task.setCondition(condition);
// parse common subelements
readTaskTimers(taskElement, task);
readEvents(taskElement, task);
readExceptionHandlers(taskElement, task);
- // duedate
+ // due date
String duedateText = taskElement.attributeValue("duedate");
- if (duedateText == null) {
- duedateText = taskElement.attributeValue("dueDate");
- }
+ if (duedateText == null) duedateText =
taskElement.attributeValue("dueDate");
task.setDueDate(duedateText);
+
// priority
String priorityText = taskElement.attributeValue("priority");
- if (priorityText != null) {
- task.setPriority(Task.parsePriority(priorityText));
- }
+ 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);
@@ -356,17 +344,14 @@
// notify
String notificationsText = taskElement.attributeValue("notify");
if (readBoolean(notificationsText, false)) {
- String notificationEvent = Event.EVENTTYPE_TASK_ASSIGN;
- Event event = task.getEvent(notificationEvent);
- if (event == null) {
- event = new Event(notificationEvent);
- task.addEvent(event);
- }
- Delegation delegation = createMailDelegation(notificationEvent, null, null, null,
null);
+ // create mail action
+ Delegation delegation = createMailDelegation(Event.EVENTTYPE_TASK_ASSIGN);
Action action = new Action(delegation);
action.setProcessDefinition(processDefinition);
action.setName(task.getName());
- event.addAction(action);
+
+ // attach action to task assign event
+ addAction(task, Event.EVENTTYPE_TASK_ASSIGN, action);
}
// task controller
@@ -389,31 +374,34 @@
protected Delegation readAssignmentDelegation(Element assignmentElement) {
Delegation assignmentDelegation = new Delegation();
+ assignmentDelegation.setProcessDefinition(processDefinition);
+
String expression = assignmentElement.attributeValue("expression");
- String actorId = assignmentElement.attributeValue("actor-id");
- String pooledActors = assignmentElement.attributeValue("pooled-actors");
+ if (expression != null) {
+ // read assigment expression
+ Element config = DocumentHelper.createElement("expression");
+ config.setText(expression);
- if (expression != null) {
- assignmentDelegation.setProcessDefinition(processDefinition);
assignmentDelegation.setClassName("org.jbpm.identity.assignment.ExpressionAssignmentHandler");
- assignmentDelegation.setConfiguration("<expression>" + expression +
"</expression>");
+ assignmentDelegation.setConfiguration(writeElement(config));
}
- 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>";
+ else {
+ String actorId = assignmentElement.attributeValue("actor-id");
+ String pooledActors = assignmentElement.attributeValue("pooled-actors");
+ if (actorId != null || pooledActors != null) {
+ // read assignment actors
+ Element config = DocumentHelper.createElement("configuration");
+ if (actorId != null) config.addElement("actorId").setText(actorId);
+ if (pooledActors != null)
config.addElement("pooledActors").setText(pooledActors);
+
+
assignmentDelegation.setClassName("org.jbpm.taskmgmt.assignment.ActorAssignmentHandler");
+ assignmentDelegation.setConfiguration(writeElementContent(config));
}
- if (pooledActors != null) {
- configuration += "<pooledActors>" + pooledActors +
"</pooledActors>";
+ else {
+ // parse custom assignment handler
+ assignmentDelegation.read(assignmentElement, this);
}
- assignmentDelegation.setConfiguration(configuration);
}
- else {
- assignmentDelegation = new Delegation();
- assignmentDelegation.read(assignmentElement, this);
- }
return assignmentDelegation;
}
@@ -437,14 +425,16 @@
List variableAccesses = new ArrayList();
for (Iterator iter = element.elementIterator("variable"); iter.hasNext();)
{
Element variableElement = (Element) iter.next();
-
+ // name
String variableName = variableElement.attributeValue("name");
if (variableName == null) {
addWarning("variable name not specified: " +
variableElement.getPath());
}
+ // access
String access = variableElement.attributeValue("access",
"read,write");
+ // mapped name
String mappedName = variableElement.attributeValue("mapped-name");
-
+ // variable access
variableAccesses.add(new VariableAccess(variableName, access, mappedName));
}
return variableAccesses;
@@ -477,9 +467,7 @@
// get the node description
String description = nodeElement.elementTextTrim("description");
- if (description != null) {
- node.setDescription(description);
- }
+ if (description != null) node.setDescription(description);
String asyncText = nodeElement.attributeValue("async");
if ("exclusive".equalsIgnoreCase(asyncText)) {
@@ -546,8 +534,8 @@
action = readSingleAction(timerElement);
}
else {
- Delegation delegation = createMailDelegation("task-reminder", null, null,
null, null);
- action = new Action(delegation);
+ Delegation mailDelegation = createMailDelegation("task-reminder");
+ action = new Action(mailDelegation);
}
createTimerAction.setTimerAction(action);
addAction(task, Event.EVENTTYPE_TASK_CREATE, createTimerAction);
@@ -576,10 +564,10 @@
protected void readEvents(Element parentElement, GraphElement graphElement) {
for (Iterator iter = parentElement.elementIterator("event");
iter.hasNext();) {
Element eventElement = (Element) iter.next();
+ // register event of the defined type
String eventType = eventElement.attributeValue("type");
- if (!graphElement.hasEvent(eventType)) {
- graphElement.addEvent(new Event(eventType));
- }
+ if (!graphElement.hasEvent(eventType)) graphElement.addEvent(new
Event(eventType));
+ // parse any actions associated to the event
readActions(eventElement, graphElement, eventType);
}
}
@@ -630,7 +618,7 @@
Action action = (Action) actionType.newInstance();
// read the common action parts of the element
readAction(actionElement, action);
- // let action parse its special configuration
+ // let action parse its specific configuration
action.read(actionElement, this);
return action;
}
@@ -717,12 +705,14 @@
* to override this method to read additional configuration properties)
*/
public Transition resolveTransitionDestination(Element transitionElement, Node node) {
+ String transitionName = transitionElement.attributeValue("name");
+
Transition transition = new Transition();
transition.setProcessDefinition(processDefinition);
-
- transition.setName(transitionElement.attributeValue("name"));
+ transition.setName(transitionName);
transition.setDescription(transitionElement.elementTextTrim("description"));
+ // read transition condition
String condition = transitionElement.attributeValue("condition");
if (condition == null) {
Element conditionElement = transitionElement.element("condition");
@@ -736,19 +726,21 @@
}
transition.setCondition(condition);
- // add the transition to the node
+ // register transition in origin
node.addLeavingTransition(transition);
- // set destinationNode of the transition
+ // register transition in destination
String toName = transitionElement.attributeValue("to");
if (toName == null) {
addWarning("node '" + node.getFullyQualifiedName()
+ "' has a transition without a 'to'-attribute");
}
else {
- Node to = ((NodeCollection) node.getParent()).findNode(toName);
+ NodeCollection parent = (NodeCollection) node.getParent();
+ Node to = parent.findNode(toName);
if (to == null) {
- addWarning("transition to '" + toName + "' from " +
node + " cannot be resolved");
+ addWarning("failed to resolve destination '" + toName + "'
of transition '"
+ + transitionName + "' leaving from " + node);
}
else {
to.addArrivingTransition(transition);
@@ -771,13 +763,14 @@
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) {
+ Action refAction =
processDefinition.getAction(actionElement.attributeValue("ref-name"));
+ if (refAction == null) {
addWarning("referenced action not found: " + actionElement.getPath());
}
- action.setReferencedAction(referencedAction);
+ else {
+ Action action = (Action) unresolvedActionReference[1];
+ action.setReferencedAction(refAction);
+ }
}
}
@@ -786,12 +779,11 @@
TaskMgmtDefinition taskMgmtDefinition = processDefinition.getTaskMgmtDefinition();
Map swimlanes;
if (taskMgmtDefinition != null && (swimlanes =
taskMgmtDefinition.getSwimlanes()) != null) {
+ Task startTask = taskMgmtDefinition.getStartTask();
+ Swimlane startTaskSwimlane = startTask != null ? startTask.getSwimlane() : 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");
}
@@ -801,120 +793,129 @@
// 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();
- if (template != null) {
- config.append("<template>");
- config.append(template);
- config.append("</template>");
+ private Delegation createMailDelegation(Element config) {
+ // read mail class name
+ String mailClassName;
+ if (Configs.hasObject("jbpm.mail.class.name")) {
+ mailClassName = Configs.getString("jbpm.mail.class.name");
}
- if (actors != null) {
- config.append("<actors>");
- config.append(actors);
- config.append("</actors>");
+ else {
+ mailClassName = Mail.class.getName();
}
- if (to != null) {
- config.append("<to>");
- config.append(to);
- config.append("</to>");
- }
- if (subject != null) {
- config.append("<subject>");
- config.append(subject);
- config.append("</subject>");
- }
- if (text != null) {
- config.append("<text>");
- config.append(text);
- config.append("</text>");
- }
- 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("mail.class.name");
- }
-
Delegation delegation = new Delegation(mailClassName);
delegation.setProcessDefinition(processDefinition);
- delegation.setConfiguration(config.toString());
+ delegation.setConfiguration(writeElementContent(config));
return delegation;
}
+ private Delegation createMailDelegation(String template) {
+ Element config = DocumentHelper.createElement("config");
+ config.addElement("template").setText(template);
+ return createMailDelegation(config);
+ }
+
+ /** @deprecated call {@link #readMailDelegation(Element)} instead */
+ public Delegation createMailDelegation(String template, String actors, String to,
+ String subject, String text) {
+ Element config = DocumentHelper.createElement("config");
+ // template
+ if (template != null) config.addElement("template").setText(template);
+ // to - addresses
+ if (to != null) config.addElement("to").setText(to);
+ // to - actors
+ if (actors != null) config.addElement("actors").setText(actors);
+ // subject
+ if (subject != null) config.addElement("subject").setText(subject);
+ // text
+ if (text != null) config.addElement("text").setText(text);
+
+ return createMailDelegation(config);
+ }
+
public Delegation readMailDelegation(Element element) {
- StringBuffer config = new StringBuffer();
+ Element config = DocumentHelper.createElement("config");
// template
String template = element.attributeValue("template");
- if (template != null) {
-
config.append("<template>").append(template).append("</template>");
- }
+ if (template != null) config.addElement("template").setText(template);
// to - addresses
String to = element.attributeValue("to");
- if (to != null) {
- config.append("<to>").append(to).append("</to>");
- }
+ if (to != null) config.addElement("to").setText(to);
// to - actors
String actors = element.attributeValue("actors");
- if (actors != null) {
-
config.append("<actors>").append(actors).append("</actors>");
- }
+ if (actors != null) config.addElement("actors").setText(actors);
// cc - addresses
String cc = element.attributeValue("cc");
- if (cc != null) {
- config.append("<cc>").append(cc).append("</cc>");
- }
+ if (cc != null) config.addElement("cc").setText(cc);
// cc - actors
String ccActors = element.attributeValue("cc-actors");
- if (ccActors != null) {
-
config.append("<ccActors>").append(ccActors).append("</ccActors>");
- }
+ if (ccActors != null) config.addElement("ccActors").setText(ccActors);
// bcc - addresses
- String bcc = element.attributeValue("cc");
- if (bcc != null) {
-
config.append("<bcc>").append(bcc).append("</bcc>");
- }
+ String bcc = element.attributeValue("bcc");
+ if (bcc != null) config.addElement("bcc").setText(bcc);
// bcc - actors
String bccActors = element.attributeValue("bcc-actors");
- if (bccActors != null) {
-
config.append("<bccActors>").append(bccActors).append("</bccActors>");
- }
+ if (bccActors != null)
config.addElement("bccActors").setText("bcc-actors");
// subject
String subject = getProperty("subject", element);
- if (subject != null) {
-
config.append("<subject>").append(subject).append("</subject>");
- }
+ if (subject != null) config.addElement("subject").setText(subject);
// text
String text = getProperty("text", element);
- if (text != null) {
-
config.append("<text>").append(text).append("</text>");
+ if (text != null) config.addElement("text").setText(text);
+
+ return createMailDelegation(config);
+ }
+
+ public String getProperty(String property, Element element) {
+ String propertyAttribute = element.attributeValue(property);
+ if (propertyAttribute == null) {
+ Element propertyElement = element.element(property);
+ if (propertyElement != null) propertyAttribute = propertyElement.getText();
}
+ return propertyAttribute;
+ }
- String mailClassName;
- if (JbpmConfiguration.Configs.hasObject("jbpm.mail.class.name")) {
- mailClassName =
JbpmConfiguration.Configs.getString("jbpm.mail.class.name");
+ private XMLWriter getXmlWriter() {
+ if (xmlWriter == null) {
+ try {
+ // configuration is saved to database, write in a compact format
+ xmlWriter = new XMLWriter(OutputFormat.createCompactFormat());
+ }
+ catch (UnsupportedEncodingException e) {
+ // WTF?
+ throw new JbpmException("failed to create xml writer", e);
+ }
}
- else {
- mailClassName = Mail.class.getName();
+ return xmlWriter;
+ }
+
+ private String writeElement(Element element) {
+ StringWriter stringWriter = new StringWriter();
+ XMLWriter xmlWriter = getXmlWriter();
+ xmlWriter.setWriter(stringWriter);
+ try {
+ xmlWriter.write(element);
}
-
- Delegation delegation = new Delegation(mailClassName);
- delegation.setProcessDefinition(processDefinition);
- delegation.setConfiguration(config.toString());
- return delegation;
+ catch (IOException e) {
+ // cannot happen, writing to memory
+ addError("failed to write mail configuration", e);
+ }
+ return stringWriter.toString();
}
- public String getProperty(String property, Element element) {
- String value = element.attributeValue(property);
- if (value == null) {
- Element propertyElement = element.element(property);
- if (propertyElement != null) {
- value = propertyElement.getText();
+ public String writeElementContent(Element element) {
+ StringWriter stringWriter = new StringWriter();
+ XMLWriter xmlWriter = getXmlWriter();
+ xmlWriter.setWriter(stringWriter);
+ try {
+ for (Iterator i = element.content().iterator(); i.hasNext();) {
+ xmlWriter.write((org.dom4j.Node) i.next());
}
}
- return value;
+ catch (IOException e) {
+ // cannot happen, writing to memory
+ addError("failed to write mail configuration", e);
+ }
+ return stringWriter.toString().trim();
}
}
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlWriter.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlWriter.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlWriter.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -30,10 +30,10 @@
import java.util.List;
import java.util.Map;
+import org.dom4j.Branch;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
-import org.dom4j.Namespace;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
@@ -47,7 +47,6 @@
import org.jbpm.graph.node.ProcessFactory;
import org.jbpm.graph.node.StartState;
import org.jbpm.jpdl.JpdlException;
-import org.jbpm.util.IoUtil;
/**
* Class for writing process definitions to character streams.
@@ -58,12 +57,11 @@
*/
public class JpdlXmlWriter {
- static final String JPDL_NAMESPACE = "http://jbpm.org/3/jpdl";
- static final Namespace jbpmNamespace = new Namespace(null, JPDL_NAMESPACE);
+ private static final String JPDL_NAMESPACE = "urn:jbpm.org:jpdl-3.2";
- Writer writer = null;
- List problems = new ArrayList();
- boolean useNamespace = false;
+ private final Writer writer;
+ private final List problems = new ArrayList();
+ private boolean useNamespace;
public JpdlXmlWriter(Writer writer) {
if (writer == null) throw new JbpmException("writer is null");
@@ -71,7 +69,7 @@
}
public void addProblem(String msg) {
- problems.add(msg);
+ problems.add(new Problem(Problem.LEVEL_ERROR, msg));
}
public static String toString(ProcessDefinition processDefinition) {
@@ -85,77 +83,65 @@
this.useNamespace = useNamespace;
}
- //newElement.add( jbpmNamespace );
-
public void write(ProcessDefinition processDefinition) {
- problems = new ArrayList();
- if (processDefinition == null) throw new JbpmException("processDefinition is
null");
+ if (processDefinition == null) throw new JbpmException("process definition is
null");
+
+ problems.clear();
try {
// collect the actions of the process definition
- // we will remove each named event action and the remaining ones will be written
+ // we will remove each named event action and the remaining ones will be written
// on the process definition.
- // create a dom4j dom-tree for the process definition
Document document = createDomTree(processDefinition);
- // write the dom-tree to the given writer
- OutputFormat outputFormat = new OutputFormat(" ", true);
- // OutputFormat outputFormat = OutputFormat.createPrettyPrint();
- XMLWriter xmlWriter = new XMLWriter(writer, outputFormat);
+ // write the document using the given writer
+ XMLWriter xmlWriter = new XMLWriter(writer, OutputFormat.createPrettyPrint());
xmlWriter.write(document);
xmlWriter.flush();
- writer.flush();
}
catch (IOException e) {
- addProblem("couldn't write process definition xml: " +
e.getMessage());
+ Problem problem = new Problem(Problem.LEVEL_ERROR, "could not write process
definition", e);
+ problems.add(problem);
}
- if (problems.size() > 0) {
- throw new JpdlException(problems);
- }
+ if (problems.size() > 0) throw new JpdlException(problems);
}
private Document createDomTree(ProcessDefinition processDefinition) {
Document document = DocumentHelper.createDocument();
+ Element root = addElement(document, "process-definition");
- Element root;
- if (useNamespace)
- root = document.addElement("process-definition",
jbpmNamespace.getURI());
- else
- root = document.addElement("process-definition");
- addAttribute(root, "name", processDefinition.getName());
+ String value = processDefinition.getName();
+ if (value != null) root.addAttribute("name", value);
// write the start-state
if (processDefinition.getStartState() != null) {
- writeComment(root, "START-STATE");
+ root.addComment("START-STATE");
writeStartNode(root, (StartState) processDefinition.getStartState());
}
// write the nodeMap
- if ((processDefinition.getNodes() != null) &&
(processDefinition.getNodes().size() > 0)) {
- writeComment(root, "NODES");
+ if (processDefinition.getNodes() != null &&
processDefinition.getNodes().size() > 0) {
+ root.addComment("NODES");
writeNodes(root, processDefinition.getNodes());
}
// write the process level actions
if (processDefinition.hasEvents()) {
- writeComment(root, "PROCESS-EVENTS");
+ root.addComment("PROCESS-EVENTS");
writeEvents(root, processDefinition);
}
if (processDefinition.hasActions()) {
- writeComment(root, "ACTIONS");
+ root.addComment("ACTIONS");
List namedProcessActions = getNamedProcessActions(processDefinition.getActions());
writeActions(root, namedProcessActions);
}
- root.addText(IoUtil.lineSeparator);
-
return document;
}
private List getNamedProcessActions(Map actions) {
List namedProcessActions = new ArrayList();
- Iterator iter = actions.values().iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = actions.values().iterator(); iter.hasNext();) {
Action action = (Action) iter.next();
- if ((action.getEvent() == null) && (action.getName() != null)) {
+ if (action.getEvent() == null && action.getName() != null) {
namedProcessActions.add(action);
}
}
@@ -169,8 +155,7 @@
}
private void writeNodes(Element parentElement, Collection nodes) {
- Iterator iter = nodes.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = nodes.iterator(); iter.hasNext();) {
org.jbpm.graph.def.Node node = (org.jbpm.graph.def.Node) iter.next();
if (!(node instanceof StartState)) {
Element nodeElement = addElement(parentElement,
ProcessFactory.getTypeName(node));
@@ -181,15 +166,15 @@
}
private void writeNode(Element element, org.jbpm.graph.def.Node node) {
- addAttribute(element, "name", node.getName());
+ String value = node.getName();
+ if (value != null) element.addAttribute("name", value);
writeTransitions(element, node);
writeEvents(element, node);
}
private void writeTransitions(Element element, org.jbpm.graph.def.Node node) {
if (node.getLeavingTransitionsMap() != null) {
- Iterator iter = node.getLeavingTransitionsList().iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = node.getLeavingTransitionsList().iterator(); iter.hasNext();)
{
Transition transition = (Transition) iter.next();
writeTransition(element.addElement("transition"), transition);
}
@@ -204,15 +189,14 @@
transitionElement.addAttribute("name", transition.getName());
}
Event transitionEvent = transition.getEvent(Event.EVENTTYPE_TRANSITION);
- if ((transitionEvent != null) && (transitionEvent.hasActions())) {
+ if (transitionEvent != null && transitionEvent.hasActions()) {
writeActions(transitionElement, transitionEvent.getActions());
}
}
private void writeEvents(Element element, GraphElement graphElement) {
if (graphElement.hasEvents()) {
- Iterator iter = graphElement.getEvents().values().iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = graphElement.getEvents().values().iterator(); iter.hasNext();)
{
Event event = (Event) iter.next();
writeEvent(element.addElement("event"), event);
}
@@ -222,8 +206,7 @@
private void writeEvent(Element eventElement, Event event) {
eventElement.addAttribute("type", event.getEventType());
if (event.hasActions()) {
- Iterator actionIter = event.getActions().iterator();
- while (actionIter.hasNext()) {
+ for (Iterator actionIter = event.getActions().iterator(); actionIter.hasNext();) {
Action action = (Action) actionIter.next();
writeAction(eventElement, action);
}
@@ -231,8 +214,7 @@
}
private void writeActions(Element parentElement, Collection actions) {
- Iterator actionIter = actions.iterator();
- while (actionIter.hasNext()) {
+ for (Iterator actionIter = actions.iterator(); actionIter.hasNext();) {
Action action = (Action) actionIter.next();
writeAction(parentElement, action);
}
@@ -253,25 +235,12 @@
action.write(actionElement);
}
- private void writeComment(Element element, String comment) {
- element.addText(IoUtil.lineSeparator);
- element.addComment(" " + comment + " ");
+ private Element addElement(Branch parent, String elementName) {
+ return useNamespace ? parent.addElement(elementName, JPDL_NAMESPACE)
+ : parent.addElement(elementName);
}
- private Element addElement(Element element, String elementName) {
- Element newElement = element.addElement(elementName);
- return newElement;
- }
-
- private void addAttribute(Element e, String attributeName, String value) {
- if (value != null) {
- e.addAttribute(attributeName, value);
- }
- }
-
private String getTypeName(Object o) {
return ProcessFactory.getTypeName((org.jbpm.graph.def.Node) o);
}
-
- // private static final Log log = LogFactory.getLog(JpdlXmlWriter.class);
}
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/module/exe/ModuleInstance.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/module/exe/ModuleInstance.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/module/exe/ModuleInstance.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -23,9 +23,9 @@
import java.io.Serializable;
-import org.jbpm.JbpmContext;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.svc.Service;
+import org.jbpm.svc.Services;
public class ModuleInstance implements Serializable {
@@ -58,12 +58,7 @@
}
protected Service getService(String serviceName) {
- Service service = null;
- JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
- if (jbpmContext != null) {
- service = jbpmContext.getServices().getService(serviceName);
- }
- return service;
+ return Services.getCurrentService(serviceName, false);
}
// getters and setters //////////////////////////////////////////////////////
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/msg/MessageService.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/msg/MessageService.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/msg/MessageService.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -21,12 +21,10 @@
*/
package org.jbpm.msg;
-import java.io.Serializable;
-
import org.jbpm.job.Job;
import org.jbpm.svc.Service;
-public interface MessageService extends Service, Serializable {
+public interface MessageService extends Service {
void send(Job job);
void close();
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -50,11 +50,10 @@
import org.jbpm.db.TaskMgmtSession;
import org.jbpm.persistence.JbpmPersistenceException;
import org.jbpm.persistence.PersistenceService;
-import org.jbpm.svc.Service;
import org.jbpm.svc.Services;
import org.jbpm.tx.TxService;
-public class DbPersistenceService implements Service, PersistenceService {
+public class DbPersistenceService implements PersistenceService {
private static final long serialVersionUID = 1L;
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/security/SecurityHelper.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/security/SecurityHelper.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/security/SecurityHelper.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -23,40 +23,32 @@
import java.security.Permission;
-import org.jbpm.JbpmContext;
+import org.jbpm.svc.Services;
/**
- * provides helper methods to access the authentication and authorization
- * services.
+ * provides helper methods to access the authentication and authorization services.
*/
-public abstract class SecurityHelper {
-
+public class SecurityHelper {
+
+ private SecurityHelper() {
+ // hide default constructor to prevent instantiation
+ }
+
/**
- * helper method to look up the authenticated actorId in the current
- * jbpm context.
+ * helper method to look up the authenticated actorId in the current jbpm context.
*/
public static String getAuthenticatedActorId() {
- String actorId = null;
- JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
- if (jbpmContext!=null) {
- AuthenticationService authenticationService =
jbpmContext.getServices().getAuthenticationService();
- if (authenticationService!=null) {
- actorId = authenticationService.getActorId();
- }
- }
- return actorId;
+ AuthenticationService authService = (AuthenticationService)
+ Services.getCurrentService(Services.SERVICENAME_AUTHENTICATION, false);
+ return authService != null ? authService.getActorId() : null;
}
-
+
/**
* helper method to check the permissions of a jbpm secured operation.
*/
public static void checkPermission(Permission permission) {
- JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
- if (jbpmContext!=null) {
- AuthorizationService authorizationService =
jbpmContext.getServices().getAuthorizationService();
- if (authorizationService!=null) {
- authorizationService.checkPermission(permission);
- }
- }
+ AuthorizationService authService = (AuthorizationService)
+ Services.getCurrentService(Services.SERVICENAME_AUTHORIZATION, false);
+ if (authService != null) authService.checkPermission(permission);
}
}
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/security/authentication/DefaultAuthenticationService.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/security/authentication/DefaultAuthenticationService.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/security/authentication/DefaultAuthenticationService.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -27,8 +27,8 @@
private static final long serialVersionUID = 1L;
- String actorId = null;
-
+ private String actorId;
+
public void setActorId(String actorId) {
this.actorId = actorId;
}
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/Services.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/Services.java 2010-12-03
17:32:13 UTC (rev 6860)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/Services.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -267,16 +267,11 @@
return DbPersistenceService.isLockingException(persistenceException);
}
+ /** assigns an identifier to the given object */
public static void assignId(Object object) {
- JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
- if (jbpmContext != null) {
- // assign id to the given object
- Services services = jbpmContext.getServices();
- if (services.hasService(Services.SERVICENAME_PERSISTENCE)) {
- PersistenceService persistenceService = services.getPersistenceService();
- persistenceService.assignId(object);
- }
- }
+ PersistenceService service =
+ (PersistenceService) Services.getCurrentService(SERVICENAME_PERSISTENCE, false);
+ if (service != null) service.assignId(object);
}
private static final Log log = LogFactory.getLog(Services.class);
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/taskmgmt/exe/SwimlaneInstance.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/taskmgmt/exe/SwimlaneInstance.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/taskmgmt/exe/SwimlaneInstance.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -21,7 +21,6 @@
*/
package org.jbpm.taskmgmt.exe;
-import java.io.Serializable;
import java.util.Set;
import org.jbpm.taskmgmt.def.Swimlane;
@@ -29,7 +28,7 @@
/**
* is a process role for a one process instance.
*/
-public class SwimlaneInstance implements Serializable, Assignable {
+public class SwimlaneInstance implements Assignable {
private static final long serialVersionUID = 1L;
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/util/JndiUtil.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/util/JndiUtil.java 2010-12-03
17:32:13 UTC (rev 6860)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/util/JndiUtil.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -28,8 +28,7 @@
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
-import org.jbpm.JbpmContext;
-import org.jbpm.configuration.ObjectFactory;
+import org.jbpm.JbpmConfiguration.Configs;
public class JndiUtil {
@@ -47,17 +46,16 @@
}
private static Object lookup(String jndiName) throws NamingException {
- Properties jndiProperties = null;
- JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
- if (jbpmContext != null) {
- ObjectFactory objectFactory = jbpmContext.getObjectFactory();
- if (objectFactory.hasObject("resource.jndi.properties")) {
- String jndiResource = (String)
objectFactory.createObject("resource.jndi.properties");
- jndiProperties = ClassLoaderUtil.getProperties(jndiResource);
- }
+ Context initialContext;
+ if (Configs.hasObject("resource.jndi.properties")) {
+ String resource = Configs.getString("resource.jndi.properties");
+ Properties properties = ClassLoaderUtil.getProperties(resource);
+ initialContext = new InitialContext(properties);
}
+ else {
+ initialContext = new InitialContext();
+ }
- Context initialContext = new InitialContext(jndiProperties);
try {
return initialContext.lookup(jndiName);
}
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -13,8 +13,8 @@
import org.jbpm.util.ClassLoaderUtil;
/**
- * Test case for ProcessClassLoader hierarchy and setting the ContextClassLoader
- * correctly. Relates to {@link ConfigurableClassLoadersTest}.
+ * Test case for ProcessClassLoader hierarchy and setting the ContextClassLoader
correctly.
+ * Relates to {@link ConfigurableClassLoadersTest}.
*
* @author Tom Baeyens
* @author bernd.ruecker(a)camunda.com
@@ -52,9 +52,9 @@
}
/*
- * DOES NOT configure usage of the context classloader. So this tests the
- * default (backwards compatible) behaviour. so the classloading hierarchy of
- * DefaultLoadedAction should be ProcessClassloader -> jbpm-lib classloader
+ * DOES NOT configure usage of the context classloader. So this tests the default
(backwards
+ * compatible) behaviour. so the classloading hierarchy of DefaultLoadedAction should
be
+ * ProcessClassloader -> jbpm-lib classloader
*/
public void testDefaultClassLoader() {
ProcessDefinition processDefinition =
ProcessDefinition.parseXmlString("<process-definition>"
@@ -93,13 +93,13 @@
}
}
- /*
- * configures usage of the context classloader so the classloading hierarchy
- * of ContextLoadedAction should be ProcessClassloader ->
- * TestContextClassLoader -> Thread.currentContextClassLoader
+ /**
+ * configures usage of the context class loader. the classloading hierarchy of
+ * ContextLoadedAction will be ProcessClassLoader -> TestClassLoader ->
originalClassLoader
*/
public void testContextClassLoader() {
JbpmConfiguration jbpmConfiguration =
JbpmConfiguration.parseXmlString("<jbpm-configuration>"
+ + " <jbpm-context />"
+ " <string name='jbpm.class.loader' value='context'
/>"
+ "</jbpm-configuration>");
@@ -135,10 +135,9 @@
}
/*
- * a third test should set the testcontextClassLoader in the test and then let
- * the action throw an exception. Then it should be verified that the original
- * classloader is still restored correctly. Easiest is to start from a copy of
- * the testContextClassLoader
+ * a third test should set the testcontextClassLoader in the test and then let the
action
+ * throw an exception. Then it should be verified that the original classloader is
still
+ * restored correctly. Easiest is to start from a copy of the testContextClassLoader
*/
public static class ContextLoadedExceptionAction implements ActionHandler {
@@ -160,6 +159,7 @@
public void testContextClassLoaderException() {
JbpmConfiguration jbpmConfiguration =
JbpmConfiguration.parseXmlString("<jbpm-configuration>"
+ + " <jbpm-context />"
+ " <string name='jbpm.class.loader' value='context'
/>"
+ "</jbpm-configuration>");
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/persistence/db/MockSession.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/persistence/db/MockSession.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/persistence/db/MockSession.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -16,13 +16,12 @@
import org.hibernate.Query;
import org.hibernate.ReplicationMode;
import org.hibernate.SQLQuery;
-import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.stat.SessionStatistics;
import org.hibernate.type.Type;
-public class MockSession implements Session, org.hibernate.classic.Session {
+public class MockSession implements org.hibernate.classic.Session {
private static final long serialVersionUID = 1L;
@@ -89,7 +88,7 @@
throw new UnsupportedOperationException();
}
- public Session getSession(EntityMode entityMode) {
+ public org.hibernate.Session getSession(EntityMode entityMode) {
throw new UnsupportedOperationException();
}
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/taskmgmt/exe/TaskAssignmentTest.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/taskmgmt/exe/TaskAssignmentTest.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/taskmgmt/exe/TaskAssignmentTest.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -35,12 +35,11 @@
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.security.authentication.DefaultAuthenticationServiceFactory;
import org.jbpm.taskmgmt.def.AssignmentHandler;
public class TaskAssignmentTest extends AbstractJbpmTestCase {
- static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
-
public static class TestAssignmentHandler implements AssignmentHandler {
private static final long serialVersionUID = 1L;
public void assign(Assignable assignable, ExecutionContext executionContext) throws
Exception {
@@ -175,6 +174,15 @@
}
public void testStartTaskSwimlaneAssignmentTest() {
+ JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
+ "<jbpm-configuration>" +
+ " <jbpm-context>" +
+ " <service name='authentication' factory='" +
+ DefaultAuthenticationServiceFactory.class.getName() +
+ "' />" +
+ " </jbpm-context>" +
+ "</jbpm-configuration>");
+
ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
"<process-definition>" +
" <swimlane name='initiator' />" +
@@ -196,10 +204,10 @@
} finally {
jbpmContext.setActorId(null);
jbpmContext.close();
+ jbpmConfiguration.close();
}
SwimlaneInstance swimlaneInstance =
taskMgmtInstance.getSwimlaneInstance("initiator");
- assertNotNull(swimlaneInstance);
assertEquals("user", swimlaneInstance.getActorId());
}
Modified:
jbpm3/branches/jbpm-3.2-soa/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java 2010-12-03
17:32:13 UTC (rev 6860)
+++
jbpm3/branches/jbpm-3.2-soa/enterprise/src/main/java/org/jbpm/msg/jms/JmsMessageServiceFactory.java 2010-12-03
21:11:52 UTC (rev 6861)
@@ -69,7 +69,6 @@
// set to current context
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
if (jbpmContext == null) throw new JbpmException("no active jbpm
context");
- assert this == jbpmContext.getServiceFactory(Services.SERVICENAME_MESSAGE) :
jbpmContext.getServiceFactory(Services.SERVICENAME_MESSAGE);
jbpmConfiguration = jbpmContext.getJbpmConfiguration();
}
return jbpmConfiguration;