Source Code Cross Referenced for WSDLToXMLProcessor.java in  » ESB » celtix-1.0 » org » objectweb » celtix » tools » processors » wsdl2 » 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 » ESB » celtix 1.0 » org.objectweb.celtix.tools.processors.wsdl2 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.tools.processors.wsdl2;
002:
003:        import java.io.IOException;
004:        import java.io.Writer;
005:        import java.util.Iterator;
006:        import java.util.List;
007:        import java.util.Map;
008:
009:        import javax.wsdl.Binding;
010:        import javax.wsdl.BindingInput;
011:        import javax.wsdl.BindingOperation;
012:        import javax.wsdl.BindingOutput;
013:        import javax.wsdl.Input;
014:        import javax.wsdl.Operation;
015:        import javax.wsdl.Output;
016:        import javax.wsdl.Port;
017:        import javax.wsdl.PortType;
018:        import javax.wsdl.Service;
019:        import javax.wsdl.WSDLException;
020:        import javax.wsdl.extensions.ExtensionRegistry;
021:        import javax.wsdl.xml.WSDLWriter;
022:        import javax.xml.namespace.QName;
023:
024:        import org.objectweb.celtix.common.i18n.Message;
025:        import org.objectweb.celtix.tools.common.ToolConstants;
026:        import org.objectweb.celtix.tools.common.ToolException;
027:        import org.objectweb.celtix.tools.common.WSDLConstants;
028:        import org.objectweb.celtix.tools.extensions.xmlformat.XMLFormat;
029:        import org.objectweb.celtix.tools.extensions.xmlformat.XMLFormatBinding;
030:        import org.objectweb.celtix.tools.extensions.xmlformat.XMLHttpAddress;
031:
032:        public class WSDLToXMLProcessor extends WSDLToProcessor {
033:
034:            private static final String NEW_FILE_NAME_MODIFIER = "-xmlbinding";
035:            private static final String HTTP_PREFIX = "http://localhost:9000";
036:
037:            private ExtensionRegistry extReg;
038:
039:            private Map services;
040:            private Service service;
041:            private Map ports;
042:            private Port port;
043:
044:            private Map portTypes;
045:            private PortType portType;
046:            private Binding binding;
047:
048:            public void process() throws ToolException {
049:                init();
050:                if (isBindingExisted()) {
051:                    Message msg = new Message("BINDING_ALREADY_EXIST", LOG);
052:                    throw new ToolException(msg);
053:                }
054:                if (!isPortTypeExisted()) {
055:                    Message msg = new Message("PORTTYPE_NOT_EXIST", LOG);
056:                    throw new ToolException(msg);
057:                }
058:                if (isServicePortExisted()) {
059:                    Message msg = new Message("SERVICE_PORT_EXIST", LOG);
060:                    throw new ToolException(msg);
061:                }
062:                extReg = this .wsdlReader.getExtensionRegistry();
063:                doAppendBinding();
064:                doAppendService();
065:                writeToWSDL();
066:            }
067:
068:            private boolean isServicePortExisted() {
069:                return isServiceExisted() && isPortExisted();
070:            }
071:
072:            private boolean isServiceExisted() {
073:                services = wsdlDefinition.getServices();
074:                if (services == null) {
075:                    return false;
076:                }
077:                Iterator it = services.keySet().iterator();
078:                while (it.hasNext()) {
079:                    QName serviceQName = (QName) it.next();
080:                    String serviceName = serviceQName.getLocalPart();
081:                    if (serviceName.equals(env.get(ToolConstants.CFG_SERVICE))) {
082:                        service = (Service) services.get(serviceQName);
083:                        break;
084:                    }
085:                }
086:                return (service == null) ? false : true;
087:            }
088:
089:            private boolean isPortExisted() {
090:                ports = service.getPorts();
091:                if (ports == null) {
092:                    return false;
093:                }
094:                Iterator it = ports.keySet().iterator();
095:                while (it.hasNext()) {
096:                    String portName = (String) it.next();
097:                    if (portName.equals(env.get(ToolConstants.CFG_PORT))) {
098:                        port = (Port) ports.get(portName);
099:                        break;
100:                    }
101:                }
102:                return (port == null) ? false : true;
103:            }
104:
105:            private boolean isPortTypeExisted() {
106:                portTypes = wsdlDefinition.getPortTypes();
107:                if (portTypes == null) {
108:                    return false;
109:                }
110:                Iterator it = portTypes.keySet().iterator();
111:                while (it.hasNext()) {
112:                    QName existPortQName = (QName) it.next();
113:                    String existPortName = existPortQName.getLocalPart();
114:                    if (existPortName.equals(env
115:                            .get(ToolConstants.CFG_PORTTYPE))) {
116:                        portType = (PortType) portTypes.get(existPortQName);
117:                        break;
118:                    }
119:                }
120:                return (portType == null) ? false : true;
121:            }
122:
123:            private boolean isBindingExisted() {
124:                Map bindings = wsdlDefinition.getBindings();
125:                if (bindings == null) {
126:                    return false;
127:                }
128:                Iterator it = bindings.keySet().iterator();
129:                while (it.hasNext()) {
130:                    QName existBindingQName = (QName) it.next();
131:                    String existBindingName = existBindingQName.getLocalPart();
132:                    String bindingName = (String) env
133:                            .get(ToolConstants.CFG_BINDING);
134:                    if (bindingName.equals(existBindingName)) {
135:                        binding = (Binding) bindings.get(existBindingQName);
136:                    }
137:                }
138:                return (binding == null) ? false : true;
139:            }
140:
141:            protected void init() throws ToolException {
142:                parseWSDL((String) env.get(ToolConstants.CFG_WSDLURL));
143:                if (wsdlDefinition
144:                        .getNamespace(ToolConstants.XML_FORMAT_PREFIX) == null) {
145:                    wsdlDefinition.addNamespace(
146:                            ToolConstants.XML_FORMAT_PREFIX,
147:                            ToolConstants.NS_XML_FORMAT);
148:                }
149:                if (wsdlDefinition.getNamespace(ToolConstants.XML_HTTP_PREFIX) == null) {
150:                    wsdlDefinition.addNamespace(ToolConstants.XML_HTTP_PREFIX,
151:                            ToolConstants.NS_XML_HTTP);
152:                }
153:            }
154:
155:            private void doAppendBinding() throws ToolException {
156:                if (binding == null) {
157:                    binding = wsdlDefinition.createBinding();
158:                    binding.setQName(new QName(wsdlDefinition
159:                            .getTargetNamespace(), (String) env
160:                            .get(ToolConstants.CFG_BINDING)));
161:                    binding.setUndefined(false);
162:                    binding.setPortType(portType);
163:                }
164:                setXMLBindingExtElement();
165:                addBindingOperation();
166:                wsdlDefinition.addBinding(binding);
167:            }
168:
169:            private void setXMLBindingExtElement() throws ToolException {
170:                if (extReg == null) {
171:                    extReg = wsdlFactory.newPopulatedExtensionRegistry();
172:                }
173:                XMLFormatBinding xmlBinding = null;
174:                try {
175:                    xmlBinding = (XMLFormatBinding) extReg.createExtension(
176:                            Binding.class, ToolConstants.XML_BINDING_FORMAT);
177:                } catch (WSDLException wse) {
178:                    Message msg = new Message("FAIL_TO_CREATE_XMLBINDING", LOG);
179:                    throw new ToolException(msg);
180:                }
181:                binding.addExtensibilityElement(xmlBinding);
182:            }
183:
184:            @SuppressWarnings("unchecked")
185:            private void addBindingOperation() throws ToolException {
186:                List<Operation> ops = portType.getOperations();
187:                for (Operation op : ops) {
188:                    BindingOperation bindingOperation = wsdlDefinition
189:                            .createBindingOperation();
190:                    bindingOperation.setName(op.getName());
191:                    if (op.getInput() != null) {
192:                        bindingOperation.setBindingInput(getBindingInput(op
193:                                .getInput(), op.getName()));
194:                    }
195:                    if (op.getOutput() != null) {
196:                        bindingOperation.setBindingOutput(getBindingOutput(op
197:                                .getOutput(), op.getName()));
198:                    }
199:                    if (op.getFaults() != null && op.getFaults().size() > 0) {
200:                        addXMLFaults(op, bindingOperation);
201:                    }
202:                    bindingOperation.setOperation(op);
203:                    binding.addBindingOperation(bindingOperation);
204:                }
205:            }
206:
207:            private BindingInput getBindingInput(Input input,
208:                    String operationName) throws ToolException {
209:                BindingInput bi = wsdlDefinition.createBindingInput();
210:                bi.setName(input.getName());
211:                //This ext element in some scenario is optional, but if provided, won't cause error
212:                bi.addExtensibilityElement(getXMLBody(BindingInput.class,
213:                        operationName));
214:                return bi;
215:            }
216:
217:            private BindingOutput getBindingOutput(Output output,
218:                    String operationName) throws ToolException {
219:                BindingOutput bo = wsdlDefinition.createBindingOutput();
220:                bo.setName(output.getName());
221:                bo.addExtensibilityElement(getXMLBody(BindingOutput.class,
222:                        operationName));
223:                return bo;
224:            }
225:
226:            private void addXMLFaults(Operation op, BindingOperation bo) {
227:                // TODO
228:            }
229:
230:            private XMLFormat getXMLBody(Class clz, String operationName)
231:                    throws ToolException {
232:                if (extReg == null) {
233:                    extReg = wsdlFactory.newPopulatedExtensionRegistry();
234:                }
235:                XMLFormat xmlFormat = null;
236:                try {
237:                    xmlFormat = (XMLFormat) extReg.createExtension(clz,
238:                            ToolConstants.XML_FORMAT);
239:                } catch (WSDLException wse) {
240:                    Message msg = new Message("FAIL_TO_CREATE_XMLBINDING", LOG);
241:                    throw new ToolException(msg);
242:                }
243:                xmlFormat.setRootNode(new QName(wsdlDefinition
244:                        .getTargetNamespace(), operationName));
245:                return xmlFormat;
246:            }
247:
248:            private void doAppendService() throws ToolException {
249:                if (service == null) {
250:                    service = wsdlDefinition.createService();
251:                    service.setQName(new QName(WSDLConstants.WSDL_PREFIX,
252:                            (String) env.get(ToolConstants.CFG_SERVICE)));
253:                }
254:                if (port == null) {
255:                    port = wsdlDefinition.createPort();
256:                    port.setName((String) env.get(ToolConstants.CFG_PORT));
257:                    port.setBinding(binding);
258:                }
259:                setAddrElement();
260:                service.addPort(port);
261:                wsdlDefinition.addService(service);
262:            }
263:
264:            private void setAddrElement() throws ToolException {
265:                extReg = this .wsdlReader.getExtensionRegistry();
266:                if (extReg == null) {
267:                    extReg = wsdlFactory.newPopulatedExtensionRegistry();
268:                }
269:                XMLHttpAddress xmlHttpAddress = null;
270:                try {
271:                    xmlHttpAddress = (XMLHttpAddress) extReg.createExtension(
272:                            Port.class,
273:                            WSDLConstants.NS_XMLHTTP_BINDING_ADDRESS);
274:                } catch (WSDLException wse) {
275:                    Message msg = new Message("FAIl_TO_CREATE_SOAPADDRESS", LOG);
276:                    throw new ToolException(msg);
277:                }
278:                if (env.get(ToolConstants.CFG_ADDRESS) != null) {
279:                    xmlHttpAddress.setLocation((String) env
280:                            .get(ToolConstants.CFG_ADDRESS));
281:                } else {
282:                    xmlHttpAddress.setLocation(HTTP_PREFIX + "/"
283:                            + env.get(ToolConstants.CFG_SERVICE) + "/"
284:                            + env.get(ToolConstants.CFG_PORT));
285:                }
286:                port.addExtensibilityElement(xmlHttpAddress);
287:            }
288:
289:            private void writeToWSDL() throws ToolException {
290:                WSDLWriter wsdlWriter = wsdlFactory.newWSDLWriter();
291:                Writer outputWriter = getOutputWriter(NEW_FILE_NAME_MODIFIER);
292:                try {
293:                    wsdlWriter.writeWSDL(wsdlDefinition, outputWriter);
294:                } catch (WSDLException wse) {
295:                    Message msg = new Message("FAIL_TO_WRITE_WSDL", LOG);
296:                    throw new ToolException(msg);
297:                }
298:                try {
299:                    outputWriter.close();
300:                } catch (IOException ioe) {
301:                    Message msg = new Message("FAIL_TO_CLOSE_WSDL_FILE", LOG);
302:                    throw new ToolException(msg);
303:                }
304:            }
305:
306:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.