Source Code Cross Referenced for Parser.java in  » Web-Services » wsif » org » apache » wsif » schema » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services » wsif » org.apache.wsif.schema 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The Apache Software License, Version 1.1
003:         *
004:         *
005:         * Copyright (c) 2002 The Apache Software Foundation.  All rights 
006:         * reserved.
007:         *
008:         * Redistribution and use in source and binary forms, with or without
009:         * modification, are permitted provided that the following conditions
010:         * are met:
011:         *
012:         * 1. Redistributions of source code must retain the above copyright
013:         *    notice, this list of conditions and the following disclaimer. 
014:         *
015:         * 2. Redistributions in binary form must reproduce the above copyright
016:         *    notice, this list of conditions and the following disclaimer in
017:         *    the documentation and/or other materials provided with the
018:         *    distribution.
019:         *
020:         * 3. The end-user documentation included with the redistribution,
021:         *    if any, must include the following acknowledgment:  
022:         *       "This product includes software developed by the
023:         *        Apache Software Foundation (http://www.apache.org/)."
024:         *    Alternately, this acknowledgment may appear in the software itself,
025:         *    if and wherever such third-party acknowledgments normally appear.
026:         *
027:         * 4. The names "WSIF" and "Apache Software Foundation" must
028:         *    not be used to endorse or promote products derived from this
029:         *    software without prior written permission. For written 
030:         *    permission, please contact apache@apache.org.
031:         *
032:         * 5. Products derived from this software may not be called "Apache",
033:         *    nor may "Apache" appear in their name, without prior written
034:         *    permission of the Apache Software Foundation.
035:         *
036:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047:         * SUCH DAMAGE.
048:         * ====================================================================
049:         *
050:         * This software consists of voluntary contributions made by many
051:         * individuals on behalf of the Apache Software Foundation and was
052:         * originally based on software copyright (c) 2001, 2002, International
053:         * Business Machines, Inc., http://www.apache.org.  For more
054:         * information on the Apache Software Foundation, please see
055:         * <http://www.apache.org/>.
056:         */
057:
058:        package org.apache.wsif.schema;
059:
060:        import java.io.Reader;
061:        import java.util.ArrayList;
062:        import java.util.Hashtable;
063:        import java.util.Iterator;
064:        import java.util.List;
065:        import java.util.Map;
066:
067:        import javax.wsdl.Definition;
068:        import javax.wsdl.Import;
069:        import javax.wsdl.Types;
070:        import javax.wsdl.extensions.UnknownExtensibilityElement;
071:        import javax.wsdl.xml.WSDLLocator;
072:        import javax.xml.namespace.QName;
073:        import javax.xml.parsers.DocumentBuilder;
074:        import javax.xml.parsers.DocumentBuilderFactory;
075:
076:        import org.apache.wsif.WSIFConstants;
077:        import org.apache.wsif.WSIFException;
078:        import org.apache.wsif.logging.Trc;
079:        import org.apache.wsif.util.WSIFUtils;
080:        import org.apache.wsif.wsdl.WSIFWSDLLocatorImpl;
081:        import org.w3c.dom.Document;
082:        import org.w3c.dom.Element;
083:        import org.xml.sax.InputSource;
084:
085:        import com.ibm.wsdl.util.xml.QNameUtils;
086:
087:        /**
088:         * A class used for parsing the schema(s) defined in a Definition object. It does not provide
089:         * full schema parsing. Its main purpose is to help in determining a list off all the types that
090:         * are defined in schemas either inline in the wsdl document or imported xsd files.
091:         * 
092:         * @author Owen Burroughs <owenb@apache.org>
093:         */
094:        public class Parser {
095:
096:            private static final QName schema1999 = new QName(
097:                    WSIFConstants.NS_URI_1999_SCHEMA_XSD, "schema");
098:            private static final QName schema2000 = new QName(
099:                    WSIFConstants.NS_URI_2000_SCHEMA_XSD, "schema");
100:            private static final QName schema2001 = new QName(
101:                    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 table)
110:                    throws WSIFException {
111:                getTypeMappings(def, table, true, null);
112:            }
113:
114:            /**
115:             * Given a Definition object, populate a Map with all the types defined in the schemas in the definition and
116:             * their corresponding Java class names.
117:             * @param def The Definition object representing the wsdl
118:             * @param table The Map to proulate with xml type -> Java class name (QName -> String) mappings
119:             * @param loader A ClassLoader to use in resolving xsd locations
120:             */
121:            public static void getTypeMappings(Definition def, Map table,
122:                    ClassLoader loader) throws WSIFException {
123:                WSDLLocator locator = new WSIFWSDLLocatorImpl((String) null,
124:                        (String) null, loader);
125:                getTypeMappings(def, table, true, locator);
126:            }
127:
128:            /**
129:             * Given a Definition object, populate a Map with all the types defined in the schemas in the definition and
130:             * their corresponding Java class names.
131:             * @param def The Definition object representing the wsdl
132:             * @param table The Map to proulate with xml type -> Java class name (QName -> String) mappings
133:             * @param loader A ClassLoader to use in resolving xsd locations
134:             * @param includeStandardMappings Flag to indicate whether or not standard xsd, soapenc and Apache SOAP mappings
135:             * should be included in the table
136:             */
137:            public static void getTypeMappings(Definition def, Map table,
138:                    ClassLoader loader, boolean includeStandardMappings)
139:                    throws WSIFException {
140:                WSDLLocator locator = new WSIFWSDLLocatorImpl((String) null,
141:                        (String) null, loader);
142:                getTypeMappings(def, table, includeStandardMappings, locator);
143:            }
144:
145:            /**
146:             * Given a Definition object, populate a Map with all the types defined in the schemas in the definition and
147:             * their corresponding Java class names.
148:             * @param def The Definition object representing the wsdl
149:             * @param table The Map to proulate with xml type -> Java class name (QName -> String) mappings
150:             * @param loc WSDLLocator equal or equivalent to that used to locate the original wsdl document
151:             */
152:            public static void getTypeMappings(Definition def, Map table,
153:                    WSDLLocator loc) throws WSIFException {
154:                getTypeMappings(def, table, true, loc);
155:            }
156:
157:            /**
158:             * Given a Definition object, populate a Map with all the types defined in the schemas in the definition and
159:             * their corresponding Java class names.
160:             * @param def The Definition object representing the wsdl
161:             * @param table The Map to proulate with xml type -> Java class name (QName -> String) mappings
162:             * @param includeStandardMappings Flag to indicate whether or not standard xsd, soapenc and Apache SOAP mappings
163:             * should be included in the table
164:             */
165:            public static void getTypeMappings(Definition def, Map table,
166:                    boolean includeStandardMappings) throws WSIFException {
167:
168:                getTypeMappings(def, table, includeStandardMappings, null);
169:            }
170:
171:            /**
172:             * Given a Definition object, populate a Map with all the types defined in the schemas in the definition and
173:             * their corresponding Java class names.
174:             * @param def The Definition object representing the wsdl
175:             * @param table The Map to proulate with xml type -> Java class name (QName -> String) mappings
176:             * @param includeStandardMappings Flag to indicate whether or not standard xsd, soapenc and Apache SOAP mappings
177:             * should be included in the table
178:             * @param loc WSDLLocator equal or equivalent to that used to locate the original wsdl document
179:             */
180:            public static void getTypeMappings(Definition def, Map table,
181:                    boolean includeStandardMappings, WSDLLocator loc)
182:                    throws WSIFException {
183:
184:                Trc.entry(null, def, table,
185:                        new Boolean(includeStandardMappings), loc);
186:                if (loc == null) {
187:                    loc = new WSIFWSDLLocatorImpl((String) null, (String) null,
188:                            null);
189:                }
190:
191:                ArrayList schemaList = new ArrayList();
192:                getTypesSchemas(def, schemaList, loc);
193:
194:                Hashtable standards = null;
195:
196:                if (includeStandardMappings) {
197:                    // set up all standard mappings
198:                    populateWithStandardMappings(table,
199:                            WSIFConstants.NS_URI_1999_SCHEMA_XSD, true);
200:                    populateWithStandardMappings(table,
201:                            WSIFConstants.NS_URI_2000_SCHEMA_XSD, false);
202:                    populateWithStandardMappings(table,
203:                            WSIFConstants.NS_URI_2001_SCHEMA_XSD, false);
204:                } else {
205:                    // set up all standard mappings in a seperate map for use when resolving arrays			
206:                    standards = new Hashtable();
207:                    populateWithStandardMappings(standards,
208:                            WSIFConstants.NS_URI_1999_SCHEMA_XSD, true);
209:                    populateWithStandardMappings(standards,
210:                            WSIFConstants.NS_URI_2000_SCHEMA_XSD, false);
211:                    populateWithStandardMappings(standards,
212:                            WSIFConstants.NS_URI_2001_SCHEMA_XSD, false);
213:                }
214:
215:                // Create temporary list to hold types which are arrays. We can then resolve them
216:                // after resolving all other types
217:                List arrays = new ArrayList();
218:
219:                // Create temporary list to hold types which are elements. We can then resolve them
220:                // after resolving all other types
221:                List elements = new ArrayList();
222:
223:                // Iterate through all the schemas found in the wsdl and imports
224:                Iterator si = schemaList.iterator();
225:                while (si.hasNext()) {
226:                    Schema ts = (Schema) si.next();
227:                    if (ts != null) {
228:                        // Get all the types defined in this schema
229:                        List types = ts.getTypes();
230:                        Iterator ti = types.iterator();
231:                        while (ti.hasNext()) {
232:                            SchemaType st = (SchemaType) ti.next();
233:                            // Ignore null types
234:                            if (st == null)
235:                                continue;
236:                            QName typeName = st.getTypeName();
237:                            if (typeName == null)
238:                                continue;
239:
240:                            if (st.isArray()) {
241:                                arrays.add(st);
242:                            } else {
243:                                // Deal with elements
244:                                if (st instanceof  ElementType) {
245:                                    QName baseType = ((ElementType) st)
246:                                            .getElementType();
247:
248:                                    if (baseType != null) {
249:                                        if (((ElementType) st).isNillable()) {
250:                                            String wrapperClass = getWrapperClassName(baseType);
251:                                            if (wrapperClass != null) {
252:                                                table.put(typeName,
253:                                                        wrapperClass);
254:                                                continue;
255:                                            }
256:                                        }
257:                                        String baseClassName = (String) table
258:                                                .get(baseType);
259:                                        if (baseClassName == null
260:                                                && !includeStandardMappings) {
261:                                            baseClassName = (String) standards
262:                                                    .get(baseType);
263:                                        }
264:                                        if (baseClassName != null) {
265:                                            table.put(typeName, baseClassName);
266:                                        } else {
267:                                            elements.add(st);
268:                                        }
269:                                    } else {
270:                                        String className = resolveClassName(typeName);
271:                                        // Distinguish the class for this element from a complexType with the same name
272:                                        // by appending "Element" onto the class name.
273:                                        className = className + "Element";
274:                                        if (className != null) {
275:                                            table.put(typeName, className);
276:                                        }
277:                                    }
278:                                } else {
279:                                    // Deal with complexTypes and simpleTypes
280:                                    String className = resolveClassName(typeName);
281:                                    if (className != null) {
282:                                        table.put(typeName, className);
283:                                    }
284:                                }
285:                            }
286:                        }
287:                    }
288:                }
289:
290:                // Create a temporary list for arrays of arrays so we can resolve them last
291:                ArrayList multiArrays = new ArrayList();
292:
293:                // Now we'll resolve any array types that were found
294:                Iterator ai = arrays.iterator();
295:                while (ai.hasNext()) {
296:                    SchemaType st = (SchemaType) ai.next();
297:                    // We've already checked that its an array so cut to the chase!
298:                    QName theType = st.getTypeName();
299:                    if (theType == null)
300:                        continue;
301:
302:                    QName arrayType = st.getArrayType();
303:                    if (arrayType != null && theType != null) {
304:                        String baseClass = (String) table.get(arrayType);
305:                        if (baseClass == null && standards != null) {
306:                            // Check for base class in the standard mappings
307:                            baseClass = (String) standards.get(arrayType);
308:                        }
309:                        if (baseClass == null) {
310:                            String lp = arrayType.getLocalPart();
311:                            if (lp != null && lp.startsWith("ArrayOf")) {
312:                                // This is an array of an array. Perhaps we've
313:                                // not mapped the base array yet so re-try this
314:                                // at the end
315:                                multiArrays.add(st);
316:                            }
317:                            continue;
318:                        }
319:                        // Deal with multidimentional array classes
320:                        String extraDims = "";
321:                        for (int x = 1; x < st.getArrayDimension(); x++) {
322:                            extraDims += "[";
323:                        }
324:                        if (baseClass != null) {
325:                            // Check for primitive types
326:                            if (baseClass.equals("int")) {
327:                                table.put(theType, extraDims + "[I");
328:                            } else if (baseClass.equals("float")) {
329:                                table.put(theType, extraDims + "[F");
330:                            } else if (baseClass.equals("long")) {
331:                                table.put(theType, extraDims + "[J");
332:                            } else if (baseClass.equals("double")) {
333:                                table.put(theType, extraDims + "[D");
334:                            } else if (baseClass.equals("boolean")) {
335:                                table.put(theType, extraDims + "[Z");
336:                            } else if (baseClass.equals("byte")) {
337:                                table.put(theType, extraDims + "[B");
338:                            } else if (baseClass.equals("short")) {
339:                                table.put(theType, extraDims + "[S");
340:                            } else if (baseClass.startsWith("[")) {
341:                                // The base for this array is another array!!						
342:                                String arrayOfBase = "[" + baseClass;
343:                                table.put(theType, arrayOfBase);
344:                            } else {
345:                                String arrayOfBase = extraDims + "[L"
346:                                        + baseClass + ";";
347:                                table.put(theType, arrayOfBase);
348:                            }
349:                        }
350:                    }
351:                }
352:
353:                // Now we'll resolve any arrays of arrays that are outstanding
354:                Iterator mi = multiArrays.iterator();
355:                while (mi.hasNext()) {
356:                    SchemaType st = (SchemaType) mi.next();
357:                    QName theType = st.getTypeName();
358:                    if (theType == null)
359:                        continue;
360:
361:                    QName arrayType = st.getArrayType();
362:                    if (arrayType != null && theType != null) {
363:                        String extraDims = "";
364:                        for (int x = 1; x < st.getArrayDimension(); x++) {
365:                            extraDims += "[";
366:                        }
367:                        String baseClass = (String) table.get(arrayType);
368:                        if (baseClass != null) {
369:                            // Base class should be an array
370:                            if (baseClass.startsWith("[")) {
371:                                String arrayOfBase = "[" + baseClass;
372:                                table.put(theType, arrayOfBase);
373:                            }
374:                        }
375:                    }
376:                }
377:
378:                // Finally we'll resolve any elements that are outstanding
379:                Iterator ei = elements.iterator();
380:                while (ei.hasNext()) {
381:                    SchemaType st = (SchemaType) ei.next();
382:                    QName theType = st.getTypeName();
383:                    if (theType == null)
384:                        continue;
385:
386:                    QName baseType = null;
387:                    if (st instanceof  ElementType) {
388:                        baseType = ((ElementType) st).getElementType();
389:                    }
390:                    if (baseType != null) {
391:                        String baseClassName = (String) table.get(baseType);
392:                        if (baseClassName != null) {
393:                            table.put(theType, baseClassName);
394:                        }
395:                    }
396:                }
397:
398:                Trc.exit();
399:            }
400:
401:            /**
402:             * Populate a List with all the top level SchemaType objects (complexTypes, simpleTypes and elements) generated
403:             * by parsing the schemas associated with a Definition object
404:             * @param def The Definition object representing the wsdl
405:             * @param schemaTypes The List to proulate with the SchemaType objects
406:             * @param loc WSDLLocator equal or equivalent to that used to locate the original wsdl document. This is required in order
407:             * to resolve imported schemas.
408:             * @exception A WSIFException is thrown if a problem occurs when parsing the schemas
409:             */
410:            public static void getAllSchemaTypes(Definition def,
411:                    List schemaTypes, WSDLLocator loc) throws WSIFException {
412:                try {
413:                    ArrayList schemas = new ArrayList();
414:                    Parser.getTypesSchemas(def, schemas, loc);
415:                    Iterator si = schemas.iterator();
416:                    while (si.hasNext()) {
417:                        Schema ts = (Schema) si.next();
418:                        if (ts != null) {
419:                            // Get all the types defined in this schema
420:                            List types = ts.getTypes();
421:                            Iterator ti = types.iterator();
422:                            while (ti.hasNext()) {
423:                                SchemaType st = (SchemaType) ti.next();
424:                                // Ignore null types
425:                                if (st == null)
426:                                    continue;
427:                                schemaTypes.add(st);
428:                            }
429:                        }
430:                    }
431:                } catch (WSIFException e) {
432:                }
433:            }
434:
435:            /**
436:             * Populate a map with the standard xml type -> Java class name mappings
437:             */
438:            private static void populateWithStandardMappings(Map t,
439:                    String schemaURI, boolean oneTimeAdds) {
440:
441:                t.put(new QName(schemaURI, "string"), "java.lang.String");
442:                t.put(new QName(schemaURI, "integer"), "java.math.BigInteger");
443:                t.put(new QName(schemaURI, "boolean"), "boolean");
444:                t.put(new QName(schemaURI, "float"), "float");
445:                t.put(new QName(schemaURI, "double"), "double");
446:                t.put(new QName(schemaURI, "base64Binary"), "[B");
447:                t.put(new QName(schemaURI, "hexBinary"), "[B");
448:                t.put(new QName(schemaURI, "long"), "long");
449:                t.put(new QName(schemaURI, "int"), "int");
450:                t.put(new QName(schemaURI, "short"), "short");
451:                t.put(new QName(schemaURI, "decimal"), "java.math.BigDecimal");
452:                t.put(new QName(schemaURI, "byte"), "byte");
453:                t.put(new QName(schemaURI, "QName"),
454:                        "javax.xml.namespace.QName");
455:
456:                // Register dateTime or timeInstant depending on schema
457:                if (schemaURI.equals(WSIFConstants.NS_URI_2001_SCHEMA_XSD)) {
458:                    t.put(new QName(schemaURI, "dateTime"),
459:                            "java.util.Calendar");
460:                } else {
461:                    t.put(new QName(schemaURI, "timeInstant"),
462:                            "java.util.Calendar");
463:                }
464:
465:                // Only add the SOAP-ENC simple types and soap collection class mappings once
466:                if (oneTimeAdds) {
467:                    // SOAP encoding simple types
468:                    t.put(new QName(WSIFConstants.NS_URI_SOAP_ENC, "string"),
469:                            "java.lang.String");
470:                    t.put(new QName(WSIFConstants.NS_URI_SOAP_ENC, "boolean"),
471:                            "java.lang.Boolean");
472:                    t.put(new QName(WSIFConstants.NS_URI_SOAP_ENC, "float"),
473:                            "java.lang.Float");
474:                    t.put(new QName(WSIFConstants.NS_URI_SOAP_ENC, "double"),
475:                            "java.lang.Double");
476:                    t.put(new QName(WSIFConstants.NS_URI_SOAP_ENC, "decimal"),
477:                            "java.math.BigDecimal");
478:                    t.put(new QName(WSIFConstants.NS_URI_SOAP_ENC, "int"),
479:                            "java.lang.Integer");
480:                    t.put(new QName(WSIFConstants.NS_URI_SOAP_ENC, "short"),
481:                            "java.lang.Short");
482:                    t.put(new QName(WSIFConstants.NS_URI_SOAP_ENC, "byte"),
483:                            "java.lang.Byte");
484:                    t.put(new QName(WSIFConstants.NS_URI_SOAP_ENC, "base64"),
485:                            "[B");
486:
487:                    // soap Java collection mappings
488:                    t.put(new QName(WSIFConstants.NS_URI_APACHE_SOAP, "Map"),
489:                            "java.util.Map");
490:                    t.put(
491:                            new QName(WSIFConstants.NS_URI_APACHE_SOAP,
492:                                    "Vector"), "java.util.Vector");
493:                    t.put(new QName(WSIFConstants.NS_URI_APACHE_SOAP,
494:                            "Hashtable"), "java.util.Hashtable");
495:                }
496:            }
497:
498:            /**
499:             * Get all the schemas defined in the Definition object
500:             */
501:            private static void getTypesSchemas(Definition def, List schemas,
502:                    WSDLLocator loc) throws WSIFException {
503:                Types types = def.getTypes();
504:                if (types != null) {
505:                    Iterator extEleIt = types.getExtensibilityElements()
506:                            .iterator();
507:
508:                    while (extEleIt.hasNext()) {
509:                        UnknownExtensibilityElement typesElement = (UnknownExtensibilityElement) extEleIt
510:                                .next();
511:
512:                        Element schemaEl = typesElement.getElement();
513:                        if (QNameUtils.matches(schema2001, schemaEl)
514:                                || QNameUtils.matches(schema2000, schemaEl)
515:                                || QNameUtils.matches(schema1999, schemaEl)) {
516:                            Schema sc = new Schema(schemaEl);
517:                            schemas.add(sc);
518:                            String docBase = def.getDocumentBaseURI();
519:                            if (docBase != null && loc != null) {
520:                                String[] importsAndIncludes = sc
521:                                        .getImportsAndIncludes();
522:                                for (int i = 0; i < importsAndIncludes.length; i++) {
523:                                    String sl = importsAndIncludes[i];
524:                                    getImportedSchemas(docBase, sl, loc,
525:                                            schemas);
526:                                }
527:                            }
528:                        }
529:                    }
530:                }
531:
532:                Map imports = def.getImports();
533:
534:                if (imports != null) {
535:                    Iterator valueIterator = imports.values().iterator();
536:
537:                    while (valueIterator.hasNext()) {
538:                        List importList = (List) valueIterator.next();
539:
540:                        if (importList != null) {
541:                            Iterator importIterator = importList.iterator();
542:
543:                            while (importIterator.hasNext()) {
544:                                Import tempImport = (Import) importIterator
545:                                        .next();
546:
547:                                if (tempImport != null) {
548:                                    Definition importedDef = tempImport
549:                                            .getDefinition();
550:
551:                                    if (importedDef != null) {
552:                                        getTypesSchemas(importedDef, schemas,
553:                                                loc);
554:                                    } else {
555:                                        String baseLoc = def
556:                                                .getDocumentBaseURI();
557:                                        String importLoc = tempImport
558:                                                .getLocationURI();
559:                                        if (baseLoc != null
560:                                                && importLoc != null
561:                                                && loc != null) {
562:                                            getImportedSchemas(baseLoc,
563:                                                    importLoc, loc, schemas);
564:                                        }
565:                                    }
566:                                }
567:                            }
568:                        }
569:                    }
570:                }
571:            }
572:
573:            /**
574:             * Get all nested schemas
575:             */
576:            private static void getImportedSchemas(String base, String rel,
577:                    WSDLLocator loc, List schemaList) throws WSIFException {
578:                try {
579:                    Reader reader = loc.getImportReader(base, rel);
580:                    if (reader == null) {
581:                        throw new WSIFException("Unable to read schema file "
582:                                + rel + " relative to " + base);
583:                    }
584:                    InputSource inputSource = new InputSource(reader);
585:                    DocumentBuilderFactory factory = DocumentBuilderFactory
586:                            .newInstance();
587:
588:                    factory.setNamespaceAware(true);
589:                    factory.setValidating(false);
590:
591:                    DocumentBuilder builder = factory.newDocumentBuilder();
592:                    Document doc = builder.parse(inputSource);
593:                    reader.close();
594:
595:                    Element el = doc.getDocumentElement();
596:                    if (el != null) {
597:                        if (QNameUtils.matches(schema2001, el)
598:                                || QNameUtils.matches(schema2000, el)
599:                                || QNameUtils.matches(schema1999, el)) {
600:                            Schema sc = new Schema(el);
601:                            schemaList.add(sc);
602:                            String[] importsAndIncludes = sc
603:                                    .getImportsAndIncludes();
604:                            String lastURI = loc.getLatestImportURI();
605:                            for (int i = 0; i < importsAndIncludes.length; i++) {
606:                                String sl = importsAndIncludes[i];
607:                                getImportedSchemas(lastURI, sl, loc, schemaList);
608:                            }
609:                        }
610:                    }
611:                } catch (Exception e) {
612:                    Trc.exception(e);
613:                    if (e instanceof  WSIFException) {
614:                        throw (WSIFException) e;
615:                    } else {
616:                        throw new WSIFException(
617:                                "Error when getting imported schemas", e);
618:                    }
619:                }
620:            }
621:
622:            /**
623:             * Generate a Java class name corresponding to an xml type
624:             */
625:            private static String resolveClassName(QName qn) {
626:                String namespace = qn.getNamespaceURI();
627:                String localPart = qn.getLocalPart();
628:                String packageName = WSIFUtils
629:                        .getPackageNameFromNamespaceURI(namespace);
630:                String className = WSIFUtils
631:                        .getJavaClassNameFromXMLName(localPart);
632:                if (packageName != null && !packageName.equals("")
633:                        && className != null && !className.equals("")) {
634:                    return packageName + "." + className;
635:                }
636:                return null;
637:            }
638:
639:            /**
640:             * Elements which are nillable and are based on xsd simple types should map to
641:             * the object wrapper version of the corresponding primitive type. This method
642:             * will return the wrapper class name for a given QName.
643:             */
644:            private static String getWrapperClassName(QName qn) {
645:                if (qn == null)
646:                    return null;
647:                String ns = qn.getNamespaceURI();
648:                if (WSIFConstants.NS_URI_1999_SCHEMA_XSD.equals(ns)
649:                        || WSIFConstants.NS_URI_2000_SCHEMA_XSD.equals(ns)
650:                        || WSIFConstants.NS_URI_2001_SCHEMA_XSD.equals(ns)) {
651:                    String lp = qn.getLocalPart();
652:                    if (lp == null)
653:                        return null;
654:                    if (lp.equals("int")) {
655:                        return "java.lang.Integer";
656:                    } else if (lp.equals("long")) {
657:                        return "java.lang.Long";
658:                    } else if (lp.equals("float")) {
659:                        return "java.lang.Float";
660:                    } else if (lp.equals("short")) {
661:                        return "java.lang.Short";
662:                    } else if (lp.equals("double")) {
663:                        return "java.lang.Double";
664:                    } else if (lp.equals("boolean")) {
665:                        return "java.lang.Boolean";
666:                    } else if (lp.equals("byte")) {
667:                        return "java.lang.Byte";
668:                    }
669:                }
670:                return null;
671:            }
672:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.