📄 jpdlxmlreader.java
字号:
}
} 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);
transition.setName(transitionElement.attributeValue("name"));
transition.setDescription(transitionElement.elementTextTrim("description"));
String condition = transitionElement.attributeValue("condition");
if (condition==null) {
Element conditionElement = transitionElement.element("condition");
if (conditionElement!=null) {
condition = conditionElement.getTextTrim();
// for backwards compatibility
if ( (condition==null)
|| (condition.length()==0)
) {
condition = conditionElement.attributeValue("expression");
}
}
}
transition.setCondition(condition);
// 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");
}
}
}
}
// mail delegations /////////////////////////////////////////////////////////
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>");
}
if (actors!=null) {
config.append("<actors>");
config.append(actors);
config.append("</actors>");
}
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());
return delegation;
}
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();
}
}
return value;
}
private static final Log log = LogFactory.getLog(JpdlXmlReader.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -