📄 node.java
字号:
public Set getArrivingTransitions() {
return arrivingTransitions;
}
/**
* add a bidirection relation between this node and the given arriving
* transition.
* @throws IllegalArgumentException if t is null.
*/
public Transition addArrivingTransition(Transition arrivingTransition) {
if (arrivingTransition == null) throw new IllegalArgumentException("can't add a null arrivingTransition to a node");
if (arrivingTransitions == null) arrivingTransitions = new HashSet();
arrivingTransitions.add(arrivingTransition);
arrivingTransition.to = this;
return arrivingTransition;
}
/**
* removes the bidirection relation between this node and the given arriving
* transition.
* @throws IllegalArgumentException if t is null.
*/
public void removeArrivingTransition(Transition arrivingTransition) {
if (arrivingTransition == null) throw new IllegalArgumentException("can't remove a null arrivingTransition from a node");
if (arrivingTransitions != null) {
if (arrivingTransitions.remove(arrivingTransition)) {
arrivingTransition.to = null;
}
}
}
// various //////////////////////////////////////////////////////////////////
/**
* is the {@link SuperState} or the {@link ProcessDefinition} in which this
* node is contained.
*/
public GraphElement getParent() {
GraphElement parent = processDefinition;
if (superState!=null) parent = superState;
return parent;
}
// behaviour methods ////////////////////////////////////////////////////////
/**
* called by a transition to pass execution to this node.
*/
public void enter(ExecutionContext executionContext) {
Token token = executionContext.getToken();
// update the runtime context information
token.setNode(this);
// fire the leave-node event for this node
fireEvent(Event.EVENTTYPE_NODE_ENTER, executionContext);
// keep track of node entrance in the token, so that a node-log can be generated at node leave time.
token.setNodeEnter(Clock.getCurrentTime());
// remove the transition references from the runtime context
executionContext.setTransition(null);
executionContext.setTransitionSource(null);
// execute the node
if (isAsync) {
ExecuteNodeJob job = createAsyncContinuationJob(token);
MessageService messageService = (MessageService) Services.getCurrentService(Services.SERVICENAME_MESSAGE);
messageService.send(job);
token.lock(job.toString());
} else {
execute(executionContext);
}
}
protected ExecuteNodeJob createAsyncContinuationJob(Token token) {
ExecuteNodeJob job = new ExecuteNodeJob(token);
job.setNode(this);
job.setDueDate(new Date());
job.setExclusive(isAsyncExclusive);
return job;
}
/**
* override this method to customize the node behaviour.
*/
public void execute(ExecutionContext executionContext) {
// if there is a custom action associated with this node
if (action!=null) {
try {
// execute the action
executeAction(action, executionContext);
} catch (Exception exception) {
// NOTE that Error's are not caught because that might halt the JVM and mask the original Error.
// search for an exception handler or throw to the client
raiseException(exception, executionContext);
}
} else {
// let this node handle the token
// the default behaviour is to leave the node over the default transition.
leave(executionContext);
}
}
/**
* called by the implementation of this node to continue execution over the default transition.
*/
public void leave(ExecutionContext executionContext) {
leave(executionContext, getDefaultLeavingTransition());
}
/**
* called by the implementation of this node to continue execution over the specified transition.
*/
public void leave(ExecutionContext executionContext, String transitionName) {
Transition transition = getLeavingTransition(transitionName);
if (transition==null) {
throw new JbpmException("transition '"+transitionName+"' is not a leaving transition of node '"+this+"'");
}
leave(executionContext, transition);
}
/**
* called by the implementation of this node to continue execution over the given transition.
*/
public void leave(ExecutionContext executionContext, Transition transition) {
if (transition==null) throw new JbpmException("can't leave node '"+this+"' without leaving transition");
Token token = executionContext.getToken();
token.setNode(this);
executionContext.setTransition(transition);
// fire the leave-node event for this node
fireEvent(Event.EVENTTYPE_NODE_LEAVE, executionContext);
// log this node
if (token.getNodeEnter()!=null) {
addNodeLog(token);
}
// update the runtime information for taking the transition
// the transitionSource is used to calculate events on superstates
executionContext.setTransitionSource(this);
// take the transition
transition.take(executionContext);
}
protected void addNodeLog(Token token) {
token.addLog(new NodeLog(this, token.getNodeEnter(), Clock.getCurrentTime()));
}
/////////////////////////////////////////////////////////////////////////////
public ProcessDefinition getProcessDefinition() {
ProcessDefinition pd = this.processDefinition;
if (superState!=null) {
pd = superState.getProcessDefinition();
}
return pd;
}
// change the name of a node ////////////////////////////////////////////////
/**
* updates the name of this node
*/
public void setName(String name) {
if (isDifferent(this.name, name)) {
String oldName = this.name;
if (superState!=null) {
if ( superState.hasNode(name) ) {
throw new IllegalArgumentException("couldn't set name '"+name+"' on node '"+this+"'cause the superState of this node has already another child node with the same name");
}
Map nodes = superState.getNodesMap();
nodes.remove(oldName);
nodes.put(name,this);
} else if (processDefinition!=null) {
if ( processDefinition.hasNode(name) ) {
throw new IllegalArgumentException("couldn't set name '"+name+"' on node '"+this+"'cause the process definition of this node has already another node with the same name");
}
Map nodeMap = processDefinition.getNodesMap();
nodeMap.remove(oldName);
nodeMap.put(name,this);
}
this.name = name;
}
}
boolean isDifferent(String name1, String name2) {
if ((name1!=null)
&& (name1.equals(name2))) {
return false;
} else if ( (name1==null)
&& (name2==null) ) {
return false;
}
return true;
}
/**
* the slash separated name that includes all the superstate names.
*/
public String getFullyQualifiedName() {
String fullyQualifiedName = name;
if (superState!=null) {
fullyQualifiedName = superState.getFullyQualifiedName()+"/"+name;
}
return fullyQualifiedName;
}
/** indicates wether this node is a superstate. */
public boolean isSuperStateNode() {
return false;
}
/** returns a list of child nodes (only applicable for {@link SuperState})s. */
public List getNodes() {
return null;
}
// getters and setters //////////////////////////////////////////////////////
public SuperState getSuperState() {
return superState;
}
public Action getAction() {
return action;
}
public void setAction(Action action) {
this.action = action;
}
public boolean isAsync() {
return isAsync;
}
public void setAsync(boolean isAsync) {
this.isAsync = isAsync;
}
public boolean isAsyncExclusive() {
return isAsyncExclusive;
}
public void setAsyncExclusive(boolean isAsyncExclusive) {
this.isAsyncExclusive = isAsyncExclusive;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -