📄 graphelement.java
字号:
// is already locked, the token doesn't need to be locked.
boolean actionMustBeLocked = (executionContext.getEvent()!=null)
&& (!token.isLocked());
try {
// update the execution context
executionContext.setAction(action);
// execute the action
log.debug("executing action '"+action+"'");
String lockOwnerId = "token["+token.getId()+"]";
try {
if (actionMustBeLocked) {
token.lock(lockOwnerId);
}
if (UserCodeInterceptorConfig.userCodeInterceptor!=null) {
UserCodeInterceptorConfig.userCodeInterceptor.executeAction(action, executionContext);
} else {
action.execute(executionContext);
}
} finally {
if (actionMustBeLocked) {
token.unlock(lockOwnerId);
}
}
} catch (Exception exception) {
// NOTE that Error's are not caught because that might halt the JVM and mask the original Error.
log.error("action threw exception: "+exception.getMessage(), exception);
// log the action exception
actionLog.setException(exception);
// if an exception handler is available
raiseException(exception, executionContext);
} finally {
executionContext.setAction(null);
token.endCompositeLog();
}
}
List getRuntimeActionsForEvent(ExecutionContext executionContext, String eventType) {
List runtimeActionsForEvent = null;
List runtimeActions = executionContext.getProcessInstance().getRuntimeActions();
if (runtimeActions!=null) {
Iterator iter = runtimeActions.iterator();
while (iter.hasNext()) {
RuntimeAction runtimeAction = (RuntimeAction) iter.next();
// if the runtime-action action is registered on this element and this eventType
if ( (this.equals(runtimeAction.getGraphElement()))
&& (eventType.equals(runtimeAction.getEventType()))
) {
// ... add its action to the list of runtime actions
if (runtimeActionsForEvent==null) runtimeActionsForEvent = new ArrayList();
runtimeActionsForEvent.add(runtimeAction.getAction());
}
}
}
return runtimeActionsForEvent;
}
/*
// the next instruction merges the actions specified in the process definition with the runtime actions
List actions = event.collectActions(executionContext);
// loop over all actions of this event
Iterator iter = actions.iterator();
while (iter.hasNext()) {
Action action = (Action) iter.next();
executionContext.setAction(action);
if ( (!isPropagated)
|| (action.acceptsPropagatedEvents() ) ) {
// create action log
ActionLog actionLog = new ActionLog(action);
executionContext.getToken().startCompositeLog(actionLog);
try {
// execute the action
action.execute(executionContext);
} catch (Exception exception) {
// NOTE that Error's are not caught because that might halt the JVM and mask the original Error.
Event.log.error("action threw exception: "+exception.getMessage(), exception);
// log the action exception
actionLog.setException(exception);
// if an exception handler is available
event.graphElement.raiseException(exception, executionContext);
} finally {
executionContext.getToken().endCompositeLog();
}
}
}
}
*/
/**
* throws an ActionException if no applicable exception handler is found.
* An ExceptionHandler is searched for in this graph element and then recursively up the
* parent hierarchy.
* If an exception handler is found, it is applied. If the exception handler does not
* throw an exception, the exception is considered handled. Otherwise the search for
* an applicable exception handler continues where it left of with the newly thrown
* exception.
*/
public void raiseException(Throwable exception, ExecutionContext executionContext) throws DelegationException {
boolean isHandled = false;
if (exceptionHandlers!=null) {
try {
ExceptionHandler exceptionHandler = findExceptionHandler(exception);
if (exceptionHandler!=null) {
executionContext.setException(exception);
exceptionHandler.handleException(this, executionContext);
isHandled = true;
}
} catch (Exception e) {
// NOTE that Error's are not caught because that might halt the JVM and mask the original Error.
exception = e;
}
}
if (!isHandled) {
GraphElement parent = getParent();
// if this graph element has a parent
if ( (parent!=null)
&& (parent!=this) ){
// action to the parent
parent.raiseException(exception, executionContext);
} else {
// rollback the actions
// rollbackActions(executionContext);
// if there is no parent we need to throw an action exception to the client
if (exception instanceof JbpmException) {
throw (JbpmException) exception;
} else {
throw new DelegationException(exception, executionContext);
}
}
}
}
protected ExceptionHandler findExceptionHandler(Throwable exception) {
ExceptionHandler exceptionHandler = null;
if (exceptionHandlers!=null) {
Iterator iter = exceptionHandlers.iterator();
while (iter.hasNext() && (exceptionHandler==null)) {
ExceptionHandler candidate = (ExceptionHandler) iter.next();
if (candidate.matches(exception)) {
exceptionHandler = candidate;
}
}
}
return exceptionHandler;
}
public GraphElement getParent() {
return processDefinition;
}
/**
* @return all the parents of this graph element ordered by age.
*/
public List getParents() {
List parents = new ArrayList();
GraphElement parent = getParent();
if (parent!=null) {
parent.addParentChain(parents);
}
return parents;
}
/**
* @return this graph element plus all the parents ordered by age.
*/
public List getParentChain() {
List parents = new ArrayList();
this.addParentChain(parents);
return parents;
}
void addParentChain(List parentChain) {
parentChain.add(this);
GraphElement parent = getParent();
if (parent!=null) {
parent.addParentChain(parentChain);
}
}
public String toString() {
String className = getClass().getName();
className = className.substring(className.lastIndexOf('.')+1);
if (name!=null) {
className = className+"("+name+")";
} else {
className = className+"("+Integer.toHexString(System.identityHashCode(this))+")";
}
return className;
}
// equals ///////////////////////////////////////////////////////////////////
// hack to support comparing hibernate proxies against the real objects
// since this always falls back to ==, we don't need to overwrite the hashcode
public boolean equals(Object o) {
return EqualsUtil.equals(this, o);
}
// getters and setters //////////////////////////////////////////////////////
public long getId() {
return id;
}
public String getName() {
return name;
}
public void setName( String name ) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public ProcessDefinition getProcessDefinition() {
return processDefinition;
}
public void setProcessDefinition(ProcessDefinition processDefinition) {
this.processDefinition = processDefinition;
}
// logger ///////////////////////////////////////////////////////////////////
private static final Log log = LogFactory.getLog(GraphElement.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -