KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > schema > Parser


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002 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 "WSIF" 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 and was
52  * originally based on software copyright (c) 2001, 2002, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.apache.wsif.schema;
59
60 import java.io.Reader JavaDoc;
61 import java.util.ArrayList JavaDoc;
62 import java.util.Hashtable JavaDoc;
63 import java.util.Iterator JavaDoc;
64 import java.util.List JavaDoc;
65 import java.util.Map JavaDoc;
66
67 import javax.wsdl.Definition;
68 import javax.wsdl.Import;
69 import javax.wsdl.Types;
70 import javax.wsdl.extensions.UnknownExtensibilityElement;
71 import javax.wsdl.xml.WSDLLocator;
72 import javax.xml.namespace.QName JavaDoc;
73 import javax.xml.parsers.DocumentBuilder JavaDoc;
74 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
75
76 import org.apache.wsif.WSIFConstants;
77 import org.apache.wsif.WSIFException;
78 import org.apache.wsif.logging.Trc;
79 import org.apache.wsif.util.WSIFUtils;
80 import org.apache.wsif.wsdl.WSIFWSDLLocatorImpl;
81 import org.w3c.dom.Document JavaDoc;
82 import org.w3c.dom.Element JavaDoc;
83 import org.xml.sax.InputSource JavaDoc;
84
85 import com.ibm.wsdl.util.xml.QNameUtils;
86
87 /**
88  * A class used for parsing the schema(s) defined in a Definition object. It does not provide
89  * full schema parsing. Its main purpose is to help in determining a list off all the types that
90  * are defined in schemas either inline in the wsdl document or imported xsd files.
91  *
92  * @author Owen Burroughs <owenb@apache.org>
93  */

94 public class Parser {
95
96     private static final QName JavaDoc schema1999 =
97         new QName JavaDoc(WSIFConstants.NS_URI_1999_SCHEMA_XSD, "schema");
98     private static final QName JavaDoc schema2000 =
99         new QName JavaDoc(WSIFConstants.NS_URI_2000_SCHEMA_XSD, "schema");
100     private static final QName JavaDoc schema2001 =
101         new QName JavaDoc(WSIFConstants.NS_URI_2001_SCHEMA_XSD, "schema");
102
103     /**
104      * Given a Definition object, populate a Map with all the types defined in the schemas in the definition and
105      * their corresponding Java class names.
106      * @param def The Definition object representing the wsdl
107      * @param table The Map to proulate with xml type -> Java class name (QName -> String) mappings
108      */

109     public static void getTypeMappings(Definition def, Map JavaDoc table) throws WSIFException {
110         getTypeMappings(def, table, true, null);
111     }
112
113     /**
114      * Given a Definition object, populate a Map with all the types defined in the schemas in the definition and
115      * their corresponding Java class names.
116      * @param def The Definition object representing the wsdl
117      * @param table The Map to proulate with xml type -> Java class name (QName -> String) mappings
118      * @param loader A ClassLoader to use in resolving xsd locations
119      */

120     public static void getTypeMappings(Definition def, Map JavaDoc table, ClassLoader JavaDoc loader) throws WSIFException {
121         WSDLLocator locator = new WSIFWSDLLocatorImpl((String JavaDoc) null, (String JavaDoc) null, loader);
122         getTypeMappings(def, table, true, locator);
123     }
124
125     /**
126      * Given a Definition object, populate a Map with all the types defined in the schemas in the definition and
127      * their corresponding Java class names.
128      * @param def The Definition object representing the wsdl
129      * @param table The Map to proulate with xml type -> Java class name (QName -> String) mappings
130      * @param loader A ClassLoader to use in resolving xsd locations
131      * @param includeStandardMappings Flag to indicate whether or not standard xsd, soapenc and Apache SOAP mappings
132      * should be included in the table
133      */

134     public static void getTypeMappings(
135         Definition def,
136         Map JavaDoc table,
137         ClassLoader JavaDoc loader,
138         boolean includeStandardMappings) throws WSIFException {
139         WSDLLocator locator = new WSIFWSDLLocatorImpl((String JavaDoc) null, (String JavaDoc) null, loader);
140         getTypeMappings(def, table, includeStandardMappings, locator);
141     }
142
143     /**
144      * Given a Definition object, populate a Map with all the types defined in the schemas in the definition and
145      * their corresponding Java class names.
146      * @param def The Definition object representing the wsdl
147      * @param table The Map to proulate with xml type -> Java class name (QName -> String) mappings
148      * @param loc WSDLLocator equal or equivalent to that used to locate the original wsdl document
149      */

150     public static void getTypeMappings(Definition def, Map JavaDoc table, WSDLLocator loc) throws WSIFException {
151         getTypeMappings(def, table, true, loc);
152     }
153
154     /**
155      * Given a Definition object, populate a Map with all the types defined in the schemas in the definition and
156      * their corresponding Java class names.
157      * @param def The Definition object representing the wsdl
158      * @param table The Map to proulate with xml type -> Java class name (QName -> String) mappings
159      * @param includeStandardMappings Flag to indicate whether or not standard xsd, soapenc and Apache SOAP mappings
160      * should be included in the table
161      */

162     public static void getTypeMappings(
163         Definition def,
164         Map JavaDoc table,
165         boolean includeStandardMappings) throws WSIFException {
166         
167         getTypeMappings(def, table, includeStandardMappings, null);
168     }
169
170     /**
171      * Given a Definition object, populate a Map with all the types defined in the schemas in the definition and
172      * their corresponding Java class names.
173      * @param def The Definition object representing the wsdl
174      * @param table The Map to proulate with xml type -> Java class name (QName -> String) mappings
175      * @param includeStandardMappings Flag to indicate whether or not standard xsd, soapenc and Apache SOAP mappings
176      * should be included in the table
177      * @param loc WSDLLocator equal or equivalent to that used to locate the original wsdl document
178      */

179     public static void getTypeMappings(
180         Definition def,
181         Map JavaDoc table,
182         boolean includeStandardMappings,
183         WSDLLocator loc) throws WSIFException {
184
185         Trc.entry(null, def, table, new Boolean JavaDoc(includeStandardMappings), loc);
186         if (loc == null) {
187             loc = new WSIFWSDLLocatorImpl((String JavaDoc) null, (String JavaDoc) null, null);
188         }
189                     
190         ArrayList JavaDoc schemaList = new ArrayList JavaDoc();
191         getTypesSchemas(def, schemaList, loc);
192         
193         Hashtable JavaDoc standards = null;
194
195         if (includeStandardMappings) {
196             // set up all standard mappings
197
populateWithStandardMappings(
198                 table,
199                 WSIFConstants.NS_URI_1999_SCHEMA_XSD,
200                 true);
201             populateWithStandardMappings(
202                 table,
203                 WSIFConstants.NS_URI_2000_SCHEMA_XSD,
204                 false);
205             populateWithStandardMappings(
206                 table,
207                 WSIFConstants.NS_URI_2001_SCHEMA_XSD,
208                 false);
209         } else {
210             // set up all standard mappings in a seperate map for use when resolving arrays
211
standards = new Hashtable JavaDoc();
212             populateWithStandardMappings(
213                 standards,
214                 WSIFConstants.NS_URI_1999_SCHEMA_XSD,
215                 true);
216             populateWithStandardMappings(
217                 standards,
218                 WSIFConstants.NS_URI_2000_SCHEMA_XSD,
219                 false);
220             populateWithStandardMappings(
221                 standards,
222                 WSIFConstants.NS_URI_2001_SCHEMA_XSD,
223                 false);
224         }
225
226         // Create temporary list to hold types which are arrays. We can then resolve them
227
// after resolving all other types
228
List JavaDoc arrays = new ArrayList JavaDoc();
229
230         // Create temporary list to hold types which are elements. We can then resolve them
231
// after resolving all other types
232
List JavaDoc elements = new ArrayList JavaDoc();
233
234         // Iterate through all the schemas found in the wsdl and imports
235
Iterator JavaDoc si = schemaList.iterator();
236         while (si.hasNext()) {
237             Schema ts = (Schema) si.next();
238             if (ts != null) {
239                 // Get all the types defined in this schema
240
List JavaDoc types = ts.getTypes();
241                 Iterator JavaDoc ti = types.iterator();
242                 while (ti.hasNext()) {
243                     SchemaType st = (SchemaType) ti.next();
244                     // Ignore null types
245
if (st == null)
246                         continue;
247                     QName JavaDoc typeName = st.getTypeName();
248                     if (typeName == null)
249                         continue;
250
251                     if (st.isArray()) {
252                         arrays.add(st);
253                     } else {
254                         // Deal with elements
255
if (st instanceof ElementType) {
256                             QName JavaDoc baseType = ((ElementType) st).getElementType();
257
258                             if (baseType != null) {
259                                 if (((ElementType) st).isNillable()) {
260                                     String JavaDoc wrapperClass = getWrapperClassName(baseType);
261                                     if (wrapperClass != null) {
262                                         table.put(typeName, wrapperClass);
263                                         continue;
264                                     }
265                                 }
266                                 String JavaDoc baseClassName =
267                                     (String JavaDoc) table.get(baseType);
268                                 if (baseClassName == null
269                                     && !includeStandardMappings) {
270                                     baseClassName =
271                                         (String JavaDoc) standards.get(baseType);
272                                 }
273                                 if (baseClassName != null) {
274                                     table.put(typeName, baseClassName);
275                                 } else {
276                                     elements.add(st);
277                                 }
278                             } else {
279                                 String JavaDoc className = resolveClassName(typeName);
280                                 // Distinguish the class for this element from a complexType with the same name
281
// by appending "Element" onto the class name.
282
className = className + "Element";
283                                 if (className != null) {
284                                     table.put(typeName, className);
285                                 }
286                             }
287                         } else {
288                             // Deal with complexTypes and simpleTypes
289
String JavaDoc className = resolveClassName(typeName);
290                             if (className != null) {
291                                 table.put(typeName, className);
292                             }
293                         }
294                     }
295                 }
296             }
297         }
298
299         // Create a temporary list for arrays of arrays so we can resolve them last
300
ArrayList JavaDoc multiArrays = new ArrayList JavaDoc();
301
302         // Now we'll resolve any array types that were found
303
Iterator JavaDoc ai = arrays.iterator();
304         while (ai.hasNext()) {
305             SchemaType st = (SchemaType) ai.next();
306             // We've already checked that its an array so cut to the chase!
307
QName JavaDoc theType = st.getTypeName();
308             if (theType == null) continue;
309             
310             QName JavaDoc arrayType = st.getArrayType();
311             if (arrayType != null && theType != null) {
312                 String JavaDoc baseClass = (String JavaDoc) table.get(arrayType);
313                 if (baseClass == null && standards != null) {
314                     // Check for base class in the standard mappings
315
baseClass = (String JavaDoc) standards.get(arrayType);
316                 }
317                 if (baseClass == null) {
318                     String JavaDoc lp = arrayType.getLocalPart();
319                     if (lp != null && lp.startsWith("ArrayOf")) {
320                         // This is an array of an array. Perhaps we've
321
// not mapped the base array yet so re-try this
322
// at the end
323
multiArrays.add(st);
324                     }
325                     continue;
326                 }
327                 // Deal with multidimentional array classes
328
String JavaDoc extraDims = "";
329                 for (int x = 1; x < st.getArrayDimension(); x++) {
330                     extraDims += "[";
331                 }
332                 if (baseClass != null) {
333                     // Check for primitive types
334
if (baseClass.equals("int")) {
335                         table.put(theType, extraDims + "[I");
336                     } else if (baseClass.equals("float")) {
337                         table.put(theType, extraDims + "[F");
338                     } else if (baseClass.equals("long")) {
339                         table.put(theType, extraDims + "[J");
340                     } else if (baseClass.equals("double")) {
341                         table.put(theType, extraDims + "[D");
342                     } else if (baseClass.equals("boolean")) {
343                         table.put(theType, extraDims + "[Z");
344                     } else if (baseClass.equals("byte")) {
345                         table.put(theType, extraDims + "[B");
346                     } else if (baseClass.equals("short")) {
347                         table.put(theType, extraDims + "[S");
348                     } else if (baseClass.startsWith("[")) {
349                         // The base for this array is another array!!
350
String JavaDoc arrayOfBase = "[" + baseClass;
351                         table.put(theType, arrayOfBase);
352                     } else {
353                         String JavaDoc arrayOfBase = extraDims + "[L" + baseClass + ";";
354                         table.put(theType, arrayOfBase);
355                     }
356                 }
357             }
358         }
359
360         // Now we'll resolve any arrays of arrays that are outstanding
361
Iterator JavaDoc mi = multiArrays.iterator();
362         while (mi.hasNext()) {
363             SchemaType st = (SchemaType) mi.next();
364             QName JavaDoc theType = st.getTypeName();
365             if (theType == null) continue;
366             
367             QName JavaDoc arrayType = st.getArrayType();
368             if (arrayType != null && theType != null) {
369                 String JavaDoc extraDims = "";
370                 for (int x = 1; x < st.getArrayDimension(); x++) {
371                     extraDims += "[";
372                 }
373                 String JavaDoc baseClass = (String JavaDoc) table.get(arrayType);
374                 if (baseClass != null) {
375                     // Base class should be an array
376
if (baseClass.startsWith("[")) {
377                         String JavaDoc arrayOfBase = "[" + baseClass;
378                         table.put(theType, arrayOfBase);
379                     }
380                 }
381             }
382         }
383         
384         // Finally we'll resolve any elements that are outstanding
385
Iterator JavaDoc ei = elements.iterator();
386         while (ei.hasNext()) {
387             SchemaType st = (SchemaType) ei.next();
388             QName JavaDoc theType = st.getTypeName();
389             if (theType == null)
390                 continue;
391
392             QName JavaDoc baseType = null;
393             if (st instanceof ElementType) {
394                 baseType = ((ElementType) st).getElementType();
395             }
396             if (baseType != null) {
397                 String JavaDoc baseClassName = (String JavaDoc) table.get(baseType);
398                 if (baseClassName != null) {
399                     table.put(theType, baseClassName);
400                 }
401             }
402         }
403                        
404         Trc.exit();
405     }
406
407     /**
408      * Populate a List with all the top level SchemaType objects (complexTypes, simpleTypes and elements) generated
409      * by parsing the schemas associated with a Definition object
410      * @param def The Definition object representing the wsdl
411      * @param schemaTypes The List to proulate with the SchemaType objects
412      * @param loc WSDLLocator equal or equivalent to that used to locate the original wsdl document. This is required in order
413      * to resolve imported schemas.
414      * @exception A WSIFException is thrown if a problem occurs when parsing the schemas
415      */

416     public static void getAllSchemaTypes(Definition def, List JavaDoc schemaTypes, WSDLLocator loc) throws WSIFException {
417         try {
418             ArrayList JavaDoc schemas = new ArrayList JavaDoc();
419             Parser.getTypesSchemas(def, schemas, loc);
420             Iterator JavaDoc si = schemas.iterator();
421             while (si.hasNext()) {
422                 Schema ts = (Schema) si.next();
423                 if (ts != null) {
424                     // Get all the types defined in this schema
425
List JavaDoc types = ts.getTypes();
426                     Iterator JavaDoc ti = types.iterator();
427                     while (ti.hasNext()) {
428                         SchemaType st = (SchemaType) ti.next();
429                         // Ignore null types
430
if (st == null)
431                             continue;
432                         schemaTypes.add(st);
433                     }
434                 }
435             }
436         } catch (WSIFException e) {
437         }
438     }
439
440     /**
441      * Populate a map with the standard xml type -> Java class name mappings
442      */

443     private static void populateWithStandardMappings(
444         Map JavaDoc t,
445         String JavaDoc schemaURI,
446         boolean oneTimeAdds) {
447
448         t.put(new QName JavaDoc(schemaURI, "string"), "java.lang.String");
449         t.put(new QName JavaDoc(schemaURI, "integer"), "java.math.BigInteger");
450         t.put(new QName JavaDoc(schemaURI, "boolean"), "boolean");
451         t.put(new QName JavaDoc(schemaURI, "float"), "float");
452         t.put(new QName JavaDoc(schemaURI, "double"), "double");
453         t.put(new QName JavaDoc(schemaURI, "base64Binary"), "[B");
454         t.put(new QName JavaDoc(schemaURI, "hexBinary"), "[B");
455         t.put(new QName JavaDoc(schemaURI, "long"), "long");
456         t.put(new QName JavaDoc(schemaURI, "int"), "int");
457         t.put(new QName JavaDoc(schemaURI, "short"), "short");
458         t.put(new QName JavaDoc(schemaURI, "decimal"), "java.math.BigDecimal");
459         t.put(new QName JavaDoc(schemaURI, "byte"), "byte");
460         t.put(new QName JavaDoc(schemaURI, "QName"), "javax.xml.namespace.QName");
461
462         // Register dateTime or timeInstant depending on schema
463
if (schemaURI.equals(WSIFConstants.NS_URI_2001_SCHEMA_XSD)) {
464             t.put(new QName JavaDoc(schemaURI, "dateTime"), "java.util.Calendar");
465         } else {
466             t.put(new QName JavaDoc(schemaURI, "timeInstant"), "java.util.Calendar");
467         }
468
469         // Only add the SOAP-ENC simple types and soap collection class mappings once
470
if (oneTimeAdds) {
471             // SOAP encoding simple types
472
t.put(
473                 new QName JavaDoc(WSIFConstants.NS_URI_SOAP_ENC, "string"),
474                 "java.lang.String");
475             t.put(
476                 new QName JavaDoc(WSIFConstants.NS_URI_SOAP_ENC, "boolean"),
477                 "java.lang.Boolean");
478             t.put(
479                 new QName JavaDoc(WSIFConstants.NS_URI_SOAP_ENC, "float"),
480                 "java.lang.Float");
481             t.put(
482                 new QName JavaDoc(WSIFConstants.NS_URI_SOAP_ENC, "double"),
483                 "java.lang.Double");
484             t.put(
485                 new QName JavaDoc(WSIFConstants.NS_URI_SOAP_ENC, "decimal"),
486                 "java.math.BigDecimal");
487             t.put(
488                 new QName JavaDoc(WSIFConstants.NS_URI_SOAP_ENC, "int"),
489                 "java.lang.Integer");
490             t.put(
491                 new QName JavaDoc(WSIFConstants.NS_URI_SOAP_ENC, "short"),
492                 "java.lang.Short");
493             t.put(
494                 new QName JavaDoc(WSIFConstants.NS_URI_SOAP_ENC, "byte"),
495                 "java.lang.Byte");
496             t.put(new QName JavaDoc(WSIFConstants.NS_URI_SOAP_ENC, "base64"), "[B");
497
498             // soap Java collection mappings
499
t.put(
500                 new QName JavaDoc(WSIFConstants.NS_URI_APACHE_SOAP, "Map"),
501                 "java.util.Map");
502             t.put(
503                 new QName JavaDoc(WSIFConstants.NS_URI_APACHE_SOAP, "Vector"),
504                 "java.util.Vector");
505             t.put(
506                 new QName JavaDoc(WSIFConstants.NS_URI_APACHE_SOAP, "Hashtable"),
507                 "java.util.Hashtable");
508         }
509     }
510
511     /**
512      * Get all the schemas defined in the Definition object
513      */

514     private static void getTypesSchemas(Definition def, List JavaDoc schemas, WSDLLocator loc) throws WSIFException {
515         Types types = def.getTypes();
516         if (types != null) {
517             Iterator JavaDoc extEleIt = types.getExtensibilityElements().iterator();
518
519             while (extEleIt.hasNext()) {
520                 UnknownExtensibilityElement typesElement =
521                     (UnknownExtensibilityElement) extEleIt.next();
522
523                 Element schemaEl = typesElement.getElement();
524                 if (QNameUtils.matches(schema2001, schemaEl)
525                     || QNameUtils.matches(schema2000, schemaEl)
526                     || QNameUtils.matches(schema1999, schemaEl)) {
527                     Schema sc = new Schema(schemaEl);
528                     schemas.add(sc);
529                     String JavaDoc docBase = def.getDocumentBaseURI();
530                     if (docBase != null && loc != null) {
531                         String JavaDoc[] importsAndIncludes = sc.getImportsAndIncludes();
532                         for (int i=0; i<importsAndIncludes.length; i++) {
533                             String JavaDoc sl = importsAndIncludes[i];
534                             getImportedSchemas(docBase, sl, loc, schemas);
535                         }
536                     }
537                 }
538             }
539         }
540
541         Map JavaDoc imports = def.getImports();
542
543         if (imports != null) {
544             Iterator JavaDoc valueIterator = imports.values().iterator();
545
546             while (valueIterator.hasNext()) {
547                 List JavaDoc importList = (List JavaDoc) valueIterator.next();
548
549                 if (importList != null) {
550                     Iterator JavaDoc importIterator = importList.iterator();
551
552                     while (importIterator.hasNext()) {
553                         Import tempImport = (Import) importIterator.next();
554
555                         if (tempImport != null) {
556                             Definition importedDef = tempImport.getDefinition();
557
558                             if (importedDef != null) {
559                                 getTypesSchemas(importedDef, schemas, loc);
560                             } else {
561                                 String JavaDoc baseLoc = def.getDocumentBaseURI();
562                                 String JavaDoc importLoc = tempImport.getLocationURI();
563                                 if (baseLoc != null && importLoc != null && loc != null) {
564                                     getImportedSchemas(baseLoc, importLoc, loc, schemas);
565                                 }
566                             }
567                         }
568                     }
569                 }
570             }
571         }
572     }
573     
574     /**
575      * Get all nested schemas
576      */

577     private static void getImportedSchemas(String JavaDoc base, String JavaDoc rel, WSDLLocator loc, List JavaDoc schemaList) throws WSIFException {
578         try {
579             Reader JavaDoc reader = loc.getImportReader(base, rel);
580             if (reader == null) {
581                 throw new WSIFException("Unable to read schema file "+rel+" relative to "+base);
582             }
583             InputSource JavaDoc inputSource = new InputSource JavaDoc(reader);
584             DocumentBuilderFactory JavaDoc factory =
585                 DocumentBuilderFactory.newInstance();
586
587             factory.setNamespaceAware(true);
588             factory.setValidating(false);
589
590             DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
591             Document JavaDoc doc = builder.parse(inputSource);
592             reader.close();
593
594             Element el = doc.getDocumentElement();
595             if (el != null) {
596                 if (QNameUtils.matches(schema2001, el)
597                     || QNameUtils.matches(schema2000, el)
598                     || QNameUtils.matches(schema1999, el)) {
599                     Schema sc = new Schema(el);
600                     schemaList.add(sc);
601                     String JavaDoc[] importsAndIncludes = sc.getImportsAndIncludes();
602                     String JavaDoc lastURI = loc.getLatestImportURI();
603                     for (int i=0; i<importsAndIncludes.length; i++) {
604                         String JavaDoc sl = importsAndIncludes[i];
605                         getImportedSchemas(lastURI, sl, loc, schemaList);
606                     }
607                 }
608             }
609         } catch (Exception JavaDoc e) {
610             Trc.exception(e);
611             if (e instanceof WSIFException) {
612                 throw (WSIFException) e;
613             } else {
614                 throw new WSIFException("Error when getting imported schemas", e);
615             }
616         }
617     }
618
619     /**
620      * Generate a Java class name corresponding to an xml type
621      */

622     private static String JavaDoc resolveClassName(QName JavaDoc qn) {
623         String JavaDoc namespace = qn.getNamespaceURI();
624         String JavaDoc localPart = qn.getLocalPart();
625         String JavaDoc packageName =
626             WSIFUtils.getPackageNameFromNamespaceURI(namespace);
627         String JavaDoc className = WSIFUtils.getJavaClassNameFromXMLName(localPart);
628         if (packageName != null
629             && !packageName.equals("")
630             && className != null
631             && !className.equals("")) {
632             return packageName + "." + className;
633         }
634         return null;
635     }
636     
637     /**
638      * Elements which are nillable and are based on xsd simple types should map to
639      * the object wrapper version of the corresponding primitive type. This method
640      * will return the wrapper class name for a given QName.
641      */

642     private static String JavaDoc getWrapperClassName(QName JavaDoc qn) {
643         if (qn == null) return null;
644         String JavaDoc ns = qn.getNamespaceURI();
645         if (WSIFConstants.NS_URI_1999_SCHEMA_XSD.equals(ns)
646             || WSIFConstants.NS_URI_2000_SCHEMA_XSD.equals(ns)
647             || WSIFConstants.NS_URI_2001_SCHEMA_XSD.equals(ns)) {
648             String JavaDoc lp = qn.getLocalPart();
649             if (lp == null) return null;
650             if (lp.equals("int")) {
651                 return "java.lang.Integer";
652             } else if (lp.equals("long")) {
653                 return "java.lang.Long";
654             } else if (lp.equals("float")) {
655                 return "java.lang.Float";
656             } else if (lp.equals("short")) {
657                 return "java.lang.Short";
658             } else if (lp.equals("double")) {
659                 return "java.lang.Double";
660             } else if (lp.equals("boolean")) {
661                 return "java.lang.Boolean";
662             } else if (lp.equals("byte")) {
663                 return "java.lang.Byte";
664             }
665         }
666         return null;
667     }
668 }
669
Popular Tags