Source Code Cross Referenced for ReadDescriptors.java in  » J2EE » openejb3 » org » apache » openejb » config » 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 » J2EE » openejb3 » org.apache.openejb.config 
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:         */package org.apache.openejb.config;
017:
018:        import static org.apache.openejb.util.URLs.toFilePath;
019:        import org.apache.openejb.OpenEJBException;
020:        import org.apache.openejb.config.sys.ServicesJar;
021:        import org.apache.openejb.config.sys.ServiceProvider;
022:        import org.apache.openejb.config.sys.ListAdapter;
023:        import org.apache.openejb.config.sys.PropertiesAdapter;
024:        import org.apache.openejb.core.webservices.WsdlResolver;
025:        import org.apache.openejb.jee.ApplicationClient;
026:        import org.apache.openejb.jee.Connector;
027:        import org.apache.openejb.jee.EjbJar;
028:        import org.apache.openejb.jee.HandlerChains;
029:        import org.apache.openejb.jee.JavaWsdlMapping;
030:        import org.apache.openejb.jee.JaxbJavaee;
031:        import org.apache.openejb.jee.TldTaglib;
032:        import org.apache.openejb.jee.WebApp;
033:        import org.apache.openejb.jee.Webservices;
034:        import org.apache.openejb.jee.jpa.unit.JaxbPersistenceFactory;
035:        import org.apache.openejb.jee.jpa.unit.Persistence;
036:        import org.apache.openejb.jee.oejb2.EnterpriseBean;
037:        import org.apache.openejb.jee.oejb2.GeronimoEjbJarType;
038:        import org.apache.openejb.jee.oejb2.JaxbOpenejbJar2;
039:        import org.apache.openejb.jee.oejb2.OpenejbJarType;
040:        import org.apache.openejb.jee.oejb2.RpcBean;
041:        import org.apache.openejb.jee.oejb2.SessionBeanType;
042:        import org.apache.openejb.jee.oejb2.TssLinkType;
043:        import org.apache.openejb.jee.oejb2.WebServiceBindingType;
044:        import org.apache.openejb.jee.oejb3.JaxbOpenejbJar3;
045:        import org.apache.openejb.jee.oejb3.OpenejbJar;
046:        import org.xml.sax.Attributes;
047:        import org.xml.sax.InputSource;
048:        import org.xml.sax.SAXException;
049:        import org.xml.sax.helpers.DefaultHandler;
050:
051:        import javax.wsdl.Definition;
052:        import javax.wsdl.factory.WSDLFactory;
053:        import javax.wsdl.xml.WSDLReader;
054:        import javax.xml.bind.JAXBElement;
055:        import javax.xml.bind.JAXBException;
056:        import javax.xml.parsers.SAXParser;
057:        import javax.xml.parsers.SAXParserFactory;
058:        import javax.xml.parsers.ParserConfigurationException;
059:        import java.io.ByteArrayInputStream;
060:        import java.io.File;
061:        import java.io.FileOutputStream;
062:        import java.io.IOException;
063:        import java.io.InputStream;
064:        import java.net.URL;
065:        import java.net.URLConnection;
066:        import java.util.List;
067:
068:        public class ReadDescriptors implements  DynamicDeployer {
069:            @SuppressWarnings({"unchecked"})
070:            public AppModule deploy(AppModule appModule)
071:                    throws OpenEJBException {
072:                for (EjbModule ejbModule : appModule.getEjbModules()) {
073:
074:                    if (ejbModule.getEjbJar() == null) {
075:                        readEjbJar(ejbModule, appModule);
076:                    }
077:
078:                    if (ejbModule.getOpenejbJar() == null) {
079:                        readOpenejbJar(ejbModule);
080:                    }
081:                }
082:
083:                for (ClientModule clientModule : appModule.getClientModules()) {
084:                    readAppClient(clientModule, appModule);
085:                }
086:
087:                for (ConnectorModule connectorModule : appModule
088:                        .getResourceModules()) {
089:                    readConnector(connectorModule, appModule);
090:                }
091:
092:                for (WebModule webModule : appModule.getWebModules()) {
093:                    readWebApp(webModule, appModule);
094:                }
095:
096:                List<URL> persistenceUrls = (List<URL>) appModule.getAltDDs()
097:                        .get("persistence.xml");
098:                if (persistenceUrls != null) {
099:                    for (URL persistenceUrl : persistenceUrls) {
100:                        String moduleName = persistenceUrl.toExternalForm()
101:                                .replaceFirst("!/?META-INF/persistence.xml$",
102:                                        "");
103:                        moduleName = moduleName.replaceFirst(
104:                                "/?META-INF/persistence.xml$", "/");
105:                        if (moduleName.startsWith("jar:"))
106:                            moduleName = moduleName.substring("jar:".length());
107:                        if (moduleName.startsWith("file:"))
108:                            moduleName = moduleName.substring("file:".length());
109:                        //                if (moduleName1.endsWith("/")) moduleName1 = moduleName1.substring(0, moduleName1.length() - 1);
110:                        try {
111:                            Persistence persistence = JaxbPersistenceFactory
112:                                    .getPersistence(persistenceUrl);
113:                            PersistenceModule persistenceModule = new PersistenceModule(
114:                                    moduleName, persistence);
115:                            persistenceModule.getWatchedResources().add(
116:                                    moduleName);
117:                            if ("file".equals(persistenceUrl.getProtocol())) {
118:                                persistenceModule.getWatchedResources().add(
119:                                        toFilePath(persistenceUrl));
120:                            }
121:                            appModule.getPersistenceModules().add(
122:                                    persistenceModule);
123:                        } catch (Exception e1) {
124:                            DeploymentLoader.logger
125:                                    .error(
126:                                            "Unable to load Persistence Unit from EAR: "
127:                                                    + appModule
128:                                                            .getJarLocation()
129:                                                    + ", module: " + moduleName
130:                                                    + ". Exception: "
131:                                                    + e1.getMessage(), e1);
132:                        }
133:                    }
134:                }
135:
136:                return appModule;
137:
138:            }
139:
140:            private void readOpenejbJar(EjbModule ejbModule)
141:                    throws OpenEJBException {
142:                Source source = getSource(ejbModule.getAltDDs().get(
143:                        "openejb-jar.xml"));
144:
145:                if (source != null) {
146:                    try {
147:                        // Attempt to parse it first as a v3 descriptor
148:                        OpenejbJar openejbJar = JaxbOpenejbJar3.unmarshal(
149:                                OpenejbJar.class, source.get());
150:                        ejbModule.setOpenejbJar(openejbJar);
151:                    } catch (final Exception v3ParsingException) {
152:                        // Attempt to parse it second as a v2 descriptor
153:                        OpenejbJar openejbJar = new OpenejbJar();
154:                        ejbModule.setOpenejbJar(openejbJar);
155:
156:                        try {
157:                            JAXBElement element = (JAXBElement) JaxbOpenejbJar2
158:                                    .unmarshal(OpenejbJarType.class, source
159:                                            .get());
160:                            OpenejbJarType o2 = (OpenejbJarType) element
161:                                    .getValue();
162:                            ejbModule.getAltDDs().put("openejb-jar.xml", o2);
163:
164:                            GeronimoEjbJarType g2 = new GeronimoEjbJarType();
165:
166:                            g2.setEnvironment(o2.getEnvironment());
167:                            g2.setSecurity(o2.getSecurity());
168:                            g2.getService().addAll(o2.getService());
169:                            g2.getMessageDestination().addAll(
170:                                    o2.getMessageDestination());
171:                            g2.getPersistence().addAll(o2.getPersistence());
172:
173:                            for (EnterpriseBean bean : o2.getEnterpriseBeans()) {
174:                                g2.getAbstractNamingEntry().addAll(
175:                                        bean.getAbstractNamingEntry());
176:                                g2.getPersistenceContextRef().addAll(
177:                                        bean.getPersistenceContextRef());
178:                                g2.getPersistenceUnitRef().addAll(
179:                                        bean.getPersistenceUnitRef());
180:                                g2.getEjbLocalRef().addAll(
181:                                        bean.getEjbLocalRef());
182:                                g2.getEjbRef().addAll(bean.getEjbRef());
183:                                g2.getResourceEnvRef().addAll(
184:                                        bean.getResourceEnvRef());
185:                                g2.getResourceRef().addAll(
186:                                        bean.getResourceRef());
187:                                g2.getServiceRef().addAll(bean.getServiceRef());
188:
189:                                if (bean instanceof  RpcBean) {
190:                                    RpcBean rpcBean = (RpcBean) bean;
191:                                    if (rpcBean.getTssLink() != null) {
192:                                        g2.getTssLink().add(
193:                                                new TssLinkType(rpcBean
194:                                                        .getEjbName(), rpcBean
195:                                                        .getTssLink(), rpcBean
196:                                                        .getJndiName()));
197:                                    }
198:                                }
199:
200:                                if (bean instanceof  SessionBeanType) {
201:                                    SessionBeanType sb = (SessionBeanType) bean;
202:                                    WebServiceBindingType b = new WebServiceBindingType();
203:                                    b.setEjbName(sb.getEjbName());
204:                                    b.setWebServiceAddress(sb
205:                                            .getWebServiceAddress());
206:                                    b.setWebServiceVirtualHost(sb
207:                                            .getWebServiceVirtualHost());
208:                                    b.setWebServiceSecurity(sb
209:                                            .getWebServiceSecurity());
210:                                    if (b.containsData()) {
211:                                        g2.getWebServiceBinding().add(b);
212:                                    }
213:                                }
214:                            }
215:
216:                            ejbModule.getAltDDs().put("geronimo-openejb.xml",
217:                                    g2);
218:                        } catch (final Exception v2ParsingException) {
219:                            // Now we have to determine which error to throw; the v3 file exception or the fallback v2 file exception.
220:                            final Exception[] realIssue = { v3ParsingException };
221:
222:                            try {
223:                                SAXParserFactory factory = SAXParserFactory
224:                                        .newInstance();
225:                                factory.setNamespaceAware(true);
226:                                factory.setValidating(false);
227:                                SAXParser parser = factory.newSAXParser();
228:                                parser.parse(source.get(),
229:                                        new DefaultHandler() {
230:                                            public void startElement(
231:                                                    String uri,
232:                                                    String localName,
233:                                                    String qName,
234:                                                    Attributes attributes)
235:                                                    throws SAXException {
236:                                                if (localName
237:                                                        .equals("environment")) {
238:                                                    realIssue[0] = v2ParsingException;
239:                                                    throw new SAXException(
240:                                                            "Throw exception to stop parsing");
241:                                                }
242:                                                if (uri == null)
243:                                                    return;
244:                                                if (uri
245:                                                        .contains("openejb-jar-2.")
246:                                                        || uri
247:                                                                .contains("geronimo.apache.org/xml/ns")) {
248:                                                    realIssue[0] = v2ParsingException;
249:                                                    throw new SAXException(
250:                                                            "Throw exception to stop parsing");
251:                                                }
252:                                            }
253:                                        });
254:                            } catch (Exception dontCare) {
255:                            }
256:
257:                            String filePath = "<error: could not be written>";
258:                            try {
259:                                File tempFile = File.createTempFile(
260:                                        "openejb-jar-", ".xml");
261:                                try {
262:                                    FileOutputStream out = new FileOutputStream(
263:                                            tempFile);
264:                                    InputStream in = source.get();
265:                                    int b = in.read();
266:                                    while (b != -1) {
267:                                        out.write(b);
268:                                        b = in.read();
269:                                    }
270:                                    out.close();
271:                                } catch (IOException e) {
272:                                }
273:                                filePath = tempFile.getAbsolutePath();
274:                            } catch (IOException e) {
275:                            }
276:
277:                            Exception e = realIssue[0];
278:                            if (e instanceof  SAXException) {
279:                                throw new OpenEJBException(
280:                                        "Cannot parse the openejb-jar.xml. Xml content written to: "
281:                                                + filePath, e);
282:                            } else if (e instanceof  JAXBException) {
283:                                throw new OpenEJBException(
284:                                        "Cannot unmarshall the openejb-jar.xml. Xml content written to: "
285:                                                + filePath, e);
286:                            } else if (e instanceof  IOException) {
287:                                throw new OpenEJBException(
288:                                        "Cannot read the openejb-jar.xml.", e);
289:                            } else {
290:                                throw new OpenEJBException(
291:                                        "Encountered unknown error parsing the openejb-jar.xml.",
292:                                        e);
293:                            }
294:                        }
295:                    }
296:                }
297:
298:                Source source1 = getSource(ejbModule.getAltDDs().get(
299:                        "geronimo-openejb.xml"));
300:                if (source1 != null) {
301:                    try {
302:                        GeronimoEjbJarType geronimoEjbJarType = null;
303:                        Object o = JaxbOpenejbJar2.unmarshal(
304:                                GeronimoEjbJarType.class, source1.get());
305:                        if (o instanceof  GeronimoEjbJarType) {
306:                            geronimoEjbJarType = (GeronimoEjbJarType) o;
307:                        } else if (o instanceof  JAXBElement) {
308:                            JAXBElement element = (JAXBElement) o;
309:                            geronimoEjbJarType = (GeronimoEjbJarType) element
310:                                    .getValue();
311:                        }
312:                        if (geronimoEjbJarType != null) {
313:                            Object nested = geronimoEjbJarType.getOpenejbJar();
314:                            if (nested != null && nested instanceof  OpenejbJar) {
315:                                OpenejbJar existingOpenejbJar = ejbModule
316:                                        .getOpenejbJar();
317:                                if (existingOpenejbJar == null
318:                                        || existingOpenejbJar
319:                                                .getEjbDeploymentCount() <= 0) {
320:                                    OpenejbJar openejbJar = (OpenejbJar) nested;
321:                                    ejbModule.getAltDDs().put(
322:                                            "openejb-jar.xml", openejbJar);
323:                                    ejbModule.setOpenejbJar(openejbJar);
324:                                }
325:                            }
326:                            ejbModule.getAltDDs().put("geronimo-openejb.xml",
327:                                    geronimoEjbJarType);
328:                        }
329:                    } catch (Exception e) {
330:                        throw new OpenEJBException(
331:                                "Failed parsing geronimo-openejb.xml", e);
332:                    }
333:                }
334:
335:            }
336:
337:            private void readAppClient(ClientModule clientModule,
338:                    AppModule appModule) throws OpenEJBException {
339:                if (clientModule.getApplicationClient() != null)
340:                    return;
341:
342:                Object data = clientModule.getAltDDs().get(
343:                        "application-client.xml");
344:                if (data instanceof  ApplicationClient) {
345:                    clientModule.setApplicationClient((ApplicationClient) data);
346:                } else if (data instanceof  URL) {
347:                    URL url = (URL) data;
348:                    ApplicationClient applicationClient = readApplicationClient(url);
349:                    clientModule.setApplicationClient(applicationClient);
350:                } else {
351:                    DeploymentLoader.logger
352:                            .warning("No application-client.xml found assuming annotations present: "
353:                                    + appModule.getJarLocation()
354:                                    + ", module: "
355:                                    + clientModule.getModuleId());
356:                    clientModule.setApplicationClient(new ApplicationClient());
357:                }
358:            }
359:
360:            private void readEjbJar(EjbModule ejbModule, AppModule appModule)
361:                    throws OpenEJBException {
362:                if (ejbModule.getEjbJar() != null)
363:                    return;
364:
365:                Object data = ejbModule.getAltDDs().get("ejb-jar.xml");
366:                if (data instanceof  EjbJar) {
367:                    ejbModule.setEjbJar((EjbJar) data);
368:                } else if (data instanceof  URL) {
369:                    URL url = (URL) data;
370:                    EjbJar ejbJar = readEjbJar(url);
371:                    ejbModule.setEjbJar(ejbJar);
372:                } else {
373:                    DeploymentLoader.logger
374:                            .debug("No ejb-jar.xml found assuming annotated beans present: "
375:                                    + appModule.getJarLocation()
376:                                    + ", module: "
377:                                    + ejbModule.getModuleId());
378:                    ejbModule.setEjbJar(new EjbJar());
379:                }
380:            }
381:
382:            private void readConnector(ConnectorModule connectorModule,
383:                    AppModule appModule) throws OpenEJBException {
384:                if (connectorModule.getConnector() != null)
385:                    return;
386:
387:                Object data = connectorModule.getAltDDs().get("ra.xml");
388:                if (data instanceof  Connector) {
389:                    connectorModule.setConnector((Connector) data);
390:                } else if (data instanceof  URL) {
391:                    URL url = (URL) data;
392:                    Connector connector = readConnector(url);
393:                    connectorModule.setConnector(connector);
394:                } else {
395:                    DeploymentLoader.logger
396:                            .debug("No ra.xml found assuming annotated beans present: "
397:                                    + appModule.getJarLocation()
398:                                    + ", module: "
399:                                    + connectorModule.getModuleId());
400:                    connectorModule.setConnector(new Connector());
401:                }
402:            }
403:
404:            private void readWebApp(WebModule webModule, AppModule appModule)
405:                    throws OpenEJBException {
406:                if (webModule.getWebApp() != null)
407:                    return;
408:
409:                Object data = webModule.getAltDDs().get("web.xml");
410:                if (data instanceof  WebApp) {
411:                    webModule.setWebApp((WebApp) data);
412:                } else if (data instanceof  URL) {
413:                    URL url = (URL) data;
414:                    WebApp webApp = readWebApp(url);
415:                    webModule.setWebApp(webApp);
416:                } else {
417:                    DeploymentLoader.logger
418:                            .debug("No web.xml found assuming annotated beans present: "
419:                                    + appModule.getJarLocation()
420:                                    + ", module: "
421:                                    + webModule.getModuleId());
422:                    webModule.setWebApp(new WebApp());
423:                }
424:            }
425:
426:            public static ApplicationClient readApplicationClient(URL url)
427:                    throws OpenEJBException {
428:                ApplicationClient applicationClient;
429:                try {
430:                    applicationClient = (ApplicationClient) JaxbJavaee
431:                            .unmarshal(ApplicationClient.class, url
432:                                    .openStream());
433:                } catch (SAXException e) {
434:                    throw new OpenEJBException(
435:                            "Cannot parse the application-client.xml file: "
436:                                    + url.toExternalForm(), e);
437:                } catch (JAXBException e) {
438:                    throw new OpenEJBException(
439:                            "Cannot unmarshall the application-client.xml file: "
440:                                    + url.toExternalForm(), e);
441:                } catch (IOException e) {
442:                    throw new OpenEJBException(
443:                            "Cannot read the application-client.xml file: "
444:                                    + url.toExternalForm(), e);
445:                } catch (Exception e) {
446:                    throw new OpenEJBException(
447:                            "Encountered unknown error parsing the application-client.xml file: "
448:                                    + url.toExternalForm(), e);
449:                }
450:                return applicationClient;
451:            }
452:
453:            public static EjbJar readEjbJar(URL url) throws OpenEJBException {
454:                try {
455:                    if (isEmptyEjbJar(url))
456:                        return new EjbJar();
457:                    return (EjbJar) JaxbJavaee.unmarshal(EjbJar.class, url
458:                            .openStream());
459:                } catch (SAXException e) {
460:                    throw new OpenEJBException(
461:                            "Cannot parse the ejb-jar.xml file: "
462:                                    + url.toExternalForm(), e);
463:                } catch (JAXBException e) {
464:                    throw new OpenEJBException(
465:                            "Cannot unmarshall the ejb-jar.xml file: "
466:                                    + url.toExternalForm(), e);
467:                } catch (IOException e) {
468:                    throw new OpenEJBException(
469:                            "Cannot read the ejb-jar.xml file: "
470:                                    + url.toExternalForm(), e);
471:                } catch (Exception e) {
472:                    throw new OpenEJBException(
473:                            "Encountered unknown error parsing the ejb-jar.xml file: "
474:                                    + url.toExternalForm(), e);
475:                }
476:            }
477:
478:            private static boolean isEmptyEjbJar(URL url) throws IOException,
479:                    ParserConfigurationException, SAXException {
480:                InputSource inputSource = new InputSource(url.openStream());
481:
482:                SAXParserFactory factory = SAXParserFactory.newInstance();
483:                factory.setNamespaceAware(true);
484:                factory.setValidating(false);
485:                SAXParser parser = factory.newSAXParser();
486:
487:                try {
488:                    parser.parse(inputSource, new DefaultHandler() {
489:                        public void startElement(String uri, String localName,
490:                                String qName, Attributes att)
491:                                throws SAXException {
492:                            if (!localName.equals("ejb-jar"))
493:                                throw new SAXException(localName);
494:                        }
495:
496:                        public InputSource resolveEntity(String publicId,
497:                                String systemId) throws IOException,
498:                                SAXException {
499:                            return new InputSource(new ByteArrayInputStream(
500:                                    new byte[0]));
501:                        }
502:                    });
503:                    return true;
504:                } catch (SAXException e) {
505:                    return false;
506:                }
507:            }
508:
509:            public static Webservices readWebservices(URL url)
510:                    throws OpenEJBException {
511:                Webservices webservices = null;
512:                try {
513:                    webservices = (Webservices) JaxbJavaee.unmarshal(
514:                            Webservices.class, url.openStream());
515:                } catch (SAXException e) {
516:                    throw new OpenEJBException(
517:                            "Cannot parse the webservices.xml file: "
518:                                    + url.toExternalForm(), e);
519:                } catch (JAXBException e) {
520:                    throw new OpenEJBException(
521:                            "Cannot unmarshall the webservices.xml file: "
522:                                    + url.toExternalForm(), e);
523:                } catch (IOException e) {
524:                    throw new OpenEJBException(
525:                            "Cannot read the webservices.xml file: "
526:                                    + url.toExternalForm(), e);
527:                } catch (Exception e) {
528:                    throw new OpenEJBException(
529:                            "Encountered unknown error parsing the webservices.xml file: "
530:                                    + url.toExternalForm(), e);
531:                }
532:                return webservices;
533:            }
534:
535:            public static HandlerChains readHandlerChains(URL url)
536:                    throws OpenEJBException {
537:                HandlerChains handlerChains = null;
538:                try {
539:                    handlerChains = (HandlerChains) JaxbJavaee.unmarshal(
540:                            HandlerChains.class, url.openStream());
541:                } catch (SAXException e) {
542:                    throw new OpenEJBException(
543:                            "Cannot parse the webservices.xml file: "
544:                                    + url.toExternalForm(), e);
545:                } catch (JAXBException e) {
546:                    throw new OpenEJBException(
547:                            "Cannot unmarshall the webservices.xml file: "
548:                                    + url.toExternalForm(), e);
549:                } catch (IOException e) {
550:                    throw new OpenEJBException(
551:                            "Cannot read the webservices.xml file: "
552:                                    + url.toExternalForm(), e);
553:                } catch (Exception e) {
554:                    throw new OpenEJBException(
555:                            "Encountered unknown error parsing the webservices.xml file: "
556:                                    + url.toExternalForm(), e);
557:                }
558:                return handlerChains;
559:            }
560:
561:            public static JavaWsdlMapping readJaxrpcMapping(URL url)
562:                    throws OpenEJBException {
563:                JavaWsdlMapping wsdlMapping = null;
564:                try {
565:                    wsdlMapping = (JavaWsdlMapping) JaxbJavaee.unmarshal(
566:                            JavaWsdlMapping.class, url.openStream());
567:                } catch (SAXException e) {
568:                    throw new OpenEJBException(
569:                            "Cannot parse the JaxRPC mapping file: "
570:                                    + url.toExternalForm(), e);
571:                } catch (JAXBException e) {
572:                    throw new OpenEJBException(
573:                            "Cannot unmarshall the JaxRPC mapping file: "
574:                                    + url.toExternalForm(), e);
575:                } catch (IOException e) {
576:                    throw new OpenEJBException(
577:                            "Cannot read the JaxRPC mapping file: "
578:                                    + url.toExternalForm(), e);
579:                } catch (Exception e) {
580:                    throw new OpenEJBException(
581:                            "Encountered unknown error parsing the JaxRPC mapping file: "
582:                                    + url.toExternalForm(), e);
583:                }
584:                return wsdlMapping;
585:            }
586:
587:            public static Definition readWsdl(URL url) throws OpenEJBException {
588:                Definition definition = null;
589:                try {
590:                    WSDLFactory factory = WSDLFactory.newInstance();
591:                    WSDLReader reader = factory.newWSDLReader();
592:                    reader.setFeature("javax.wsdl.verbose", true);
593:                    reader.setFeature("javax.wsdl.importDocuments", true);
594:                    WsdlResolver wsdlResolver = new WsdlResolver(new URL(url,
595:                            ".").toExternalForm(), new InputSource(url
596:                            .openStream()));
597:                    definition = reader.readWSDL(wsdlResolver);
598:                } catch (IOException e) {
599:                    throw new OpenEJBException("Cannot read the wsdl file: "
600:                            + url.toExternalForm(), e);
601:                } catch (Exception e) {
602:                    throw new OpenEJBException(
603:                            "Encountered unknown error parsing the wsdl file: "
604:                                    + url.toExternalForm(), e);
605:                }
606:                return definition;
607:            }
608:
609:            public static Connector readConnector(URL url)
610:                    throws OpenEJBException {
611:                Connector connector = null;
612:                try {
613:                    connector = (Connector) JaxbJavaee.unmarshal(
614:                            Connector.class, url.openStream());
615:                } catch (SAXException e) {
616:                    throw new OpenEJBException(
617:                            "Cannot parse the web.xml file: "
618:                                    + url.toExternalForm(), e);
619:                } catch (JAXBException e) {
620:                    throw new OpenEJBException(
621:                            "Cannot unmarshall the web.xml file: "
622:                                    + url.toExternalForm(), e);
623:                } catch (IOException e) {
624:                    throw new OpenEJBException("Cannot read the web.xml file: "
625:                            + url.toExternalForm(), e);
626:                } catch (Exception e) {
627:                    throw new OpenEJBException(
628:                            "Encountered unknown error parsing the web.xml file: "
629:                                    + url.toExternalForm(), e);
630:                }
631:                return connector;
632:            }
633:
634:            public static WebApp readWebApp(URL url) throws OpenEJBException {
635:                WebApp webApp = null;
636:                try {
637:                    webApp = (WebApp) JaxbJavaee.unmarshal(WebApp.class, url
638:                            .openStream());
639:                } catch (SAXException e) {
640:                    throw new OpenEJBException(
641:                            "Cannot parse the web.xml file: "
642:                                    + url.toExternalForm(), e);
643:                } catch (JAXBException e) {
644:                    throw new OpenEJBException(
645:                            "Cannot unmarshall the web.xml file: "
646:                                    + url.toExternalForm(), e);
647:                } catch (IOException e) {
648:                    throw new OpenEJBException("Cannot read the web.xml file: "
649:                            + url.toExternalForm(), e);
650:                } catch (Exception e) {
651:                    throw new OpenEJBException(
652:                            "Encountered unknown error parsing the web.xml file: "
653:                                    + url.toExternalForm(), e);
654:                }
655:                return webApp;
656:            }
657:
658:            public static TldTaglib readTldTaglib(URL url)
659:                    throws OpenEJBException {
660:                TldTaglib tldTaglib = null;
661:                try {
662:                    tldTaglib = (TldTaglib) JaxbJavaee.unmarshal(
663:                            TldTaglib.class, url.openStream());
664:                } catch (SAXException e) {
665:                    throw new OpenEJBException(
666:                            "Cannot parse the JSP tag library definition file: "
667:                                    + url.toExternalForm(), e);
668:                } catch (JAXBException e) {
669:                    throw new OpenEJBException(
670:                            "Cannot unmarshall the JSP tag library definition file: "
671:                                    + url.toExternalForm(), e);
672:                } catch (IOException e) {
673:                    throw new OpenEJBException(
674:                            "Cannot read the JSP tag library definition file: "
675:                                    + url.toExternalForm(), e);
676:                } catch (Exception e) {
677:                    throw new OpenEJBException(
678:                            "Encountered unknown error parsing the JSP tag library definition file: "
679:                                    + url.toExternalForm(), e);
680:                }
681:                return tldTaglib;
682:            }
683:
684:            private Source getSource(Object o) {
685:                if (o instanceof  URL) {
686:                    return new UrlSource((URL) o);
687:                }
688:
689:                if (o instanceof  String) {
690:                    return new StringSource((String) o);
691:                }
692:
693:                return null;
694:            }
695:
696:            public static abstract class Source {
697:                abstract InputStream get() throws IOException;
698:            }
699:
700:            public static class UrlSource extends Source {
701:                private final URL url;
702:
703:                public UrlSource(URL url) {
704:                    this .url = url;
705:                }
706:
707:                InputStream get() throws IOException {
708:                    return url.openStream();
709:                }
710:            }
711:
712:            public static class StringSource extends Source {
713:                private byte[] bytes;
714:
715:                public StringSource(String content) {
716:                    bytes = content.getBytes();
717:                }
718:
719:                InputStream get() throws IOException {
720:                    return new ByteArrayInputStream(bytes);
721:                }
722:            }
723:
724:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.