Source Code Cross Referenced for JaxMeExtension.java in  » Web-Services-AXIS2 » codegen-wsdl2java » org » apache » axis2 » wsdl » codegen » extension » 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 » codegen wsdl2java » org.apache.axis2.wsdl.codegen.extension 
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:
020:        package org.apache.axis2.wsdl.codegen.extension;
021:
022:        import org.apache.axis2.description.AxisService;
023:        import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
024:        import org.apache.axis2.wsdl.databinding.DefaultTypeMapper;
025:        import org.apache.axis2.wsdl.databinding.JavaTypeMapper;
026:        import org.apache.axis2.wsdl.databinding.TypeMapper;
027:        import org.apache.axis2.wsdl.i18n.CodegenMessages;
028:        import org.apache.axis2.wsdl.util.ConfigPropertyFileLoader;
029:        import org.apache.ws.commons.schema.XmlSchema;
030:        import org.apache.ws.jaxme.generator.impl.GeneratorImpl;
031:        import org.apache.ws.jaxme.generator.sg.GroupSG;
032:        import org.apache.ws.jaxme.generator.sg.ObjectSG;
033:        import org.apache.ws.jaxme.generator.sg.SchemaSG;
034:        import org.apache.ws.jaxme.generator.sg.TypeSG;
035:        import org.apache.ws.jaxme.generator.sg.impl.JAXBSchemaReader;
036:        import org.apache.ws.jaxme.js.JavaQName;
037:        import org.apache.ws.jaxme.xs.xml.XsQName;
038:        import org.w3c.dom.Document;
039:        import org.w3c.dom.Element;
040:        import org.xml.sax.InputSource;
041:
042:        import javax.xml.namespace.QName;
043:        import javax.xml.parsers.DocumentBuilder;
044:        import javax.xml.parsers.DocumentBuilderFactory;
045:        import javax.xml.parsers.ParserConfigurationException;
046:        import java.io.ByteArrayOutputStream;
047:        import java.io.File;
048:        import java.io.InputStream;
049:        import java.io.StringReader;
050:        import java.util.ArrayList;
051:        import java.util.Iterator;
052:        import java.util.List;
053:        import java.util.Vector;
054:
055:        public class JaxMeExtension extends AbstractDBProcessingExtension {
056:            public static final String SCHEMA_FOLDER = "schemas";
057:
058:            public static String MAPPINGS = "mappings";
059:            public static String MAPPING = "mapping";
060:            public static String MESSAGE = "message";
061:            public static String JAVA_NAME = "javaclass";
062:
063:            public static final String MAPPING_FOLDER = "Mapping";
064:            public static final String MAPPER_FILE_NAME = "mapper";
065:            public static final String SCHEMA_PATH = "/org/apache/axis2/wsdl/codegen/schema/";
066:
067:            boolean debug = false;
068:
069:            public void engage(CodeGenConfiguration configuration) {
070:
071:                //test the databinding type. If not just fall through
072:                if (testFallThrough(configuration.getDatabindingType())) {
073:                    return;
074:                }
075:
076:                try {
077:                    //get the types from the types section
078:                    List typesList = new ArrayList();
079:                    List axisServices = configuration.getAxisServices();
080:                    AxisService axisService = null;
081:                    for (Iterator iter = axisServices.iterator(); iter
082:                            .hasNext();) {
083:                        axisService = (AxisService) iter.next();
084:                        typesList.addAll(axisService.getSchema());
085:                    }
086:
087:                    //check for the imported types. Any imported types are supposed to be here also
088:                    if (typesList == null || typesList.isEmpty()) {
089:                        //there are no types to be code generated
090:                        //However if the type mapper is left empty it will be a problem for the other
091:                        //processes. Hence the default type mapper is set to the configuration
092:                        configuration.setTypeMapper(new DefaultTypeMapper());
093:                        return;
094:                    }
095:
096:                    Vector xmlObjectsVector = new Vector();
097:                    //create the type mapper
098:                    //First try to take the one that is already there
099:                    TypeMapper mapper = configuration.getTypeMapper();
100:                    if (mapper == null) {
101:                        mapper = new JavaTypeMapper();
102:                    }
103:
104:                    for (int i = 0; i < typesList.size(); i++) {
105:                        XmlSchema schema = (XmlSchema) typesList.get(i);
106:                        xmlObjectsVector.add(new InputSource(new StringReader(
107:                                getSchemaAsString(schema))));
108:                    }
109:
110:                    //            TODO: FIXME            
111:                    //            Element[] additionalSchemas = loadAdditionalSchemas();
112:                    //            // Need to add the third party schemas
113:                    //            for (int i = 0; i < additionalSchemas.length; i++) {
114:                    //                String s = DOM2Writer.nodeToString(additionalSchemas[i]);
115:                    //                xmlObjectsVector.add(new InputSource(new StringReader(s)));
116:                    //            }
117:
118:                    File outputDir = new File(
119:                            configuration.getOutputLocation(), configuration
120:                                    .getSourceLocation());
121:
122:                    JAXBSchemaReader reader = new JAXBSchemaReader();
123:                    reader.setSupportingExtensions(true);
124:
125:                    GeneratorImpl generator = new GeneratorImpl();
126:                    generator.setTargetDirectory(outputDir);
127:                    generator.setForcingOverwrite(false);
128:                    generator.setSchemaReader(reader);
129:
130:                    for (int i = 0; i < xmlObjectsVector.size(); i++) {
131:                        SchemaSG sg = generator
132:                                .generate((InputSource) xmlObjectsVector
133:                                        .elementAt(i));
134:                        ObjectSG[] elements = sg.getElements();
135:                        for (int j = 0; j < elements.length; j++) {
136:                            XsQName qName = elements[j].getName();
137:                            JavaQName name = elements[j].getClassContext()
138:                                    .getXMLInterfaceName();
139:                            mapper.addTypeMappingName(new QName(qName
140:                                    .getNamespaceURI(), qName.getLocalName()),
141:                                    name.getPackageName() + '.'
142:                                            + name.getClassName());
143:                        }
144:                        TypeSG[] types = sg.getTypes();
145:                        for (int j = 0; j < types.length; j++) {
146:                            XsQName qName = types[j].getName();
147:                            JavaQName name = types[j].getRuntimeType();
148:                            mapper.addTypeMappingName(new QName(qName
149:                                    .getNamespaceURI(), qName.getLocalName()),
150:                                    name.getPackageName() + '.'
151:                                            + name.getClassName());
152:                        }
153:                        GroupSG[] groups = sg.getGroups();
154:                        for (int j = 0; j < groups.length; j++) {
155:                            XsQName qName = groups[j].getName();
156:                            JavaQName name = groups[j].getClassContext()
157:                                    .getXMLInterfaceName();
158:                            mapper.addTypeMappingName(new QName(qName
159:                                    .getNamespaceURI(), qName.getLocalName()),
160:                                    name.getPackageName() + '.'
161:                                            + name.getClassName());
162:                        }
163:                    }
164:
165:                    //set the type mapper to the config
166:                    configuration.setTypeMapper(mapper);
167:
168:                } catch (Exception e) {
169:                    throw new RuntimeException(e);
170:                }
171:
172:            }
173:
174:            /**
175:             * Loading the external schemas.
176:             *
177:             * @return element array consisting of the the DOM element objects that represent schemas
178:             */
179:            private Element[] loadAdditionalSchemas() {
180:                //load additional schemas
181:                String[] schemaNames = ConfigPropertyFileLoader
182:                        .getThirdPartySchemaNames();
183:                Element[] schemaElements;
184:
185:                try {
186:                    ArrayList additionalSchemaElements = new ArrayList();
187:                    DocumentBuilder documentBuilder = getNamespaceAwareDocumentBuilder();
188:                    for (int i = 0; i < schemaNames.length; i++) {
189:                        //the location for the third party schema;s is hardcoded
190:                        if (!"".equals(schemaNames[i].trim())) {
191:                            InputStream schemaStream = this .getClass()
192:                                    .getResourceAsStream(
193:                                            SCHEMA_PATH + schemaNames[i]);
194:                            Document doc = documentBuilder.parse(schemaStream);
195:                            additionalSchemaElements.add(doc
196:                                    .getDocumentElement());
197:                        }
198:                    }
199:
200:                    //Create the Schema element array
201:                    schemaElements = new Element[additionalSchemaElements
202:                            .size()];
203:                    for (int i = 0; i < additionalSchemaElements.size(); i++) {
204:                        schemaElements[i] = (Element) additionalSchemaElements
205:                                .get(i);
206:
207:                    }
208:                } catch (Exception e) {
209:                    throw new RuntimeException(CodegenMessages
210:                            .getMessage("extension.additionalSchemaFailure"), e);
211:                }
212:
213:                return schemaElements;
214:            }
215:
216:            private DocumentBuilder getNamespaceAwareDocumentBuilder()
217:                    throws ParserConfigurationException {
218:                DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
219:                        .newInstance();
220:                documentBuilderFactory.setNamespaceAware(true);
221:                return documentBuilderFactory.newDocumentBuilder();
222:            }
223:
224:            private String getSchemaAsString(XmlSchema schema) {
225:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
226:                schema.write(baos);
227:                return baos.toString();
228:            }
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.