?? graphelement.java
字號:
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.graph.def;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jbpm.JbpmException;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.RuntimeAction;
import org.jbpm.graph.exe.Token;
import org.jbpm.graph.log.ActionLog;
import org.jbpm.instantiation.UserCodeInterceptor;
import org.jbpm.instantiation.UserCodeInterceptorConfig;
import org.jbpm.job.ExecuteActionJob;
import org.jbpm.msg.MessageService;
import org.jbpm.svc.Services;
import org.jbpm.taskmgmt.def.AssignmentHandler;
import org.jbpm.taskmgmt.def.TaskControllerHandler;
import org.jbpm.taskmgmt.exe.TaskInstance;
import org.jbpm.util.EqualsUtil;
public abstract class GraphElement implements Serializable {
private static final long serialVersionUID = 1L;
long id = 0;
protected String name = null;
protected String description = null;
protected ProcessDefinition processDefinition = null;
protected Map events = null;
protected List exceptionHandlers = null;
public GraphElement() {
}
public GraphElement( String name ) {
setName( name );
}
// events ///////////////////////////////////////////////////////////////////
/**
* indicative set of event types supported by this graph element.
* this is currently only used by the process designer to know which
* event types to show on a given graph element. in process definitions
* and at runtime, there are no contstraints on the event-types.
*/
public abstract String[] getSupportedEventTypes();
/**
* gets the events, keyd by eventType (java.lang.String).
*/
public Map getEvents() {
return events;
}
public boolean hasEvents() {
return ( (events!=null)
&& (events.size()>0) );
}
public Event getEvent(String eventType) {
Event event = null;
if (events!=null) {
event = (Event) events.get(eventType);
}
return event;
}
public boolean hasEvent(String eventType) {
boolean hasEvent = false;
if (events!=null) {
hasEvent = events.containsKey(eventType);
}
return hasEvent;
}
public Event addEvent(Event event) {
if (event == null) throw new IllegalArgumentException("can't add a null event to a graph element");
if (event.getEventType() == null) throw new IllegalArgumentException("can't add an event without an eventType to a graph element");
if (events == null) events = new HashMap();
events.put(event.getEventType(), event);
event.graphElement = this;
return event;
}
public Event removeEvent(Event event) {
Event removedEvent = null;
if (event == null) throw new IllegalArgumentException("can't remove a null event from a graph element");
if (event.getEventType() == null) throw new IllegalArgumentException("can't remove an event without an eventType from a graph element");
if (events != null) {
removedEvent = (Event) events.remove(event.getEventType());
if (removedEvent!=null) {
event.graphElement = null;
}
}
return removedEvent;
}
// exception handlers ///////////////////////////////////////////////////////
/**
* is the list of exception handlers associated to this graph element.
*/
public List getExceptionHandlers() {
return exceptionHandlers;
}
public ExceptionHandler addExceptionHandler(ExceptionHandler exceptionHandler) {
if (exceptionHandler == null) throw new IllegalArgumentException("can't add a null exceptionHandler to a graph element");
if (exceptionHandlers == null) exceptionHandlers = new ArrayList();
exceptionHandlers.add(exceptionHandler);
exceptionHandler.graphElement = this;
return exceptionHandler;
}
public void removeExceptionHandler(ExceptionHandler exceptionHandler) {
if (exceptionHandler == null) throw new IllegalArgumentException("can't remove a null exceptionHandler from an graph element");
if (exceptionHandlers != null) {
if (exceptionHandlers.remove(exceptionHandler)) {
exceptionHandler.graphElement = null;
}
}
}
public void reorderExceptionHandler(int oldIndex, int newIndex) {
if ( (exceptionHandlers!=null)
&& (Math.min(oldIndex, newIndex)>=0)
&& (Math.max(oldIndex, newIndex)<exceptionHandlers.size()) ) {
Object o = exceptionHandlers.remove(oldIndex);
exceptionHandlers.add(newIndex, o);
} else {
throw new IndexOutOfBoundsException("couldn't reorder element from index '"+oldIndex+"' to index '"+newIndex+"' in exceptionHandler-list '"+exceptionHandlers+"'");
}
}
// event handling ///////////////////////////////////////////////////////////
public void fireEvent(String eventType, ExecutionContext executionContext) {
Token token = executionContext.getToken();
log.debug( "event '"+eventType+"' on '"+this+"' for '"+token+"'" );
try {
executionContext.setEventSource(this);
fireAndPropagateEvent(eventType, executionContext);
} finally {
executionContext.setEventSource(null);
}
}
public void fireAndPropagateEvent(String eventType, ExecutionContext executionContext) {
// calculate if the event was fired on this element or if it was a propagated event
boolean isPropagated = !(this.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);
}
}
void executeActions(List actions, ExecutionContext executionContext, boolean isPropagated) {
if (actions!=null) {
Iterator iter = actions.iterator();
while (iter.hasNext()) {
Action action = (Action) iter.next();
if ( action.acceptsPropagatedEvents()
|| (!isPropagated)
) {
if (action.isAsync()) {
ExecuteActionJob job = createAsyncActionExecutionJob(executionContext.getToken(), action);
MessageService messageService = (MessageService) Services.getCurrentService(Services.SERVICENAME_MESSAGE);
messageService.send(job);
} else {
executeAction(action, executionContext);
}
}
}
}
}
protected ExecuteActionJob createAsyncActionExecutionJob(Token token, Action action) {
ExecuteActionJob job = new ExecuteActionJob(token);
job.setAction(action);
job.setDueDate(new Date());
job.setExclusive(action.isAsyncExclusive());
return job;
}
public void executeAction(Action action, ExecutionContext executionContext) {
Token token = executionContext.getToken();
// create action log
ActionLog actionLog = new ActionLog(action);
token.startCompositeLog(actionLog);
// if this is an action being executed in an event,
// the token needs to be locked. if this is an action
// being executed as the node behaviour or if the token
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -