KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > wsdl > symbolTable > TypeEntry


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.wsdl.symbolTable;
56
57 import org.jboss.axis.utils.Messages;
58 import org.w3c.dom.Node JavaDoc;
59
60 import javax.xml.namespace.QName JavaDoc;
61 import java.io.IOException JavaDoc;
62
63 /**
64  * This class represents a wsdl types entry that is supported by the WSDL2Java emitter.
65  * A TypeEntry has a QName representing its XML name and a name, which in the
66  * WSDL2Java back end is its full java name. The TypeEntry may also have a Node,
67  * which locates the definition of the emit type in the xml.
68  * A TypeEntry object extends SymTabEntry and is built by the SymbolTable class for
69  * each supported root complexType, simpleType, and elements that are
70  * defined or encountered.
71  * <p/>
72  * SymTabEntry
73  * |
74  * TypeEntry
75  * / \
76  * Type Element
77  * | |
78  * (BaseType, (DefinedElement,
79  * CollectionType CollectionElement,
80  * DefinedType, UndefinedElement)
81  * UndefinedType)
82  * <p/>
83  * UndefinedType and UndefinedElement are placeholders when the real type or element
84  * is not encountered yet. Both of these implement the Undefined interface.
85  * <p/>
86  * A TypeEntry whose java (or other language) name depends on an Undefined type, will
87  * have its name initialization deferred until the Undefined type is replaced with
88  * a defined type. The updateUndefined() method is invoked by the UndefinedDelegate to
89  * update the information.
90  * <p/>
91  * Each TypeEntry whose language name depends on another TypeEntry will have the refType
92  * field set. For example:
93  * <element name="foo" type="bar" />
94  * The TypeEntry for "foo" will have a refType set to the TypeEntry of "bar".
95  * <p/>
96  * Another Example:
97  * <xsd:complexType name="hobbyArray">
98  * <xsd:complexContent>
99  * <xsd:restriction base="soapenc:Array">
100  * <xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
101  * </xsd:restriction>
102  * </xsd:complexContent>
103  * </xsd:complexType>
104  * The TypeEntry for "hobbyArray" will have a refType that locates the TypeEntry for xsd:string
105  * and the dims field will be "[]"
106  *
107  * @author Rich Scheuerle (scheu@us.ibm.com)
108  */

109 public abstract class TypeEntry extends SymTabEntry
110 {
111    protected Node JavaDoc node; // Node
112

113    protected TypeEntry refType; // Some TypeEntries refer to other types.
114

115
116    protected String JavaDoc dims = ""; // If refType is an element, dims indicates
117
// the array dims (for example "[]").
118

119    protected boolean undefined; // If refType is an Undefined type
120
// (or has a refType that is Undefined)
121
// then the undefined flag is set.
122
// The name cannot be determined
123
// until the Undefined type is found.
124
protected boolean isBaseType;// Indicates if represented by a
125
// primitive or util class
126
protected boolean isSimpleType = false; // Indicates if this type is a simple type
127
protected boolean onlyLiteralReference = false; // Indicates
128
// whether this type is only referenced
129
// via a binding's literal use.
130

131    /**
132     * Create a TypeEntry object for an xml construct that references another type.
133     * Defer processing until refType is known.
134     */

135    protected TypeEntry(QName JavaDoc pqName, TypeEntry refType, Node JavaDoc pNode, String JavaDoc dims)
136    {
137       super(pqName);
138       node = pNode;
139       this.undefined = refType.undefined;
140       this.refType = refType;
141       if (dims == null)
142          dims = "";
143       this.dims = dims;
144
145       if (refType.undefined)
146       {
147          // Need to defer processing until known.
148
TypeEntry uType = refType;
149          while (!(uType instanceof Undefined))
150          {
151             uType = uType.refType;
152          }
153          ((Undefined)uType).register(this);
154       }
155       else
156       {
157          isBaseType = (refType.isBaseType && refType.dims.equals("") && dims.equals(""));
158       }
159
160       //System.out.println(toString());
161

162    }
163
164    /**
165     * Create a TypeEntry object for an xml construct that is not a base type
166     */

167    protected TypeEntry(QName JavaDoc pqName, Node JavaDoc pNode)
168    {
169       super(pqName);
170       node = pNode;
171       refType = null;
172       undefined = false;
173       dims = "";
174       isBaseType = false;
175       //System.out.println(toString());
176
}
177
178    /**
179     * Create a TypeEntry object for an xml construct name that represents a base type
180     */

181    protected TypeEntry(QName JavaDoc pqName)
182    {
183       super(pqName);
184       node = null;
185       undefined = false;
186       dims = "";
187       isBaseType = true;
188       //System.out.println(toString());
189
}
190
191    /**
192     * Query the node for this type.
193     */

194    public Node JavaDoc getNode()
195    {
196       return node;
197    }
198
199    /**
200     * Returns the Base Type Name.
201     * For example if the Type represents a schema integer, "int" is returned.
202     * If this is a user defined type, null is returned.
203     */

204    public String JavaDoc getBaseType()
205    {
206       if (isBaseType)
207       {
208          return name;
209       }
210       else
211       {
212          return null;
213       }
214    }
215
216    public boolean isBaseType()
217    {
218       return isBaseType;
219    }
220
221    public boolean isSimpleType()
222    {
223       return isSimpleType;
224    }
225
226    public void setSimpleType(boolean simpleType)
227    {
228       isSimpleType = simpleType;
229    }
230
231    /**
232     * Is this type references ONLY as a literal type? If a binding's
233     * message's soapBody says: use="literal", then a type is referenced
234     * literally. Note that that type's contained types (ie., an address
235     * contains a phone#) are not referenced literally. Since a type
236     * that is ONLY referenced as a literal may cause a generator to act
237     * differently (like WSDL2Java), this extra reference distinction is
238     * needed.
239     */

240    public boolean isOnlyLiteralReferenced()
241    {
242       return onlyLiteralReference;
243    } // isOnlyLiteralReferenced
244

245    /**
246     * Set the isOnlyLiteralReference flag.
247     */

248    public void setOnlyLiteralReference(boolean set)
249    {
250       onlyLiteralReference = set;
251    } // setOnlyLiteralRefeerence
252

253    /**
254     * getUndefinedTypeRef returns the Undefined TypeEntry that this entry depends on or NULL.
255     */

256    protected TypeEntry getUndefinedTypeRef()
257    {
258       if (this instanceof Undefined)
259          return this;
260       if (undefined && refType != null)
261       {
262          if (refType.undefined)
263          {
264             TypeEntry uType = refType;
265             while (!(uType instanceof Undefined))
266             {
267                uType = uType.refType;
268             }
269             return uType;
270          }
271       }
272       return null;
273    }
274
275    /**
276     * UpdateUndefined is called when the ref TypeEntry is finally known.
277     *
278     * @param oldRef The TypeEntry representing the Undefined TypeEntry
279     * @param newRef The replacement TypeEntry
280     * @return true if TypeEntry is changed in any way.
281     */

282    protected boolean updateUndefined(TypeEntry oldRef, TypeEntry newRef) throws IOException JavaDoc
283    {
284       boolean changedState = false;
285       // Replace refType with the new one if applicable
286
if (refType == oldRef)
287       {
288          refType = newRef;
289          changedState = true;
290          // Detect a loop
291
TypeEntry te = refType;
292          while (te != null && te != this)
293          {
294             te = te.refType;
295          }
296          if (te == this)
297          {
298             // Detected a loop.
299
undefined = false;
300             isBaseType = false;
301             node = null;
302             throw new IOException JavaDoc(Messages.getMessage("undefinedloop00", getQName().toString()));
303          }
304       }
305
306       // Update information if refType is now defined
307
if (refType != null && undefined && refType.undefined == false)
308       {
309          undefined = false;
310          changedState = true;
311          isBaseType = (refType.isBaseType && refType.dims.equals("") && dims.equals(""));
312       }
313       return changedState;
314    }
315
316
317    /**
318     * If this type references another type, return that type, otherwise return null.
319     */

320    public TypeEntry getRefType()
321    {
322       return refType;
323    } // getRefType
324

325    public void setRefType(TypeEntry refType)
326    {
327       this.refType = refType;
328    }
329
330    /**
331     * Return the dimensions of this type, which can be 0 or more "[]".
332     */

333    public String JavaDoc getDimensions()
334    {
335       return dims;
336    } // getDimensions
337

338    /**
339     * Get string representation.
340     */

341    public String JavaDoc toString()
342    {
343       return toString("");
344    }
345
346    /**
347     * Get string representation with indentation
348     */

349    protected String JavaDoc toString(String JavaDoc indent)
350    {
351       String JavaDoc refString = indent + "RefType: null \n";
352       if (refType != null)
353          refString = indent + "RefType:\n" + refType.toString(indent + " ") + "\n";
354       return super.toString(indent) +
355               indent + "Class: " + this.getClass().getName() + "\n" +
356               indent + "Base?: " + isBaseType + "\n" +
357               indent + "Undefined?: " + undefined + "\n" +
358               indent + "isSimpleType? " + isSimpleType + "\n" +
359               indent + "Node: " + getNode() + "\n" +
360               indent + "Dims: " + dims + "\n" +
361               refString;
362    }
363 }
364
365 ;
366
Popular Tags