Source Code Cross Referenced for ExtensionUtility.java in  » Web-Services-AXIS2 » adb » org » apache » axis2 » 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 AXIS2 » adb » org.apache.axis2.schema 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:        package org.apache.axis2.schema;
020:
021:        import org.apache.axis2.description.AxisMessage;
022:        import org.apache.axis2.description.AxisOperation;
023:        import org.apache.axis2.description.AxisService;
024:        import org.apache.axis2.description.Parameter;
025:        import org.apache.axis2.wsdl.WSDLConstants;
026:        import org.apache.axis2.wsdl.WSDLUtil;
027:        import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
028:        import org.apache.axis2.wsdl.databinding.*;
029:        import org.apache.axis2.wsdl.util.Constants;
030:        import org.apache.axis2.util.URLProcessor;
031:        import org.apache.axis2.AxisFault;
032:        import org.apache.axis2.schema.typemap.TypeMap;
033:        import org.apache.axis2.schema.typemap.JavaTypeMap;
034:        import org.apache.ws.commons.schema.*;
035:
036:        import javax.xml.namespace.QName;
037:        import java.io.File;
038:        import java.util.*;
039:
040:        /**
041:         * This is the utility for the extension to call by reflection.
042:         */
043:        public class ExtensionUtility {
044:
045:            public static void invoke(CodeGenConfiguration configuration)
046:                    throws Exception {
047:                List schemaList = new ArrayList();
048:                // add all the schemas to the list
049:                List services = configuration.getAxisServices();
050:                for (Iterator iter = services.iterator(); iter.hasNext();) {
051:                    schemaList.addAll(((AxisService) iter.next()).getSchema());
052:                }
053:
054:                //hashmap that keeps the targetnamespace and the xmlSchema object
055:                //this is a convenience to locate the relevant schema quickly
056:                //by looking at the target namespace
057:                Map schemaMap = new HashMap();
058:                populateSchemaMap(schemaMap, schemaList);
059:
060:                if (schemaList == null || schemaList.isEmpty()) {
061:                    //there are no types to be code generated
062:                    //However if the type mapper is left empty it will be a problem for the other
063:                    //processes. Hence the default type mapper is set to the configuration
064:                    configuration.setTypeMapper(new DefaultTypeMapper());
065:                    return;
066:                }
067:                //call the schema compiler
068:                CompilerOptions options = new CompilerOptions();
069:
070:                //set the default options
071:                populateDefaultOptions(options, configuration);
072:
073:                //set the user parameters. the user parameters get the preference over
074:                //the default ones. But the user better know what he's doing if he
075:                //used module specific parameters
076:                populateUserparameters(options, configuration);
077:
078:                SchemaCompiler schemaCompiler = new SchemaCompiler(options);
079:                // run the schema compiler
080:                schemaCompiler.compile(schemaList);
081:
082:                //create the type mapper
083:                //First try to take the one that is already there
084:                TypeMapper mapper = configuration.getTypeMapper();
085:                if (mapper == null) {
086:                    if (configuration.getOutputLanguage() != null
087:                            && !configuration.getOutputLanguage().trim()
088:                                    .equals("")
089:                            && configuration.getOutputLanguage().toLowerCase()
090:                                    .equals("c")) {
091:                        mapper = new CTypeMapper();
092:
093:                    } else {
094:                        mapper = new JavaTypeMapper();
095:                    }
096:
097:                }
098:
099:                if (options.isWriteOutput()) {
100:                    //get the processed element map and transfer it to the type mapper
101:                    Map processedMap = schemaCompiler.getProcessedElementMap();
102:                    Iterator processedkeys = processedMap.keySet().iterator();
103:                    QName qNameKey;
104:                    while (processedkeys.hasNext()) {
105:                        qNameKey = (QName) processedkeys.next();
106:                        mapper.addTypeMappingName(qNameKey, processedMap.get(
107:                                qNameKey).toString());
108:                    }
109:
110:                } else {
111:                    //get the processed model map and transfer it to the type mapper
112:                    //since the options mentiond that its not writable, it should have
113:                    //populated the model map
114:                    Map processedModelMap = schemaCompiler
115:                            .getProcessedModelMap();
116:                    Iterator processedkeys = processedModelMap.keySet()
117:                            .iterator();
118:                    QName qNameKey;
119:                    while (processedkeys.hasNext()) {
120:                        qNameKey = (QName) processedkeys.next();
121:                        mapper.addTypeMappingObject(qNameKey, processedModelMap
122:                                .get(qNameKey));
123:                    }
124:
125:                    Map processedMap = schemaCompiler.getProcessedElementMap();
126:                    processedkeys = processedMap.keySet().iterator();
127:                    while (processedkeys.hasNext()) {
128:                        qNameKey = (QName) processedkeys.next();
129:                        mapper.addTypeMappingName(qNameKey, processedMap.get(
130:                                qNameKey).toString());
131:                    }
132:
133:                    //get the ADB template from the schema compilers property bag and set the
134:                    //template
135:                    configuration
136:                            .putProperty(
137:                                    Constants.EXTERNAL_TEMPLATE_PROPERTY_KEY,
138:                                    schemaCompiler
139:                                            .getCompilerProperties()
140:                                            .getProperty(
141:                                                    SchemaConstants.SchemaPropertyNames.BEAN_WRITER_TEMPLATE_KEY));
142:
143:                }
144:
145:                //process the unwrapped parameters
146:                if (!configuration.isParametersWrapped()) {
147:                    //figure out the unwrapped operations
148:                    List axisServices = configuration.getAxisServices();
149:                    AxisService axisService;
150:                    for (Iterator servicesIter = axisServices.iterator(); servicesIter
151:                            .hasNext();) {
152:                        axisService = (AxisService) servicesIter.next();
153:                        for (Iterator operations = axisService.getOperations(); operations
154:                                .hasNext();) {
155:                            AxisOperation op = (AxisOperation) operations
156:                                    .next();
157:                            if (WSDLUtil.isInputPresentForMEP(op
158:                                    .getMessageExchangePattern())) {
159:                                walkSchema(
160:                                        op
161:                                                .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE),
162:                                        mapper, schemaMap, op.getName()
163:                                                .getLocalPart(),
164:                                        WSDLConstants.INPUT_PART_QNAME_SUFFIX);
165:                            }
166:
167:                            // TODO: support for xml beans
168:                            if (configuration.getDatabindingType()
169:                                    .equals("adb")) {
170:                                if (WSDLUtil.isOutputPresentForMEP(op
171:                                        .getMessageExchangePattern())) {
172:                                    walkSchema(
173:                                            op
174:                                                    .getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE),
175:                                            mapper,
176:                                            schemaMap,
177:                                            op.getName().getLocalPart(),
178:                                            WSDLConstants.OUTPUT_PART_QNAME_SUFFIX);
179:                                }
180:                            }
181:
182:                        }
183:                    }
184:
185:                }
186:
187:                //put the complext types for the top level elements having them
188:                // this is needed in unwrapping and to provide backwordCompatibility
189:                if (!configuration.isParametersWrapped()
190:                        || configuration.isBackwordCompatibilityMode()) {
191:                    List axisServices = configuration.getAxisServices();
192:                    AxisService axisService;
193:                    for (Iterator servicesIter = axisServices.iterator(); servicesIter
194:                            .hasNext();) {
195:                        axisService = (AxisService) servicesIter.next();
196:                        AxisOperation axisOperation;
197:                        AxisMessage axisMessage;
198:                        for (Iterator operators = axisService.getOperations(); operators
199:                                .hasNext();) {
200:                            axisOperation = (AxisOperation) operators.next();
201:                            if (WSDLUtil.isInputPresentForMEP(axisOperation
202:                                    .getMessageExchangePattern())) {
203:                                axisMessage = axisOperation
204:                                        .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
205:                                setComplexTypeName(axisMessage);
206:                            }
207:                            if (WSDLUtil.isOutputPresentForMEP(axisOperation
208:                                    .getMessageExchangePattern())) {
209:                                axisMessage = axisOperation
210:                                        .getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
211:                                setComplexTypeName(axisMessage);
212:                            }
213:                        }
214:                    }
215:
216:                }
217:
218:                //set the type mapper to the config
219:                configuration.setTypeMapper(mapper);
220:
221:            }
222:
223:            /**
224:             * set the complext type class name as an message parameter if it exits
225:             * @param axisMessage
226:             */
227:            private static void setComplexTypeName(AxisMessage axisMessage)
228:                    throws AxisFault {
229:
230:                if (axisMessage.getSchemaElement() != null) {
231:
232:                    XmlSchemaElement schemaElement = axisMessage
233:                            .getSchemaElement();
234:                    XmlSchemaType schemaType = schemaElement.getSchemaType();
235:                    QName schemaTypeQname = schemaElement.getSchemaTypeName();
236:
237:                    if (schemaType == null) {
238:                        if (schemaTypeQname != null) {
239:                            // find the schema type from all the schemas
240:                            // now we need to get the schema of the extension type from the parent schema. For that let's first retrieve
241:                            // the parent schema
242:                            AxisService axisService = axisMessage
243:                                    .getAxisOperation().getAxisService();
244:                            ArrayList schemasList = axisService.getSchema();
245:                            XmlSchema schema = null;
246:                            for (Iterator iter = schemasList.iterator(); iter
247:                                    .hasNext();) {
248:                                schema = (XmlSchema) iter.next();
249:                                schemaType = getSchemaType(schema,
250:                                        schemaTypeQname);
251:                                if (schemaType != null) {
252:                                    break;
253:                                }
254:                            }
255:                        }
256:                    }
257:
258:                    if (schemaType instanceof  XmlSchemaComplexType) {
259:                        XmlSchemaComplexType complexType = (XmlSchemaComplexType) schemaType;
260:                        if ((complexType.getName() != null)
261:                                && (complexType.getQName() != null)) {
262:                            Map metaInfo = complexType.getMetaInfoMap();
263:                            String complexTypeName = (String) metaInfo
264:                                    .get(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY);
265:                            if (complexTypeName.endsWith("[]")) {
266:                                complexTypeName = complexTypeName.substring(0,
267:                                        complexTypeName.length() - 2);
268:                            }
269:                            // store the complext type name to process later
270:                            axisMessage.addParameter(new Parameter(
271:                                    Constants.COMPLEX_TYPE, complexTypeName));
272:                        }
273:                    }
274:                }
275:
276:            }
277:
278:            /**
279:             * Populate the schema objects into the
280:             *
281:             * @param schemaMap
282:             * @param schemaList
283:             */
284:            private static void populateSchemaMap(Map schemaMap, List schemaList) {
285:                for (int i = 0; i < schemaList.size(); i++) {
286:                    XmlSchema xmlSchema = (XmlSchema) schemaList.get(i);
287:                    schemaMap.put(xmlSchema.getTargetNamespace(), xmlSchema);
288:                }
289:            }
290:
291:            /**
292:             * @param message
293:             * @param mapper
294:             */
295:            private static void walkSchema(AxisMessage message,
296:                    TypeMapper mapper, Map schemaMap, String opName,
297:                    String qnameSuffix) {
298:
299:                if (message.getParameter(Constants.UNWRAPPED_KEY) != null) {
300:
301:                    XmlSchemaElement schemaElement = message.getSchemaElement();
302:                    XmlSchemaType schemaType = schemaElement.getSchemaType();
303:                    QName schemaTypeQname = schemaElement.getSchemaTypeName();
304:
305:                    if (schemaType == null) {
306:                        if (schemaTypeQname != null) {
307:                            // find the schema type from all the schemas
308:                            // now we need to get the schema of the extension type from the parent schema. For that let's first retrieve
309:                            // the parent schema
310:                            AxisService axisService = message
311:                                    .getAxisOperation().getAxisService();
312:                            ArrayList schemasList = axisService.getSchema();
313:
314:                            XmlSchema schema = null;
315:                            for (Iterator iter = schemasList.iterator(); iter
316:                                    .hasNext();) {
317:                                schema = (XmlSchema) iter.next();
318:                                schemaType = getSchemaType(schema,
319:                                        schemaTypeQname);
320:                                if (schemaType != null) {
321:                                    break;
322:                                }
323:                            }
324:                        }
325:                    }
326:
327:                    //create a type mapper
328:                    TypeMap basicTypeMap = new JavaTypeMap();
329:                    if (schemaType instanceof  XmlSchemaComplexType) {
330:                        processXMLSchemaComplexType(schemaType, mapper, opName,
331:                                schemaMap, qnameSuffix);
332:                    } else if ((schemaTypeQname != null)
333:                            && basicTypeMap.getTypeMap().containsKey(
334:                                    schemaTypeQname)) {
335:                        QName partQName = WSDLUtil.getPartQName(opName,
336:                                qnameSuffix, message.getElementQName()
337:                                        .getLocalPart());
338:                        mapper.addTypeMappingName(partQName,
339:                                (String) basicTypeMap.getTypeMap().get(
340:                                        schemaTypeQname));
341:                    } else if (schemaType instanceof  XmlSchemaSimpleType) {
342:                        XmlSchemaSimpleType xmlSchemaSimpleType = (XmlSchemaSimpleType) schemaType;
343:                        populateClassName(xmlSchemaSimpleType.getMetaInfoMap(),
344:                                mapper, opName, false, message
345:                                        .getElementQName().getLocalPart(),
346:                                qnameSuffix);
347:                        // handle xsd:anyType
348:                    }
349:
350:                }
351:            }
352:
353:            private static void processXMLSchemaComplexType(
354:                    XmlSchemaType schemaType, TypeMapper mapper, String opName,
355:                    Map schemaMap, String qnameSuffix) {
356:                if (schemaType instanceof  XmlSchemaComplexType) {
357:                    XmlSchemaComplexType cmplxType = (XmlSchemaComplexType) schemaType;
358:                    if (cmplxType.getContentModel() == null) {
359:                        processSchemaSequence(cmplxType.getParticle(), mapper,
360:                                opName, schemaMap, qnameSuffix);
361:                    } else {
362:                        processComplexContentModel(cmplxType, mapper, opName,
363:                                schemaMap, qnameSuffix);
364:                    }
365:                    processAttributes(cmplxType, opName, qnameSuffix, mapper);
366:                }
367:            }
368:
369:            private static void processAttributes(
370:                    XmlSchemaComplexType complexType, String opName,
371:                    String qnameSuffix, TypeMapper typeMap) {
372:                XmlSchemaObjectCollection xmlObjectCollection = complexType
373:                        .getAttributes();
374:                XmlSchemaObject item;
375:                for (Iterator iter = xmlObjectCollection.getIterator(); iter
376:                        .hasNext();) {
377:                    item = (XmlSchemaObject) iter.next();
378:                    XmlSchemaAttribute xmlSchemaAttribute;
379:                    if (item instanceof  XmlSchemaAttribute) {
380:                        xmlSchemaAttribute = (XmlSchemaAttribute) item;
381:                        populateClassName(xmlSchemaAttribute.getMetaInfoMap(),
382:                                typeMap, opName, false, xmlSchemaAttribute
383:                                        .getName(), qnameSuffix);
384:                    }
385:
386:                }
387:
388:            }
389:
390:            private static XmlSchemaType getSchemaType(XmlSchema schema,
391:                    QName typeName) {
392:                XmlSchemaType xmlSchemaType = null;
393:                if (schema != null) {
394:                    xmlSchemaType = schema.getTypeByName(typeName);
395:                    if (xmlSchemaType == null) {
396:                        // try to find in an import or an include
397:                        XmlSchemaObjectCollection includes = schema
398:                                .getIncludes();
399:                        if (includes != null) {
400:                            Iterator includesIter = includes.getIterator();
401:                            Object object = null;
402:                            while (includesIter.hasNext()) {
403:                                object = includesIter.next();
404:                                if (object instanceof  XmlSchemaImport) {
405:                                    XmlSchema schema1 = ((XmlSchemaImport) object)
406:                                            .getSchema();
407:                                    xmlSchemaType = getSchemaType(schema1,
408:                                            typeName);
409:                                }
410:                                if (object instanceof  XmlSchemaInclude) {
411:                                    XmlSchema schema1 = ((XmlSchemaInclude) object)
412:                                            .getSchema();
413:                                    xmlSchemaType = getSchemaType(schema1,
414:                                            typeName);
415:                                }
416:                                if (xmlSchemaType != null) {
417:                                    break;
418:                                }
419:                            }
420:                        }
421:                    }
422:                }
423:                return xmlSchemaType;
424:            }
425:
426:            private static void processComplexContentModel(
427:                    XmlSchemaComplexType cmplxType, TypeMapper mapper,
428:                    String opName, Map schemaMap, String qnameSuffix) {
429:                XmlSchemaContentModel contentModel = cmplxType
430:                        .getContentModel();
431:                if (contentModel instanceof  XmlSchemaComplexContent) {
432:                    XmlSchemaComplexContent xmlSchemaComplexContent = (XmlSchemaComplexContent) contentModel;
433:                    XmlSchemaContent content = xmlSchemaComplexContent
434:                            .getContent();
435:                    if (content instanceof  XmlSchemaComplexContentExtension) {
436:                        XmlSchemaComplexContentExtension schemaExtension = (XmlSchemaComplexContentExtension) content;
437:
438:                        // process particles inside this extension, if any
439:                        processSchemaSequence(schemaExtension.getParticle(),
440:                                mapper, opName, schemaMap, qnameSuffix);
441:
442:                        XmlSchema xmlSchema = null;
443:                        XmlSchemaType extensionSchemaType = null;
444:                        for (Iterator iter = schemaMap.values().iterator(); iter
445:                                .hasNext();) {
446:                            xmlSchema = (XmlSchema) iter.next();
447:                            extensionSchemaType = getSchemaType(xmlSchema,
448:                                    schemaExtension.getBaseTypeName());
449:                            if (extensionSchemaType != null) {
450:                                break;
451:                            }
452:                        }
453:
454:                        processXMLSchemaComplexType(extensionSchemaType,
455:                                mapper, opName, schemaMap, qnameSuffix);
456:                    }
457:                }
458:            }
459:
460:            private static void processSchemaSequence(
461:                    XmlSchemaParticle particle, TypeMapper mapper,
462:                    String opName, Map schemaMap, String qnameSuffix) {
463:                if (particle instanceof  XmlSchemaSequence) {
464:                    XmlSchemaObjectCollection items = ((XmlSchemaSequence) particle)
465:                            .getItems();
466:                    for (Iterator i = items.getIterator(); i.hasNext();) {
467:                        Object item = i.next();
468:                        // get each and every element in the sequence and
469:                        // traverse through them
470:                        if (item instanceof  XmlSchemaElement) {
471:                            //populate the map with the partname - class name
472:                            //attached to the schema element
473:                            XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) item;
474:                            boolean isArray = xmlSchemaElement.getMaxOccurs() > 1;
475:
476:                            XmlSchemaType schemaType = xmlSchemaElement
477:                                    .getSchemaType();
478:                            String partName = null;
479:                            if (xmlSchemaElement.getRefName() != null) {
480:                                partName = xmlSchemaElement.getRefName()
481:                                        .getLocalPart();
482:                            } else {
483:                                partName = xmlSchemaElement.getName();
484:                            }
485:
486:                            // get the element class name from the element and populate the mapper
487:                            populateClassName(
488:                                    xmlSchemaElement.getMetaInfoMap(), mapper,
489:                                    opName, isArray, partName, qnameSuffix);
490:                        } else if (item instanceof  XmlSchemaAny) {
491:
492:                            // if this is an instance of xs:any, then there is no part name for it. Using ANY_ELEMENT_FIELD_NAME
493:                            // for it for now
494:
495:                            XmlSchemaAny xmlSchemaAny = (XmlSchemaAny) item;
496:                            boolean isArray = xmlSchemaAny.getMaxOccurs() > 1;
497:
498:                            QName partQName = WSDLUtil.getPartQName(opName,
499:                                    qnameSuffix,
500:                                    Constants.ANY_ELEMENT_FIELD_NAME);
501:
502:                            if (isArray) {
503:                                mapper.addTypeMappingName(partQName,
504:                                        "org.apache.axiom.om.OMElement[]");
505:                            } else {
506:                                mapper.addTypeMappingName(partQName,
507:                                        "org.apache.axiom.om.OMElement");
508:                            }
509:                        }
510:                    }
511:                }
512:            }
513:
514:            // private static void
515:
516:            /**
517:             * Util method to populate the class name into the typeMap
518:             *
519:             */
520:            private static void populateClassName(Map metaInfoMap,
521:                    TypeMapper typeMap, String opName, boolean isArray,
522:                    String partName, String qnameSuffix) {
523:
524:                if (metaInfoMap != null) {
525:                    String className = (String) metaInfoMap
526:                            .get(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY);
527:
528:                    // this is a temporary patch
529:                    // the acual problem is keeping the class name details on the schemaType in
530:                    // XmlSchema compiler.
531:                    // we have to store them in XmlElement
532:                    if (isArray && !className.endsWith("[]")) {
533:                        className += "[]";
534:                    } else if (!isArray && className.endsWith("[]")) {
535:                        className = className.substring(0,
536:                                className.length() - 2);
537:                    }
538:
539:                    QName partQName = WSDLUtil.getPartQName(opName,
540:                            qnameSuffix, partName);
541:                    typeMap.addTypeMappingName(partQName, className);
542:                    if (Boolean.TRUE
543:                            .equals(metaInfoMap
544:                                    .get(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_PRIMITVE_KEY))) {
545:
546:                        //this type is primitive - add that to the type mapper status
547:                        //for now lets add a boolean
548:                        typeMap.addTypeMappingStatus(partQName, Boolean.TRUE);
549:                    }
550:                }
551:            }
552:
553:            /**
554:             * Look for a given schema type given the schema type Qname
555:             *
556:             * @param schemaMap
557:             * @return null if the schema is not found
558:             */
559:            private static XmlSchemaType findSchemaType(Map schemaMap,
560:                    QName schemaTypeName) {
561:                //find the schema
562:                XmlSchema schema = (XmlSchema) schemaMap.get(schemaTypeName
563:                        .getNamespaceURI());
564:                if (schema != null) {
565:                    return schema.getTypeByName(schemaTypeName);
566:                }
567:                return null;
568:            }
569:
570:            /**
571:             * populate parameters from the user
572:             *
573:             * @param options
574:             */
575:            private static void populateUserparameters(CompilerOptions options,
576:                    CodeGenConfiguration configuration) {
577:                Map propertyMap = configuration.getProperties();
578:                if (propertyMap
579:                        .containsKey(SchemaConstants.SchemaCompilerArguments.WRAP_SCHEMA_CLASSES)) {
580:                    if (Boolean
581:                            .valueOf(
582:                                    propertyMap
583:                                            .get(
584:                                                    SchemaConstants.SchemaCompilerArguments.WRAP_SCHEMA_CLASSES)
585:                                            .toString()).booleanValue()) {
586:                        options.setWrapClasses(true);
587:                    } else {
588:                        options.setWrapClasses(false);
589:                    }
590:                }
591:
592:                if (propertyMap
593:                        .containsKey(SchemaConstants.SchemaCompilerArguments.WRITE_SCHEMA_CLASSES)) {
594:                    if (Boolean
595:                            .valueOf(
596:                                    propertyMap
597:                                            .get(
598:                                                    SchemaConstants.SchemaCompilerArguments.WRITE_SCHEMA_CLASSES)
599:                                            .toString()).booleanValue()) {
600:                        options.setWriteOutput(true);
601:                    } else {
602:                        options.setWriteOutput(false);
603:                    }
604:                }
605:
606:                // add the custom package name
607:                if (propertyMap
608:                        .containsKey(SchemaConstants.SchemaCompilerArguments.PACKAGE)) {
609:                    String packageName = (String) propertyMap
610:                            .get(SchemaConstants.SchemaCompilerArguments.PACKAGE);
611:                    if (packageName != null || !"".equals(packageName)) {
612:                        options.setPackageName(packageName);
613:                    }
614:
615:                }
616:
617:                // set the package namespace to uri details
618:                options.setNs2PackageMap(configuration.getUri2PackageNameMap());
619:
620:                //add custom mapper package name
621:                if (propertyMap
622:                        .containsKey(SchemaConstants.SchemaCompilerArguments.MAPPER_PACKAGE)) {
623:                    String packageName = (String) propertyMap
624:                            .get(SchemaConstants.SchemaCompilerArguments.MAPPER_PACKAGE);
625:                    if (packageName != null || !"".equals(packageName)) {
626:                        options.setMapperClassPackage(packageName);
627:                    }
628:
629:                }
630:
631:                if (propertyMap
632:                        .containsKey(SchemaConstants.SchemaCompilerArguments.OFF_STRICT_VALIDATION)) {
633:                    options.setOffStrictValidation(true);
634:                }
635:
636:                //set helper mode
637:                //this becomes effective only if the classes are unpacked
638:                if (!options.isWrapClasses()) {
639:                    if (propertyMap
640:                            .containsKey(SchemaConstants.SchemaCompilerArguments.HELPER_MODE)) {
641:                        options.setHelperMode(true);
642:                    }
643:                }
644:            }
645:
646:            /**
647:             * populate the default options - called before the applying of user parameters
648:             *
649:             * @param options
650:             */
651:            private static void populateDefaultOptions(CompilerOptions options,
652:                    CodeGenConfiguration configuration) {
653:                //create the output directory
654:                File outputDir = configuration.isFlattenFiles() ? configuration
655:                        .getOutputLocation()
656:                        : new File(configuration.getOutputLocation(),
657:                                configuration.getSourceLocation());
658:
659:                if (!outputDir.exists()) {
660:                    outputDir.mkdirs();
661:                }
662:
663:                /// these options need to be taken from the command line
664:                options.setOutputLocation(outputDir);
665:                options
666:                        .setNs2PackageMap(configuration.getUri2PackageNameMap() == null ? new HashMap()
667:                                : configuration.getUri2PackageNameMap());
668:
669:                //default setting is to set the wrap status depending on whether it's
670:                //the server side or the client side
671:                if (configuration.isServerSide()) {
672:                    //for the serverside we generate unwrapped  by default
673:                    options.setWrapClasses(false);
674:                    //for the serverside we write the output by default
675:                    options.setWriteOutput(true);
676:                } else {
677:                    // for the client let the users preference be the word here
678:                    options.setWrapClasses(configuration.isPackClasses());
679:                    //for the client side the default setting is not to write the
680:                    //output
681:                    options.setWriteOutput(!configuration.isPackClasses());
682:                }
683:
684:                if (configuration.isGenerateAll()) {
685:                    options.setGenerateAll(true);
686:                }
687:
688:                if (configuration.isBackwordCompatibilityMode()) {
689:                    options.setBackwordCompatibilityMode(true);
690:                }
691:
692:                if (configuration.isSuppressPrefixesMode()) {
693:                    options.setSuppressPrefixesMode(true);
694:                }
695:            }
696:
697:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.