Source Code Cross Referenced for WSDL11Validator.java in  » Web-Services-apache-cxf-2.0.1 » tools-validator » org » apache » cxf » tools » validator » internal » 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 apache cxf 2.0.1 » tools validator » org.apache.cxf.tools.validator.internal 
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:         */package org.apache.cxf.tools.validator.internal;
019:
020:        import java.io.File;
021:        import java.io.FileFilter;
022:        import java.io.IOException;
023:        import java.net.JarURLConnection;
024:        import java.net.URI;
025:        import java.net.URISyntaxException;
026:        import java.net.URL;
027:        import java.util.ArrayList;
028:        import java.util.Collections;
029:        import java.util.Comparator;
030:        import java.util.Enumeration;
031:        import java.util.List;
032:        import java.util.jar.JarEntry;
033:        import java.util.jar.JarFile;
034:        import java.util.logging.Level;
035:        import java.util.logging.Logger;
036:        import javax.wsdl.Definition;
037:
038:        import org.w3c.dom.Document;
039:        import org.xml.sax.InputSource;
040:
041:        import org.apache.cxf.common.i18n.Message;
042:        import org.apache.cxf.common.logging.LogUtils;
043:        import org.apache.cxf.common.util.StringUtils;
044:        import org.apache.cxf.helpers.XMLUtils;
045:        import org.apache.cxf.resource.URIResolver;
046:        import org.apache.cxf.tools.common.ToolConstants;
047:        import org.apache.cxf.tools.common.ToolContext;
048:        import org.apache.cxf.tools.common.ToolException;
049:        import org.apache.cxf.tools.util.URIParserUtil;
050:        import org.apache.cxf.tools.validator.AbstractValidator;
051:
052:        public class WSDL11Validator extends AbstractDefinitionValidator {
053:            protected static final Logger LOG = LogUtils
054:                    .getL7dLogger(SchemaValidator.class);
055:            private final List<AbstractValidator> validators = new ArrayList<AbstractValidator>();
056:
057:            public WSDL11Validator(Definition definition) {
058:                super (definition);
059:            }
060:
061:            public WSDL11Validator(Definition definition, ToolContext pe) {
062:                super (definition, pe);
063:            }
064:
065:            private Document getWSDLDoc(String wsdl) {
066:                LOG.log(Level.INFO, new Message("VALIDATE_WSDL", LOG, wsdl)
067:                        .toString());
068:                try {
069:                    return XMLUtils.parse(new InputSource(URIParserUtil
070:                            .getAbsoluteURI(wsdl)));
071:                } catch (Exception e) {
072:                    throw new ToolException(e);
073:                }
074:            }
075:
076:            public boolean isValid() throws ToolException {
077:                //boolean isValid = true;
078:                String schemaDir = getSchemaDir();
079:                SchemaValidator schemaValidator = null;
080:                String[] schemas = (String[]) env
081:                        .get(ToolConstants.CFG_SCHEMA_URL);
082:                // Tool will use the following sequence to find the schema files
083:                // 1.ToolConstants.CFG_SCHEMA_DIR from ToolContext
084:                // 2.ToolConstants.CXF_SCHEMA_DIR from System property
085:                // 3.If 1 and 2 is null , then load these schema files from jar file
086:                String wsdl = (String) env.get(ToolConstants.CFG_WSDLURL);
087:
088:                WSDLRefValidator wsdlRefValidator = new WSDLRefValidator(wsdl,
089:                        getWSDLDoc(wsdl));
090:                wsdlRefValidator.setSuppressWarnings(env
091:                        .optionSet(ToolConstants.CFG_SUPPRESS_WARNINGS));
092:
093:                this .def = wsdlRefValidator.getDefinition();
094:
095:                validators.add(wsdlRefValidator);
096:                validators.add(new UniqueBodyPartsValidator(this .def));
097:                validators.add(new WSIBPValidator(this .def));
098:                validators.add(new MIMEBindingValidator(this .def));
099:
100:                for (AbstractValidator validator : validators) {
101:                    if (!validator.isValid()) {
102:                        addErrorMessage(validator.getErrorMessage());
103:                        throw new ToolException(this .getErrorMessage());
104:                    }
105:                }
106:
107:                if (!StringUtils.isEmpty(schemaDir)) {
108:                    schemaValidator = new SchemaValidator(schemaDir, wsdl,
109:                            schemas);
110:                } else {
111:                    try {
112:                        schemaValidator = new SchemaValidator(
113:                                getDefaultSchemas(), wsdl, schemas);
114:                    } catch (IOException e) {
115:                        throw new ToolException(
116:                                "Schemas can not be loaded before validating wsdl",
117:                                e);
118:                    }
119:
120:                }
121:                if (!schemaValidator.isValid()) {
122:                    this .addErrorMessage(schemaValidator.getErrorMessage());
123:                    throw new ToolException(this .getErrorMessage());
124:
125:                }
126:
127:                return true;
128:            }
129:
130:            public String getSchemaDir() {
131:                String dir = "";
132:                if (env.get(ToolConstants.CFG_SCHEMA_DIR) == null) {
133:                    dir = System.getProperty(ToolConstants.CXF_SCHEMA_DIR);
134:                } else {
135:                    dir = (String) env.get(ToolConstants.CFG_SCHEMA_DIR);
136:                }
137:                return dir;
138:            }
139:
140:            protected List<InputSource> getDefaultSchemas() throws IOException {
141:                List<InputSource> xsdList = new ArrayList<InputSource>();
142:                ClassLoader clzLoader = Thread.currentThread()
143:                        .getContextClassLoader();
144:                Enumeration<URL> urls = clzLoader
145:                        .getResources(ToolConstants.CXF_SCHEMAS_DIR_INJAR);
146:                while (urls.hasMoreElements()) {
147:                    URL url = urls.nextElement();
148:                    //from jar files 
149:                    if (url.toString().startsWith("jar")) {
150:
151:                        JarURLConnection jarConnection = (JarURLConnection) url
152:                                .openConnection();
153:
154:                        JarFile jarFile = jarConnection.getJarFile();
155:
156:                        Enumeration<JarEntry> entry = jarFile.entries();
157:
158:                        while (entry.hasMoreElements()) {
159:                            JarEntry ele = (JarEntry) entry.nextElement();
160:                            if (ele.getName().endsWith(".xsd")
161:                                    && ele
162:                                            .getName()
163:                                            .indexOf(
164:                                                    ToolConstants.CXF_SCHEMAS_DIR_INJAR) > -1) {
165:
166:                                URIResolver resolver = new URIResolver(ele
167:                                        .getName());
168:                                if (resolver.isResolved()) {
169:                                    InputSource is = new InputSource(resolver
170:                                            .getInputStream());
171:                                    // Use the resolved URI of the schema if available.
172:                                    // The ibm jdk won't resolve the schema if we set
173:                                    // the id to the relative path.
174:                                    if (resolver.getURI() != null) {
175:                                        is.setSystemId(resolver.getURI()
176:                                                .toString());
177:                                    } else {
178:                                        is.setSystemId(ele.getName());
179:                                    }
180:                                    xsdList.add(is);
181:                                }
182:                            }
183:                        }
184:                        //from class path direcotry
185:                    } else if (url.toString().startsWith("file")) {
186:                        URI loc = null;
187:                        try {
188:                            loc = url.toURI();
189:                        } catch (URISyntaxException e) {
190:                            //
191:                        }
192:                        java.io.File file = new java.io.File(loc);
193:                        if (file.exists()) {
194:                            File[] files = file.listFiles(new FileFilter() {
195:                                public boolean accept(File pathname) {
196:                                    if (pathname.getAbsolutePath().endsWith(
197:                                            ".xsd")) {
198:                                        return true;
199:                                    }
200:                                    return false;
201:                                }
202:                            });
203:                            for (int i = 0; i < files.length; i++) {
204:                                InputSource is = new InputSource(files[i]
205:                                        .toURI().toURL().openStream());
206:                                is.setSystemId(files[i].toURI().toURL()
207:                                        .toString());
208:                                xsdList.add(is);
209:                            }
210:                        }
211:
212:                    }
213:                }
214:
215:                sort(xsdList);
216:                return xsdList;
217:            }
218:
219:            private void sort(List<InputSource> list) {
220:                Collections.sort(list, new Comparator<InputSource>() {
221:                    public int compare(InputSource i1, InputSource i2) {
222:                        if (i1 == null && i2 == null) {
223:                            return -1;
224:                        }
225:                        return i1.getSystemId().compareTo(i2.getSystemId());
226:                    }
227:                });
228:            }
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.