Source Code Cross Referenced for Wsdl1Deployer.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » runtime » ccsl » jbi » messaging » 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.runtime.ccsl.jbi.messaging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        /*
019:         * ChainBuilder ESB
020:         * 		Visual Enterprise Integration
021:         * 
022:         * Copyright (C) 2006 Bostech Corporation
023:         * 
024:         * This program is free software; you can redistribute it and/or modify it 
025:         * under the terms of the GNU General Public License as published by the 
026:         * Free Software Foundation; either version 2 of the License, or (at your option) 
027:         * any later version.
028:         *
029:         * This program is distributed in the hope that it will be useful, 
030:         * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
031:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
032:         * for more details.
033:         * 
034:         * You should have received a copy of the GNU General Public License along with 
035:         * this program; if not, write to the Free Software Foundation, Inc., 
036:         * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
037:         *
038:         * $Id: Wsdl1Deployer.java 10598 2007-12-06 08:14:39Z lzheng $
039:         */
040:        package com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging;
041:
042:        import java.io.File;
043:        import java.io.FilenameFilter;
044:        import java.sql.SQLException;
045:        import java.util.ArrayList;
046:        import java.util.Collection;
047:        import java.util.Iterator;
048:        import java.util.List;
049:        import java.util.Map;
050:        import java.util.Vector;
051:
052:        import javax.jbi.management.DeploymentException;
053:        import javax.wsdl.Binding;
054:        import javax.wsdl.Definition;
055:        import javax.wsdl.Port;
056:        import javax.wsdl.Service;
057:        import javax.wsdl.WSDLException;
058:        import javax.wsdl.extensions.ExtensibilityElement;
059:        import javax.wsdl.extensions.ExtensionRegistry;
060:        import javax.wsdl.factory.WSDLFactory;
061:        import javax.wsdl.xml.WSDLReader;
062:        import javax.xml.parsers.DocumentBuilderFactory;
063:
064:        import org.w3c.dom.Document;
065:
066:        import com.bostechcorp.cbesb.common.util.runtimedb.DaoConfig;
067:        import com.bostechcorp.cbesb.common.util.runtimedb.vo.EndpointSettingVO;
068:        import com.ibatis.sqlmap.client.SqlMapClient;
069:        import com.ibm.wsdl.Constants;
070:
071:        public abstract class Wsdl1Deployer extends CbDeployer {
072:
073:            protected FilenameFilter filter;
074:
075:            public Wsdl1Deployer(CbComponent component) {
076:                super (component);
077:                filter = new WsdlFilter();
078:            }
079:
080:            /* (non-Javadoc)
081:             * @see org.apache.servicemix.common.Deployer#canDeploy(java.lang.String, java.lang.String)
082:             */
083:            public boolean canDeploy(String serviceUnitName,
084:                    String serviceUnitRootPath) {
085:                File[] wsdls = new File(serviceUnitRootPath).listFiles(filter);
086:                return wsdls != null && wsdls.length > 0;
087:            }
088:
089:            /* (non-Javadoc)
090:             * @see org.apache.servicemix.common.Deployer#deploy(java.lang.String, java.lang.String)
091:             */
092:            public CbServiceUnit deploy(String serviceUnitName,
093:                    String serviceUnitRootPath) throws DeploymentException {
094:                File[] wsdls = new File(serviceUnitRootPath).listFiles(filter);
095:                if (wsdls == null || wsdls.length == 0) {
096:                    throw failure("deploy", "No wsdl found", null);
097:                }
098:                CbServiceUnit su = createServiceUnit();
099:                su.setComponent(component);
100:                su.setName(serviceUnitName);
101:                su.setRootPath(serviceUnitRootPath);
102:                loadServiceUnitDescriptor(su, serviceUnitRootPath);
103:                for (int i = 0; i < wsdls.length; i++) {
104:                    initFromWsdl(su, wsdls[i]);
105:                }
106:                if (su.getEndpoints().size() == 0) {
107:                    throw failure("deploy", "Invalid wsdl: no endpoints found",
108:                            null);
109:                } else if (su.getComponent() instanceof  CbExtendedComponent) {
110:                    DaoConfig dao = new DaoConfig();
111:                    SqlMapClient sqlMap = dao.getSqlMapInstance();
112:                    Collection<CbEndpoint> epVals = su.endpoints.values();
113:                    for (CbEndpoint ep : epVals) {
114:                        if (ep instanceof  LifeCycleEndpoint) {
115:                            LifeCycleEndpoint lcep = (LifeCycleEndpoint) ep;
116:                            String endpointName = lcep.getEndpoint();
117:                            logger.debug("endpoint Name is: " + endpointName
118:                                    + ".");
119:                            EndpointSettingVO settingVO = new EndpointSettingVO();
120:                            settingVO.setEndpointName(endpointName);
121:                            List<EndpointSettingVO> resultList = new ArrayList<EndpointSettingVO>();
122:                            try {
123:                                resultList = sqlMap.queryForList(
124:                                        "queryEndpointSettingByEndpointName",
125:                                        settingVO);
126:                            } catch (SQLException e) {
127:                                logger.error("SQLException occured: "
128:                                        + e.getMessage());
129:                            }
130:                            String[][] propertyObjects = new String[resultList
131:                                    .size()][2];
132:                            for (int i = 0; i < resultList.size(); i++) {
133:                                EndpointSettingVO endpointSettingVO = (EndpointSettingVO) resultList
134:                                        .get(i);
135:                                propertyObjects[i][0] = endpointSettingVO
136:                                        .getPropertyName();
137:                                propertyObjects[i][1] = endpointSettingVO
138:                                        .getPropertyValue();
139:                                logger.info("Get endpoint["
140:                                        + propertyObjects[i][0] + "] : value["
141:                                        + propertyObjects[i][1]
142:                                        + "] from EndpointSetting Database.");
143:                            }
144:                            for (int i = 0; i < propertyObjects.length; i++) {
145:                                String[] object = propertyObjects[i];
146:                                lcep.setProperty(object[0], object[1]);
147:                            }
148:                        }
149:                    }
150:                }
151:                return su;
152:            }
153:
154:            protected void initFromWsdl(CbServiceUnit su, File wsdl)
155:                    throws DeploymentException {
156:                Document description;
157:                Definition definition;
158:                Vector<ExtensibilityElement> portElements = new Vector<ExtensibilityElement>();
159:                Vector<ExtensibilityElement> bindingElements = new Vector<ExtensibilityElement>();
160:
161:                try {
162:                    DocumentBuilderFactory factory = DocumentBuilderFactory
163:                            .newInstance();
164:                    factory.setNamespaceAware(true);
165:                    description = factory.newDocumentBuilder().parse(wsdl);
166:                    definition = createWsdlReader().readWSDL(null, description);
167:                } catch (Exception e) {
168:                    throw failure("deploy", "Could not parse " + wsdl, e);
169:                }
170:                Map services = definition.getServices();
171:
172:                if (services.size() == 0) {
173:                    failure("deploy", "Invalid wsdl " + wsdl
174:                            + ": no defined services", null);
175:                }
176:                for (Iterator itSvc = services.values().iterator(); itSvc
177:                        .hasNext();) {
178:                    Service svc = (Service) itSvc.next();
179:                    for (Iterator itPorts = svc.getPorts().values().iterator(); itPorts
180:                            .hasNext();) {
181:                        Port port = (Port) itPorts.next();
182:                        //              ExtensibilityElement portElement = null;
183:                        for (Iterator itElems = port.getExtensibilityElements()
184:                                .iterator(); itElems.hasNext();) {
185:                            ExtensibilityElement elem = (ExtensibilityElement) itElems
186:                                    .next();
187:                            if (filterPortElement(elem)) {
188:                                portElements.add(elem);
189:                                //                        if (portElement == null) {
190:                                //                            portElement = elem;
191:                                //                        } else {
192:                                //                            throw failure("deploy", "Invalid wsdl " + wsdl + ": more than one port element match", null);
193:                                //                        }
194:                            }
195:                        }
196:                        if (portElements.size() > 0) {
197:                            Binding binding = port.getBinding();
198:                            //                  ExtensibilityElement bindingElement = null;
199:                            for (Iterator itElems = binding
200:                                    .getExtensibilityElements().iterator(); itElems
201:                                    .hasNext();) {
202:                                ExtensibilityElement elem = (ExtensibilityElement) itElems
203:                                        .next();
204:                                if (filterBindingElement(elem)) {
205:                                    bindingElements.add(elem);
206:                                    //                            if (bindingElement == null) {
207:                                    //                                bindingElement = elem;
208:                                    //                            } else {
209:                                    //                                throw failure("deploy", "Invalid wsdl " + wsdl + ": more than one binding element match", null);
210:                                    //                            }
211:                                }
212:                            }
213:                            if (bindingElements.size() == 0) {
214:                                throw failure(
215:                                        "deploy",
216:                                        "Invalid wsdl "
217:                                                + wsdl
218:                                                + ": no matching binding element found",
219:                                        null);
220:                            }
221:                            ExtensibilityElement[] portElementArray = new ExtensibilityElement[portElements
222:                                    .size()];
223:                            ExtensibilityElement[] bindingElementArray = new ExtensibilityElement[bindingElements
224:                                    .size()];
225:                            for (int i = 0; i < portElements.size(); i++) {
226:                                portElementArray[i] = portElements.elementAt(i);
227:                            }
228:                            for (int i = 0; i < bindingElements.size(); i++) {
229:                                bindingElementArray[i] = bindingElements
230:                                        .elementAt(i);
231:                            }
232:                            CbEndpoint ep = createEndpoint(portElementArray,
233:                                    bindingElementArray);
234:                            if (ep != null) {
235:                                ep.setServiceUnit(su);
236:                                ep.setDescription(description);
237:                                ep.setDefinition(definition);
238:                                ep.setService(svc.getQName());
239:                                ep.setEndpoint(port.getName());
240:                                ep.setInterfaceName(binding.getPortType()
241:                                        .getQName());
242:                                su.addEndpoint(ep);
243:                            }
244:                        }
245:                    }
246:                }
247:            }
248:
249:            protected WSDLReader createWsdlReader() throws WSDLException {
250:                WSDLFactory factory = WSDLFactory.newInstance();
251:                ExtensionRegistry registry = factory
252:                        .newPopulatedExtensionRegistry();
253:                registerExtensions(registry);
254:                WSDLReader reader = factory.newWSDLReader();
255:                reader.setFeature(Constants.FEATURE_VERBOSE, false);
256:                reader.setExtensionRegistry(registry);
257:                return reader;
258:            }
259:
260:            protected void registerExtensions(ExtensionRegistry registry) {
261:                // nothing to do in the base class. sub-class will do it.
262:            }
263:
264:            protected void loadServiceUnitDescriptor(CbServiceUnit su,
265:                    String serviceUnitRootPath) {
266:                File jbixml = new File(serviceUnitRootPath + File.separator
267:                        + "META-INF" + File.separator + "jbi.xml");
268:                try {
269:                    ServiceUnitDescriptor suDesc = ServiceUnitDescriptor
270:                            .load(jbixml);
271:                    su.serviceUnitDescriptor = suDesc;
272:                } catch (Exception e) {
273:                    logger.error(
274:                            "Exception caught while loading SU Descriptor:", e);
275:                }
276:            }
277:
278:            protected CbServiceUnit createServiceUnit() {
279:                return new CbServiceUnit();
280:            }
281:
282:            protected abstract CbEndpoint createEndpoint(
283:                    ExtensibilityElement[] portElement,
284:                    ExtensibilityElement[] bindingElement);
285:
286:            protected abstract boolean filterPortElement(
287:                    ExtensibilityElement element);
288:
289:            protected abstract boolean filterBindingElement(
290:                    ExtensibilityElement element);
291:
292:            public static class WsdlFilter implements  FilenameFilter {
293:
294:                public boolean accept(File dir, String name) {
295:                    return name.endsWith(".wsdl");
296:                }
297:
298:            }
299:
300:        }
ww___w__.___j__a___v__a___2__s__.c_o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.