Source Code Cross Referenced for WSDLFileValidator.java in  » ESB » open-esb » com » sun » jbi » binding » jms » deploy » 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.jms.deploy 
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.jms.deploy;
030:
031:        import com.sun.jbi.StringTranslator;
032:        import com.sun.jbi.binding.jms.JMSBindingContext;
033:        import com.sun.jbi.binding.jms.JMSBindingResources;
034:        import com.sun.jbi.binding.jms.JMSConstants;
035:        import com.sun.jbi.binding.jms.config.ConfigConstants;
036:        import com.sun.jbi.binding.jms.util.UtilBase;
037:
038:        import com.sun.jbi.wsdl2.Binding;
039:        import com.sun.jbi.wsdl2.Description;
040:        import com.sun.jbi.wsdl2.Endpoint;
041:        import com.sun.jbi.wsdl2.WsdlFactory;
042:
043:        import com.sun.jbi.wsdl2.Interface;
044:        import com.sun.jbi.wsdl2.InterfaceOperation;
045:        import com.sun.jbi.wsdl2.BindingOperation;
046:
047:        import org.w3c.dom.DocumentFragment;
048:        import org.w3c.dom.NamedNodeMap;
049:        import org.w3c.dom.Node;
050:
051:        import java.util.logging.Logger;
052:
053:        import javax.xml.namespace.QName;
054:
055:        /**
056:         * This class is uses to validate the configuration file supplied during
057:         * deployment conforms to the schema.
058:         *
059:         * @author Sun Microsystems Inc.
060:         */
061:        public final class WSDLFileValidator extends
062:                com.sun.jbi.binding.jms.util.UtilBase implements 
063:                JMSBindingResources {
064:            /**
065:             * Description object.
066:             */
067:            private static Description sDefinition;
068:
069:            /**
070:             * Logger object.
071:             */
072:            private Logger mLogger;
073:            /**
074:             * Current value.
075:             */
076:            private String mCurValue = "";
077:
078:            /**
079:             * Name of the file to parse.
080:             */
081:            private String mFileName;
082:
083:            /**
084:             * Translator for i18n messages.
085:             */
086:            private StringTranslator mStringTranslator;
087:
088:            /**
089:             * Creates a new WSDLFileValidator object.
090:             *
091:             * @param wsdlfile schema file name.
092:             */
093:            public WSDLFileValidator(String wsdlfile) {
094:                mFileName = wsdlfile;
095:                mLogger = JMSBindingContext.getInstance().getLogger();
096:                mStringTranslator = JMSBindingContext.getInstance()
097:                        .getStringTranslator();
098:            }
099:
100:            /**
101:             * Returns the document object obtained as a result of parsing.
102:             *
103:             * @return document object.
104:             */
105:            public Description getDocument() {
106:                return sDefinition;
107:            }
108:
109:            /**
110:             * This method has to be invoked to check the validity of the input
111:             * document.
112:             */
113:            public void validate() {
114:                parse();
115:
116:                if (isValid()) {
117:                    validateEndpoints();
118:                }
119:
120:                mLogger.info(mStringTranslator.getString(JMS_CONFIG_FILE_CHECK)
121:                        + isValid());
122:            }
123:
124:            /**
125:             * Checks if the binding is a JMS binding.
126:             *
127:             * @param df document fragment.
128:             *
129:             * @return true if JMS binding.
130:             */
131:            private boolean isJMSBinding(DocumentFragment df) {
132:                NamedNodeMap n = df.getFirstChild().getAttributes();
133:
134:                for (int g = 0; g < n.getLength(); g++) {
135:                    if (n.item(g).getLocalName().equals("type")) {
136:                        if (n.item(g).getNodeValue().equals(
137:                                ConfigConstants.JMS_NAMESPACE)) {
138:                            return true;
139:                        }
140:                    }
141:                }
142:
143:                return false;
144:            }
145:
146:            /**
147:             * Gets the role.
148:             *
149:             * @param map map object.
150:             *
151:             * @return  role.
152:             */
153:            private int getRole(NamedNodeMap map) {
154:                Node attrnode = map.getNamedItemNS(
155:                        ConfigConstants.JMS_NAMESPACE,
156:                        ConfigConstants.ENDPOINT_TYPE);
157:
158:                if ((attrnode == null)) {
159:                    setError(mStringTranslator.getString(
160:                            JMS_REQUIRED_ATTR_ERROR,
161:                            ConfigConstants.ENDPOINT_TYPE));
162:
163:                    return -1;
164:                }
165:
166:                try {
167:                    mCurValue = attrnode.getNodeValue().trim();
168:
169:                    if (mCurValue.equals("")) {
170:                        setError(mStringTranslator.getString(
171:                                JMS_REQUIRED_ATTR_ERROR,
172:                                ConfigConstants.ENDPOINT_TYPE));
173:
174:                        return -1;
175:                    }
176:                } catch (Exception e) {
177:                    setError(mStringTranslator.getString(
178:                            JMS_REQUIRED_ATTR_ERROR,
179:                            ConfigConstants.ENDPOINT_TYPE));
180:                    setException(e);
181:                }
182:
183:                if (mCurValue.trim().equalsIgnoreCase(
184:                        ConfigConstants.CONSUMER_STRING)) {
185:                    return ConfigConstants.CONSUMER;
186:                } else if (mCurValue.trim().equalsIgnoreCase(
187:                        ConfigConstants.PROVIDER_STRING)) {
188:                    return ConfigConstants.PROVIDER;
189:                } else {
190:                    return -1;
191:                }
192:            }
193:
194:            /**
195:             * Checks the endpoint for valid information.
196:             *
197:             * @param ep endpoint.
198:             */
199:            private void checkEndpoint(Endpoint ep) {
200:                DocumentFragment docfrag = ep.toXmlDocumentFragment();
201:
202:                Node epnode = docfrag.getFirstChild();
203:                NamedNodeMap epattributes = epnode.getAttributes();
204:                checkRequired(epattributes, ConfigConstants.DESTINATION_NAME);
205:                checkRequired(epattributes, ConfigConstants.DESTINATION_STYLE);
206:                checkRequired(epattributes, ConfigConstants.CONNECTION_FACTORY);
207:
208:                // checkRequired(epattributes, ConfigConstants.ENDPOINT_TYPE);
209:                int role = getRole(epattributes);
210:
211:                if (role == -1) {
212:                    setError(mStringTranslator.getString(JMS_INVALID_ROLE));
213:                } else if (role == ConfigConstants.PROVIDER) {
214:                    checkRequired(epattributes, ConfigConstants.TIME_TO_LIVE);
215:                } else if (role == ConfigConstants.CONSUMER) {
216:                    mLogger.fine("Role is consumer");
217:                }
218:
219:                if (!isValid()) {
220:                    setError("\n\tEndpoint : " + ep.getName());
221:                }
222:            }
223:
224:            /**
225:             * Checks the madatory information.
226:             *
227:             * @param map map object.
228:             * @param attr attribute to be checked.
229:             */
230:            private void checkRequired(NamedNodeMap map, String attr) {
231:                Node attrnode = map.getNamedItemNS(
232:                        ConfigConstants.JMS_NAMESPACE, attr);
233:
234:                if ((attrnode == null)) {
235:
236:                    setError(mStringTranslator.getString(
237:                            JMS_REQUIRED_ATTR_ERROR, attr));
238:
239:                    return;
240:                }
241:
242:                try {
243:                    mCurValue = attrnode.getNodeValue().trim();
244:
245:                    if (mCurValue.equals("")) {
246:                        setError(mStringTranslator.getString(
247:                                JMS_REQUIRED_ATTR_ERROR, attr));
248:                    }
249:                } catch (Exception e) {
250:                    setError(mStringTranslator.getString(
251:                            JMS_REQUIRED_ATTR_ERROR, attr));
252:                    setException(e);
253:                }
254:            }
255:
256:            /**
257:             * Finds if endpoint is provider or consumer.
258:             *
259:             * @param ep endpoint.
260:             *
261:             * @return provider or consumer.
262:             */
263:            private int findDirection(Endpoint ep) {
264:                Binding b = ep.getBinding();
265:                Interface bindingif = b.getInterface();
266:
267:                for (int oper = 0; oper < b.getOperationsLength(); oper++) {
268:                    BindingOperation boper = b.getOperation(oper);
269:                    QName bindingopername = boper.getInterfaceOperation();
270:                    int ifoperlength = bindingif.getOperationsLength();
271:
272:                    for (int j = 0; j < ifoperlength; j++) {
273:                        InterfaceOperation op = bindingif.getOperation(j);
274:                        String pat = op.getPattern();
275:
276:                        if (pat.trim().equals(ConfigConstants.IN_OUT)
277:                                || pat.trim().equals(ConfigConstants.IN_ONLY)
278:                                || pat.trim().equals(
279:                                        ConfigConstants.ROBUST_IN_ONLY)
280:                                || pat.trim().equals(
281:                                        ConfigConstants.IN_OPTIONAL_OUT)) {
282:                            return 1;
283:                        } else if (pat.trim().equals(ConfigConstants.OUT_IN)
284:                                || pat.trim().equals(ConfigConstants.OUT_ONLY)
285:                                || pat.trim().equals(
286:                                        ConfigConstants.ROBUST_OUT_ONLY)
287:                                || pat.trim().equals(
288:                                        ConfigConstants.OUT_OPTIONAL_IN)) {
289:                            return 0;
290:                        }
291:                    }
292:                }
293:
294:                return -1;
295:            }
296:
297:            /**
298:             * Parses the input XML file.
299:             */
300:            private void parse() {
301:                try {
302:                    com.sun.jbi.component.ComponentContext ctx = (com.sun.jbi.component.ComponentContext) JMSBindingContext
303:                            .getInstance().getContext();
304:                    WsdlFactory wsdlFactory = ctx.getWsdlFactory();
305:                    com.sun.jbi.wsdl2.WsdlReader wsdlRdr = wsdlFactory
306:                            .newWsdlReader();
307:                    sDefinition = wsdlRdr.readDescription(mFileName);
308:                } catch (Exception e) {
309:                    setError("WSDL file " + mFileName + " parse error, reason "
310:                            + e.getMessage());
311:                    setException(e);
312:                    e.printStackTrace();
313:                }
314:            }
315:
316:            /**
317:             * Validates the endpoints.
318:             */
319:            private void validateEndpoints() {
320:                int services = sDefinition.getServicesLength();
321:                boolean found = false;
322:
323:                for (int i = 0; i < services; i++) {
324:                    try {
325:                        com.sun.jbi.wsdl2.Service ser = sDefinition
326:                                .getService(i);
327:                        int endpoints = ser.getEndpointsLength();
328:
329:                        for (int k = 0; k < endpoints; k++) {
330:                            Endpoint ep = ser.getEndpoint(k);
331:                            Binding b = ep.getBinding();
332:
333:                            if ((b == null)
334:                                    || (!isJMSBinding(b.toXmlDocumentFragment()))) {
335:                                continue;
336:                            }
337:
338:                            found = true;
339:                            checkEndpoint(ep);
340:
341:                            if (!isValid()) {
342:                                setError("\n\tBinding " + " : " + b.getName());
343:
344:                                return;
345:                            }
346:                        }
347:                    } catch (Exception e) {
348:                        setError("Error occurred during endpoint validation "
349:                                + e.getMessage());
350:                        setException(e);
351:                        e.printStackTrace();
352:
353:                        return;
354:                    }
355:                }
356:
357:                if (!found) {
358:                    setError(mStringTranslator.getString(JMS_NO_ENDPOINTS));
359:                }
360:            }
361:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.