📄 jpdlxmlreader.java
字号:
String description = taskElement.elementTextTrim("description");
if (description!=null) {
task.setDescription(description);
} else {
task.setDescription(taskElement.attributeValue("description"));
}
// get the condition
String condition = taskElement.elementTextTrim("condition");
if (condition!=null) {
task.setCondition(condition);
} else {
task.setCondition(taskElement.attributeValue("condition"));
}
// parse common subelements
readTaskTimers(taskElement, task);
readEvents(taskElement, task);
readExceptionHandlers(taskElement, task);
// duedate and priority
String duedateText = taskElement.attributeValue("duedate");
if (duedateText==null) {
duedateText = taskElement.attributeValue("dueDate");
}
task.setDueDate(duedateText);
String priorityText = taskElement.attributeValue("priority");
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);
}
// blocking
String blockingText = taskElement.attributeValue("blocking");
if (blockingText!=null) {
if ( ("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);
}
}
// assignment
String swimlaneName = taskElement.attributeValue("swimlane");
Element assignmentElement = taskElement.element("assignment");
// if there is a swimlane attribute specified
if (swimlaneName!=null) {
Swimlane swimlane = taskMgmtDefinition.getSwimlane(swimlaneName);
if (swimlane==null) {
addWarning("task references unknown swimlane '"+swimlaneName+"':"+taskElement.asXML());
} 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)
) {
task.setActorIdExpression(assignmentElement.attributeValue("actor-id"));
task.setPooledActorsExpression(assignmentElement.attributeValue("pooled-actors"));
} 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 warn him/her.
addWarning("warning: no swimlane or assignment specified for task '"+taskElement.asXML()+"'");
}
// notify
String notificationsText = taskElement.attributeValue("notify");
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) {
event = new Event(notificationEvent);
task.addEvent(event);
}
Delegation delegation = createMailDelegation(notificationEvent, null, null, null, null);
Action action = new Action(delegation);
action.setProcessDefinition(processDefinition);
action.setName(task.getName());
event.addAction(action);
}
// task controller
Element taskControllerElement = taskElement.element("controller");
if (taskControllerElement!=null) {
task.setTaskController(readTaskController(taskControllerElement));
}
return task;
}
protected Delegation readAssignmentDelegation(Element assignmentElement) {
Delegation assignmentDelegation = new Delegation();
String expression = assignmentElement.attributeValue("expression");
String actorId = assignmentElement.attributeValue("actor-id");
String pooledActors = assignmentElement.attributeValue("pooled-actors");
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.setProcessDefinition(processDefinition);
assignmentDelegation.setClassName("org.jbpm.taskmgmt.assignment.ActorAssignmentHandler");
String configuration = "";
if (actorId!=null) {
configuration += "<actorId>"+actorId+"</actorId>";
}
if (pooledActors!=null) {
configuration += "<pooledActors>"+pooledActors+"</pooledActors>";
}
assignmentDelegation.setConfiguration(configuration);
} else {
assignmentDelegation = new Delegation();
assignmentDelegation.read(assignmentElement, this);
}
return assignmentDelegation;
}
protected TaskController readTaskController(Element taskControllerElement) {
TaskController taskController = new TaskController();
if (taskControllerElement.attributeValue("class")!=null) {
Delegation taskControllerDelegation = new Delegation();
taskControllerDelegation.read(taskControllerElement, this);
taskController.setTaskControllerDelegation(taskControllerDelegation);
} 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()) {
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()));
}
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();
Task startTask = readTask(startTaskElement, taskMgmtDefinition, null);
startTask.setStartState(startState);
if (startTask.getName()==null) {
startTask.setName(startState.getName());
}
taskMgmtDefinition.setStartTask(startTask);
}
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
// processDefinitions and nodes contained in superstates
nodeCollection.addNode(node);
// get the node name
String name = nodeElement.attributeValue("name");
if (name!=null) {
node.setName(name);
// check if this is the initial node
if ( (initialNodeName!=null)
&& (initialNodeName.equals(node.getFullyQualifiedName()))
) {
processDefinition.setStartState(node);
}
}
// get the node description
String description = nodeElement.elementTextTrim("description");
if (description!=null) {
node.setDescription(description);
}
String asyncText = nodeElement.attributeValue("async");
if ("true".equalsIgnoreCase(asyncText)) {
node.setAsync(true);
} else if ("exclusive".equalsIgnoreCase(asyncText)) {
node.setAsync(true);
node.setAsyncExclusive(true);
}
// parse common subelements
readNodeTimers(nodeElement, node);
readEvents(nodeElement, node);
readExceptionHandlers(nodeElement, node);
// save the transitions and parse them at the end
addUnresolvedTransitionDestination(nodeElement, node);
}
protected void readNodeTimers(Element nodeElement, Node node) {
Iterator iter = nodeElement.elementIterator("timer");
while (iter.hasNext()) {
Element timerElement = (Element) iter.next();
readNodeTimer(timerElement, node);
}
}
protected void readNodeTimer(Element timerElement, Node node) {
String name = timerElement.attributeValue("name", node.getName());
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);
}
protected void readTaskTimers(Element taskElement, Task task) {
Iterator iter = taskElement.elementIterator();
while (iter.hasNext()) {
Element element = (Element) iter.next();
if ( ("timer".equals(element.getName()))
|| ("reminder".equals(element.getName()))
) {
readTaskTimer(element, task);
}
}
}
protected void readTaskTimer(Element timerElement, Task task) {
String name = timerElement.attributeValue("name", task.getName());
if (name==null) name = "timer-for-task-"+task.getId();
CreateTimerAction createTimerAction = new CreateTimerAction();
createTimerAction.read(timerElement, this);
createTimerAction.setTimerName(name);
Action action = null;
if ("timer".equals(timerElement.getName())) {
action = readSingleAction(timerElement);
} else {
Delegation delegation = createMailDelegation("task-reminder", null, null, null, null);
action = new Action(delegation);
}
createTimerAction.setTimerAction(action);
addAction(task, Event.EVENTTYPE_TASK_CREATE, createTimerAction);
// read the cancel-event types
Collection cancelEventTypes = new ArrayList();
String cancelEventTypeText = timerElement.attributeValue("cancel-event");
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());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -