001: /*--
002:
003: Copyright (C) 2002-2005 Adrian Price.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The names "OBE" and "Open Business Engine" must not be used to
019: endorse or promote products derived from this software without prior
020: written permission. For written permission, please contact
021: adrianprice@sourceforge.net.
022:
023: 4. Products derived from this software may not be called "OBE" or
024: "Open Business Engine", nor may "OBE" or "Open Business Engine"
025: appear in their name, without prior written permission from
026: Adrian Price (adrianprice@users.sourceforge.net).
027:
028: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
029: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
030: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
031: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
032: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
033: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
034: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
035: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
036: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
037: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
038: POSSIBILITY OF SUCH DAMAGE.
039:
040: For more information on OBE, please see
041: <http://obe.sourceforge.net/>.
042:
043: */
044:
045: package org.obe.xpdl.model.activity;
046:
047: import org.obe.xpdl.PackageVisitor;
048: import org.obe.xpdl.model.XPDLProperties;
049: import org.obe.xpdl.model.ext.AssignmentStrategyDef;
050: import org.obe.xpdl.model.ext.CalendarRef;
051: import org.obe.xpdl.model.ext.ToolMode;
052: import org.obe.xpdl.model.misc.AbstractWFElement;
053: import org.obe.xpdl.model.misc.Deadline;
054: import org.obe.xpdl.model.misc.Duration;
055: import org.obe.xpdl.model.misc.SimulationInformation;
056: import org.obe.xpdl.model.transition.TransitionRestriction;
057: import org.obe.xpdl.model.workflow.WorkflowProcess;
058:
059: import java.awt.*;
060: import java.beans.PropertyVetoException;
061: import java.net.URL;
062: import java.util.HashMap;
063: import java.util.Map;
064:
065: /**
066: * Models an XPDL activity definition.
067: */
068: public final class Activity extends AbstractWFElement implements
069: CalendarRef {
070: private static final long serialVersionUID = -7464664489372049213L;
071: private static final Deadline[] EMPTY_DEADLINE = {};
072: private static final TransitionRestriction[] EMPTY_TRANSITION_RESTR = {};
073: public static final String BOUNDS = XPDLProperties.BOUNDS;
074: public static final String LIMIT = XPDLProperties.LIMIT;
075: public static final String IMPLEMENTATION = XPDLProperties.IMPLEMENTATION;
076: public static final String ROUTE = XPDLProperties.ROUTE;
077: public static final String BLOCK_ACTIVITY = XPDLProperties.BLOCK_ACTIVITY;
078: public static final String PERFORMER = XPDLProperties.PERFORMER;
079: public static final String START_MODE = XPDLProperties.START_MODE;
080: public static final String FINISH_MODE = XPDLProperties.FINISH_MODE;
081: public static final String TOOL_MODE = XPDLProperties.TOOL_MODE;
082: public static final String ASSIGNMENT_STRATEGY = XPDLProperties.ASSIGNMENT_STRATEGY;
083: public static final String COMPLETION_STRATEGY = XPDLProperties.COMPLETION_STRATEGY;
084: public static final String CALENDAR = XPDLProperties.CALENDAR;
085: public static final String PRIORITY = XPDLProperties.PRIORITY;
086: public static final String DEADLINE = XPDLProperties.DEADLINE;
087: public static final String SIMULATION_INFORMATION = XPDLProperties.SIMULATION_INFORMATION;
088: public static final String DOCUMENTATION = XPDLProperties.DOCUMENTATION;
089: public static final String ICON = XPDLProperties.ICON;
090: public static final String TRANSITION_RESTRICTION = XPDLProperties.TRANSITION_RESTRICTION;
091: public static final String AFFERENT_TRANSITION = XPDLProperties.AFFERENT_TRANSITION;
092: public static final String EFFERENT_TRANSITION = XPDLProperties.EFFERENT_TRANSITION;
093: private static final String[] _indexedPropertyNames = { DEADLINE,
094: TRANSITION_RESTRICTION };
095: private static final Object[] _indexedPropertyValues = {
096: EMPTY_DEADLINE, EMPTY_TRANSITION_RESTR };
097: private static final int DEADLINE_IDX = 0;
098: private static final int TRANSITION_RESTRICTION_IDX = 1;
099:
100: private Rectangle _bounds;
101: private WorkflowProcess _workflowProcess;
102: private Duration _limit;
103: private Implementation _implementation;
104: private Route _route;
105: private BlockActivity _blockActivity;
106: private String _performer;
107: private AutomationMode _startMode;
108: private AutomationMode _finishMode;
109: private ToolMode _toolMode;
110: private AssignmentStrategyDef _assignmentStrategy;
111: private String _completionStrategy;
112: private String _calendar;
113: private String _priority;
114: private SimulationInformation _simulationInformation;
115: private URL _documentation;
116: private URL _icon;
117: private final Map _afferentTransitions = new HashMap();
118: private final Map _efferentTransitions = new HashMap();
119:
120: public Activity() {
121: super (_indexedPropertyNames, _indexedPropertyValues);
122: }
123:
124: /**
125: * Construct a new Activity with the given ID and name.
126: *
127: * @param id The Activity ID
128: * @param name The Activity name
129: */
130: public Activity(String id, String name,
131: WorkflowProcess workflowProcess) {
132: super (_indexedPropertyNames, _indexedPropertyValues, id, name);
133:
134: _workflowProcess = workflowProcess;
135: }
136:
137: public void accept(PackageVisitor visitor) {
138: visitor.visit(this );
139: if (_implementation != null)
140: _implementation.accept(visitor);
141: }
142:
143: public Rectangle getBounds() {
144: return _bounds;
145: }
146:
147: public void setBounds(Rectangle bounds) {
148: _bounds = bounds;
149: }
150:
151: /**
152: * Get the WorkflowProcess in which this activity is declared.
153: *
154: * @return The WorkflowProcess
155: */
156: public WorkflowProcess getWorkflowProcess() {
157: return _workflowProcess;
158: }
159:
160: /**
161: * Get the time limit allowed for the execution of the activity.
162: *
163: * @return The time limit
164: */
165: public Duration getLimit() {
166: return _limit;
167: }
168:
169: /**
170: * Set the time limit allowed for the execution of the activity.
171: *
172: * @param limit The time limit
173: */
174: public void setLimit(Duration limit) {
175: _limit = limit;
176: }
177:
178: /**
179: * Get the implementation object for the activity. If this method returns
180: * null then the <code>getRoute()</code> must return a valid Route object.
181: *
182: * @return The Implementation object
183: */
184: public Implementation getImplementation() {
185: return _implementation;
186: }
187:
188: /**
189: * Set the implementation object for the activity.
190: *
191: * @param implementation The new Implementation object
192: */
193: public void setImplementation(Implementation implementation) {
194: _implementation = implementation;
195: }
196:
197: /**
198: * Get the Route object for the activity. If the <code>getImplementation()</code>
199: * method returns null then this method must return a valid Route object.
200: *
201: * @return The Route object
202: */
203: public Route getRoute() {
204: return _route;
205: }
206:
207: /**
208: * Set the Route object for the activity.
209: *
210: * @param route The new Route object
211: */
212: public void setRoute(Route route) {
213: _route = route;
214: }
215:
216: public BlockActivity getBlockActivity() {
217: return _blockActivity;
218: }
219:
220: public void setBlockActivity(BlockActivity blockActivity) {
221: _blockActivity = blockActivity;
222: }
223:
224: /**
225: * Get the ID of the activity performer.
226: *
227: * @return The ID of the performer
228: */
229: public String getPerformer() {
230: return _performer;
231: }
232:
233: /**
234: * Set the ID of the activity performer.
235: *
236: * @param performer The ID of the performer
237: */
238: public void setPerformer(String performer) {
239: _performer = performer;
240: }
241:
242: /**
243: * Get the start mode for the activity. The start mode is used to determine
244: * if the activity should start automatically or manually. The default value
245: * is <code>AutomationMode.AUTOMATIC</code>.
246: *
247: * @return The start mode
248: */
249: public AutomationMode getStartMode() {
250: return _startMode;
251: }
252:
253: /**
254: * Set the start mode for the activity. The start mode is used to determine
255: * if the activity should start automatically or manually.
256: *
257: * @param startMode The new start mode
258: */
259: public void setStartMode(AutomationMode startMode) {
260: _startMode = startMode;
261: }
262:
263: /**
264: * Get the finish mode for the activity. The finish mode is used to
265: * determine if the activity should complete automatically or manually. The
266: * default value is <code>AutomationMode.AUTOMATIC</code>.
267: *
268: * @return The finish mode
269: */
270: public AutomationMode getFinishMode() {
271: return _finishMode;
272: }
273:
274: /**
275: * Set the finish mode for the activity. The finish mode is used to
276: * determine if the activity should complete automatically or manually.
277: *
278: * @param finishMode The new finish mode
279: */
280: public void setFinishMode(AutomationMode finishMode) {
281: _finishMode = finishMode;
282: }
283:
284: /**
285: * Returns the tool invocation mode.
286: *
287: * @return The tool invocation mode.
288: */
289: public ToolMode getToolMode() {
290: return _toolMode;
291: }
292:
293: /**
294: * Sets the tool invocation mode.
295: *
296: * @param toolMode The tool invocation mode.
297: */
298: public void setToolMode(ToolMode toolMode) {
299: _toolMode = toolMode;
300: }
301:
302: /**
303: * Returns the work item assignment strategy for this activity.
304: *
305: * @return Assignment strategy definition, which must have a matching
306: * implementation registered in the AssignmentStrategyRepository.
307: */
308: public AssignmentStrategyDef getAssignmentStrategy() {
309: return _assignmentStrategy;
310: }
311:
312: /**
313: * Sets the activity assignment strategy.
314: *
315: * @param strategy Assignment strategy definition, which must have a
316: * matching implementation registered in the AssignmentStrategyRepository.
317: */
318: public void setAssignmentStrategy(AssignmentStrategyDef strategy) {
319: _assignmentStrategy = strategy;
320: }
321:
322: /**
323: * Returns the completion strategy for this activity.
324: *
325: * @return Activity completion strategy tag name, which must have a matching
326: * implementation in the ???Repository.
327: */
328: public String getCompletionStrategy() {
329: return _completionStrategy;
330: }
331:
332: /**
333: * Sets the completion strategy for this activity.
334: *
335: * @param strategy Activity completion strategy tag name, which must have a
336: * matching implementation in the ???Repository.
337: */
338: public void setCompletionStrategy(String strategy) {
339: _completionStrategy = strategy;
340: }
341:
342: /**
343: * Get the priority of the activity.
344: *
345: * @return The priority
346: */
347: public String getPriority() {
348: return _priority;
349: }
350:
351: /**
352: * Set the priority of the activity.
353: *
354: * @param priority The new priority
355: */
356: public void setPriority(String priority) {
357: _priority = priority;
358: }
359:
360: /**
361: * Returns the business calendar name.
362: *
363: * @return The business calendar tag name, which must have a matching
364: * entry in the OBE Calendar Factory.
365: */
366: public String getCalendar() {
367: return _calendar;
368: }
369:
370: /**
371: * Sets the business calendar name.
372: *
373: * @param calendar The business calendar tag name, which must have a
374: * matching entry in the OBE Calendar Factory.
375: */
376: public void setCalendar(String calendar) {
377: _calendar = calendar;
378: }
379:
380: public void add(Deadline deadline) throws PropertyVetoException {
381: add(DEADLINE_IDX, deadline);
382: }
383:
384: public void remove(Deadline deadline) throws PropertyVetoException {
385: remove(DEADLINE_IDX, deadline);
386: }
387:
388: /**
389: * Gets the activity deadlines.
390: *
391: * @return The deadline
392: */
393: public Deadline[] getDeadline() {
394: return (Deadline[]) get(DEADLINE_IDX);
395: }
396:
397: /**
398: * Gets an activity deadline.
399: *
400: * @param i The deadline index.
401: * @return The deadline
402: */
403: public Deadline getDeadline(int i) {
404: return (Deadline) get(DEADLINE_IDX, i);
405: }
406:
407: /**
408: * Sets the activity deadlines.
409: *
410: * @param deadlines
411: */
412: public void setDeadline(Deadline[] deadlines)
413: throws PropertyVetoException {
414: set(DEADLINE_IDX, deadlines == null ? EMPTY_DEADLINE
415: : deadlines);
416: }
417:
418: /**
419: * Sets an activity deadline.
420: *
421: * @param i The deadline index.
422: * @param deadline
423: */
424: public void setDeadline(int i, Deadline deadline)
425: throws PropertyVetoException {
426:
427: set(DEADLINE_IDX, deadline);
428: }
429:
430: /**
431: * Get the SimulationInformation for the activity. This information can be
432: * used to make estimations for the execution time of an activity which can
433: * then be used to test a workflow definition timing.
434: *
435: * @return The SimulationInformation
436: */
437: public SimulationInformation getSimulationInformation() {
438: return _simulationInformation;
439: }
440:
441: /**
442: * Set the SimulationInformation for the activity.
443: *
444: * @param simulationInformation The new SimulationInformation
445: */
446: public void setSimulationInformation(
447: SimulationInformation simulationInformation) {
448: _simulationInformation = simulationInformation;
449: }
450:
451: /**
452: * Get the URL for the documentation for the activity. This URL should
453: * point to documentation which can be used by developers, administrators
454: * and other users to understand what the activity does.
455: *
456: * @return The URL for the activity documentation
457: */
458: public URL getDocumentation() {
459: return _documentation;
460: }
461:
462: /**
463: * Get the URL for the documentation for the activity.
464: *
465: * @param documentation The new URL for the activity documentation
466: */
467: public void setDocumentation(URL documentation) {
468: _documentation = documentation;
469: }
470:
471: /**
472: * Get the URL for the icon for the activity. The icon is used to represent
473: * the activity in a graphical representatioin of the workflow process.
474: *
475: * @return The URL for the activity's icon
476: */
477: public URL getIcon() {
478: return _icon;
479: }
480:
481: /**
482: * Set the URL for the icon for the activity.
483: *
484: * @param icon The new URL for the activity's icon
485: */
486: public void setIcon(URL icon) {
487: _icon = icon;
488: }
489:
490: public void add(TransitionRestriction restriction)
491: throws PropertyVetoException {
492:
493: add(TRANSITION_RESTRICTION_IDX, restriction);
494: }
495:
496: public void remove(TransitionRestriction restriction)
497: throws PropertyVetoException {
498:
499: remove(TRANSITION_RESTRICTION_IDX, restriction);
500: }
501:
502: /**
503: * Get a List of transition restrictions for transitions which connect to
504: * this activity.
505: *
506: * @return a List of transition restrictions
507: */
508: public TransitionRestriction[] getTransitionRestriction() {
509: return (TransitionRestriction[]) get(TRANSITION_RESTRICTION_IDX);
510: }
511:
512: public TransitionRestriction getTransitionRestriction(int i) {
513: return (TransitionRestriction) get(TRANSITION_RESTRICTION_IDX,
514: i);
515: }
516:
517: public void setTransitionRestriction(
518: TransitionRestriction[] restrictions)
519: throws PropertyVetoException {
520:
521: set(TRANSITION_RESTRICTION_IDX,
522: restrictions == null ? EMPTY_TRANSITION_RESTR
523: : restrictions);
524: }
525:
526: public void setTransitionRestriction(int i,
527: TransitionRestriction restriction)
528: throws PropertyVetoException {
529:
530: set(TRANSITION_RESTRICTION_IDX, i, restriction);
531: }
532:
533: public Map getAfferentTransitions() {
534: return _afferentTransitions;
535: }
536:
537: public Map getEfferentTransitions() {
538: return _efferentTransitions;
539: }
540:
541: public String toString() {
542: return "Activity[id='" + getId() + ", name="
543: + (getName() == null ? null : '\'' + getName() + '\'')
544: + ']';
545: }
546:
547: public boolean isExitActivity() {
548: return _efferentTransitions.isEmpty();
549: }
550:
551: public boolean isStartActivity() {
552: return _afferentTransitions.isEmpty();
553: }
554: }
|