001: package org.emforge.jbpm.parser;
002:
003: import java.io.Reader;
004:
005: import org.dom4j.Element;
006: import org.emforge.jbpm.BpmSystemRole;
007: import org.jbpm.graph.node.TaskNode;
008: import org.jbpm.instantiation.Delegation;
009: import org.jbpm.jpdl.xml.JpdlXmlReader;
010: import org.jbpm.jpdl.xml.ProblemListener;
011: import org.jbpm.taskmgmt.def.Swimlane;
012: import org.jbpm.taskmgmt.def.Task;
013: import org.jbpm.taskmgmt.def.TaskMgmtDefinition;
014: import org.xml.sax.InputSource;
015:
016: /**
017: *
018: */
019: public class EmForgeJpdlReader extends JpdlXmlReader {
020:
021: private static final long serialVersionUID = -7785137528064121736L;
022:
023: /**
024: * @param inputSource
025: */
026: public EmForgeJpdlReader(InputSource inputSource) {
027:
028: super (inputSource);
029: }
030:
031: /**
032: * @param inputSource
033: * @param problemListener
034: */
035: public EmForgeJpdlReader(InputSource inputSource,
036: ProblemListener problemListener) {
037:
038: super (inputSource, problemListener);
039: }
040:
041: /**
042: * @param reader
043: */
044: public EmForgeJpdlReader(Reader reader) {
045:
046: super (reader);
047: }
048:
049: /**
050: * @see org.jbpm.jpdl.xml.JpdlXmlReader#readTask(org.dom4j.Element, org.jbpm.taskmgmt.def.TaskMgmtDefinition, org.jbpm.graph.node.TaskNode)
051: */
052: @Override
053: public Task readTask(Element taskElement,
054: TaskMgmtDefinition taskMgmtDefinition, TaskNode taskNode) {
055:
056: Task task = new Task();
057: task.setProcessDefinition(processDefinition);
058:
059: // get the task name
060: String name = taskElement.attributeValue("name");
061: if (name != null) {
062: task.setName(name);
063: taskMgmtDefinition.addTask(task);
064: } else if (taskNode != null) {
065: task.setName(taskNode.getName());
066: taskMgmtDefinition.addTask(task);
067: }
068:
069: // parse common subelements
070: readTaskTimers(taskElement, task);
071: readEvents(taskElement, task);
072: readExceptionHandlers(taskElement, task);
073:
074: // description and duration
075: task.setDescription(taskElement.attributeValue("description"));
076: String duedateText = taskElement.attributeValue("duedate");
077: if (duedateText == null) {
078: duedateText = taskElement.attributeValue("dueDate");
079: }
080: task.setDueDate(duedateText);
081: String priorityText = taskElement.attributeValue("priority");
082: if (priorityText != null) {
083: task.setPriority(Task.parsePriority(priorityText));
084: }
085:
086: // if this task is in the context of a taskNode, associate them
087: if (taskNode != null) {
088: taskNode.addTask(task);
089: }
090:
091: // blocking
092: String blockingText = taskElement.attributeValue("blocking");
093: if (blockingText != null) {
094: if (("true".equalsIgnoreCase(blockingText))
095: || ("yes".equalsIgnoreCase(blockingText))
096: || ("on".equalsIgnoreCase(blockingText))) {
097: task.setBlocking(true);
098: }
099: }
100:
101: // signalling
102: String signallingText = taskElement
103: .attributeValue("signalling");
104: if (signallingText != null) {
105: if (("false".equalsIgnoreCase(signallingText))
106: || ("no".equalsIgnoreCase(signallingText))
107: || ("off".equalsIgnoreCase(signallingText))) {
108: task.setSignalling(false);
109: }
110: }
111:
112: // assignment
113: String swimlaneName = taskElement.attributeValue("swimlane");
114: Element assignmentElement = taskElement.element("assignment");
115:
116: // if there is a swimlane attribute specified
117: if (swimlaneName != null) {
118: Swimlane swimlane = taskMgmtDefinition
119: .getSwimlane(swimlaneName);
120: if (swimlane == null) {
121: // if swimlane is not exists: create it
122: swimlane = new Swimlane(swimlaneName);
123: taskMgmtDefinition.addSwimlane(swimlane);
124: }
125:
126: // if delegation is not specified - set default EmForge delegation
127: if (swimlane.getActorIdExpression() == null
128: && swimlane.getAssignmentDelegation() == null) {
129: if (swimlaneName.equals(BpmSystemRole.OWNER
130: .getRoleName())) {
131: swimlane
132: .setAssignmentDelegation(createSpringDelegation("assignToProcessOwner"));
133: } else {
134: swimlane
135: .setAssignmentDelegation(createSpringDelegation("assignToSwimlane"));
136: }
137: }
138:
139: task.setSwimlane(swimlane);
140:
141: // else if there is a direct assignment specified
142: } else if (assignmentElement != null) {
143: if ((assignmentElement.attribute("actor-id") != null)
144: || (assignmentElement.attribute("pooled-actors") != null)) {
145: task.setActorIdExpression(assignmentElement
146: .attributeValue("actor-id"));
147: task.setPooledActorsExpression(assignmentElement
148: .attributeValue("pooled-actors"));
149:
150: } else {
151: Delegation assignmentDelegation = readAssignmentDelegation(assignmentElement);
152: task.setAssignmentDelegation(assignmentDelegation);
153: }
154:
155: // if no assignment or swimlane is specified
156: } else {
157: // the user has to manage assignment manually, so we better warn him/her.
158: addWarning("warning: no swimlane or assignment specified for task '"
159: + taskElement.asXML() + "'");
160: }
161:
162: // task controller
163: Element taskControllerElement = taskElement
164: .element("controller");
165: if (taskControllerElement != null) {
166: task
167: .setTaskController(readTaskController(taskControllerElement));
168: }
169:
170: return task;
171: }
172:
173: /**
174: * @param i_beanName
175: * @return
176: */
177: public static Delegation createSpringDelegation(String i_beanName) {
178:
179: Delegation delegation = new Delegation(
180: "org.springmodules.workflow.jbpm31.JbpmHandler");
181: delegation.setConfigType("bean");
182: delegation
183: .setConfiguration("<beanName>"
184: + i_beanName
185: + "</beanName><factoryKey>jbpmConfiguration</factoryKey>");
186:
187: return delegation;
188: }
189:
190: }
|