Source Code Cross Referenced for WSDLFileValidator.java in  » ESB » open-esb » com » sun » jbi » binding » file » util » 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 » open esb » com.sun.jbi.binding.file.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)WSDLFileValidator.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.binding.file.util;
030:
031:        import com.sun.jbi.binding.file.FileBindingResources;
032:        import com.sun.jbi.binding.file.FileBindingContext;
033:        import com.sun.jbi.wsdl2.Binding;
034:        import com.sun.jbi.wsdl2.Description;
035:        import com.sun.jbi.wsdl2.Endpoint;
036:        import com.sun.jbi.wsdl2.WsdlFactory;
037:
038:        import org.w3c.dom.DocumentFragment;
039:        import org.w3c.dom.NamedNodeMap;
040:        import org.w3c.dom.Node;
041:
042:        import java.util.logging.Logger;
043:
044:        /**
045:         * This class is uses to validate the configuration file supplied during
046:         * deployment conforms to the schema.
047:         *
048:         * @author Sun Microsystems, Inc.
049:         */
050:        public final class WSDLFileValidator extends UtilBase implements 
051:                FileBindingResources {
052:            /**
053:             * Description object
054:             */
055:            private static Description sDefinition;
056:
057:            /**
058:             * Inbound / Outbound
059:             */
060:            private String mCurValue = "";
061:
062:            /**
063:             * Name of the file to parse.
064:             */
065:            private String mFileName;
066:
067:            /**
068:             * Translator for i18n messages.
069:             */
070:            private StringTranslator mTranslator;
071:
072:            /**
073:             * Creates a new WSDLFileValidator object.
074:             *
075:             * @param wsdlfile schema file name
076:             */
077:            public WSDLFileValidator(String wsdlfile) {
078:                mFileName = wsdlfile;
079:                mTranslator = new StringTranslator();
080:            }
081:
082:            /**
083:             * Returns the document object obtained as a result of parsing.
084:             *
085:             * @return document object
086:             */
087:            public Description getDocument() {
088:                return sDefinition;
089:            }
090:
091:            /**
092:             * This method has to be invoked to check the validity of the input
093:             * document.
094:             */
095:            public void validate() {
096:                parse();
097:
098:                if (isValid()) {
099:                    validateEndpoints();
100:                }
101:            }
102:
103:            /**
104:             * Checks if a binging is file binding
105:             *
106:             * @param df Document fragment
107:             *
108:             * @return true if file binding
109:             */
110:            private boolean isFileBinding(DocumentFragment df) {
111:                NamedNodeMap n = df.getFirstChild().getAttributes();
112:
113:                for (int g = 0; g < n.getLength(); g++) {
114:                    if (n.item(g).getLocalName().equals(
115:                            ConfigData.WSDL_BINDING_TYPE)) {
116:                        if (n.item(g).getNodeValue().equals(
117:                                ConfigData.FILENAMESPACE)) {
118:                            return true;
119:                        }
120:                    }
121:                }
122:
123:                return false;
124:            }
125:
126:            /**
127:             * Checks the Endpoint.
128:             *
129:             * @param ep endpoint
130:             */
131:            private void checkEndpoint(Endpoint ep) {
132:                DocumentFragment docfrag = ep.toXmlDocumentFragment();
133:
134:                Node epnode = docfrag.getFirstChild();
135:                NamedNodeMap epattributes = epnode.getAttributes();
136:                checkRequired(epattributes, ConfigData.ENDPOINT_TYPE);
137:
138:                if (mCurValue.trim().equalsIgnoreCase(
139:                        ConfigData.CONSUMER_STRING)) {
140:                    checkRequired(epattributes, ConfigData.WSDL_INPUT_LOCATION);
141:                    checkRequired(epattributes,
142:                            ConfigData.WSDL_PROCESSED_LOCATION);
143:                }
144:
145:                checkRequired(epattributes, ConfigData.WSDL_OUTPUT_LOCATION);
146:
147:                if (!isValid()) {
148:                    setError("\n\tEndpoint : " + ep.getName() + getError());
149:                }
150:            }
151:
152:            /**
153:             * Checks the required attributes.
154:             *
155:             * @param map Node map
156:             * @param attr attributes that has to be checked.
157:             */
158:            private void checkRequired(NamedNodeMap map, String attr) {
159:                Node attrnode = map.getNamedItemNS(ConfigData.FILENAMESPACE,
160:                        attr);
161:
162:                if ((attrnode == null)) {
163:                    setValid(false);
164:                    setError(getError() + "\n\t" + "Required attribute \""
165:                            + attr + "\" not found");
166:
167:                    return;
168:                }
169:
170:                try {
171:                    mCurValue = attrnode.getNodeValue().trim();
172:
173:                    if (mCurValue.equals("")) {
174:                        setValid(false);
175:                        setError(getError() + "\n\t" + "Required attribute \""
176:                                + attr
177:                                + "\" has to have a value, cannot be null");
178:                    }
179:                } catch (Exception e) {
180:                    setValid(false);
181:                    setError(getError() + "\n\t"
182:                            + "Cannot get attribute value of " + attr);
183:                    setException(e);
184:                }
185:            }
186:
187:            /**
188:             * Parses the input XML file.
189:             */
190:            private void parse() {
191:                try {
192:                    com.sun.jbi.component.ComponentContext ctx = (com.sun.jbi.component.ComponentContext) FileBindingContext
193:                            .getInstance().getContext();
194:                    WsdlFactory wsdlFactory = ctx.getWsdlFactory();
195:                    com.sun.jbi.wsdl2.WsdlReader wsdlRdr = wsdlFactory
196:                            .newWsdlReader();
197:                    sDefinition = wsdlRdr.readDescription(mFileName);
198:                } catch (Exception e) {
199:                    setError("WSDL file " + mFileName + " parse error, reason "
200:                            + e.getMessage());
201:                    setException(e);
202:                    setValid(false);
203:                    e.printStackTrace();
204:                }
205:            }
206:
207:            /**
208:             * Validates the endpoints.
209:             */
210:            private void validateEndpoints() {
211:                int services = sDefinition.getServicesLength();
212:                boolean found = false;
213:
214:                for (int i = 0; i < services; i++) {
215:                    try {
216:                        com.sun.jbi.wsdl2.Service ser = sDefinition
217:                                .getService(i);
218:                        int endpoints = ser.getEndpointsLength();
219:
220:                        for (int k = 0; k < endpoints; k++) {
221:                            Endpoint ep = ser.getEndpoint(k);
222:                            Binding b = ep.getBinding();
223:
224:                            if (!isFileBinding(b.toXmlDocumentFragment())) {
225:                                continue;
226:                            }
227:
228:                            found = true;
229:                            checkEndpoint(ep);
230:
231:                            if (!isValid()) {
232:                                setError("\n\tBinding " + " : " + b.getName()
233:                                        + getError());
234:
235:                                return;
236:                            }
237:                        }
238:                    } catch (Exception e) {
239:                        setError(mTranslator.getString(FBC_WSDL_ENDPOINT_ERROR,
240:                                e.getMessage()));
241:                        setException(e);
242:                        setValid(false);
243:                        e.printStackTrace();
244:
245:                        return;
246:                    }
247:                }
248:
249:                if (!found) {
250:                    setError(getError()
251:                            + mTranslator.getString(FBC_WSDL_NO_ENDPOINTS));
252:                    setValid(false);
253:                }
254:            }
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.