001: /*
002: JSPWiki - a JSP-based WikiWiki clone.
003:
004: Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
005:
006: This program is free software; you can redistribute it and/or modify
007: it under the terms of the GNU Lesser General Public License as published by
008: the Free Software Foundation; either version 2.1 of the License, or
009: (at your option) any later version.
010:
011: This program is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: GNU Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public License
017: along with this program; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: package com.ecyrd.jspwiki.workflow;
021:
022: /**
023: * Resolution of a workflow Step, such as "approve," "deny," "hold," "task
024: * error," or other potential resolutions.
025: *
026: * @author Andrew Jaquith
027: * @since 2.5
028: */
029: public final class Outcome {
030:
031: /** Complete workflow step (without errors) */
032: public static final Outcome STEP_COMPLETE = new Outcome(
033: "outcome.step.complete", true);
034:
035: /** Terminate workflow step (without errors) */
036: public static final Outcome STEP_ABORT = new Outcome(
037: "outcome.step.abort", true);
038:
039: /** Continue workflow step (without errors) */
040: public static final Outcome STEP_CONTINUE = new Outcome(
041: "outcome.step.continue", false);
042:
043: /** Acknowlege the Decision. */
044: public static final Outcome DECISION_ACKNOWLEDGE = new Outcome(
045: "outcome.decision.acknowledge", true);
046:
047: /** Approve the Decision (and complete the step). */
048: public static final Outcome DECISION_APPROVE = new Outcome(
049: "outcome.decision.approve", true);
050:
051: /** Deny the Decision (and complete the step). */
052: public static final Outcome DECISION_DENY = new Outcome(
053: "outcome.decision.deny", true);
054:
055: /** Put the Decision on hold (and pause the step). */
056: public static final Outcome DECISION_HOLD = new Outcome(
057: "outcome.decision.hold", false);
058:
059: /** Reassign the Decision to another actor (and pause the step). */
060: public static final Outcome DECISION_REASSIGN = new Outcome(
061: "outcome.decision.reassign", false);
062:
063: private static final Outcome[] OUTCOMES = new Outcome[] {
064: STEP_COMPLETE, STEP_ABORT, STEP_CONTINUE,
065: DECISION_ACKNOWLEDGE, DECISION_APPROVE, DECISION_DENY,
066: DECISION_HOLD, DECISION_REASSIGN };
067:
068: private final String m_key;
069:
070: private final boolean m_completion;
071:
072: /**
073: * Private constructor to prevent direct instantiation.
074: *
075: * @param key
076: * message key for the Outcome
077: * @param completion
078: * whether this Outcome should be interpreted as the logical
079: * completion of a Step.
080: */
081: private Outcome(String key, boolean completion) {
082: if (key == null) {
083: throw new IllegalArgumentException("Key cannot be null.");
084: }
085: m_key = key;
086: m_completion = completion;
087: }
088:
089: /**
090: * Returns <code>true</code> if this Outcome represents a completion
091: * condition for a Step.
092: *
093: * @return the result
094: */
095: public boolean isCompletion() {
096: return m_completion;
097: }
098:
099: /**
100: * The i18n key for this outcome, which is prefixed by <code>outcome.</code>.
101: * If calling classes wish to return a locale-specific name for this task
102: * (such as "approve this request"), they can use this method to obtain the
103: * correct key suffix.
104: *
105: * @return the i18n key for this outcome
106: */
107: public String getMessageKey() {
108: return m_key;
109: }
110:
111: /**
112: * The hashcode of an Outcome is identical to the hashcode of its message
113: * key, multiplied by 2 if it is a "completion" Outcome.
114: * @return the hash code
115: */
116: public int hashCode() {
117: return m_key.hashCode() * (m_completion ? 1 : 2);
118: }
119:
120: /**
121: * Two Outcome objects are equal if their message keys are equal.
122: * @param obj the object to test
123: * @return <code>true</code> if logically equal, <code>false</code> if not
124: */
125: public boolean equals(Object obj) {
126: if (!(obj instanceof Outcome)) {
127: return false;
128: }
129: return m_key.equals(((Outcome) obj).getMessageKey());
130: }
131:
132: /**
133: * Returns a named Outcome. If an Outcome matching the supplied key is not
134: * found, this method throws a {@link NoSuchOutcomeException}.
135: *
136: * @param key
137: * the name of the outcome
138: * @return the Outcome
139: * @throws NoSuchOutcomeException
140: * if an Outcome matching the key isn't found.
141: */
142: public static Outcome forName(String key)
143: throws NoSuchOutcomeException {
144: if (key != null) {
145: for (int i = 0; i < OUTCOMES.length; i++) {
146: if (OUTCOMES[i].m_key.equals(key)) {
147: return OUTCOMES[i];
148: }
149: }
150: }
151: throw new NoSuchOutcomeException("Outcome " + key
152: + " not found.");
153: }
154:
155: /**
156: * {@inheritDoc}
157: */
158: public String toString() {
159: return "[Outcome:" + m_key + "]";
160: }
161:
162: }
|