001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2004 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 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 General Public License for more details.
015: *
016: * You should have received a copy of the GNU 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: * $Id: FormalParameter.java,v 1.4 2007/03/27 21:59:44 mlipp Exp $
021: *
022: * $Log: FormalParameter.java,v $
023: * Revision 1.4 2007/03/27 21:59:44 mlipp
024: * Fixed lots of checkstyle warnings.
025: *
026: * Revision 1.3 2006/09/29 12:32:07 drmlipp
027: * Consistently using WfMOpen as projct name now.
028: *
029: * Revision 1.2 2006/03/08 14:46:44 drmlipp
030: * Synchronized with 1.3.3p5.
031: *
032: * Revision 1.1.1.3.6.1 2006/02/15 20:17:08 drmlipp
033: * Added toString() for diagnostic purposes.
034: *
035: * Revision 1.1.1.3 2004/08/18 15:17:36 drmlipp
036: * Update to 1.2
037: *
038: * Revision 1.4 2004/01/19 12:30:58 lipp
039: * SchemaType now supported properly.
040: *
041: * Revision 1.3 2003/06/27 08:51:46 lipp
042: * Fixed copyright/license information.
043: *
044: * Revision 1.2 2003/05/15 07:46:41 lipp
045: * Proper handling of JavaScript default double result.
046: *
047: * Revision 1.1 2003/05/06 13:21:29 lipp
048: * Resolved cyclic dependency.
049: *
050: * Revision 1.1 2002/12/19 21:37:42 lipp
051: * Reorganized interfaces.
052: *
053: * Revision 1.1 2002/10/06 20:14:38 lipp
054: * Updated argument handling.
055: *
056: * Revision 1.6 2002/09/27 11:28:25 huaiyang
057: * Make constructor of Mode private and use fromString instead.
058: *
059: * Revision 1.5 2002/09/27 10:47:57 lipp
060: * Added equals and hashcode.
061: *
062: * Revision 1.4 2002/09/26 09:53:00 huaiyang
063: * In readresolve method use text representation to compare.
064: *
065: * Revision 1.3 2002/09/23 20:31:28 lipp
066: * Implemented async/sync invocation.
067: *
068: * Revision 1.2 2002/09/23 15:12:39 lipp
069: * Extended tool implementation definition and usage.
070: *
071: * Revision 1.1 2002/09/23 09:32:34 huaiyang
072: * initial.
073: *
074: *
075: */
076: package de.danet.an.workflow.api;
077:
078: import java.io.Serializable;
079:
080: /**
081: * This class provides a description of a formal parameter as used
082: * for workflow processes and workflow applications.
083: */
084: public class FormalParameter implements Serializable {
085:
086: /** Identifier for the parameter. */
087: private String id;
088: /** Index for the parameter. */
089: private String index;
090: /** Defined how this formal parameter defined. */
091: private Mode mode;
092: /** Parameter type. */
093: private Object type;
094:
095: /**
096: * Defines a class for representing priorities in a type save way.
097: */
098: public static final class Mode implements Serializable {
099: private static final long serialVersionUID = -3349015565438817722L;
100: /** Mode as Input Parameter. */
101: public static final Mode IN = new Mode("IN");
102: /** Mode as Output Parameter. */
103: public static final Mode OUT = new Mode("OUT");
104: /** Mode as input and output parameter. */
105: public static final Mode INOUT = new Mode("INOUT");
106:
107: private String mode = null;
108:
109: /**
110: * Default constructor.
111: * @param newMode mode as String.
112: */
113: private Mode(String newMode) {
114: mode = newMode;
115: }
116:
117: /**
118: * Get a Mode by name.
119: * @param text mode name to search
120: * @return mode object
121: * @throws IllegalArgumentException if <code>text</code> is not a valid
122: * mode name.
123: */
124: public static Mode fromString(String text)
125: throws IllegalArgumentException {
126: if (text == null) {
127: throw new IllegalArgumentException(text);
128: }
129: if (text.equals(IN.toString())) {
130: return IN;
131: } else if (text.equals(OUT.toString())) {
132: return OUT;
133: } else if (text.equals(INOUT.toString())) {
134: return INOUT;
135: } else {
136: throw new IllegalArgumentException(text);
137: }
138: }
139:
140: /**
141: * Returns the mode as text.
142: * @return mode as text
143: */
144: public final String toString() {
145: return mode;
146: }
147:
148: /**
149: * Perform instance substitution during serialization.
150: */
151: private Object readResolve() throws IllegalArgumentException {
152: try {
153: return fromString(mode);
154: } catch (IllegalArgumentException iae) {
155: throw new IllegalArgumentException(
156: "Unexpected error in serialization");
157: }
158: }
159: }
160:
161: /**
162: * Creates a new <code>FormalParameter</code>.
163: * @param newId identifier of the formal parameter in String
164: * @param newIndex index of the formal parameter in String. In the
165: * 1.iteration if the new Index is not null, a warning will be
166: * generated.
167: * @param newMode mode of this formal parameter
168: * @param newType type of this formal parameter
169: */
170: public FormalParameter(String newId, String newIndex, Mode newMode,
171: Object newType) {
172: id = newId;
173: index = newIndex;
174: mode = newMode;
175: type = newType;
176: }
177:
178: /**
179: * Return the id of the formal parameter.
180: * @return a String representing the id value
181: */
182: public String id() {
183: return id;
184: }
185:
186: /**
187: * Return the index of the formal parameter.
188: * @return a String representing the index value
189: */
190: public String index() {
191: return index;
192: }
193:
194: /**
195: * Return the mode of the formal parameter.
196: * @return the <code>FormalParameter.Mode</code> of the formal parameter.
197: */
198: public Mode mode() {
199: return mode;
200: }
201:
202: /**
203: * Return the type of the formal parameter. Types are represented
204: * as defined for {@link de.danet.an.workflow.api.ProcessMgr
205: * <code>ProcessMgr.contextSignature</code>}.
206: * @return the type of the formal parameter.
207: */
208: public Object type() {
209: return type;
210: }
211:
212: /**
213: * Compare two formal parameter objects.
214: * @param obj the object to compare with.
215: * @return <code>true</code> if the objects are equal.
216: */
217: public boolean equals(Object obj) {
218: FormalParameter o = (FormalParameter) obj;
219: return (id.equals(o.id) && index.equals(o.index) && mode
220: .equals(o.mode));
221: }
222:
223: /**
224: * Evaluate hash code.
225: * @return the hash code.
226: */
227: public int hashCode() {
228: return (id.hashCode() ^ index.hashCode());
229: }
230:
231: /**
232: * Create string representation for debugging purposes.
233: * @return the result.
234: */
235: public String toString() {
236: return "FormalParameter[id=" + id + ";index=" + index
237: + ";mode=" + mode + ";type=" + type + "]";
238: }
239: }
|