KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > description > ParameterDesc


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis.description;
17
18 import org.apache.axis.utils.Messages;
19 import org.apache.axis.wsdl.symbolTable.TypeEntry;
20
21 import javax.xml.namespace.QName JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.io.ObjectInputStream JavaDoc;
24 import java.io.ObjectOutputStream JavaDoc;
25 import java.io.Serializable JavaDoc;
26
27 /**
28  * A Parameter descriptor, collecting the interesting info about an
29  * operation parameter.
30  *
31  * (mostly taken from org.apache.axis.wsdl.toJava.Parameter right now)
32  *
33  * @author Glen Daniels (gdaniels@apache.org)
34  */

35 public class ParameterDesc implements Serializable JavaDoc {
36
37     // constant values for the parameter mode.
38
public static final byte IN = 1;
39     public static final byte OUT = 2;
40     public static final byte INOUT = 3;
41
42     /** The Parameter's XML QName */
43     private transient QName JavaDoc name;
44     /** A TypeEntry corresponding to this parameter */
45     public TypeEntry typeEntry;
46     /** The Parameter mode (in, out, inout) */
47     private byte mode = IN;
48     /** The XML type of this parameter */
49     private QName JavaDoc typeQName;
50     /** The Java type of this parameter */
51     private Class JavaDoc javaType = null;
52     /** The order of this parameter (-1 indicates unordered) */
53     private int order = -1;
54     /** Indicates if this ParameterDesc represents a return or normal parameter **/
55     private boolean isReturn = false;
56     /** MIME type for this parameter, if there is one */
57     private String JavaDoc mimeType = null;
58     /** If this ParamDesc represents a literal array, this QName will
59      * determine if it gets written as a "bare" or a "wrapped" schema.
60      */

61     private QName JavaDoc itemQName;
62     private QName JavaDoc itemType;
63
64     /** Indicates whether input/output values are stored in the header */
65     private boolean inHeader = false;
66     private boolean outHeader = false;
67
68     /** The documentation for the parameter */
69     private String JavaDoc documentation = null;
70
71     public ParameterDesc() {
72     }
73
74     /**
75      * Constructor-copy
76      *
77      * @param copy the copy
78      */

79     public ParameterDesc(ParameterDesc copy) {
80         name = copy.name;
81         typeEntry = copy.typeEntry;
82         mode = copy.mode;
83         typeQName = copy.typeQName;
84         javaType = copy.javaType;
85         order = copy.order;
86         isReturn = copy.isReturn;
87         mimeType = copy.mimeType;
88         inHeader = copy.inHeader;
89         outHeader = copy.outHeader;
90     }
91
92     /**
93      * Constructor
94      *
95      * @param name the parameter's fully qualified XML name
96      * @param mode IN, OUT, INOUT
97      * @param typeQName the parameter's XML type QName
98      */

99     public ParameterDesc(QName JavaDoc name, byte mode, QName JavaDoc typeQName) {
100         this.name = name;
101         this.mode = mode;
102         this.typeQName = typeQName;
103     }
104
105     /**
106      * "Complete" constructor, suitable for usage in skeleton code
107      *
108      * @param name the parameter's fully qualified XML name
109      * @param mode IN, OUT, INOUT
110      * @param typeQName the parameter's XML type QName
111      * @param javaType the parameter's javaType
112      * @param inHeader does this parameter go into the input message header?
113      * @param outHeader does this parameter go into the output message header?
114      */

115     public ParameterDesc(QName JavaDoc name, byte mode, QName JavaDoc typeQName,
116             Class JavaDoc javaType, boolean inHeader, boolean outHeader) {
117         this(name,mode,typeQName);
118         this.javaType = javaType;
119         this.inHeader = inHeader;
120         this.outHeader = outHeader;
121     }
122
123     /**
124      * @deprecated
125      * @param name the parameter's fully qualified XML name
126      * @param mode IN, OUT, INOUT
127      * @param typeQName the parameter's XML type QName
128      * @param javaType the parameter's javaType
129      */

130     public ParameterDesc(QName JavaDoc name, byte mode, QName JavaDoc typeQName, Class JavaDoc javaType) {
131       this(name,mode,typeQName,javaType,false,false);
132     }
133
134     public String JavaDoc toString() {
135         return toString("");
136     }
137     public String JavaDoc toString(String JavaDoc indent) {
138         String JavaDoc text="";
139         text+=indent + "name: " + name + "\n";
140         text+=indent + "typeEntry: " + typeEntry + "\n";
141         text+=indent + "mode: " + (mode == IN ?
142                                          "IN" : mode == INOUT ?
143                                          "INOUT" : "OUT") + "\n";
144         text+=indent + "position: " + order + "\n";
145         text+=indent + "isReturn: " + isReturn + "\n";
146         text+=indent + "typeQName: " + typeQName + "\n";
147         text+=indent + "javaType: " + javaType + "\n";
148         text+=indent + "inHeader: " + inHeader + "\n";
149         text+=indent + "outHeader: " + outHeader+ "\n";
150         return text;
151     } // toString
152

153     /**
154      * Get a mode constant from a string. Defaults to IN, and returns
155      * OUT or INOUT if the string matches (ignoring case).
156      */

157     public static byte modeFromString(String JavaDoc modeStr)
158     {
159         byte ret = IN;
160         if (modeStr == null) {
161             return IN;
162         } else if (modeStr.equalsIgnoreCase("out")) {
163             ret = OUT;
164         } else if (modeStr.equalsIgnoreCase("inout")) {
165             ret = INOUT;
166         }
167         return ret;
168     }
169
170     public static String JavaDoc getModeAsString(byte mode)
171     {
172         if (mode == INOUT) {
173             return "inout";
174         } else if (mode == OUT) {
175             return "out";
176         } else if (mode == IN) {
177             return "in";
178         }
179
180         throw new IllegalArgumentException JavaDoc(
181                 Messages.getMessage("badParameterMode", Byte.toString(mode)));
182     }
183
184     public QName JavaDoc getQName() {
185         return name;
186     }
187
188     public String JavaDoc getName() {
189         if (name == null) {
190             return null;
191         }
192         else {
193             return name.getLocalPart();
194         }
195     }
196
197     public void setName(String JavaDoc name) {
198         this.name = new QName JavaDoc("", name);
199     }
200
201     public void setQName(QName JavaDoc name) {
202         this.name = name;
203     }
204
205     public QName JavaDoc getTypeQName() {
206         return typeQName;
207     }
208
209     public void setTypeQName(QName JavaDoc typeQName) {
210         this.typeQName = typeQName;
211     }
212
213     /**
214      * Get the java type (note that this is javaType in the signature.)
215      * @return Class javaType
216      */

217     public Class JavaDoc getJavaType() {
218         return javaType;
219     }
220
221     /**
222      * Set the java type (note that this is javaType in the signature.)
223      */

224     public void setJavaType(Class JavaDoc javaType) {
225         // The javaType must match the mode. A Holder is expected for OUT/INOUT
226
// parameters that don't represent the return type.
227
if (javaType != null) {
228             if ((mode == IN || isReturn) &&
229                 javax.xml.rpc.holders.Holder JavaDoc.class.isAssignableFrom(javaType) ||
230                 mode != IN && !isReturn &&
231                 !javax.xml.rpc.holders.Holder JavaDoc.class.isAssignableFrom(javaType)) {
232                 throw new IllegalArgumentException JavaDoc(
233                      Messages.getMessage("setJavaTypeErr00",
234                                           javaType.getName(),
235                                           getModeAsString(mode)));
236             }
237         }
238
239         this.javaType = javaType;
240     }
241
242     public byte getMode() {
243         return mode;
244     }
245
246     public void setMode(byte mode) {
247         this.mode = mode;
248     }
249
250     public int getOrder() {
251         return order;
252     }
253
254     public void setOrder(int order) {
255         this.order = order;
256     }
257
258     public void setInHeader(boolean value) {
259         this.inHeader = value;
260     }
261
262     public boolean isInHeader() {
263         return this.inHeader;
264     }
265
266     public void setOutHeader(boolean value) {
267         this.outHeader = value;
268     }
269
270     public boolean isOutHeader() {
271         return this.outHeader;
272     }
273
274     /**
275      * Indicates ParameterDesc represents return of OperationDesc
276      * @return true if return parameter of OperationDesc
277      */

278     public boolean getIsReturn() {
279         return isReturn;
280     }
281     /**
282      * Set to true to indicate return parameter of OperationDesc
283      * @param value boolean that indicates if return parameter of OperationDesc
284      */

285     public void setIsReturn(boolean value) {
286         isReturn = value;
287     }
288
289     /**
290      * get the documentation for the parameter
291      */

292     public String JavaDoc getDocumentation() {
293         return documentation;
294     }
295
296     /**
297      * set the documentation for the parameter
298      */

299     public void setDocumentation(String JavaDoc documentation) {
300         this.documentation = documentation;
301     }
302
303     private void writeObject(ObjectOutputStream JavaDoc out)
304         throws IOException JavaDoc {
305         if (name == null) {
306             out.writeBoolean(false);
307         } else {
308             out.writeBoolean(true);
309             out.writeObject(name.getNamespaceURI());
310             out.writeObject(name.getLocalPart());
311         }
312         if (typeQName == null) {
313             out.writeBoolean(false);
314         } else {
315             out.writeBoolean(true);
316             out.writeObject(typeQName.getNamespaceURI());
317             out.writeObject(typeQName.getLocalPart());
318         }
319         out.defaultWriteObject();
320     }
321
322     private void readObject(ObjectInputStream JavaDoc in)
323         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
324         if (in.readBoolean()) {
325             name = new QName JavaDoc((String JavaDoc)in.readObject(),
326                              (String JavaDoc)in.readObject());
327         } else {
328             name = null;
329         }
330         if (in.readBoolean()) {
331             typeQName = new QName JavaDoc((String JavaDoc)in.readObject(),
332                                   (String JavaDoc)in.readObject());
333         } else {
334             typeQName = null;
335         }
336         in.defaultReadObject();
337     }
338
339     public QName JavaDoc getItemQName() {
340         return itemQName;
341     }
342
343     public void setItemQName(QName JavaDoc itemQName) {
344         this.itemQName = itemQName;
345     }
346
347     public QName JavaDoc getItemType() {
348         return itemType;
349     }
350
351     public void setItemType(QName JavaDoc itemType) {
352         this.itemType = itemType;
353     }
354 }
355
Popular Tags