Source Code Cross Referenced for WSDescriptorParser.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » webservices » builder » 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 » EJB Server geronimo » plugins » org.apache.geronimo.webservices.builder 
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.geronimo.webservices.builder;
017:
018:        import java.io.IOException;
019:        import java.io.InputStream;
020:        import java.lang.reflect.Method;
021:        import java.math.BigDecimal;
022:        import java.math.BigInteger;
023:        import java.net.URI;
024:        import java.net.URL;
025:        import java.util.ArrayList;
026:        import java.util.Calendar;
027:        import java.util.HashMap;
028:        import java.util.List;
029:        import java.util.Map;
030:        import java.util.jar.JarFile;
031:        import java.util.zip.ZipEntry;
032:
033:        import javax.wsdl.Definition;
034:        import javax.wsdl.Operation;
035:        import javax.xml.namespace.QName;
036:        import javax.xml.rpc.handler.HandlerInfo;
037:        import javax.xml.rpc.holders.BigDecimalHolder;
038:        import javax.xml.rpc.holders.BigIntegerHolder;
039:        import javax.xml.rpc.holders.BooleanHolder;
040:        import javax.xml.rpc.holders.BooleanWrapperHolder;
041:        import javax.xml.rpc.holders.ByteArrayHolder;
042:        import javax.xml.rpc.holders.ByteHolder;
043:        import javax.xml.rpc.holders.ByteWrapperHolder;
044:        import javax.xml.rpc.holders.CalendarHolder;
045:        import javax.xml.rpc.holders.DoubleHolder;
046:        import javax.xml.rpc.holders.DoubleWrapperHolder;
047:        import javax.xml.rpc.holders.FloatHolder;
048:        import javax.xml.rpc.holders.FloatWrapperHolder;
049:        import javax.xml.rpc.holders.IntHolder;
050:        import javax.xml.rpc.holders.IntegerWrapperHolder;
051:        import javax.xml.rpc.holders.LongHolder;
052:        import javax.xml.rpc.holders.LongWrapperHolder;
053:        import javax.xml.rpc.holders.ObjectHolder;
054:        import javax.xml.rpc.holders.QNameHolder;
055:        import javax.xml.rpc.holders.ShortHolder;
056:        import javax.xml.rpc.holders.ShortWrapperHolder;
057:        import javax.xml.rpc.holders.StringHolder;
058:
059:        import org.apache.geronimo.common.DeploymentException;
060:        import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
061:        import org.apache.geronimo.kernel.ClassLoading;
062:        import org.apache.geronimo.xbeans.j2ee.ExceptionMappingType;
063:        import org.apache.geronimo.xbeans.j2ee.JavaWsdlMappingDocument;
064:        import org.apache.geronimo.xbeans.j2ee.JavaWsdlMappingType;
065:        import org.apache.geronimo.xbeans.j2ee.PackageMappingType;
066:        import org.apache.geronimo.xbeans.j2ee.ParamValueType;
067:        import org.apache.geronimo.xbeans.j2ee.PortComponentHandlerType;
068:        import org.apache.geronimo.xbeans.j2ee.PortComponentType;
069:        import org.apache.geronimo.xbeans.j2ee.ServiceEndpointInterfaceMappingType;
070:        import org.apache.geronimo.xbeans.j2ee.ServiceEndpointMethodMappingType;
071:        import org.apache.geronimo.xbeans.j2ee.ServiceImplBeanType;
072:        import org.apache.geronimo.xbeans.j2ee.WebserviceDescriptionType;
073:        import org.apache.geronimo.xbeans.j2ee.WebservicesDocument;
074:        import org.apache.geronimo.xbeans.j2ee.WebservicesType;
075:        import org.apache.geronimo.xbeans.j2ee.XsdQNameType;
076:        import org.apache.xmlbeans.XmlCursor;
077:        import org.apache.xmlbeans.XmlException;
078:        import org.apache.xmlbeans.XmlObject;
079:
080:        /**
081:         * @version $Rev: 561958 $ $Date: 2007-08-01 14:20:09 -0700 (Wed, 01 Aug 2007) $
082:         */
083:        public class WSDescriptorParser {
084:
085:            public static JavaWsdlMappingType readJaxrpcMapping(
086:                    JarFile moduleFile, URI jaxrpcMappingURI)
087:                    throws DeploymentException {
088:                String jaxrpcMappingPath = jaxrpcMappingURI.toString();
089:                return readJaxrpcMapping(moduleFile, jaxrpcMappingPath);
090:            }
091:
092:            public static JavaWsdlMappingType readJaxrpcMapping(
093:                    JarFile moduleFile, String jaxrpcMappingPath)
094:                    throws DeploymentException {
095:                JavaWsdlMappingType mapping;
096:                InputStream jaxrpcInputStream;
097:                try {
098:                    ZipEntry zipEntry = moduleFile.getEntry(jaxrpcMappingPath);
099:                    if (zipEntry == null) {
100:                        throw new DeploymentException(
101:                                "The JAX-RPC mapping file "
102:                                        + jaxrpcMappingPath
103:                                        + " specified in webservices.xml could not be found.");
104:                    }
105:                    jaxrpcInputStream = moduleFile.getInputStream(zipEntry);
106:                } catch (IOException e) {
107:                    throw new DeploymentException(
108:                            "Could not open stream to jaxrpc mapping document",
109:                            e);
110:                }
111:                JavaWsdlMappingDocument mappingDocument;
112:                try {
113:                    mappingDocument = JavaWsdlMappingDocument.Factory
114:                            .parse(jaxrpcInputStream);
115:                } catch (XmlException e) {
116:                    throw new DeploymentException(
117:                            "Could not parse jaxrpc mapping document", e);
118:                } catch (IOException e) {
119:                    throw new DeploymentException(
120:                            "Could not read jaxrpc mapping document", e);
121:                }
122:                mapping = mappingDocument.getJavaWsdlMapping();
123:                return mapping;
124:            }
125:
126:            public static Map<QName, ExceptionMappingType> getExceptionMap(
127:                    JavaWsdlMappingType mapping) {
128:                Map<QName, ExceptionMappingType> exceptionMap = new HashMap<QName, ExceptionMappingType>();
129:                if (mapping != null) {
130:                    ExceptionMappingType[] exceptionMappings = mapping
131:                            .getExceptionMappingArray();
132:                    for (ExceptionMappingType exceptionMapping : exceptionMappings) {
133:                        QName exceptionMessageQName = exceptionMapping
134:                                .getWsdlMessage().getQNameValue();
135:                        exceptionMap.put(exceptionMessageQName,
136:                                exceptionMapping);
137:                    }
138:                }
139:                return exceptionMap;
140:            }
141:
142:            public static String getPackageFromNamespace(String namespace,
143:                    JavaWsdlMappingType mapping) throws DeploymentException {
144:                PackageMappingType[] packageMappings = mapping
145:                        .getPackageMappingArray();
146:                for (PackageMappingType packageMapping : packageMappings) {
147:                    if (namespace.equals(packageMapping.getNamespaceURI()
148:                            .getStringValue().trim())) {
149:                        return packageMapping.getPackageType().getStringValue()
150:                                .trim();
151:                    }
152:                }
153:                throw new DeploymentException("Namespace " + namespace
154:                        + " was not mapped in jaxrpc mapping file");
155:            }
156:
157:            private static final Map<Class, Class> rpcHolderClasses = new HashMap<Class, Class>();
158:
159:            static {
160:                rpcHolderClasses.put(BigDecimal.class, BigDecimalHolder.class);
161:                rpcHolderClasses.put(BigInteger.class, BigIntegerHolder.class);
162:                rpcHolderClasses.put(boolean.class, BooleanHolder.class);
163:                rpcHolderClasses.put(Boolean.class, BooleanWrapperHolder.class);
164:                rpcHolderClasses.put(byte[].class, ByteArrayHolder.class);
165:                rpcHolderClasses.put(byte.class, ByteHolder.class);
166:                rpcHolderClasses.put(Byte.class, ByteWrapperHolder.class);
167:                rpcHolderClasses.put(Calendar.class, CalendarHolder.class);
168:                rpcHolderClasses.put(double.class, DoubleHolder.class);
169:                rpcHolderClasses.put(Double.class, DoubleWrapperHolder.class);
170:                rpcHolderClasses.put(float.class, FloatHolder.class);
171:                rpcHolderClasses.put(Float.class, FloatWrapperHolder.class);
172:                rpcHolderClasses.put(int.class, IntHolder.class);
173:                rpcHolderClasses.put(Integer.class, IntegerWrapperHolder.class);
174:                rpcHolderClasses.put(long.class, LongHolder.class);
175:                rpcHolderClasses.put(Long.class, LongWrapperHolder.class);
176:                rpcHolderClasses.put(Object.class, ObjectHolder.class);
177:                rpcHolderClasses.put(QName.class, QNameHolder.class);
178:                rpcHolderClasses.put(short.class, ShortHolder.class);
179:                rpcHolderClasses.put(Short.class, ShortWrapperHolder.class);
180:                rpcHolderClasses.put(String.class, StringHolder.class);
181:            }
182:
183:            public static Class getHolderType(String paramJavaTypeName,
184:                    boolean isInOnly, QName typeQName, boolean isComplexType,
185:                    JavaWsdlMappingType mapping, ClassLoader classLoader)
186:                    throws DeploymentException {
187:                Class paramJavaType;
188:                if (isInOnly) {
189:                    //IN parameters just use their own type
190:                    try {
191:                        paramJavaType = ClassLoading.loadClass(
192:                                paramJavaTypeName, classLoader);
193:                    } catch (ClassNotFoundException e) {
194:                        throw new DeploymentException(
195:                                "could not load parameter type", e);
196:                    }
197:                    return paramJavaType;
198:                } else {
199:                    //INOUT and OUT parameters use holders.  See jaxrpc spec 4.3.5
200:                    String holderName;
201:                    if (isComplexType) {
202:                        //complex types get mapped:
203:                        //package is determined from the namespace to package map + ".holders"
204:                        //class name is the complex type QNMAne local part + "Holder", with the initial character uppercased.
205:                        String namespace = typeQName.getNamespaceURI();
206:                        String packageName = WSDescriptorParser
207:                                .getPackageFromNamespace(namespace, mapping);
208:                        StringBuffer buf = new StringBuffer(packageName
209:                                .length()
210:                                + typeQName.getLocalPart().length() + 14);
211:                        buf.append(packageName).append(".holders.").append(
212:                                typeQName.getLocalPart()).append("Holder");
213:                        buf.setCharAt(packageName.length() + 9,
214:                                Character.toUpperCase(typeQName.getLocalPart()
215:                                        .charAt(0)));
216:                        holderName = buf.toString();
217:                    } else {
218:                        //see if it is in the primitive type and simple type mapping
219:                        try {
220:                            paramJavaType = ClassLoading.loadClass(
221:                                    paramJavaTypeName, classLoader);
222:                        } catch (ClassNotFoundException e) {
223:                            throw new DeploymentException(
224:                                    "could not load parameter type", e);
225:                        }
226:                        Class holder = rpcHolderClasses.get(paramJavaType);
227:                        if (holder != null) {
228:                            try {
229:                                //TODO use class names in map or make sure we are in the correct classloader to start with.
230:                                holder = ClassLoading.loadClass(holder
231:                                        .getName(), classLoader);
232:                            } catch (ClassNotFoundException e) {
233:                                throw new DeploymentException(
234:                                        "could not load holder type in correct classloader",
235:                                        e);
236:                            }
237:                            return holder;
238:                        }
239:                        //Otherwise, the holder must be in:
240:                        //package same as type's package + ".holders"
241:                        //class name same as type name + "Holder"
242:                        String paramTypeName = paramJavaType.getName();
243:                        StringBuffer buf = new StringBuffer(paramTypeName
244:                                .length() + 14);
245:                        int dot = paramTypeName.lastIndexOf(".");
246:                        //foo.Bar >>> foo.holders.BarHolder
247:                        buf.append(paramTypeName.substring(0, dot)).append(
248:                                ".holders")
249:                                .append(paramTypeName.substring(dot)).append(
250:                                        "Holder");
251:                        holderName = buf.toString();
252:                    }
253:                    try {
254:                        return ClassLoading.loadClass(holderName, classLoader);
255:                    } catch (ClassNotFoundException e) {
256:                        throw new DeploymentException(
257:                                "Could not load holder class", e);
258:                    }
259:                }
260:            }
261:
262:            public static ServiceEndpointMethodMappingType getMethodMappingForOperation(
263:                    String operationName,
264:                    ServiceEndpointMethodMappingType[] methodMappings)
265:                    throws DeploymentException {
266:                for (ServiceEndpointMethodMappingType methodMapping : methodMappings) {
267:                    if (operationName.equals(methodMapping.getWsdlOperation()
268:                            .getStringValue())) {
269:                        return methodMapping;
270:                    }
271:                }
272:                // Build list of available operations for exception
273:                StringBuffer availOps = new StringBuffer(128);
274:                for (int i = 0; i < methodMappings.length; i++) {
275:                    if (i != 0)
276:                        availOps.append(",");
277:                    availOps.append(methodMappings[i].getWsdlOperation()
278:                            .getStringValue());
279:                }
280:                throw new DeploymentException(
281:                        "No method found for operation named '" + operationName
282:                                + "'. Available operations: " + availOps);
283:            }
284:
285:            public static ServiceEndpointInterfaceMappingType getServiceEndpointInterfaceMapping(
286:                    ServiceEndpointInterfaceMappingType[] endpointMappings,
287:                    QName portTypeQName) throws DeploymentException {
288:                for (ServiceEndpointInterfaceMappingType endpointMapping : endpointMappings) {
289:                    QName testPortQName = endpointMapping.getWsdlPortType()
290:                            .getQNameValue();
291:                    if (portTypeQName.equals(testPortQName)) {
292:                        return endpointMapping;
293:                    }
294:                }
295:                throw new DeploymentException(
296:                        "Could not find service endpoint interface for port named "
297:                                + portTypeQName);
298:            }
299:
300:            public static javax.wsdl.Service getService(QName serviceQName,
301:                    Definition definition) throws DeploymentException {
302:                javax.wsdl.Service service;
303:                if (serviceQName != null) {
304:                    service = definition.getService(serviceQName);
305:                } else {
306:                    Map services = definition.getServices();
307:                    if (services.size() != 1) {
308:                        throw new DeploymentException(
309:                                "no serviceQName supplied, and there are "
310:                                        + services.size() + " services");
311:                    }
312:                    service = (javax.wsdl.Service) services.values().iterator()
313:                            .next();
314:                }
315:                if (service == null) {
316:                    throw new DeploymentException(
317:                            "No service wsdl for supplied service qname "
318:                                    + serviceQName);
319:                }
320:                return service;
321:            }
322:
323:            public static Method getMethodForOperation(
324:                    Class serviceEndpointInterface, Operation operation)
325:                    throws DeploymentException {
326:                Method[] methods = serviceEndpointInterface.getMethods();
327:                String opName = operation.getName();
328:                Method found = null;
329:                for (Method method : methods) {
330:                    if (method.getName().equals(opName)) {
331:                        if (found != null) {
332:                            throw new DeploymentException(
333:                                    "Overloaded methods are not allowed in lightweight mappings");
334:                        }
335:                        found = method;
336:                    }
337:                }
338:                if (found == null) {
339:                    throw new DeploymentException(
340:                            "No method found for operation named " + opName);
341:                }
342:                return found;
343:            }
344:
345:            /**
346:             * Parses a webservice.xml file and returns a map PortInfo instances indexed by the
347:             * corresponding ejb-link or servlet-link element .
348:             *
349:             * @param webservicesType
350:             * @param moduleFile
351:             * @param isEJB
352:             * @param servletLocations
353:             * @return
354:             * @throws org.apache.geronimo.common.DeploymentException
355:             *
356:             */
357:            public static Map<String, PortInfo> parseWebServiceDescriptor(
358:                    WebservicesType webservicesType, JarFile moduleFile,
359:                    boolean isEJB, Map servletLocations)
360:                    throws DeploymentException {
361:                Map<String, PortInfo> portMap = new HashMap<String, PortInfo>();
362:                WebserviceDescriptionType[] webserviceDescriptions = webservicesType
363:                        .getWebserviceDescriptionArray();
364:                SharedPortInfo sharedPortInfo;
365:                for (WebserviceDescriptionType webserviceDescription : webserviceDescriptions) {
366:                    String wsdlLocation = webserviceDescription.getWsdlFile()
367:                            .getStringValue().trim();
368:                    String jaxrpcMappingFile = webserviceDescription
369:                            .getJaxrpcMappingFile().getStringValue().trim();
370:
371:                    sharedPortInfo = new SharedPortInfo(wsdlLocation,
372:                            jaxrpcMappingFile, DescriptorVersion.J2EE);
373:
374:                    PortComponentType[] portComponents = webserviceDescription
375:                            .getPortComponentArray();
376:                    for (PortComponentType portComponent : portComponents) {
377:                        String portComponentName = portComponent
378:                                .getPortComponentName().getStringValue().trim();
379:                        QName portQName = portComponent.getWsdlPort()
380:                                .getQNameValue();
381:                        String seiInterfaceName = portComponent
382:                                .getServiceEndpointInterface().getStringValue()
383:                                .trim();
384:                        ServiceImplBeanType serviceImplBeanType = portComponent
385:                                .getServiceImplBean();
386:                        if (isEJB == serviceImplBeanType.isSetServletLink()) {
387:                            throw new DeploymentException(
388:                                    "Wrong kind of web service described in web service descriptor: expected "
389:                                            + (isEJB ? "EJB" : "POJO(Servlet)"));
390:                        }
391:                        String linkName;
392:                        String servletLocation;
393:                        if (serviceImplBeanType.isSetServletLink()) {
394:                            linkName = serviceImplBeanType.getServletLink()
395:                                    .getStringValue().trim();
396:                            servletLocation = (String) servletLocations
397:                                    .get(linkName);
398:                            if (servletLocation == null) {
399:                                throw new DeploymentException(
400:                                        "No servlet mapping for port "
401:                                                + portComponentName);
402:                            }
403:                        } else {
404:                            linkName = serviceImplBeanType.getEjbLink()
405:                                    .getStringValue().trim();
406:                            servletLocation = (String) servletLocations
407:                                    .get(linkName);
408:                        }
409:                        PortComponentHandlerType[] handlers = portComponent
410:                                .getHandlerArray();
411:
412:                        PortInfo portInfo = new PortInfo(sharedPortInfo,
413:                                portComponentName, portQName, seiInterfaceName,
414:                                handlers, servletLocation);
415:
416:                        if (portMap.put(linkName, portInfo) != null) {
417:                            throw new DeploymentException(
418:                                    "Ambiguous description of port associated with j2ee component "
419:                                            + linkName);
420:                        }
421:                    }
422:                }
423:                return portMap;
424:            }
425:
426:            public static Map<String, PortInfo> parseWebServiceDescriptor(
427:                    org.apache.geronimo.xbeans.javaee.WebservicesType webservicesType,
428:                    JarFile moduleFile, boolean isEJB, Map servletLocations)
429:                    throws DeploymentException {
430:                Map<String, PortInfo> portMap = new HashMap<String, PortInfo>();
431:                org.apache.geronimo.xbeans.javaee.WebserviceDescriptionType[] webserviceDescriptions = webservicesType
432:                        .getWebserviceDescriptionArray();
433:                SharedPortInfo sharedPortInfo;
434:                for (org.apache.geronimo.xbeans.javaee.WebserviceDescriptionType webserviceDescription : webserviceDescriptions) {
435:                    String wsdlLocation = null;
436:                    if (webserviceDescription.isSetWsdlFile()) {
437:                        wsdlLocation = webserviceDescription.getWsdlFile()
438:                                .getStringValue().trim();
439:                    }
440:                    String jaxrpcMappingFile = null;
441:                    if (webserviceDescription.isSetJaxrpcMappingFile()) {
442:                        jaxrpcMappingFile = webserviceDescription
443:                                .getJaxrpcMappingFile().getStringValue().trim();
444:                    }
445:
446:                    sharedPortInfo = new SharedPortInfo(wsdlLocation,
447:                            jaxrpcMappingFile, DescriptorVersion.JAVAEE);
448:
449:                    org.apache.geronimo.xbeans.javaee.PortComponentType[] portComponents = webserviceDescription
450:                            .getPortComponentArray();
451:                    for (org.apache.geronimo.xbeans.javaee.PortComponentType portComponent : portComponents) {
452:                        String portComponentName = portComponent
453:                                .getPortComponentName().getStringValue().trim();
454:                        QName portQName = null;
455:                        if (portComponent.isSetWsdlPort()) {
456:                            portQName = portComponent.getWsdlPort()
457:                                    .getQNameValue();
458:                        }
459:                        String seiInterfaceName = null;
460:                        if (portComponent.isSetServiceEndpointInterface()) {
461:                            seiInterfaceName = portComponent
462:                                    .getServiceEndpointInterface()
463:                                    .getStringValue().trim();
464:                        }
465:                        org.apache.geronimo.xbeans.javaee.ServiceImplBeanType serviceImplBeanType = portComponent
466:                                .getServiceImplBean();
467:                        if (isEJB == serviceImplBeanType.isSetServletLink()) {
468:                            throw new DeploymentException(
469:                                    "Wrong kind of web service described in web service descriptor: expected "
470:                                            + (isEJB ? "EJB" : "POJO(Servlet)"));
471:                        }
472:                        String linkName;
473:                        String servletLocation;
474:                        if (serviceImplBeanType.isSetServletLink()) {
475:                            linkName = serviceImplBeanType.getServletLink()
476:                                    .getStringValue().trim();
477:                            servletLocation = (String) servletLocations
478:                                    .get(linkName);
479:                            if (servletLocation == null) {
480:                                throw new DeploymentException(
481:                                        "No servlet mapping for port "
482:                                                + portComponentName);
483:                            }
484:                        } else {
485:                            linkName = serviceImplBeanType.getEjbLink()
486:                                    .getStringValue().trim();
487:                            servletLocation = (String) servletLocations
488:                                    .get(linkName);
489:                        }
490:                        PortComponentHandlerType[] handlers = null;
491:                        if (portComponent.getHandlerArray() != null) {
492:                            handlers = new PortComponentHandlerType[portComponent
493:                                    .getHandlerArray().length];
494:                            for (int i = 0; i < portComponent.getHandlerArray().length; i++) {
495:                                handlers[i] = (PortComponentHandlerType) portComponent
496:                                        .getHandlerArray()[i]
497:                                        .changeType(PortComponentHandlerType.type);
498:                            }
499:                        }
500:
501:                        PortInfo portInfo = new PortInfo(sharedPortInfo,
502:                                portComponentName, portQName, seiInterfaceName,
503:                                handlers, servletLocation);
504:
505:                        if (portMap.put(linkName, portInfo) != null) {
506:                            throw new DeploymentException(
507:                                    "Ambiguous description of port associated with j2ee component "
508:                                            + linkName);
509:                        }
510:                    }
511:                }
512:                return portMap;
513:            }
514:
515:            public static Map<String, PortInfo> parseWebServiceDescriptor(
516:                    URL wsDDUrl, JarFile moduleFile, boolean isEJB,
517:                    Map servletLocations) throws DeploymentException {
518:                XmlObject webservicesType = getWebservicesType(wsDDUrl);
519:                if (webservicesType instanceof  WebservicesType) {
520:                    WebservicesType webServices = (WebservicesType) webservicesType;
521:                    return parseWebServiceDescriptor(webServices, moduleFile,
522:                            isEJB, servletLocations);
523:                } else if (webservicesType instanceof  org.apache.geronimo.xbeans.javaee.WebservicesType) {
524:                    org.apache.geronimo.xbeans.javaee.WebservicesType webServices = (org.apache.geronimo.xbeans.javaee.WebservicesType) webservicesType;
525:                    return parseWebServiceDescriptor(webServices, moduleFile,
526:                            isEJB, servletLocations);
527:                } else {
528:                    return null;
529:                }
530:            }
531:
532:            static XmlObject getWebservicesType(URL wsDDUrl)
533:                    throws DeploymentException {
534:                try {
535:                    XmlObject webservicesDocumentUntyped = XmlObject.Factory
536:                            .parse(wsDDUrl);
537:                    XmlCursor cursor = webservicesDocumentUntyped.newCursor();
538:                    try {
539:                        if (cursor.currentTokenType() != XmlCursor.TokenType.START) {
540:                            while (cursor.toNextToken() != XmlCursor.TokenType.START) {
541:                            }
542:                        }
543:                        QName qname = cursor.getName();
544:                        if (WebservicesDocument.type.getDocumentElementName()
545:                                .equals(qname)) {
546:                            return getJ2EEWebServices(webservicesDocumentUntyped);
547:                        } else if (org.apache.geronimo.xbeans.javaee.WebservicesDocument.type
548:                                .getDocumentElementName().equals(qname)) {
549:                            return getJavaEEWebServices(webservicesDocumentUntyped);
550:                        } else {
551:                            return null;
552:                        }
553:                    } finally {
554:                        cursor.dispose();
555:                    }
556:                } catch (XmlException e) {
557:                    throw new DeploymentException(
558:                            "Could not read descriptor document", e);
559:                } catch (IOException e) {
560:                    return null;
561:                }
562:            }
563:
564:            private static XmlObject getJ2EEWebServices(
565:                    XmlObject webservicesDocumentUntyped) throws XmlException {
566:                WebservicesDocument webservicesDocument;
567:                if (webservicesDocumentUntyped instanceof  WebservicesDocument) {
568:                    webservicesDocument = (WebservicesDocument) webservicesDocumentUntyped;
569:                } else {
570:                    webservicesDocument = (WebservicesDocument) webservicesDocumentUntyped
571:                            .changeType(WebservicesDocument.type);
572:                }
573:                XmlBeansUtil.validateDD(webservicesDocument);
574:                return webservicesDocument.getWebservices();
575:            }
576:
577:            private static XmlObject getJavaEEWebServices(
578:                    XmlObject webservicesDocumentUntyped) throws XmlException {
579:                org.apache.geronimo.xbeans.javaee.WebservicesDocument webservicesDocument;
580:                if (webservicesDocumentUntyped instanceof  org.apache.geronimo.xbeans.javaee.WebservicesDocument) {
581:                    webservicesDocument = (org.apache.geronimo.xbeans.javaee.WebservicesDocument) webservicesDocumentUntyped;
582:                } else {
583:                    webservicesDocument = (org.apache.geronimo.xbeans.javaee.WebservicesDocument) webservicesDocumentUntyped
584:                            .changeType(org.apache.geronimo.xbeans.javaee.WebservicesDocument.type);
585:                }
586:                XmlBeansUtil.validateDD(webservicesDocument);
587:                return webservicesDocument.getWebservices();
588:            }
589:
590:            public static List<HandlerInfo> createHandlerInfoList(
591:                    PortComponentHandlerType[] handlers, ClassLoader classLoader)
592:                    throws DeploymentException {
593:                List<HandlerInfo> list = new ArrayList<HandlerInfo>();
594:                for (PortComponentHandlerType handler : handlers) {
595:                    // Get handler class
596:                    Class handlerClass;
597:                    String className = handler.getHandlerClass()
598:                            .getStringValue().trim();
599:                    try {
600:                        handlerClass = classLoader.loadClass(className);
601:                    } catch (ClassNotFoundException e) {
602:                        throw new DeploymentException(
603:                                "Unable to load handler class: " + className, e);
604:                    }
605:
606:                    // config data for the handler
607:                    Map<String, String> config = new HashMap<String, String>();
608:                    ParamValueType[] paramValues = handler.getInitParamArray();
609:                    for (ParamValueType paramValue : paramValues) {
610:                        String paramName = paramValue.getParamName()
611:                                .getStringValue().trim();
612:                        String paramStringValue = paramValue.getParamValue()
613:                                .getStringValue().trim();
614:                        config.put(paramName, paramStringValue);
615:                    }
616:
617:                    // QName array of headers it processes
618:                    XsdQNameType[] soapHeaderQNames = handler
619:                            .getSoapHeaderArray();
620:                    QName[] headers = new QName[soapHeaderQNames.length];
621:                    for (int j = 0; j < soapHeaderQNames.length; j++) {
622:                        XsdQNameType soapHeaderQName = soapHeaderQNames[j];
623:                        headers[j] = soapHeaderQName.getQNameValue();
624:                    }
625:
626:                    list.add(new HandlerInfo(handlerClass, config, headers));
627:                }
628:                return list;
629:            }
630:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.