001: /*
002: * JBoss, Home of Professional Open Source
003: * Copyright 2005, JBoss Inc., and individual contributors as indicated
004: * by the @authors tag. See the copyright.txt in the distribution for a
005: * full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jbpm.command;
023:
024: import java.util.Map;
025:
026: import org.jbpm.JbpmContext;
027: import org.jbpm.taskmgmt.exe.TaskInstance;
028:
029: /**
030: * end the task with the given id if variables are given as a map, they are
031: * added/changed bevore ending the task
032: *
033: * @author ??, Bernd Ruecker (bernd.ruecker@camunda.com)
034: */
035: public class TaskInstanceEndCommand implements Command {
036:
037: private static final long serialVersionUID = 5721341060757950369L;
038:
039: private long taskInstanceId = 0;
040:
041: private String transitionName = null;
042:
043: private Map variables;
044:
045: private TaskInstance previoustaskInstance = null;
046:
047: public TaskInstanceEndCommand() {
048: }
049:
050: public TaskInstanceEndCommand(long taskInstanceId,
051: String transitionName) {
052: this .taskInstanceId = taskInstanceId;
053: this .transitionName = transitionName;
054: }
055:
056: public TaskInstanceEndCommand(long taskInstanceId,
057: String transitionName, Map variables) {
058: this .taskInstanceId = taskInstanceId;
059: this .transitionName = transitionName;
060: this .variables = variables;
061: }
062:
063: public Object execute(JbpmContext jbpmContext) {
064: TaskInstance taskInstance = getTaskInstance(jbpmContext);
065:
066: if (variables != null && variables.size() > 0) {
067: taskInstance.getContextInstance().addVariables(variables);
068: }
069:
070: if (transitionName == null) {
071: taskInstance.end();
072: } else {
073: taskInstance.end(transitionName);
074: }
075: return taskInstance;
076: }
077:
078: protected TaskInstance getTaskInstance(JbpmContext jbpmContext) {
079: if (previoustaskInstance != null) {
080: return previoustaskInstance;
081: }
082: return jbpmContext.getTaskInstance(taskInstanceId);
083: }
084:
085: public long getTaskInstanceId() {
086: return taskInstanceId;
087: }
088:
089: public void setTaskInstanceId(long taskInstanceId) {
090: this .taskInstanceId = taskInstanceId;
091: }
092:
093: public String getTransitionName() {
094: return transitionName;
095: }
096:
097: public void setTransitionName(String transitionName) {
098: this .transitionName = transitionName;
099: }
100:
101: public Map getVariables() {
102: return variables;
103: }
104:
105: public void setVariables(Map variables) {
106: this.variables = variables;
107: }
108:
109: }
|