001: /**
002: * $Id: ParameterDescriptor.java,v 1.6 2003/12/01 10:47:36 vv138407 Exp $
003: * Copyright 2002-2003 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.providers.simplewebservice;
014:
015: import java.util.Iterator;
016:
017: import com.sun.portal.providers.simplewebservice.util.XList;
018: import com.sun.portal.providers.simplewebservice.util.SimpleWebServiceTypeConstants;
019:
020: /**
021: * A ParameterDescriptor represents the meta information of
022: * an (input or output) parameter involved in a SOAP call.
023: */
024:
025: public class ParameterDescriptor {
026:
027: private String name = null;
028: private Class type = null;
029: private Object value = null;
030: private ParameterDescriptor parent = null;
031:
032: private boolean arrayType = false;
033: private String arrayTypeName = null;
034: private boolean isRepeated = false;//Indicates if this is
035:
036: //a DocLiteralArray or not
037: /**
038: * Default constructor.
039: *
040: * @param name the name of the parameter.
041: * @param type the Class type of the parameter.
042: * @param value the default value of the parameter.
043: * @param parent the parameter which contains this parameter.
044: */
045: public ParameterDescriptor(String name, Class type, Object value,
046: ParameterDescriptor parent) {
047: this .name = name;
048: this .type = type;
049: this .value = value;
050: this .parent = parent;
051: }
052:
053: /**
054: * Get the name of the parameter.
055: *
056: * @return the name of the parameter.
057: */
058: public String getName() {
059: return name;
060: }
061:
062: /**
063: * Get the Class type of the parameter.
064: *
065: * @return the Class type of the parameter.
066: */
067: public Class getType() {
068: return type;
069: }
070:
071: /**
072: * Get the default value of the parameter (if any exists).
073: *
074: * @return the default value of the parameter.
075: */
076: public Object getValue() {
077: return value;
078: }
079:
080: /**
081: * Determines if the parameter is representing an array.
082: *
083: * @return true if the parameter represents an array, else false.
084: */
085: public boolean isArrayType() {
086: return this .arrayType;
087: }
088:
089: /**
090: * Sets the parameter to represent an array.
091: *
092: * @see ParameterDescriptor#isArrayType
093: */
094: public void setArrayType(boolean isArray) {
095: this .arrayType = isArray;
096: }
097:
098: /**
099: * Gets the name of the array type.
100: * If the parameter does not represent an array, then a null value is returned.
101: * <code> isArrayType </code> should be used for determining, if the parameter represents an array.
102: *
103: * @see ParameterDescriptor#isArrayType
104: * @return the name of the array element's type.
105: */
106: public String getArrayTypeName() {
107: return this .arrayTypeName;
108: }
109:
110: /**
111: * Sets the name of the array type.
112: * If the parameter represents an array, then <code> setArrayType </code> should be called
113: * before setting name of the array type.
114: *
115: * @see ParameterDescriptor#setArrayType
116: */
117: public void setArrayTypeName(String typeName) {
118: this .arrayTypeName = typeName;
119: }
120:
121: /**
122: * Determines if the parameter is representing a simple type.
123: *
124: * @return true if the parameter represents a simple type, else false.
125: */
126: public boolean isSimpleType() {
127: return isSimpleType(this .type);
128: }
129:
130: /**
131: * Determines if the parameter is representing a simple type array.
132: *
133: * @return true if the parameter represents a simple type array, else false.
134: */
135: public boolean isSimpleTypeArray() {
136: return isSimpleType(this .arrayTypeName);
137: }
138:
139: public ParameterDescriptor getParent() {
140: return parent;
141: }
142:
143: public String getFullName() {
144: StringBuffer fullName = new StringBuffer(getName());
145: ParameterDescriptor currParent = parent;
146: while (currParent != null) {
147: fullName.insert(0, currParent.getName() + "_");
148: currParent = currParent.getParent();
149: }
150: return fullName.toString();
151: }
152:
153: /**
154: * Get the String representation of this parameter.
155: *
156: * @return the String representation of the parameter.
157: */
158: public String toString() {
159: StringBuffer strBuf = new StringBuffer();
160:
161: strBuf.append("ParameterDescriptor- ");
162: strBuf.append("[name=" + name + "] ");
163: strBuf.append("[type=" + type + "] ");
164: strBuf.append("isRepeatable" + isRepeatable());
165: //strBuf.append("Array Type" + getArrayTypeName());
166:
167: if (type.equals(XList.class)) {
168: XList paramDescriptorList = (XList) getValue();
169: Iterator paramDescriptorListIter = paramDescriptorList
170: .iterator();
171: while (paramDescriptorListIter.hasNext()) {
172: ParameterDescriptor childDesc = (ParameterDescriptor) paramDescriptorListIter
173: .next();
174: strBuf.append("\t\t child=" + childDesc + "] ");
175: }
176:
177: } else {
178: strBuf.append("[value=" + value + "] ");
179: }
180:
181: return strBuf.toString();
182: }
183:
184: private boolean isSimpleType(Class elementType) {
185: if (elementType == null)
186: return false;
187:
188: return (elementType.equals(java.lang.String.class)
189: || elementType.equals(Integer.class)
190: || elementType.equals(Float.class)
191: || elementType.equals(Double.class)
192: || elementType.equals(Boolean.class)
193: || elementType.equals(Long.class)
194: || elementType.equals(Byte.class) || elementType
195: .equals(Short.class));
196: }
197:
198: private boolean isSimpleType(String elementType) {
199: if (elementType == null)
200: return false;
201:
202: return (elementType
203: .endsWith(SimpleWebServiceTypeConstants.STRING)
204: || elementType
205: .endsWith(SimpleWebServiceTypeConstants.INT)
206: || elementType
207: .endsWith(SimpleWebServiceTypeConstants.FLOAT)
208: || elementType
209: .endsWith(SimpleWebServiceTypeConstants.DOUBLE)
210: || elementType
211: .endsWith(SimpleWebServiceTypeConstants.BOOLEAN)
212: || elementType
213: .endsWith(SimpleWebServiceTypeConstants.LONG)
214: || elementType
215: .endsWith(SimpleWebServiceTypeConstants.BYTE) || elementType
216: .endsWith(SimpleWebServiceTypeConstants.SHORT));
217: }
218:
219: public boolean isRepeatable() {
220: return isRepeated;
221: }
222:
223: public void setRepeated(boolean isRepeated) {
224: this.isRepeated = isRepeated;
225: }
226:
227: }
|