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.taskmgmt.def;
023:
024: import org.jbpm.JbpmException;
025: import org.jbpm.graph.def.Event;
026: import org.jbpm.graph.def.GraphElement;
027: import org.jbpm.graph.node.StartState;
028: import org.jbpm.graph.node.TaskNode;
029: import org.jbpm.instantiation.Delegation;
030:
031: /**
032: * defines a task and how the actor must be calculated at runtime.
033: */
034: public class Task extends GraphElement {
035:
036: private static final long serialVersionUID = 1L;
037:
038: public static final int PRIORITY_HIGHEST = 1;
039: public static final int PRIORITY_HIGH = 2;
040: public static final int PRIORITY_NORMAL = 3;
041: public static final int PRIORITY_LOW = 4;
042: public static final int PRIORITY_LOWEST = 5;
043:
044: public static int parsePriority(String priorityText) {
045: if ("highest".equalsIgnoreCase(priorityText))
046: return PRIORITY_HIGHEST;
047: else if ("high".equalsIgnoreCase(priorityText))
048: return PRIORITY_HIGH;
049: else if ("normal".equalsIgnoreCase(priorityText))
050: return PRIORITY_NORMAL;
051: else if ("low".equalsIgnoreCase(priorityText))
052: return PRIORITY_LOW;
053: else if ("lowest".equalsIgnoreCase(priorityText))
054: return PRIORITY_LOWEST;
055: try {
056: return Integer.parseInt(priorityText);
057: } catch (NumberFormatException e) {
058: throw new JbpmException("priority '" + priorityText
059: + "' could not be parsed as a priority");
060: }
061: }
062:
063: protected boolean isBlocking = false;
064: protected boolean isSignalling = true;
065: protected String condition = null;
066: protected String dueDate = null;
067: protected int priority = PRIORITY_NORMAL;
068: protected TaskNode taskNode = null;
069: protected StartState startState = null;
070: protected TaskMgmtDefinition taskMgmtDefinition = null;
071: protected Swimlane swimlane = null;
072: protected String actorIdExpression = null;
073: protected String pooledActorsExpression = null;
074: protected Delegation assignmentDelegation = null;
075: protected TaskController taskController = null;
076:
077: public Task() {
078: }
079:
080: public Task(String name) {
081: this .name = name;
082: }
083:
084: // event types //////////////////////////////////////////////////////////////
085:
086: static final String[] supportedEventTypes = new String[] {
087: Event.EVENTTYPE_TASK_CREATE, Event.EVENTTYPE_TASK_ASSIGN,
088: Event.EVENTTYPE_TASK_START, Event.EVENTTYPE_TASK_END };
089:
090: public String[] getSupportedEventTypes() {
091: return supportedEventTypes;
092: }
093:
094: // task instance factory methods ////////////////////////////////////////////
095:
096: /**
097: * sets the taskNode unidirectionally. use {@link TaskNode#addTask(Task)} to create
098: * a bidirectional relation.
099: */
100: public void setTaskNode(TaskNode taskNode) {
101: this .taskNode = taskNode;
102: }
103:
104: /**
105: * sets the taskMgmtDefinition unidirectionally. use TaskMgmtDefinition.addTask to create
106: * a bidirectional relation.
107: */
108: public void setTaskMgmtDefinition(
109: TaskMgmtDefinition taskMgmtDefinition) {
110: this .taskMgmtDefinition = taskMgmtDefinition;
111: }
112:
113: /**
114: * sets the swimlane. Since a task can have max one of swimlane or assignmentHandler,
115: * this method removes the swimlane if it is set.
116: */
117: public void setAssignmentDelegation(Delegation assignmentDelegation) {
118: this .actorIdExpression = null;
119: this .pooledActorsExpression = null;
120: this .assignmentDelegation = assignmentDelegation;
121: this .swimlane = null;
122: }
123:
124: /**
125: * sets the actorId expression. The assignmentExpression is a JSF-like
126: * expression to perform assignment. Since a task can have max one of swimlane or
127: * assignmentHandler, this method removes the swimlane and assignmentDelegation if
128: * it is set.
129: */
130: public void setActorIdExpression(String actorIdExpression) {
131: this .actorIdExpression = actorIdExpression;
132: // Note: combination of actorIdExpression and pooledActorsExpression is allowed
133: // this.pooledActorsExpression = null;
134: this .assignmentDelegation = null;
135: this .swimlane = null;
136: }
137:
138: /**
139: * sets the actorId expression. The assignmentExpression is a JSF-like
140: * expression to perform assignment. Since a task can have max one of swimlane or
141: * assignmentHandler, this method removes the other forms of assignment.
142: */
143: public void setPooledActorsExpression(String pooledActorsExpression) {
144: // Note: combination of actorIdExpression and pooledActorsExpression is allowed
145: // this.actorIdExpression = null;
146: this .pooledActorsExpression = pooledActorsExpression;
147: this .assignmentDelegation = null;
148: this .swimlane = null;
149: }
150:
151: /**
152: * sets the swimlane unidirectionally. Since a task can have max one of swimlane or assignmentHandler,
153: * this method removes the assignmentHandler and assignmentExpression if one of those isset. To create
154: * a bidirectional relation, use {@link Swimlane#addTask(Task)}.
155: */
156: public void setSwimlane(Swimlane swimlane) {
157: this .actorIdExpression = null;
158: this .pooledActorsExpression = null;
159: this .assignmentDelegation = null;
160: this .swimlane = swimlane;
161: }
162:
163: // parent ///////////////////////////////////////////////////////////////////
164:
165: public GraphElement getParent() {
166: if (taskNode != null) {
167: return taskNode;
168: }
169: if (startState != null) {
170: return startState;
171: }
172: return processDefinition;
173: }
174:
175: // getters and setters //////////////////////////////////////////////////////
176:
177: public TaskMgmtDefinition getTaskMgmtDefinition() {
178: return taskMgmtDefinition;
179: }
180:
181: public Swimlane getSwimlane() {
182: return swimlane;
183: }
184:
185: public boolean isBlocking() {
186: return isBlocking;
187: }
188:
189: public void setBlocking(boolean isBlocking) {
190: this .isBlocking = isBlocking;
191: }
192:
193: public TaskNode getTaskNode() {
194: return taskNode;
195: }
196:
197: public String getActorIdExpression() {
198: return actorIdExpression;
199: }
200:
201: public String getPooledActorsExpression() {
202: return pooledActorsExpression;
203: }
204:
205: public Delegation getAssignmentDelegation() {
206: return assignmentDelegation;
207: }
208:
209: public String getDueDate() {
210: return dueDate;
211: }
212:
213: public void setDueDate(String duedate) {
214: this .dueDate = duedate;
215: }
216:
217: public TaskController getTaskController() {
218: return taskController;
219: }
220:
221: public void setTaskController(TaskController taskController) {
222: this .taskController = taskController;
223: }
224:
225: public int getPriority() {
226: return priority;
227: }
228:
229: public void setPriority(int priority) {
230: this .priority = priority;
231: }
232:
233: public StartState getStartState() {
234: return startState;
235: }
236:
237: public void setStartState(StartState startState) {
238: this .startState = startState;
239: }
240:
241: public boolean isSignalling() {
242: return isSignalling;
243: }
244:
245: public void setSignalling(boolean isSignalling) {
246: this .isSignalling = isSignalling;
247: }
248:
249: public String getCondition() {
250: return condition;
251: }
252:
253: public void setCondition(String condition) {
254: this.condition = condition;
255: }
256: }
|