Source Code Cross Referenced for WSDL11Writer.java in  » Web-Services-AXIS2 » codegen-wsdl2java » org » apache » axis2 » wsdl » codegen » writer » 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.writer 
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.wsdl.codegen.writer;
020:
021:        import org.apache.axis2.description.AxisService;
022:        import org.apache.axis2.util.FileWriter;
023:        import org.w3c.dom.Element;
024:        import org.w3c.dom.NamedNodeMap;
025:        import org.w3c.dom.Node;
026:        import org.w3c.dom.NodeList;
027:
028:        import javax.wsdl.Definition;
029:        import javax.wsdl.Import;
030:        import javax.wsdl.Types;
031:        import javax.wsdl.Service;
032:        import javax.wsdl.extensions.schema.Schema;
033:        import javax.wsdl.factory.WSDLFactory;
034:        import javax.wsdl.xml.WSDLWriter;
035:        import java.io.File;
036:        import java.io.FileOutputStream;
037:        import java.util.Iterator;
038:        import java.util.List;
039:        import java.util.Map;
040:        import java.util.Vector;
041:        import java.util.ArrayList;
042:        import java.util.Stack;
043:
044:        public class WSDL11Writer {
045:
046:            public static final String IMPORT_TAG = "import";
047:            public static final String INCLUDE_TAG = "include";
048:            public static final String SCHEMA_LOCATION = "schemaLocation";
049:
050:            private File baseFolder = null;
051:            private int count;
052:
053:            public WSDL11Writer(File baseFolder) {
054:                this .baseFolder = baseFolder;
055:                this .count = 0;
056:            }
057:
058:            public void writeWSDL(AxisService axisService) {
059:                try {
060:                    if (axisService != null) {
061:                        //create a output file
062:                        File outputFile = FileWriter.createClassFile(
063:                                baseFolder, null, axisService.getName(),
064:                                ".wsdl");
065:                        FileOutputStream fos = new FileOutputStream(outputFile);
066:                        axisService.printWSDL(fos);
067:                        fos.flush();
068:                        fos.close();
069:                    }
070:                } catch (Exception e) {
071:                    throw new RuntimeException("WSDL writing failed!", e);
072:                }
073:            }
074:
075:            public void writeWSDL(AxisService axisService,
076:                    Definition definition, Map changedMap) {
077:                try {
078:                    if (axisService != null) {
079:                        writeWSDL(definition, axisService.getName(),
080:                                changedMap, new Stack());
081:                    }
082:                } catch (Exception e) {
083:                    throw new RuntimeException("WSDL writing failed!", e);
084:                }
085:            }
086:
087:            private void writeWSDL(Definition definition, String serviceName,
088:                    Map changedMap, Stack stack) throws Exception {
089:                stack.push(definition);
090:                // first process the imports and save them.
091:                Map imports = definition.getImports();
092:                if (imports != null && (imports.size() > 0)) {
093:                    Vector importsVector = null;
094:                    Import wsdlImport = null;
095:                    String wsdlName = null;
096:                    for (Iterator improtsVectorIter = imports.values()
097:                            .iterator(); improtsVectorIter.hasNext();) {
098:                        importsVector = (Vector) improtsVectorIter.next();
099:                        for (Iterator importsIter = importsVector.iterator(); importsIter
100:                                .hasNext();) {
101:                            wsdlImport = (Import) importsIter.next();
102:                            wsdlName = "wsdl_" + count++ + ".wsdl";
103:                            Definition innerDefinition = wsdlImport
104:                                    .getDefinition();
105:                            if (!stack.contains(innerDefinition)) {
106:                                writeWSDL(innerDefinition, wsdlName,
107:                                        changedMap, stack);
108:                            }
109:                            wsdlImport.setLocationURI(wsdlName);
110:                        }
111:                    }
112:                }
113:                // change the locations on the imported schemas
114:                adjustWSDLSchemaLocations(definition, changedMap);
115:                // finally save the file
116:                WSDLWriter wsdlWriter = WSDLFactory.newInstance()
117:                        .newWSDLWriter();
118:                File outputFile = FileWriter.createClassFile(baseFolder, null,
119:                        serviceName, ".wsdl");
120:                FileOutputStream out = new FileOutputStream(outputFile);
121:
122:                // we have a catch here
123:                // if there are multimple services in the definition object
124:                // we have to write only the relavent service.
125:
126:                if (definition.getServices().size() > 1) {
127:                    List removedServices = new ArrayList();
128:                    List servicesList = new ArrayList();
129:
130:                    Map services = definition.getServices();
131:                    // populate the services list
132:                    for (Iterator iter = services.values().iterator(); iter
133:                            .hasNext();) {
134:                        servicesList.add(iter.next());
135:                    }
136:                    Service service;
137:                    for (Iterator iter = servicesList.iterator(); iter
138:                            .hasNext();) {
139:                        service = (Service) iter.next();
140:                        if (!service.getQName().getLocalPart().equals(
141:                                serviceName)) {
142:                            definition.removeService(service.getQName());
143:                            removedServices.add(service);
144:                        }
145:                    }
146:
147:                    //now we have only the required service so write it
148:                    wsdlWriter.writeWSDL(definition, out);
149:
150:                    // again add the removed services
151:                    for (Iterator iter = removedServices.iterator(); iter
152:                            .hasNext();) {
153:                        service = (Service) iter.next();
154:                        definition.addService(service);
155:                    }
156:                } else {
157:                    // no problem proceed normaly
158:                    wsdlWriter.writeWSDL(definition, out);
159:                }
160:                out.flush();
161:                out.close();
162:                stack.pop();
163:            }
164:
165:            /**
166:             * @deprecated  please use adjustWSDLSchemaLocations
167:             * @param definition
168:             * @param changedSchemaLocations
169:             */
170:            public void adjustWSDLSchemaLocatins(Definition definition,
171:                    Map changedSchemaLocations) {
172:                adjustWSDLSchemaLocations(definition, changedSchemaLocations);
173:            }
174:
175:            /**
176:             * adjust the schema locations in the original wsdl
177:             *
178:             * @param definition
179:             * @param changedSchemaLocations
180:             */
181:            public void adjustWSDLSchemaLocations(Definition definition,
182:                    Map changedSchemaLocations) {
183:                Types wsdlTypes = definition.getTypes();
184:                if (wsdlTypes != null) {
185:                    List extensibilityElements = wsdlTypes
186:                            .getExtensibilityElements();
187:                    Object currentObject;
188:                    Schema schema;
189:                    for (Iterator iter = extensibilityElements.iterator(); iter
190:                            .hasNext();) {
191:                        currentObject = iter.next();
192:                        if (currentObject instanceof  Schema) {
193:                            schema = (Schema) currentObject;
194:                            changeLocations(schema.getElement(),
195:                                    changedSchemaLocations);
196:                        }
197:                    }
198:                }
199:            }
200:
201:            private void changeLocations(Element element,
202:                    Map changedScheamLocations) {
203:                NodeList nodeList = element.getChildNodes();
204:                String tagName;
205:                for (int i = 0; i < nodeList.getLength(); i++) {
206:                    tagName = nodeList.item(i).getLocalName();
207:                    if (IMPORT_TAG.equals(tagName)
208:                            || INCLUDE_TAG.equals(tagName)) {
209:                        processImport(nodeList.item(i), changedScheamLocations);
210:                    }
211:                }
212:            }
213:
214:            private void processImport(Node importNode,
215:                    Map changedScheamLocations) {
216:                NamedNodeMap nodeMap = importNode.getAttributes();
217:                Node attribute;
218:                String attributeValue;
219:                for (int i = 0; i < nodeMap.getLength(); i++) {
220:                    attribute = nodeMap.item(i);
221:                    if (attribute.getNodeName().equals("schemaLocation")) {
222:                        attributeValue = attribute.getNodeValue();
223:                        if (changedScheamLocations.get(attributeValue) != null) {
224:                            attribute
225:                                    .setNodeValue((String) changedScheamLocations
226:                                            .get(attributeValue));
227:                        }
228:                    }
229:                }
230:            }
231:
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.