📄 taskmgmtinstance.java
字号:
} catch (ClassCastException e) {
throw new JbpmException("actor-id expression '"+actorIdExpression+"' didn't resolve to a java.lang.String: '"+result+"' ("+result.getClass().getName()+")");
}
assignable.setActorId(actorId);
}
void performAssignmentPooledActorsExpr(String pooledActorsExpression, Assignable assignable, ExecutionContext executionContext) {
String[] pooledActors = null;
Object result = JbpmExpressionEvaluator.evaluate(pooledActorsExpression, executionContext);
if (result==null) {
throw new JbpmException("pooled-actors expression '"+pooledActorsExpression+"' returned null");
}
if (result instanceof String[]) {
pooledActors = (String[]) result;
} else if (result instanceof Collection) {
Collection collection = (Collection)result;
pooledActors = (String[]) collection.toArray(new String[collection.size()]);
} else if (result instanceof String) {
List pooledActorList = new ArrayList();
StringTokenizer tokenizer = new StringTokenizer((String) result, ",");
while (tokenizer.hasMoreTokens()) {
pooledActorList.add(tokenizer.nextToken().trim());
}
pooledActors = (String[]) pooledActorList.toArray(new String[pooledActorList.size()]);
} else {
throw new JbpmException("pooled-actors expression '"+pooledActorsExpression+"' didn't resolve to a comma separated String, a Collection or a String[]: '"+result+"' ("+result.getClass().getName()+")");
}
assignable.setPooledActors(pooledActors);
}
/**
* creates a task instance on the rootToken, and assigns it
* to the currently authenticated user.
*/
public TaskInstance createStartTaskInstance() {
TaskInstance taskInstance = null;
Task startTask = taskMgmtDefinition.getStartTask();
Token rootToken = processInstance.getRootToken();
ExecutionContext executionContext = new ExecutionContext(rootToken);
taskInstance = createTaskInstance(startTask, executionContext);
taskInstance.setActorId(SecurityHelper.getAuthenticatedActorId());
return taskInstance;
}
TaskInstance instantiateNewTaskInstance(ExecutionContext executionContext) {
TaskInstance newTaskInstance = null;
TaskInstanceFactory taskInstanceFactory = (TaskInstanceFactory) JbpmConfiguration.Configs.getObject("jbpm.task.instance.factory");
try {
newTaskInstance = taskInstanceFactory.createTaskInstance(executionContext);
} catch (NullPointerException e) {
throw new JbpmException("jbpm.task.instance.factory was not configured in jbpm.cfg.xml", e);
} catch (Exception e) {
e.printStackTrace();
throw new JbpmException("couldn't instantiate task instance with task instance factory '"+taskInstanceFactory+"'", e);
}
return newTaskInstance;
}
/**
* is true if the given token has task instances that keep the
* token from leaving the current node.
*/
public boolean hasBlockingTaskInstances(Token token) {
boolean hasBlockingTasks = false;
if (taskInstances!=null) {
Iterator iter = taskInstances.iterator();
while ( (iter.hasNext())
&& (! hasBlockingTasks)) {
TaskInstance taskInstance = (TaskInstance) iter.next();
if ( (! taskInstance.hasEnded())
&& (taskInstance.isBlocking())
&& (token.equals(taskInstance.getToken())) ) {
hasBlockingTasks = true;
}
}
}
return hasBlockingTasks;
}
/**
* is true if the given token has task instances that are not yet ended.
*/
public boolean hasUnfinishedTasks(Token token) {
return (getUnfinishedTasks(token).size()>0);
}
/**
* is the collection of {@link TaskInstance}s on the given token that are not ended.
*/
public Collection getUnfinishedTasks(Token token) {
Collection unfinishedTasks = new ArrayList();
if ( taskInstances != null ) {
Iterator iter = taskInstances.iterator();
while (iter.hasNext()) {
TaskInstance task = (TaskInstance) iter.next();
if ( (!task.hasEnded())
&& (token!=null)
&& (token.equals(task.getToken()))
) {
unfinishedTasks.add( task );
}
}
}
return unfinishedTasks;
}
/**
* is true if there are {@link TaskInstance}s on the given token that can trigger
* the token to continue.
*/
public boolean hasSignallingTasks(ExecutionContext executionContext) {
return (getSignallingTasks(executionContext).size()>0);
}
/**
* is the collection of {@link TaskInstance}s for the given token that can trigger
* the token to continue.
*/
public Collection getSignallingTasks(ExecutionContext executionContext) {
Collection signallingTasks = new ArrayList();
if ( taskInstances != null ) {
Iterator iter = taskInstances.iterator();
while (iter.hasNext()) {
TaskInstance taskInstance = (TaskInstance) iter.next();
if ( (taskInstance.isSignalling())
&& (executionContext.getToken().equals(taskInstance.getToken()))
) {
signallingTasks.add(taskInstance);
}
}
}
return signallingTasks;
}
/**
* returns all the taskInstances for the this process instance. This
* includes task instances that have been completed previously.
*/
public Collection getTaskInstances() {
return taskInstances;
}
public void addTaskInstance(TaskInstance taskInstance) {
if (taskInstances==null) taskInstances = new HashSet();
taskInstances.add(taskInstance);
taskInstance.setTaskMgmtInstance(this);
}
public void removeTaskInstance(TaskInstance taskInstance) {
if (taskInstances!=null) {
taskInstances.remove(taskInstance);
}
}
// swimlane instances ///////////////////////////////////////////////////////
public Map getSwimlaneInstances() {
return swimlaneInstances;
}
public void addSwimlaneInstance( SwimlaneInstance swimlaneInstance ) {
if (swimlaneInstances==null) swimlaneInstances = new HashMap();
swimlaneInstances.put(swimlaneInstance.getName(), swimlaneInstance);
swimlaneInstance.setTaskMgmtInstance(this);
}
public SwimlaneInstance getSwimlaneInstance(String swimlaneName) {
return (SwimlaneInstance) (swimlaneInstances!=null ? swimlaneInstances.get(swimlaneName) : null );
}
// getters and setters //////////////////////////////////////////////////////
public TaskMgmtDefinition getTaskMgmtDefinition() {
return taskMgmtDefinition;
}
/**
* suspends all task instances for this process instance.
*/
public void suspend(Token token) {
if (token==null) {
throw new JbpmException("can't suspend task instances for token null");
}
if (taskInstances!=null) {
Iterator iter = taskInstances.iterator();
while (iter.hasNext()) {
TaskInstance taskInstance = (TaskInstance) iter.next();
if (token.equals(taskInstance.getToken())) {
taskInstance.suspend();
}
}
}
}
/**
* resumes all task instances for this process instance.
*/
public void resume(Token token) {
if (token==null) {
throw new JbpmException("can't suspend task instances for token null");
}
if (taskInstances!=null) {
Iterator iter = taskInstances.iterator();
while (iter.hasNext()) {
TaskInstance taskInstance = (TaskInstance) iter.next();
if (token.equals(taskInstance.getToken())) {
taskInstance.resume();
}
}
}
}
void notifyVariableUpdate(TaskInstance taskInstance) {
if (taskInstanceVariableUpdates==null) {
taskInstanceVariableUpdates=new HashSet();
}
taskInstanceVariableUpdates.add(taskInstance);
}
/**
* returns the collection of task instance with variable updates.
*/
public Collection getTaskInstancesWithVariableUpdates() {
return taskInstanceVariableUpdates;
}
// private static final Log log = LogFactory.getLog(TaskMgmtInstance.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -