📄 jpdlxmlreader.java
字号:
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.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) {
// get the action name
String name = nodeElement.attributeValue("name");
if (name!=null) {
node.setName(name);
}
String asyncText = nodeElement.attributeValue("async");
if ("true".equalsIgnoreCase(asyncText)) {
node.setAsync(true);
}
// add the node to the parent
nodeCollection.addNode(node);
// 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("timer");
while (iter.hasNext()) {
Element timerElement = (Element) iter.next();
readTaskTimer(timerElement, 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);
createTimerAction.setTimerAction(readSingleAction(timerElement));
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());
}
} else {
// set the default
cancelEventTypes.add(Event.EVENTTYPE_TASK_END);
}
Iterator iter = cancelEventTypes.iterator();
while (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()) {
Element eventElement = (Element) iter.next();
String eventType = eventElement.attributeValue("type");
if (!graphElement.hasEvent(eventType)) {
graphElement.addEvent(new Event(eventType));
}
readActions(eventElement, graphElement, 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();
String actionName = actionElement.getName();
if (ActionTypes.hasActionName(actionName)) {
Action action = createAction(actionElement);
if ( (graphElement!=null)
&& (eventType!=null)
) {
// add the action to the event
addAction(graphElement, eventType, action);
}
}
}
}
protected void addAction(GraphElement graphElement, String eventType, Action action) {
Event event = graphElement.getEvent(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)) {
Element candidate = (Element) iter.next();
if (ActionTypes.hasActionName(candidate.getName())) {
// parse the action and assign it to this node
action = createAction(candidate);
}
}
return action;
}
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);
}
// read the common node parts of the action
readAction(actionElement, action);
return action;
}
public void readAction(Element element, Action action) {
// if a name is specified for this action
String actionName = element.attributeValue("name");
if (actionName!=null) {
action.setName(actionName);
// 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)
action.read(element, this);
}
protected void readExceptionHandlers(Element graphElementElement, GraphElement graphElement) {
Iterator iter = graphElementElement.elementIterator("exception-handler");
while (iter.hasNext()) {
Element exceptionHandlerElement = (Element) iter.next();
readExceptionHandler(exceptionHandlerElement, graphElement);
}
}
protected void readExceptionHandler(Element exceptionHandlerElement, GraphElement graphElement) {
// create the exception handler
ExceptionHandler exceptionHandler = new ExceptionHandler();
exceptionHandler.setExceptionClassName(exceptionHandlerElement.attributeValue("exception-class"));
// add it to the graph element
graphElement.addExceptionHandler(exceptionHandler);
// read the actions in the body of the exception-handler element
Iterator iter = exceptionHandlerElement.elementIterator();
while (iter.hasNext()) {
Element childElement = (Element) iter.next();
if (ActionTypes.hasActionName(childElement.getName())) {
Action action = createAction(childElement);
exceptionHandler.addAction(action);
}
}
}
// transition destinations are parsed in a second pass //////////////////////
public void addUnresolvedTransitionDestination(Element nodeElement, Node node) {
unresolvedTransitionDestinations.add(new Object[]{nodeElement, node});
}
public void resolveTransitionDestinations() {
Iterator iter = unresolvedTransitionDestinations.iterator();
while (iter.hasNext()) {
Object[] unresolvedTransition = (Object[]) iter.next();
Element nodeElement = (Element) unresolvedTransition[0];
Node node = (Node) unresolvedTransition[1];
resolveTransitionDestinations(nodeElement.elements("transition"), node);
}
}
public void resolveTransitionDestinations(List transitionElements, Node node) {
Iterator iter = transitionElements.iterator();
while (iter.hasNext()) {
Element transitionElement = (Element) iter.next();
resolveTransitionDestination(transitionElement, node);
}
}
public void resolveTransitionDestination(Element transitionElement, Node node) {
Transition transition = new Transition();
transition.setProcessDefinition(processDefinition);
// get the action name
String name = transitionElement.attributeValue("name");
if (name!=null) {
transition.setName(name);
}
// add the transition to the node
node.addLeavingTransition(transition);
// 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 {
to.addArrivingTransition(transition);
}
}
// read the actions
readActions(transitionElement, transition, Event.EVENTTYPE_TRANSITION);
readExceptionHandlers(transitionElement, transition);
}
// action references are parsed in a second pass ////////////////////////////
public void addUnresolvedActionReference(Element actionElement, Action action) {
unresolvedActionReferences.add(new Object[]{actionElement, action});
}
public void resolveActionReferences() {
Iterator iter = unresolvedActionReferences.iterator();
while (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.setReferencedAction(referencedAction);
}
}
// 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()) {
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");
}
}
}
}
private static final Log log = LogFactory.getLog(JpdlXmlReader.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -