Source Code Cross Referenced for WSDLValidator.java in  » IDE-Netbeans » mobility » org » netbeans » modules » e2e » wsdl » wsdl2java » 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 » IDE Netbeans » mobility » org.netbeans.modules.e2e.wsdl.wsdl2java 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * WSDLValidator.java
003:         *
004:         * Created on October 30, 2006, 5:17 PM
005:         *
006:         * To change this template, choose Tools | Template Manager
007:         * and open the template in the editor.
008:         */
009:
010:        package org.netbeans.modules.e2e.wsdl.wsdl2java;
011:
012:        import java.util.ArrayList;
013:        import java.util.HashSet;
014:        import java.util.List;
015:        import java.util.Set;
016:        import javax.xml.namespace.QName;
017:        import org.netbeans.modules.e2e.api.schema.Element;
018:        import org.netbeans.modules.e2e.api.schema.SchemaConstruct;
019:        import org.netbeans.modules.e2e.api.schema.Type;
020:        import org.netbeans.modules.e2e.api.wsdl.Binding;
021:        import org.netbeans.modules.e2e.api.wsdl.BindingInput;
022:        import org.netbeans.modules.e2e.api.wsdl.BindingOperation;
023:        import org.netbeans.modules.e2e.api.wsdl.BindingOutput;
024:        import org.netbeans.modules.e2e.api.wsdl.Definition;
025:        import org.netbeans.modules.e2e.api.wsdl.Input;
026:        import org.netbeans.modules.e2e.api.wsdl.Message;
027:        import org.netbeans.modules.e2e.api.wsdl.Operation;
028:        import org.netbeans.modules.e2e.api.wsdl.Output;
029:        import org.netbeans.modules.e2e.api.wsdl.Part;
030:        import org.netbeans.modules.e2e.api.wsdl.Port;
031:        import org.netbeans.modules.e2e.api.wsdl.PortType;
032:        import org.netbeans.modules.e2e.api.wsdl.Service;
033:        import org.netbeans.modules.e2e.api.wsdl.extensions.ExtensibilityElement;
034:        import org.netbeans.modules.e2e.api.wsdl.extensions.soap.SOAPAddress;
035:        import org.netbeans.modules.e2e.api.wsdl.extensions.soap.SOAPBinding;
036:        import org.netbeans.modules.e2e.api.wsdl.extensions.soap.SOAPBody;
037:        import org.netbeans.modules.e2e.api.wsdl.extensions.soap.SOAPOperation;
038:        import org.netbeans.modules.e2e.api.wsdl.wsdl2java.WSDL2Java;
039:        import org.netbeans.modules.e2e.api.wsdl.wsdl2java.WSDL2Java.ValidationResult;
040:        import org.netbeans.modules.e2e.api.wsdl.wsdl2java.WSDL2Java.ValidationResult.ErrorLevel;
041:        import org.netbeans.modules.e2e.schema.SchemaConstants;
042:        import org.netbeans.modules.e2e.wsdl.extensions.soap.SOAPConstants;
043:        import org.openide.util.NbBundle;
044:
045:        /**
046:         *
047:         * @author Michal Skvor
048:         */
049:        class WSDLValidator {
050:
051:            private Definition definition;
052:
053:            private List<ValidationResult> result;
054:
055:            private Service service;
056:
057:            // validation flags
058:            private boolean flagNoSoapBinding;
059:
060:            /** Creates a new instance of WSDLValidator */
061:            public WSDLValidator(List<ValidationResult> result,
062:                    Definition definition) {
063:                this .definition = definition;
064:
065:                this .result = new ArrayList();
066:                this .result.addAll(result);
067:            }
068:
069:            public List<ValidationResult> validate() {
070:                checkDefinition(definition);
071:
072:                printMessages();
073:
074:                return result;
075:            }
076:
077:            private void checkDefinition(Definition definition) {
078:                for (Service service : definition.getServices().values()) {
079:
080:                    checkService(service);
081:                }
082:            }
083:
084:            private void checkService(Service service) {
085:                this .service = service;
086:                for (Port port : service.getPorts()) {
087:                    //            System.err.println("Checking port: " + port.getName());
088:                    checkPort(port);
089:                }
090:            }
091:
092:            private void checkPort(Port port) {
093:                for (ExtensibilityElement portEE : port
094:                        .getExtensibilityElements()) {
095:                    if (SOAPConstants.ADDRESS.equals(portEE.getElementType())) {
096:                        SOAPAddress soapAddress = (SOAPAddress) portEE;
097:
098:                        // Port contains at least one with SOAP binding
099:                        //                    flags.add( SOAPConstants.ADDRESS );
100:
101:                        Binding binding = port.getBinding();
102:                        //                System.err.println("Checking binding: " + binding.getName());
103:                        checkBinding(binding);
104:                    }
105:                }
106:            }
107:
108:            private void checkBinding(Binding binding) {
109:                for (ExtensibilityElement bindingEE : binding
110:                        .getExtensibilityElements()) {
111:                    if (SOAPConstants.BINDING
112:                            .equals(bindingEE.getElementType())) {
113:                        SOAPBinding soapBinding = (SOAPBinding) bindingEE;
114:
115:                        // Binding is SOAP
116:                        //                flags.add( SOAPConstants.BINDING );
117:
118:                        //                System.err.println(" binding - style = " + soapBinding.getStyle());
119:
120:                        for (BindingOperation bindingOperation : binding
121:                                .getBindingOperations()) {
122:                            //                    System.err.println("Checking bindingOperation:" + bindingOperation.getName());
123:                            checkBindingOperation(bindingOperation);
124:                        }
125:                        PortType portType = binding.getPortType();
126:                        for (Operation operation : portType.getOperations()) {
127:                            //                    System.err.println("Checking operation: " + operation.getName());
128:                            checkOperation(operation);
129:                        }
130:                    }
131:                }
132:            }
133:
134:            private void checkBindingOperation(BindingOperation bindingOperation) {
135:                SOAPOperation soapOperation = null;
136:                for (ExtensibilityElement bindingOperationEE : bindingOperation
137:                        .getExtensibilityElements()) {
138:                    if (SOAPConstants.OPERATION.equals(bindingOperationEE
139:                            .getElementType())) {
140:                        if (soapOperation == null) {
141:                            soapOperation = (SOAPOperation) bindingOperationEE;
142:                        } else {
143:                            addMessage(ErrorLevel.FATAL, "0011",
144:                                    bindingOperation.getName());
145:                        }
146:                    }
147:                }
148:                if (soapOperation != null) {
149:                    //            System.err.println(" operation - style = " + soapOperation.getStyle());
150:                    if (!SOAPConstants.STYLE_DOCUMENT.equals(soapOperation
151:                            .getStyle())) {
152:                        addMessage(ErrorLevel.FATAL, "0001", bindingOperation
153:                                .getName());
154:                    }
155:                }
156:
157:                // BindingInput
158:                BindingInput bindingInput = bindingOperation.getBindingInput();
159:                if (bindingInput != null) {//it is not notification operation
160:                    for (ExtensibilityElement bindingInputEE : bindingInput
161:                            .getExtensibilityElements()) {
162:                        if (SOAPConstants.BODY.equals(bindingInputEE
163:                                .getElementType())) {
164:                            SOAPBody soapBody = (SOAPBody) bindingInputEE;
165:                            //                        System.err.println("body - use = " + soapBody.getUse());
166:                            if (!SOAPConstants.USE_LITERAL.equals(soapBody
167:                                    .getUse())) {
168:                                addMessage(ErrorLevel.FATAL, "0002",
169:                                        bindingOperation.getName(), "input");
170:                            }
171:                        }
172:                    }
173:                } else {
174:                    addMessage(ErrorLevel.FATAL, "0012", bindingOperation
175:                            .getName());
176:                }
177:
178:                // BindingOutput
179:                BindingOutput bindingOutput = bindingOperation
180:                        .getBindingOutput();
181:                if (bindingOutput != null) {//it is not one way operation
182:                    for (ExtensibilityElement bindingOutputEE : bindingOutput
183:                            .getExtensibilityElements()) {
184:                        if (SOAPConstants.BODY.equals(bindingOutputEE
185:                                .getElementType())) {
186:                            SOAPBody soapBody = (SOAPBody) bindingOutputEE;
187:                            //                    System.err.println("body - use = " + soapBody.getUse());
188:                            if (!SOAPConstants.USE_LITERAL.equals(soapBody
189:                                    .getUse())) {
190:                                addMessage(ErrorLevel.FATAL, "0002",
191:                                        bindingOperation.getName(), "output");
192:                            }
193:                        }
194:                    }
195:                } else {
196:                    addMessage(ErrorLevel.FATAL, "0013", bindingOperation
197:                            .getName());
198:                }
199:            }
200:
201:            private void checkOperation(Operation operation) {
202:                // Output
203:                Output output = operation.getOutput();
204:                if (output == null) {
205:                    addMessage(ErrorLevel.FATAL, "0007", operation.getName());
206:                    return;
207:                }
208:                Message message = output.getMessage();
209:                if (message.getParts().size() == 0) {
210:                    addMessage(ErrorLevel.FATAL, "0014", message.getName());
211:                } else if (message.getParts().size() > 1) {
212:                    addMessage(ErrorLevel.FATAL, "0006", operation.getName());
213:                } else {
214:
215:                }
216:                for (Part part : message.getParts()) {
217:                    QName elementName = part.getElementName();
218:                    QName typeName = part.getTypeName();
219:                    Element element = null;
220:                    Type type = null;
221:                    if (elementName != null) {
222:                        element = definition.getSchemaHolder()
223:                                .getSchemaElement(elementName);
224:                        type = element.getType();
225:                        checkType(element, new HashSet());
226:                    } else {
227:                        addMessage(ErrorLevel.FATAL, "0008", operation
228:                                .getName());
229:                    }
230:                }
231:
232:                // Input
233:                Input input = operation.getInput();
234:                if (input == null) {
235:                    addMessage(ErrorLevel.FATAL, "0009", operation.getName());
236:                    return;
237:                }
238:                message = input.getMessage();
239:                if (message.getParts().size() == 0) {
240:                    addMessage(ErrorLevel.FATAL, "0014", message.getName());
241:                } else if (message.getParts().size() > 1) {
242:                    addMessage(ErrorLevel.FATAL, "0006", operation.getName());
243:                } else {
244:
245:                }
246:
247:                for (Part part : message.getParts()) {
248:                    QName elementName = part.getElementName();
249:                    QName typeName = part.getTypeName();
250:                    Element element = null;
251:                    Type type = null;
252:                    if (elementName != null) {
253:                        element = definition.getSchemaHolder()
254:                                .getSchemaElement(elementName);
255:                        type = element.getType();
256:                        checkType(element, new HashSet());
257:                    } else {
258:                        addMessage(ErrorLevel.FATAL, "0008", operation
259:                                .getName());
260:                    }
261:                }
262:            }
263:
264:            private void checkType(Element element,
265:                    Set<Element> usedComplexTypes) {
266:                Type type = element.getType();
267:                if (Type.FLAVOR_PRIMITIVE == type.getFlavor()) {
268:                    QName typeName = type.getName();
269:                    if (SchemaConstants.TYPE_INT.equals(typeName)) {
270:                    } else if (SchemaConstants.TYPE_BOOLEAN.equals(typeName)) {
271:                    } else if (SchemaConstants.TYPE_BYTE.equals(typeName)) {
272:                    } else if (SchemaConstants.TYPE_DOUBLE.equals(typeName)) {
273:                    } else if (SchemaConstants.TYPE_FLOAT.equals(typeName)) {
274:                    } else if (SchemaConstants.TYPE_LONG.equals(typeName)) {
275:                    } else if (SchemaConstants.TYPE_SHORT.equals(typeName)) {
276:                    } else if (SchemaConstants.TYPE_BASE64_BINARY
277:                            .equals(typeName)) {
278:                    } else if (SchemaConstants.TYPE_HEX_BINARY.equals(typeName)) {
279:                    } else if (SchemaConstants.TYPE_STRING.equals(typeName)) {
280:                    } else if (SchemaConstants.TYPE_QNAME.equals(typeName)) {
281:                        addMessage(ErrorLevel.WARNING, "0015");
282:                    } else {
283:                        addMessage(ErrorLevel.FATAL, "0003", typeName
284:                                .toString());
285:                    }
286:                } else if (Type.FLAVOR_SEQUENCE == type.getFlavor()) {
287:                    usedComplexTypes.add(element);
288:                    if (type.getSubconstructs().size() == 0) {
289:                        return;
290:                    } else {
291:                        for (SchemaConstruct sc : type.getSubconstructs()) {
292:                            if (SchemaConstruct.ConstructType.ELEMENT.equals(sc
293:                                    .getConstructType())) {
294:                                Element sce = (Element) sc;
295:                                if (!usedComplexTypes.contains(sce)) {
296:                                    checkType(sce, usedComplexTypes);
297:                                } else {
298:                                    addMessage(ErrorLevel.FATAL, "0010");
299:                                }
300:                            } else {
301:                                addMessage(ErrorLevel.FATAL, "0005", element
302:                                        .getName().toString());
303:                            }
304:                        }
305:                    }
306:                } else {
307:                    addMessage(ErrorLevel.FATAL, "0004", element.getName()
308:                            .toString());
309:                }
310:            }
311:
312:            private void printMessages() {
313:                //        System.err.println("Validation messages: " + result.size());
314:                //        for( ValidationResult msg : result ) {
315:                //            System.err.println(" - " + msg.getErrorLevel() + " " + msg.getMessage());
316:                //        }
317:            }
318:
319:            private void addMessage(ValidationResult.ErrorLevel errorLevel,
320:                    String messageKey) {
321:                result.add(new ValidationResult(errorLevel, NbBundle
322:                        .getMessage(WSDLValidator.class, messageKey)));
323:            }
324:
325:            private void addMessage(ValidationResult.ErrorLevel errorLevel,
326:                    String messageKey, String param1) {
327:                result.add(new ValidationResult(errorLevel, NbBundle
328:                        .getMessage(WSDLValidator.class, messageKey, param1)));
329:            }
330:
331:            private void addMessage(ValidationResult.ErrorLevel errorLevel,
332:                    String messageKey, String param1, String param2) {
333:                result.add(new ValidationResult(errorLevel, NbBundle
334:                        .getMessage(WSDLValidator.class, messageKey, param1,
335:                                param2)));
336:            }
337:
338:            private void addMessage(ValidationResult.ErrorLevel errorLevel,
339:                    String messageKey, String[] params) {
340:                result.add(new ValidationResult(errorLevel, NbBundle
341:                        .getMessage(WSDLValidator.class, messageKey, params)));
342:            }
343:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.