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.data;
046:
047: import org.obe.util.AbstractBean;
048: import org.obe.xpdl.PackageVisitor;
049: import org.obe.xpdl.XPDLMessages;
050:
051: /**
052: * FormalParameter defines input and output parameters which are passed to
053: * tools.
054: *
055: * @author Adrian Price
056: */
057: public class FormalParameter extends AbstractBean {
058: private static final long serialVersionUID = 3019502908080770457L;
059:
060: private String _id;
061: private Integer _index;
062: private ParameterMode _mode;
063: private DataType _dataType;
064: private String _description;
065:
066: /**
067: * Constructs a new FormalParameter object.
068: */
069: public FormalParameter() {
070: }
071:
072: /**
073: * Constructs a new FormalParameter object.
074: *
075: * @param id The unique id
076: * @param index The index of the parameter
077: * @param mode The ParameterMode
078: * @param dataType The DataType
079: * @param description The name
080: */
081: public FormalParameter(String id, String index, String mode,
082: DataType dataType, String description) {
083:
084: this (id, index == null ? null : Integer.valueOf(index),
085: ParameterMode.valueOf(mode), dataType, description);
086: }
087:
088: /**
089: * Constructs a new FormalParameter object.
090: *
091: * @param id The unique id
092: * @param index The index of the parameter
093: * @param mode The ParameterMode
094: * @param dataType The DataType
095: * @param description The description
096: */
097: public FormalParameter(String id, Integer index,
098: ParameterMode mode, DataType dataType, String description) {
099:
100: _id = id;
101: _description = description;
102: setIndex(index);
103: setMode(mode);
104: setDataType(dataType);
105: }
106:
107: public final void accept(PackageVisitor visitor) {
108: visitor.visit(this );
109: }
110:
111: /**
112: * Get the unique id.
113: *
114: * @return The id
115: */
116: public final String getId() {
117: return _id;
118: }
119:
120: public final void setId(String id) {
121: _id = id;
122: }
123:
124: public final String getDescription() {
125: return _description;
126: }
127:
128: public final void setDescription(String description) {
129: _description = description;
130: }
131:
132: public final Integer getIndex() {
133: return _index;
134: }
135:
136: public final void setIndex(Integer index) {
137: _index = index;
138: }
139:
140: public final void setIndex(String index) {
141: setIndex(index == null ? null : Integer.valueOf(index));
142: }
143:
144: public final DataType getDataType() {
145: return _dataType;
146: }
147:
148: public final void setDataType(DataType dataType) {
149: if (dataType == null)
150: throw new IllegalArgumentException(
151: XPDLMessages.DATA_TYPE_REQUIRED);
152: _dataType = dataType;
153: }
154:
155: public final String getDataTypeString() {
156: return _dataType == null
157: || !(_dataType.getType() instanceof BasicType) ? null
158: : _dataType.getType().toString();
159: }
160:
161: public final void setDataTypeString(String basicType) {
162: setDataType(new DataType(BasicType.valueOf(basicType)));
163: }
164:
165: /**
166: * Get the parameter mode. The default parameter mode of
167: * <code>ParameterMode.IN</code>.
168: *
169: * @return The parameter mode
170: */
171: public final ParameterMode getMode() {
172: return _mode;
173: }
174:
175: /**
176: * Set the parameter mode. If a null value is passed then the parameter
177: * mode will be treated as {@link ParameterMode#IN}.
178: *
179: * @param mode The new parameter mode
180: */
181: public final void setMode(ParameterMode mode) {
182: _mode = mode;
183: }
184:
185: /**
186: * Returns the parameter mode as a string.
187: *
188: * @return Parameter mode string.
189: */
190: public final String getModeString() {
191: return _mode == null ? null : _mode.toString();
192: }
193:
194: /**
195: * Sets the parameter mode as a string. If a null value is passed then the
196: * parameter mode will be reset to the default (ParameterMode.IN).
197: *
198: * @param mode The new parameter mode. Must be a valid {@link ParameterMode}.
199: */
200: public final void setModeString(String mode) {
201: setMode(ParameterMode.valueOf(mode));
202: }
203:
204: public String toString() {
205: return "FormalParameter[id=" + _id + ", index=" + _index
206: + ", mode=" + _mode + ", dataType=" + _dataType
207: + ", description=" + _description + ']';
208: }
209: }
|