protected void readEvents(Element parentElement, GraphElement graphElement) { for (Iterator iter = parentElement.elementIterator("event"); iter.hasNext();) { Element eventElement = (Element) iter.next(); // register event of the defined type String eventType = eventElement.attributeValue("type"); if (!graphElement.hasEvent(eventType)) graphElement.addEvent(new Event(eventType)); // parse any actions associated to the event readActions(eventElement, graphElement, eventType); } }
private void addParentChain(List parentChain) { parentChain.add(this); GraphElement parent = getParent(); if (parent != null) parent.addParentChain(parentChain); }
public void fireAndPropagateEvent(String eventType, ExecutionContext executionContext) { // check whether the event was fired on this element // or propagated from another element boolean isPropagated = !equals(executionContext.getEventSource()); // execute static actions Event event = getEvent(eventType); if (event != null) { // update the context executionContext.setEvent(event); // execute the static actions specified in the process definition executeActions(event.getActions(), executionContext, isPropagated); } // execute the runtime actions List runtimeActions = getRuntimeActionsForEvent(executionContext, eventType); executeActions(runtimeActions, executionContext, isPropagated); // remove the event from the context executionContext.setEvent(null); // propagate the event to the parent element GraphElement parent = getParent(); if (parent != null) { parent.fireAndPropagateEvent(eventType, executionContext); } }
public GraphElement getParent() { if (from != null && to != null) { if (from.equals(to)) return from.getParent(); for (GraphElement fromParent = from; fromParent != null; fromParent = fromParent.getParent()) { for (GraphElement toParent = to; toParent != null; toParent = toParent.getParent()) { if (fromParent.equals(toParent)) return fromParent; } } } return processDefinition; } }
if (isAbleToHandleExceptions(executionContext)) { ExceptionHandler exceptionHandler = findExceptionHandler(exception); GraphElement parent = getParent(); if (parent != null && !equals(parent)) { parent.raiseException(exception, executionContext); return;
public boolean equals(Object o) { if (o == this) return true; if (!getClass().isInstance(o)) return false; GraphElement other = (GraphElement) o; if (id != 0 && id == other.getId()) return true; GraphElement parent = getParent(); GraphElement otherParent = other.getParent(); boolean result; if (name != null && parent != null) { result = name.equals(other.getName()); } else if (parent instanceof NodeCollection && otherParent instanceof NodeCollection) { NodeCollection nodeCollection = (NodeCollection) parent; int index = nodeCollection.getNodes().indexOf(this); assert index != -1 : nodeCollection.getNodes(); NodeCollection otherNodeCollection = (NodeCollection) otherParent; int otherIndex = otherNodeCollection.getNodes().indexOf(other); result = index == otherIndex; } else { return false; } return result && parent.equals(otherParent); }
private void executeActions(List actions, ExecutionContext executionContext, boolean isPropagated) { if (actions == null) return; for (Iterator iter = actions.iterator(); iter.hasNext();) { Action action = (Action) iter.next(); if (!action.acceptsPropagatedEvents() && isPropagated) continue; if (action.isAsync()) { ExecuteActionJob job = createAsyncActionExecutionJob(executionContext.getToken(), action); MessageService messageService = executionContext.getJbpmContext() .getServices() .getMessageService(); messageService.send(job); } else { executeAction(action, executionContext); } } }
token.lock(lockOwner); try { executeActionImpl(action, executionContext); executeActionImpl(action, executionContext); raiseException(exception, executionContext);
graphElement.fireEvent(Event.EVENTTYPE_TIMER, executionContext); graphElement.executeAction(action, executionContext);
public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Event)) return false; Event other = (Event) o; if (id != 0 && id == other.getId()) return true; return eventType.equals(other.getEventType()) && graphElement.equals(other.getGraphElement()); }
/** * @return this graph element plus the ancestors ordered by depth. */ public List getParentChain() { List parents = new ArrayList(); addParentChain(parents); return parents; }
public void handleException(GraphElement graphElement, ExecutionContext executionContext) throws Exception { if (actions != null) { for (Iterator iter = actions.iterator(); iter.hasNext();) { Action action = (Action) iter.next(); graphElement.executeAction(action, executionContext); } } }
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 for (Iterator iter = exceptionHandlerElement.elementIterator(); iter.hasNext();) { Element childElement = (Element) iter.next(); if (ActionTypes.hasActionName(childElement.getName())) { Action action = createAction(childElement); exceptionHandler.addAction(action); } } }
public void fireEvent(String eventType, ExecutionContext executionContext) { Token token = executionContext.getToken(); if (log.isDebugEnabled()) log.debug(token + " fires event '" + eventType + "' on " + this); GraphElement eventSource = executionContext.getEventSource(); try { executionContext.setEventSource(this); JbpmContext jbpmContext = executionContext.getJbpmContext(); if (jbpmContext != null) { EventService eventService = (EventService) jbpmContext.getServices() .getService(EventService.SERVICE_NAME); if (eventService != null) eventService.fireEvent(eventType, this, executionContext); } fireAndPropagateEvent(eventType, executionContext); } finally { executionContext.setEventSource(eventSource); } }
if (isAbleToHandleExceptions(executionContext)) { ExceptionHandler exceptionHandler = findExceptionHandler(exception); GraphElement parent = getParent(); if (parent != null && !equals(parent)) { parent.raiseException(exception, executionContext); return;
public GraphElement getParent() { if (from != null && to != null) { if (from.equals(to)) return from.getParent(); for (GraphElement fromParent = from; fromParent != null; fromParent = fromParent.getParent()) { for (GraphElement toParent = to; toParent != null; toParent = toParent.getParent()) { if (fromParent.equals(toParent)) return fromParent; } } } return processDefinition; } }
private void executeActions(List actions, ExecutionContext executionContext, boolean isPropagated) { if (actions == null) return; for (Iterator iter = actions.iterator(); iter.hasNext();) { Action action = (Action) iter.next(); if (!action.acceptsPropagatedEvents() && isPropagated) continue; if (action.isAsync()) { ExecuteActionJob job = createAsyncActionExecutionJob(executionContext.getToken(), action); MessageService messageService = executionContext.getJbpmContext() .getServices() .getMessageService(); messageService.send(job); } else { executeAction(action, executionContext); } } }