Source Code Cross Referenced for OperationInfo.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » common » wsdl » 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 » cbesb 1.2 » com.bostechcorp.cbesb.common.wsdl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.bostechcorp.cbesb.common.wsdl;
002:
003:        import java.io.File;
004:        import java.io.IOException;
005:
006:        import java.util.Iterator;
007:        import java.util.LinkedHashMap;
008:        import java.util.Map;
009:        import java.util.Set;
010:        import java.util.List;
011:        import java.util.ArrayList;
012:        import java.util.HashMap;
013:
014:        import javax.wsdl.BindingFault;
015:        import javax.wsdl.BindingInput;
016:        import javax.wsdl.BindingOperation;
017:        import javax.wsdl.BindingOutput;
018:        import javax.wsdl.Definition;
019:        import javax.wsdl.Fault;
020:        import javax.wsdl.Input;
021:        import javax.wsdl.Message;
022:        import javax.wsdl.Operation;
023:        import javax.wsdl.Output;
024:        import javax.wsdl.WSDLException;
025:        import javax.wsdl.Part;
026:        import javax.wsdl.extensions.ExtensibilityElement;
027:        import javax.wsdl.extensions.ElementExtensible;
028:        import javax.wsdl.extensions.soap.SOAPBody;
029:        import javax.wsdl.extensions.soap.SOAPFault;
030:        import javax.wsdl.extensions.soap.SOAPOperation;
031:        import javax.wsdl.extensions.soap12.SOAP12Body;
032:        import javax.wsdl.extensions.soap12.SOAP12Fault;
033:        import javax.wsdl.extensions.soap12.SOAP12Operation;
034:
035:        import javax.xml.namespace.QName;
036:
037:        import org.eclipse.xsd.*;
038:
039:        public class OperationInfo extends ComponentInfo {
040:
041:            protected static final String SOAP_NS_URL = "http://schemas.xmlsoap.org/wsdl/soap/";
042:            protected static final String SOAP_ENCODING_URL = "http://schemas.xmlsoap.org/soap/encoding/";
043:            protected static final String CBESB_WRAPPER_NS = "http://cbesb.bostechcorp.com/soap/1.0";
044:            protected static final String CBESB_WRAPPER_NS_PREFIX = "cbesb_soap";
045:
046:            private WsdlInfo wsdlInfo = null;
047:
048:            /** The encoding type "document" vs. "rpc" */
049:            private String style = "document";
050:
051:            /** The input message **/
052:            private Message inputMessage = null;
053:
054:            private String inputNamespace = null;
055:
056:            /** The output message **/
057:            private Message outputMessage = null;
058:
059:            private String outputNamespace = null;
060:
061:            private LinkedHashMap<String, Message> faultMessages = null;
062:            private LinkedHashMap<String, String> faultNamespaces = null;
063:
064:            //Some helpful items when generating schemas
065:            //So we don't have to pass them to every method.
066:            private File destDir;
067:            private String wsdlBaseName;
068:            private String opSchemaBaseName;
069:            private XSDFactory xsdFactory;
070:
071:            private class SchemaEntry {
072:                public String filename;
073:                public XSDSchema schema;
074:            };
075:
076:            private HashMap<String, SchemaEntry> schemaNamespaceMap;
077:
078:            /**
079:             * Constructor
080:             */
081:            public OperationInfo() {
082:                faultMessages = new LinkedHashMap<String, Message>();
083:                faultNamespaces = new LinkedHashMap<String, String>();
084:            }
085:
086:            /**
087:             * Constructor
088:             *
089:             * @param style Pass "document" or "rpc"
090:             */
091:            public OperationInfo(String style) {
092:                faultMessages = new LinkedHashMap<String, Message>();
093:                setStyle(style);
094:            }
095:
096:            protected static OperationInfo load(WsdlInfo wsdlInfo,
097:                    BindingOperation wsdlOperation, String defaultStyle)
098:                    throws WSDLException {
099:                OperationInfo opInfo = null;
100:
101:                ExtensibilityElement operElem = findExtensibilityElement(
102:                        wsdlOperation.getExtensibilityElements(), "operation");
103:
104:                String opStyle = null;
105:                Operation operation = null;
106:
107:                if (operElem != null && operElem instanceof  SOAPOperation) {
108:                    SOAPOperation soapOperation = (SOAPOperation) operElem;
109:                    operation = wsdlOperation.getOperation();
110:                    opStyle = soapOperation.getStyle();
111:
112:                } else if (operElem != null
113:                        && operElem instanceof  SOAP12Operation) {
114:                    SOAP12Operation soapOperation = (SOAP12Operation) operElem;
115:                    operation = wsdlOperation.getOperation();
116:                    opStyle = soapOperation.getStyle();
117:                }
118:
119:                if (operation != null) {
120:
121:                    if (opStyle == null || opStyle.equals("")) {
122:                        opStyle = defaultStyle;
123:                    }
124:                    opInfo = new OperationInfo(opStyle);
125:                    opInfo.setName(wsdlOperation.getName());
126:                    opInfo.wsdlInfo = wsdlInfo;
127:
128:                    ExtensibilityElement bodyElem = null;
129:                    // Get the Input Message
130:                    BindingInput bindingInput = wsdlOperation.getBindingInput();
131:                    if (bindingInput != null) {
132:                        processSoapHeaders(bindingInput);
133:                        bodyElem = findExtensibilityElement(bindingInput
134:                                .getExtensibilityElements(), "body");
135:                        opInfo.setInputNamespace(processSoapBody(bodyElem));
136:                        Input input = operation.getInput();
137:                        if (input != null) {
138:                            opInfo.setInputMessage(input.getMessage());
139:                        }
140:                    }
141:
142:                    // Get the Output Message
143:                    BindingOutput bindingOutput = wsdlOperation
144:                            .getBindingOutput();
145:                    if (bindingOutput != null) {
146:                        processSoapHeaders(bindingOutput);
147:                        bodyElem = findExtensibilityElement(bindingOutput
148:                                .getExtensibilityElements(), "body");
149:                        opInfo.setOutputNamespace(processSoapBody(bodyElem));
150:                        Output output = operation.getOutput();
151:                        if (output != null) {
152:                            opInfo.setOutputMessage(output.getMessage());
153:                        }
154:                    }
155:
156:                    // Get the Fault Message(s)
157:                    Map bindingFaults = wsdlOperation.getBindingFaults();
158:                    for (Iterator iter = bindingFaults.values().iterator(); iter
159:                            .hasNext();) {
160:                        BindingFault bindingFault = (BindingFault) iter.next();
161:                        ExtensibilityElement faultElem = findExtensibilityElement(
162:                                bindingFault.getExtensibilityElements(),
163:                                "fault");
164:                        String namespace = processSoapFault(faultElem);
165:                        if (namespace != null) {
166:                            opInfo.faultNamespaces.put(bindingFault.getName(),
167:                                    namespace);
168:                        }
169:                    }
170:
171:                    for (Iterator iter = operation.getFaults().values()
172:                            .iterator(); iter.hasNext();) {
173:                        Fault fault = (Fault) iter.next();
174:                        Message faultMessage = fault.getMessage();
175:                        opInfo.addFaultMessage(faultMessage);
176:                    }
177:
178:                }
179:
180:                return opInfo;
181:            }
182:
183:            private static void processSoapHeaders(
184:                    ElementExtensible bindingInputOrOutput) {
185:                List extensibilityElements = bindingInputOrOutput
186:                        .getExtensibilityElements();
187:                if (extensibilityElements != null) {
188:                    QName soapHeaderQName = new QName(SOAP_NS_URL, "header");
189:                    Iterator iter = extensibilityElements.iterator();
190:                    while (iter.hasNext()) {
191:                        ExtensibilityElement element = (ExtensibilityElement) iter
192:                                .next();
193:                        if (element.getElementType().equals(soapHeaderQName)) {
194:                            //Found a header, process it here
195:
196:                        }
197:                    }
198:                }
199:                ExtensibilityElement bodyElem = findExtensibilityElement(
200:                        bindingInputOrOutput.getExtensibilityElements(), "body");
201:
202:            }
203:
204:            private static String processSoapBody(ExtensibilityElement extElem)
205:                    throws WSDLException {
206:                String namespace = null;
207:                if (extElem != null && extElem instanceof  SOAPBody) {
208:                    SOAPBody soapBody = (SOAPBody) extElem;
209:                    //Check if something other than Soap Encoding is specified
210:                    if ("encoded".equals(soapBody.getUse())) {
211:                        List encodingStyles = soapBody.getEncodingStyles();
212:                        for (Iterator iter = encodingStyles.iterator(); iter
213:                                .hasNext();) {
214:                            String encodingStyle = (String) iter.next();
215:                            if (!SOAP_ENCODING_URL.equals(encodingStyle)) {
216:                                throw new WSDLException(
217:                                        WSDLException.OTHER_ERROR,
218:                                        "Detected an unsupported encodingStyle: "
219:                                                + encodingStyle);
220:                            }
221:                        }
222:                    }
223:                    //Get the namespace and return it
224:                    namespace = soapBody.getNamespaceURI();
225:                } else if (extElem != null && extElem instanceof  SOAP12Body) {
226:                    SOAP12Body soapBody = (SOAP12Body) extElem;
227:                    //Check if something other than Soap Encoding is specified
228:                    if ("encoded".equals(soapBody.getUse())) {
229:                        String encodingStyle = soapBody.getEncodingStyle();
230:
231:                        if (!SOAP_ENCODING_URL.equals(encodingStyle)) {
232:                            throw new WSDLException(WSDLException.OTHER_ERROR,
233:                                    "Detected an unsupported encodingStyle: "
234:                                            + encodingStyle);
235:                        }
236:
237:                    }
238:                    //Get the namespace and return it
239:                    namespace = soapBody.getNamespaceURI();
240:                }
241:
242:                return namespace;
243:            }
244:
245:            private static String processSoapFault(ExtensibilityElement extElem)
246:                    throws WSDLException {
247:                String namespace = null;
248:                if (extElem != null && extElem instanceof  SOAPFault) {
249:                    SOAPFault soapFault = (SOAPFault) extElem;
250:                    //Check if something other than Soap Encoding is specified
251:                    if ("encoded".equals(soapFault.getUse())) {
252:                        List encodingStyles = soapFault.getEncodingStyles();
253:                        for (Iterator iter = encodingStyles.iterator(); iter
254:                                .hasNext();) {
255:                            String encodingStyle = (String) iter.next();
256:                            if (!SOAP_ENCODING_URL.equals(encodingStyle)) {
257:                                throw new WSDLException(
258:                                        WSDLException.OTHER_ERROR,
259:                                        "Detected an unsupported encodingStyle: "
260:                                                + encodingStyle);
261:                            }
262:                        }
263:                    }
264:                    //Get the namespace and return it
265:                    namespace = soapFault.getNamespaceURI();
266:                } else if (extElem != null && extElem instanceof  SOAP12Fault) {
267:                    SOAP12Fault soapFault = (SOAP12Fault) extElem;
268:                    //Check if something other than Soap Encoding is specified
269:                    if ("encoded".equals(soapFault.getUse())) {
270:                        String encodingStyle = soapFault.getEncodingStyle();
271:
272:                        if (!SOAP_ENCODING_URL.equals(encodingStyle)) {
273:                            throw new WSDLException(WSDLException.OTHER_ERROR,
274:                                    "Detected an unsupported encodingStyle: "
275:                                            + encodingStyle);
276:                        }
277:
278:                    }
279:                    //Get the namespace and return it
280:                    namespace = soapFault.getNamespaceURI();
281:                }
282:                return namespace;
283:            }
284:
285:            /**
286:             * Sets the encoding document/literal vs. rpc/encoded
287:             *
288:             * @return value A string value "document" or "rpc" should be passed.
289:             */
290:            public void setStyle(String value) {
291:                style = value;
292:            }
293:
294:            /**
295:             * Returns the style "document" or "rpc"
296:             *
297:             * @return The style type is returned
298:             */
299:            public String getStyle() {
300:                return style;
301:            }
302:
303:            /**
304:             * @return the inputMessage
305:             */
306:            public Message getInputMessage() {
307:                return inputMessage;
308:            }
309:
310:            /**
311:             * @param inputMessage the inputMessage to set
312:             */
313:            public void setInputMessage(Message inputMessage) {
314:                this .inputMessage = inputMessage;
315:            }
316:
317:            /**
318:             * @return the outputMessage
319:             */
320:            public Message getOutputMessage() {
321:                return outputMessage;
322:            }
323:
324:            /**
325:             * @param outputMessage the outputMessage to set
326:             */
327:            public void setOutputMessage(Message outputMessage) {
328:                this .outputMessage = outputMessage;
329:            }
330:
331:            /**
332:             * @return the inputNamespace
333:             */
334:            public String getInputNamespace() {
335:                return inputNamespace;
336:            }
337:
338:            /**
339:             * @param inputNamespace the inputNamespace to set
340:             */
341:            public void setInputNamespace(String inputNamespace) {
342:                this .inputNamespace = inputNamespace;
343:            }
344:
345:            /**
346:             * @return the outputNamespace
347:             */
348:            public String getOutputNamespace() {
349:                return outputNamespace;
350:            }
351:
352:            /**
353:             * @param outputNamespace the outputNamespace to set
354:             */
355:            public void setOutputNamespace(String outputNamespace) {
356:                this .outputNamespace = outputNamespace;
357:            }
358:
359:            public String[] getFaultMessageNames() {
360:                String[] retArray = null;
361:                Set faultNames = faultMessages.keySet();
362:                retArray = new String[faultNames.size()];
363:                int i = 0;
364:                for (Iterator iter = faultNames.iterator(); iter.hasNext();) {
365:                    retArray[i] = (String) iter.next();
366:                    i++;
367:                }
368:                return retArray;
369:            }
370:
371:            public List getFaultMessages() {
372:                return new ArrayList<Message>(faultMessages.values());
373:            }
374:
375:            public Message getFaultMessage(String name) {
376:                return faultMessages.get(name);
377:            }
378:
379:            public void addFaultMessage(Message faultMessage) {
380:                faultMessages.put(faultMessage.getQName().getLocalPart(),
381:                        faultMessage);
382:            }
383:
384:            public void SaveAsSchema(File destFile) throws IOException {
385:                XSDSchema schema = generateSchema(destFile);
386:                SchemaUtil.saveXSDSchema(schema, destFile);
387:            }
388:
389:            @SuppressWarnings("unchecked")
390:            public XSDSchema generateSchema(File destFile) throws IOException {
391:                destDir = destFile.getParentFile();
392:                wsdlBaseName = wsdlInfo.wsdlBaseName;
393:                opSchemaBaseName = destFile.getName();
394:                if (opSchemaBaseName.endsWith(".xsd")) {
395:                    opSchemaBaseName = opSchemaBaseName.substring(0,
396:                            opSchemaBaseName.lastIndexOf('.'));
397:                }
398:                xsdFactory = SchemaUtil.getXSDFactory();
399:                XSDSchema operationSchema = SchemaUtil.createBlankSchema();
400:                operationSchema.setTargetNamespace(CBESB_WRAPPER_NS);
401:                operationSchema
402:                        .setElementFormDefault(XSDForm.QUALIFIED_LITERAL);
403:                Map nsMap = operationSchema.getQNamePrefixToNamespaceMap();
404:                nsMap.put("tns", CBESB_WRAPPER_NS);
405:                //		populateSchemaNamespaceMap(operationSchema);
406:
407:                if (getStyle().equals("document")) {
408:                    addReferencesToTypesSchemas(operationSchema);
409:                }
410:
411:                if (inputMessage != null) {
412:                    XSDModelGroup requestContainer = addWrapperRoot(
413:                            operationSchema, "SoapRequest");
414:                    XSDModelGroup headerContainer = addWrapperHeader(requestContainer);
415:                    XSDModelGroup bodyContainer = addWrapperBody(requestContainer);
416:                    if (getStyle().equals("document")) {
417:                        populateBodyDocStyle(operationSchema, bodyContainer,
418:                                inputMessage, inputNamespace);
419:                    } else {
420:                        populateBodyRpcStyle(operationSchema, bodyContainer,
421:                                inputMessage, inputNamespace, name);
422:                    }
423:                }
424:                if (outputMessage != null) {
425:                    XSDModelGroup requestContainer = addWrapperRoot(
426:                            operationSchema, "SoapResponse");
427:                    XSDModelGroup headerContainer = addWrapperHeader(requestContainer);
428:                    XSDModelGroup bodyContainer = addWrapperBody(requestContainer);
429:                    if (getStyle().equals("document")) {
430:                        populateBodyDocStyle(operationSchema, bodyContainer,
431:                                outputMessage, outputNamespace);
432:                    } else {
433:                        populateBodyRpcStyle(operationSchema, bodyContainer,
434:                                outputMessage, outputNamespace, name
435:                                        + "Response");
436:
437:                    }
438:                }
439:
440:                //TODO: generate fault messages
441:
442:                return operationSchema;
443:            }
444:
445:            @SuppressWarnings("unchecked")
446:            private void populateSchemaNamespaceMap(XSDSchema operationSchema) {
447:                Map schemaNamespaceMap = operationSchema
448:                        .getQNamePrefixToNamespaceMap();
449:                Map wsdlNamespaceMap = wsdlInfo.wsdlDefinition.getNamespaces();
450:                schemaNamespaceMap.put(CBESB_WRAPPER_NS_PREFIX,
451:                        CBESB_WRAPPER_NS);
452:
453:                //For each namespace prefix defined in the wsdl, add to the schema
454:                for (Iterator iter = wsdlNamespaceMap.entrySet().iterator(); iter
455:                        .hasNext();) {
456:                    Map.Entry<String, String> entry = (Map.Entry<String, String>) iter
457:                            .next();
458:                    //Filter out the default namespace
459:                    if (!entry.getKey().equals("")) {
460:                        schemaNamespaceMap
461:                                .put(entry.getKey(), entry.getValue());
462:                    }
463:                }
464:            }
465:
466:            @SuppressWarnings("unchecked")
467:            private XSDModelGroup addWrapperRoot(XSDSchema operationSchema,
468:                    String name) {
469:                // Create global element declaration
470:                XSDElementDeclaration messageElement = xsdFactory
471:                        .createXSDElementDeclaration();
472:                messageElement.setName(name);
473:                operationSchema.getContents().add(messageElement);
474:                // Add anonymous complexType definition inside element
475:                XSDComplexTypeDefinition complexType = xsdFactory
476:                        .createXSDComplexTypeDefinition();
477:                messageElement.setAnonymousTypeDefinition(complexType);
478:                // Add sequence to complexType
479:                XSDModelGroup sequenceModelGroup = xsdFactory
480:                        .createXSDModelGroup();
481:                sequenceModelGroup
482:                        .setCompositor(XSDCompositor.SEQUENCE_LITERAL);
483:                XSDParticle sequenceParticle = xsdFactory.createXSDParticle();
484:                sequenceParticle.setContent(sequenceModelGroup);
485:                complexType.setContent(sequenceParticle);
486:
487:                return sequenceModelGroup;
488:            }
489:
490:            @SuppressWarnings("unchecked")
491:            private XSDModelGroup addWrapperHeader(XSDModelGroup container) {
492:                //		//Create SoapBody wrapper
493:                //		XSDElementDeclaration headerElement = xsdFactory.createXSDElementDeclaration();
494:                //		headerElement.setName("SoapHeader");
495:                //		XSDParticle headerParticle = xsdFactory.createXSDParticle();
496:                //		headerParticle.setContent(headerElement);
497:                //		container.getContents().add(headerParticle);
498:                //		// Add anonymous complexType definition inside element
499:                //		XSDComplexTypeDefinition complexType = xsdFactory.createXSDComplexTypeDefinition();
500:                //		headerElement.setAnonymousTypeDefinition(complexType);
501:                //		// Add sequence to complexType
502:                //		XSDModelGroup sequenceModelGroup = xsdFactory.createXSDModelGroup();
503:                //		sequenceModelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
504:                //		XSDParticle sequenceParticle = xsdFactory.createXSDParticle();
505:                //		sequenceParticle.setContent(sequenceModelGroup);
506:                //		complexType.setContent(sequenceParticle);
507:                //
508:                //		return sequenceModelGroup;
509:                return null;
510:            }
511:
512:            @SuppressWarnings("unchecked")
513:            private XSDModelGroup addWrapperBody(XSDModelGroup container) {
514:                //Create SoapBody wrapper
515:                XSDElementDeclaration bodyElement = xsdFactory
516:                        .createXSDElementDeclaration();
517:                bodyElement.setName("SoapBody");
518:                XSDParticle bodyParticle = xsdFactory.createXSDParticle();
519:                bodyParticle.setContent(bodyElement);
520:                container.getContents().add(bodyParticle);
521:                // Add anonymous complexType definition inside element
522:                XSDComplexTypeDefinition complexType = xsdFactory
523:                        .createXSDComplexTypeDefinition();
524:                bodyElement.setAnonymousTypeDefinition(complexType);
525:                // Add sequence to complexType
526:                XSDModelGroup sequenceModelGroup = xsdFactory
527:                        .createXSDModelGroup();
528:                sequenceModelGroup
529:                        .setCompositor(XSDCompositor.SEQUENCE_LITERAL);
530:                XSDParticle sequenceParticle = xsdFactory.createXSDParticle();
531:                sequenceParticle.setContent(sequenceModelGroup);
532:                complexType.setContent(sequenceParticle);
533:
534:                return sequenceModelGroup;
535:            }
536:
537:            @SuppressWarnings("unchecked")
538:            private void populateBodyDocStyle(XSDSchema operationSchema,
539:                    XSDModelGroup container, Message message,
540:                    String messageNamespace) {
541:                //		Map partMap = message.getParts();
542:                //		for (Iterator partIter = partMap.values().iterator(); partIter.hasNext();)
543:                List partList = message.getOrderedParts(null);
544:                for (Iterator partIter = partList.iterator(); partIter
545:                        .hasNext();) {
546:                    Part part = (Part) partIter.next();
547:                    XSDElementDeclaration partElem = xsdFactory
548:                            .createXSDElementDeclaration();
549:                    if (part.getElementName() != null) {
550:                        QName elemName = part.getElementName();
551:                        XSDElementDeclaration resolvedElem = operationSchema
552:                                .resolveElementDeclaration(elemName
553:                                        .getNamespaceURI(), elemName
554:                                        .getLocalPart());
555:                        partElem.setResolvedElementDeclaration(resolvedElem);
556:                    } else if (part.getTypeName() != null) {
557:                        partElem.setName(part.getName());
558:                        QName partType = part.getTypeName();
559:                        XSDTypeDefinition resolvedType = operationSchema
560:                                .resolveTypeDefinition(partType
561:                                        .getNamespaceURI(), partType
562:                                        .getLocalPart());
563:                        partElem.setTypeDefinition(resolvedType);
564:                    }
565:                    XSDParticle partParticle = xsdFactory.createXSDParticle();
566:                    partParticle.setContent(partElem);
567:                    container.getContents().add(partParticle);
568:                }
569:            }
570:
571:            @SuppressWarnings("unchecked")
572:            private void populateBodyRpcStyle(XSDSchema operationSchema,
573:                    XSDModelGroup container, Message message,
574:                    String messageNamespace, String elementName)
575:                    throws IOException {
576:                SchemaEntry se = createRpcMessageSchema(message,
577:                        messageNamespace, elementName);
578:
579:                //Add import to operation schema
580:                addReferenceToSchema(operationSchema, messageNamespace,
581:                        se.filename);
582:
583:                //Add ref element pointing to the element defined in the external schema
584:                XSDElementDeclaration partElem = xsdFactory
585:                        .createXSDElementDeclaration();
586:                partElem.setResolvedElementDeclaration(operationSchema
587:                        .resolveElementDeclaration(messageNamespace,
588:                                elementName));
589:                XSDParticle partParticle = xsdFactory.createXSDParticle();
590:                partParticle.setContent(partElem);
591:                container.getContents().add(partParticle);
592:
593:            }
594:
595:            @SuppressWarnings("unchecked")
596:            private SchemaEntry createRpcMessageSchema(Message message,
597:                    String messageNamespace, String elementName)
598:                    throws IOException {
599:                SchemaEntry se = getSchemaforNamespace(messageNamespace);
600:                XSDSchema schema = se.schema;
601:
602:                addReferencesToTypesSchemas(schema);
603:
604:                // Create global element declaration
605:                XSDElementDeclaration messageElement = xsdFactory
606:                        .createXSDElementDeclaration();
607:                messageElement.setName(elementName);
608:                schema.getContents().add(messageElement);
609:                // Add anonymous complexType definition inside element
610:                XSDComplexTypeDefinition complexType = xsdFactory
611:                        .createXSDComplexTypeDefinition();
612:                messageElement.setAnonymousTypeDefinition(complexType);
613:                // Add sequence to complexType
614:                XSDModelGroup sequenceModelGroup = xsdFactory
615:                        .createXSDModelGroup();
616:                sequenceModelGroup
617:                        .setCompositor(XSDCompositor.SEQUENCE_LITERAL);
618:                XSDParticle sequenceParticle = xsdFactory.createXSDParticle();
619:                sequenceParticle.setContent(sequenceModelGroup);
620:                complexType.setContent(sequenceParticle);
621:
622:                //		Map partMap = message.getParts();
623:                List partList = message.getOrderedParts(null);
624:                //		for (Iterator partIter = partMap.values().iterator(); partIter.hasNext();)
625:                for (Iterator partIter = partList.iterator(); partIter
626:                        .hasNext();) {
627:                    Part part = (Part) partIter.next();
628:
629:                    XSDElementDeclaration partElement = xsdFactory
630:                            .createXSDElementDeclaration();
631:                    if (part.getTypeName() != null) {
632:                        partElement.setName(part.getName());
633:                        QName partType = part.getTypeName();
634:                        XSDTypeDefinition resolvedType = schema
635:                                .resolveTypeDefinition(partType
636:                                        .getNamespaceURI(), partType
637:                                        .getLocalPart());
638:                        partElement.setTypeDefinition(resolvedType);
639:                    } else if (part.getElementName() != null) {
640:                        QName elemName = part.getElementName();
641:                        XSDElementDeclaration resolvedElem = schema
642:                                .resolveElementDeclaration(elemName
643:                                        .getNamespaceURI(), elemName
644:                                        .getLocalPart());
645:                        partElement.setResolvedElementDeclaration(resolvedElem);
646:                    }
647:                    XSDParticle partParticle = xsdFactory.createXSDParticle();
648:                    partParticle.setContent(partElement);
649:                    sequenceModelGroup.getContents().add(partParticle);
650:                }
651:
652:                SchemaUtil
653:                        .saveXSDSchema(schema, new File(destDir, se.filename));
654:                return se;
655:            }
656:
657:            private void addReferencesToTypesSchemas(XSDSchema schema) {
658:                TypesInfo types = wsdlInfo.wsdlTypes;
659:                Map typesMap = types.getSchemaMap();
660:                for (Iterator iter = typesMap.entrySet().iterator(); iter
661:                        .hasNext();) {
662:                    Map.Entry<String, String> entry = (Map.Entry<String, String>) iter
663:                            .next();
664:                    String namespace = entry.getKey();
665:                    if (namespace == null) {
666:                        namespace = "";
667:                    }
668:                    String schemaLoc = entry.getValue();
669:                    addReferenceToSchema(schema, namespace, schemaLoc);
670:                }
671:            }
672:
673:            @SuppressWarnings("unchecked")
674:            private void addReferenceToSchema(XSDSchema schema,
675:                    String namespace, String schemaLoc) {
676:                String targetNamespace = schema.getTargetNamespace();
677:                if (targetNamespace == null) {
678:                    targetNamespace = "";
679:                }
680:                if (targetNamespace.equals(namespace)) {
681:                    //Same namespace, use include
682:                    List contents = schema.getContents();
683:                    for (Iterator iter = contents.iterator(); iter.hasNext();) {
684:                        XSDSchemaContent schemaContent = (XSDSchemaContent) iter
685:                                .next();
686:                        if (schemaContent instanceof  XSDInclude) {
687:                            XSDInclude xsdInclude = (XSDInclude) schemaContent;
688:                            String incLoc = xsdInclude.getSchemaLocation();
689:                            if (incLoc.equals(schemaLoc)) {
690:                                //The schema has already been included.
691:                                return;
692:                            }
693:                        }
694:                    }
695:                    //Didn't find an existing include.
696:                    //Add a new one
697:                    XSDInclude xsdInclude = xsdFactory.createXSDInclude();
698:                    xsdInclude.setSchemaLocation(schemaLoc);
699:                    schema.getContents().add(0, xsdInclude);
700:                } else {
701:                    //Different namespace, use import
702:                    List contents = schema.getContents();
703:                    for (Iterator iter = contents.iterator(); iter.hasNext();) {
704:                        XSDSchemaContent schemaContent = (XSDSchemaContent) iter
705:                                .next();
706:                        if (schemaContent instanceof  XSDImport) {
707:                            XSDImport xsdImport = (XSDImport) schemaContent;
708:                            String importNS = xsdImport.getNamespace();
709:                            if (importNS == null) {
710:                                importNS = "";
711:                            }
712:                            if (importNS.equals(namespace)) {
713:                                if (xsdImport.getSchemaLocation().equals(
714:                                        schemaLoc)) {
715:                                    //The schema has already imported.
716:                                    return;
717:                                } else {
718:                                    //This namespace was already imported,
719:                                    //but from another schema.
720:                                    System.err
721:                                            .println("Trying to import the same namespace from multiple schemas.");
722:                                    return;
723:                                }
724:                            }
725:                        }
726:                    }
727:                    //Didn't find an existing import.
728:                    //Add a new one
729:                    XSDImport xsdImport = xsdFactory.createXSDImport();
730:                    if (!namespace.equals("")) {
731:                        xsdImport.setNamespace(namespace);
732:                    }
733:                    xsdImport.setSchemaLocation(schemaLoc);
734:                    schema.getContents().add(0, xsdImport);
735:                }
736:
737:            }
738:
739:            @SuppressWarnings("unchecked")
740:            private SchemaEntry getSchemaforNamespace(String namespace) {
741:                if (namespace == null) {
742:                    namespace = "";
743:                }
744:                if (schemaNamespaceMap == null) {
745:                    schemaNamespaceMap = new HashMap<String, SchemaEntry>();
746:                }
747:                SchemaEntry se = schemaNamespaceMap.get(namespace);
748:                if (se == null) {
749:                    se = new SchemaEntry();
750:                    //create a new schema for this namespace
751:                    se.schema = SchemaUtil.createBlankSchema();
752:                    if (!namespace.equals("")) {
753:                        se.schema.setTargetNamespace(namespace);
754:                        Map nsMap = se.schema.getQNamePrefixToNamespaceMap();
755:                        nsMap.put("tns", namespace);
756:                    }
757:                    se.filename = opSchemaBaseName + ".inc"
758:                            + schemaNamespaceMap.size();
759:                    schemaNamespaceMap.put(namespace, se);
760:                }
761:                return se;
762:            }
763:
764:            /**
765:             * Override toString to return a name for the operation
766:             *
767:             * @return The name of the operation is returned
768:             */
769:            public String toString() {
770:                StringBuffer buffer = new StringBuffer();
771:                buffer.append("Operation: " + name + "\n");
772:                buffer.append("Input:\n");
773:                buffer.append(inputMessage.getQName().toString());
774:                buffer.append("\n");
775:                buffer.append("Output:\n");
776:                buffer.append(outputMessage.getQName().toString());
777:                buffer.append("\n");
778:                buffer.append("Faults:\n");
779:                for (Iterator iter = getFaultMessages().iterator(); iter
780:                        .hasNext();) {
781:                    Message fault = (Message) iter.next();
782:                    buffer.append(fault.getQName().toString() + "\n");
783:                }
784:                return buffer.toString();
785:            }
786:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.