KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55 package org.jboss.axis.description;
56
57 import org.jboss.axis.utils.Messages;
58 import org.jboss.axis.wsdl.symbolTable.TypeEntry;
59
60 import javax.xml.namespace.QName JavaDoc;
61 import javax.xml.rpc.holders.Holder JavaDoc;
62
63 /**
64  * A Parameter descriptor, collecting the interesting info about an
65  * operation parameter.
66  * <p/>
67  * (mostly taken from org.jboss.axis.wsdl.toJava.Parameter right now)
68  *
69  * @author Glen Daniels (gdaniels@apache.org)
70  */

71 public class ParameterDesc
72 {
73    // constant values for the parameter mode.
74
public static final byte IN = 1;
75    public static final byte OUT = 2;
76    public static final byte INOUT = 3;
77
78    /**
79     * The Parameter's XML QName
80     */

81    private transient QName JavaDoc name;
82    /**
83     * A TypeEntry corresponding to this parameter
84     */

85    public TypeEntry typeEntry;
86    /**
87     * The Parameter mode (in, out, inout)
88     */

89    private byte mode = IN;
90    /**
91     * The XML type of this parameter
92     */

93    private QName JavaDoc typeQName;
94    /**
95     * The Java type of this parameter
96     */

97    private Class JavaDoc javaType = null;
98    /**
99     * The order of this parameter (-1 indicates unordered)
100     */

101    private int order = -1;
102    /**
103     * Indicates if this ParameterDesc represents a return or normal parameter *
104     */

105    private boolean isReturn = false;
106    /**
107     * MIME type for this parameter, if there is one
108     */

109    private String JavaDoc mimeType = null;
110
111    /**
112     * Indicates whether input/output values are stored in the header
113     */

114    private boolean inHeader = false;
115    private boolean outHeader = false;
116
117    public ParameterDesc()
118    {
119    }
120
121    /**
122     * Constructor-copy
123     *
124     * @param copy the copy
125     */

126    public ParameterDesc(ParameterDesc copy)
127    {
128       name = copy.name;
129       typeEntry = copy.typeEntry;
130       mode = copy.mode;
131       typeQName = copy.typeQName;
132       javaType = copy.javaType;
133       order = copy.order;
134       isReturn = copy.isReturn;
135       mimeType = copy.mimeType;
136       inHeader = copy.inHeader;
137       outHeader = copy.outHeader;
138    }
139
140    /**
141     * Constructor
142     *
143     * @param name the parameter's fully qualified XML name
144     * @param mode IN, OUT, INOUT
145     * @param typeQName the parameter's XML type QName
146     */

147    public ParameterDesc(QName JavaDoc name, byte mode, QName JavaDoc typeQName)
148    {
149       this.name = name;
150       this.mode = mode;
151       this.typeQName = typeQName;
152    }
153
154    /**
155     * "Complete" constructor, suitable for usage in skeleton code
156     *
157     * @param name the parameter's fully qualified XML name
158     * @param mode IN, OUT, INOUT
159     * @param typeQName the parameter's XML type QName
160     * @param javaType the parameter's javaType
161     * @param inHeader does this parameter go into the input message header?
162     * @param outHeader does this parameter go into the output message header?
163     */

164    public ParameterDesc(QName JavaDoc name, byte mode, QName JavaDoc typeQName,
165                         Class JavaDoc javaType, boolean inHeader, boolean outHeader)
166    {
167       this(name, mode, typeQName);
168       this.javaType = javaType;
169       this.inHeader = inHeader;
170       this.outHeader = outHeader;
171    }
172
173    /**
174     * @param name the parameter's fully qualified XML name
175     * @param mode IN, OUT, INOUT
176     * @param typeQName the parameter's XML type QName
177     * @param javaType the parameter's javaType
178     * @deprecated
179     */

180    public ParameterDesc(QName JavaDoc name, byte mode, QName JavaDoc typeQName, Class JavaDoc javaType)
181    {
182       this(name, mode, typeQName, javaType, false, false);
183    }
184
185    public String JavaDoc toString()
186    {
187       return toString("");
188    }
189
190    public String JavaDoc toString(String JavaDoc indent)
191    {
192       String JavaDoc text = "";
193       text += indent + "name: " + name + "\n";
194       text += indent + "typeEntry: " + typeEntry + "\n";
195       text += indent + "mode: " + (mode == IN ?
196               "IN" : mode == INOUT ?
197               "INOUT" : "OUT: "
198               + "position:" + order) + "\n";
199       text += indent + "isReturn: " + isReturn + "\n";
200       text += indent + "typeQName: " + typeQName + "\n";
201       text += indent + "javaType: " + javaType + "\n";
202       text += indent + "inHeader: " + inHeader + "\n";
203       text += indent + "outHeader: " + outHeader + "\n";
204       return text;
205    } // toString
206

207    /**
208     * Get a mode constant from a string. Defaults to IN, and returns
209     * OUT or INOUT if the string matches (ignoring case).
210     */

211    public static byte modeFromString(String JavaDoc modeStr)
212    {
213       byte ret = IN;
214       if (modeStr == null)
215       {
216          return IN;
217       }
218       else if (modeStr.equalsIgnoreCase("out"))
219       {
220          ret = OUT;
221       }
222       else if (modeStr.equalsIgnoreCase("inout"))
223       {
224          ret = INOUT;
225       }
226       return ret;
227    }
228
229    public static String JavaDoc getModeAsString(byte mode)
230    {
231       if (mode == INOUT)
232       {
233          return "inout";
234       }
235       else if (mode == OUT)
236       {
237          return "out";
238       }
239       else if (mode == IN)
240       {
241          return "in";
242       }
243
244       throw new IllegalArgumentException JavaDoc(Messages.getMessage("badParameterMode", Byte.toString(mode)));
245    }
246
247    public QName JavaDoc getQName()
248    {
249       return name;
250    }
251
252    public String JavaDoc getName()
253    {
254       if (name == null)
255       {
256          return null;
257       }
258       else
259       {
260          return name.getLocalPart();
261       }
262    }
263
264    public void setName(String JavaDoc name)
265    {
266       this.name = new QName JavaDoc("", name);
267    }
268
269    public void setQName(QName JavaDoc name)
270    {
271       this.name = name;
272    }
273
274    public QName JavaDoc getTypeQName()
275    {
276       return typeQName;
277    }
278
279    public void setTypeQName(QName JavaDoc typeQName)
280    {
281       this.typeQName = typeQName;
282    }
283
284    /**
285     * Get the java type (note that this is javaType in the signature.)
286     *
287     * @return Class javaType
288     */

289    public Class JavaDoc getJavaType()
290    {
291       return javaType;
292    }
293
294    /**
295     * Set the java type (note that this is javaType in the signature.)
296     */

297    public void setJavaType(Class JavaDoc javaType)
298    {
299       // The javaType must match the mode. A Holder is expected for OUT/INOUT
300
// parameters that don't represent the return type.
301
if (javaType != null && !isReturn && mode != IN)
302       {
303          if (!Holder JavaDoc.class.isAssignableFrom(javaType))
304          {
305             throw new IllegalArgumentException JavaDoc(Messages.getMessage("setJavaTypeErr00",
306                     javaType.getName(), getModeAsString(mode)));
307          }
308       }
309
310       this.javaType = javaType;
311    }
312
313    public byte getMode()
314    {
315       return mode;
316    }
317
318    public void setMode(byte mode)
319    {
320       this.mode = mode;
321    }
322
323    public int getOrder()
324    {
325       return order;
326    }
327
328    public void setOrder(int order)
329    {
330       this.order = order;
331    }
332
333    public void setInHeader(boolean value)
334    {
335       this.inHeader = value;
336    }
337
338    public boolean isInHeader()
339    {
340       return this.inHeader;
341    }
342
343    public void setOutHeader(boolean value)
344    {
345       this.outHeader = value;
346    }
347
348    public boolean isOutHeader()
349    {
350       return this.outHeader;
351    }
352
353    /**
354     * Indicates ParameterDesc represents return of OperationDesc
355     *
356     * @return true if return parameter of OperationDesc
357     */

358    public boolean getIsReturn()
359    {
360       return isReturn;
361    }
362
363    /**
364     * Set to true to indicate return parameter of OperationDesc
365     *
366     * @param value boolean that indicates if return parameter of OperationDesc
367     */

368    public void setIsReturn(boolean value)
369    {
370       isReturn = value;
371    }
372 }
373
Popular Tags