KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > axis > builder > AxisBuilder


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.axis.builder;
18
19 import java.lang.reflect.Method JavaDoc;
20 import java.net.MalformedURLException JavaDoc;
21 import java.net.URI JavaDoc;
22 import java.net.URISyntaxException JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.util.Collections JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.Set JavaDoc;
33 import java.util.jar.JarFile JavaDoc;
34
35 import javax.wsdl.Binding;
36 import javax.wsdl.BindingOperation;
37 import javax.wsdl.Definition;
38 import javax.wsdl.Operation;
39 import javax.wsdl.Port;
40 import javax.wsdl.PortType;
41 import javax.wsdl.extensions.soap.SOAPAddress;
42 import javax.wsdl.extensions.soap.SOAPBinding;
43 import javax.xml.namespace.QName JavaDoc;
44 import javax.xml.rpc.handler.HandlerInfo JavaDoc;
45
46 import org.apache.axis.constants.Style;
47 import org.apache.axis.description.JavaServiceDesc;
48 import org.apache.axis.handlers.HandlerInfoChainFactory;
49 import org.apache.axis.handlers.soap.SOAPService;
50 import org.apache.axis.providers.java.RPCProvider;
51 import org.apache.axis.soap.SOAPConstants;
52 import org.apache.geronimo.axis.client.AxisServiceReference;
53 import org.apache.geronimo.axis.client.OperationInfo;
54 import org.apache.geronimo.axis.client.SEIFactory;
55 import org.apache.geronimo.axis.client.SEIFactoryImpl;
56 import org.apache.geronimo.axis.server.AxisWebServiceContainer;
57 import org.apache.geronimo.axis.server.POJOProvider;
58 import org.apache.geronimo.axis.server.ServiceInfo;
59 import org.apache.geronimo.common.DeploymentException;
60 import org.apache.geronimo.gbean.GBeanData;
61 import org.apache.geronimo.gbean.GBeanInfo;
62 import org.apache.geronimo.gbean.GBeanInfoBuilder;
63 import org.apache.geronimo.gbean.AbstractName;
64 import org.apache.geronimo.j2ee.deployment.Module;
65 import org.apache.geronimo.j2ee.deployment.WebServiceBuilder;
66 import org.apache.geronimo.j2ee.deployment.HandlerInfoInfo;
67 import org.apache.geronimo.j2ee.deployment.WebModule;
68 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
69 import org.apache.geronimo.xbeans.geronimo.naming.GerPortCompletionType;
70 import org.apache.geronimo.xbeans.geronimo.naming.GerPortType;
71 import org.apache.geronimo.xbeans.geronimo.naming.GerServiceCompletionType;
72 import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType;
73 import org.apache.geronimo.xbeans.j2ee.JavaWsdlMappingType;
74 import org.apache.geronimo.xbeans.j2ee.JavaXmlTypeMappingType;
75 import org.apache.geronimo.xbeans.j2ee.ServiceEndpointInterfaceMappingType;
76 import org.apache.geronimo.xbeans.j2ee.ServiceEndpointMethodMappingType;
77 import org.apache.geronimo.deployment.util.DeploymentUtil;
78 import org.apache.geronimo.deployment.DeploymentContext;
79 import org.apache.geronimo.deployment.service.EnvironmentBuilder;
80 import org.apache.geronimo.webservices.SerializableWebServiceContainerFactoryGBean;
81 import org.apache.geronimo.webservices.builder.PortInfo;
82 import org.apache.geronimo.webservices.builder.SchemaInfoBuilder;
83 import org.apache.geronimo.webservices.builder.WSDescriptorParser;
84 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
85 import org.apache.geronimo.kernel.repository.Environment;
86
87 /**
88  * @version $Rev: 479496 $ $Date: 2006-11-26 20:57:00 -0500 (Sun, 26 Nov 2006) $
89  */

90 public class AxisBuilder implements WebServiceBuilder {
91
92     private static final SOAPConstants SOAP_VERSION = SOAPConstants.SOAP11_CONSTANTS;
93
94     private final Environment defaultEnvironment;
95     private static final String JavaDoc KEY = AxisBuilder.class.getName();
96
97     public AxisBuilder() {
98         defaultEnvironment = null;
99     }
100
101     public AxisBuilder(Environment defaultEnvironment) {
102         this.defaultEnvironment = defaultEnvironment;
103     }
104
105
106     public void findWebServices(JarFile JavaDoc moduleFile, boolean isEJB, Map JavaDoc servletLocations, Environment environment, Map JavaDoc sharedContext) throws DeploymentException {
107         final String JavaDoc path = isEJB ? "META-INF/webservices.xml" : "WEB-INF/webservices.xml";
108         try {
109             URL JavaDoc wsDDUrl = DeploymentUtil.createJarURL(moduleFile, path);
110             Map JavaDoc portMap = WSDescriptorParser.parseWebServiceDescriptor(wsDDUrl, moduleFile, isEJB, servletLocations);
111             if (portMap != null) {
112                 if (defaultEnvironment != null) {
113                     EnvironmentBuilder.mergeEnvironments(environment, defaultEnvironment);
114                 }
115                 sharedContext.put(KEY, portMap);
116             }
117         } catch (MalformedURLException JavaDoc e) {
118             // The webservices.xml file doesn't exist.
119
}
120     }
121
122     public boolean configurePOJO(GBeanData targetGBean, String JavaDoc servletName, Module module, String JavaDoc seiClassName, DeploymentContext context) throws DeploymentException {
123         ClassLoader JavaDoc cl = context.getClassLoader();
124         Map JavaDoc sharedContext = ((WebModule) module).getSharedContext();
125         Map JavaDoc portInfoMap = (Map JavaDoc) sharedContext.get(KEY);
126         PortInfo portInfo = (PortInfo) portInfoMap.get(servletName);
127         if (portInfo == null) {
128             //not ours
129
return false;
130         }
131         ServiceInfo serviceInfo = AxisServiceBuilder.createServiceInfo(portInfo, cl);
132         JavaServiceDesc serviceDesc = serviceInfo.getServiceDesc();
133
134         targetGBean.setAttribute("pojoClassName", seiClassName);
135         RPCProvider provider = new POJOProvider();
136
137         SOAPService service = new SOAPService(null, provider, null);
138         service.setServiceDescription(serviceDesc);
139         service.setOption("className", seiClassName);
140
141         HandlerInfoChainFactory handlerInfoChainFactory = new HandlerInfoChainFactory(serviceInfo.getHandlerInfos());
142         service.setOption(org.apache.axis.Constants.ATTR_HANDLERINFOCHAIN, handlerInfoChainFactory);
143
144         URI JavaDoc location;
145         try {
146             location = new URI JavaDoc(serviceDesc.getEndpointURL());
147         } catch (URISyntaxException JavaDoc e) {
148             throw new DeploymentException("Invalid webservice endpoint URI", e);
149         }
150         URI JavaDoc wsdlURI;
151         try {
152             wsdlURI = new URI JavaDoc(serviceDesc.getWSDLFile());
153         } catch (URISyntaxException JavaDoc e) {
154             throw new DeploymentException("Invalid wsdl URI", e);
155
156         }
157
158         AxisWebServiceContainer axisWebServiceContainer = new AxisWebServiceContainer(location, wsdlURI, service, serviceInfo.getWsdlMap(), cl);
159         AbstractName webServiceContainerFactoryName = context.getNaming().createChildName(targetGBean.getAbstractName(), "webServiceContainer", NameFactory.GERONIMO_SERVICE);
160         GBeanData webServiceContainerFactoryGBean = new GBeanData(webServiceContainerFactoryName, SerializableWebServiceContainerFactoryGBean.GBEAN_INFO);
161         webServiceContainerFactoryGBean.setAttribute("webServiceContainer", axisWebServiceContainer);
162         try {
163             context.addGBean(webServiceContainerFactoryGBean);
164         } catch (GBeanAlreadyExistsException e) {
165             throw new DeploymentException("Could not add webServiceContainerFactoryGBean", e);
166         }
167         targetGBean.setReferencePattern("WebServiceContainerFactory", webServiceContainerFactoryName);
168         return true;
169     }
170
171     public boolean configureEJB(GBeanData targetGBean, String JavaDoc ejbName, JarFile JavaDoc moduleFile, Map JavaDoc sharedContext, ClassLoader JavaDoc classLoader) throws DeploymentException {
172         Map JavaDoc portInfoMap = (Map JavaDoc) sharedContext.get(KEY);
173         PortInfo portInfo = (PortInfo) portInfoMap.get(ejbName);
174         if (portInfo == null) {
175             //not ours
176
return false;
177         }
178         ServiceInfo serviceInfo = AxisServiceBuilder.createServiceInfo(portInfo, classLoader);
179         targetGBean.setAttribute("serviceInfo", serviceInfo);
180         JavaServiceDesc serviceDesc = serviceInfo.getServiceDesc();
181         URI JavaDoc location = portInfo.getContextURI();
182         targetGBean.setAttribute("location", location);
183         URI JavaDoc wsdlURI;
184         try {
185             wsdlURI = new URI JavaDoc(serviceDesc.getWSDLFile());
186         } catch (URISyntaxException JavaDoc e) {
187             throw new DeploymentException("Invalid wsdl URI", e);
188         }
189         targetGBean.setAttribute("wsdlURI", wsdlURI);
190         return true;
191     }
192
193
194     //ServicereferenceBuilder
195
public Object JavaDoc createService(Class JavaDoc serviceInterface, URI JavaDoc wsdlURI, URI JavaDoc jaxrpcMappingURI, QName JavaDoc serviceQName, Map JavaDoc portComponentRefMap, List JavaDoc handlerInfos, Object JavaDoc serviceRefType, Module module, ClassLoader JavaDoc classLoader) throws DeploymentException {
196         GerServiceRefType gerServiceRefType = (GerServiceRefType) serviceRefType;
197         JarFile JavaDoc moduleFile = module.getModuleFile();
198         SchemaInfoBuilder schemaInfoBuilder = null;
199         JavaWsdlMappingType mapping = null;
200         if (wsdlURI != null) {
201             schemaInfoBuilder = new SchemaInfoBuilder(moduleFile, wsdlURI);
202
203             mapping = WSDescriptorParser.readJaxrpcMapping(moduleFile, jaxrpcMappingURI);
204         }
205
206         return createService(serviceInterface, schemaInfoBuilder, mapping, serviceQName, SOAP_VERSION, handlerInfos, gerServiceRefType, module, classLoader);
207     }
208
209     public Object JavaDoc createService(Class JavaDoc serviceInterface, SchemaInfoBuilder schemaInfoBuilder, JavaWsdlMappingType mapping, QName JavaDoc serviceQName, SOAPConstants soapVersion, List JavaDoc handlerInfos, GerServiceRefType serviceRefType, Module module, ClassLoader JavaDoc classloader) throws DeploymentException {
210         Map JavaDoc seiPortNameToFactoryMap = new HashMap JavaDoc();
211         Map JavaDoc seiClassNameToFactoryMap = new HashMap JavaDoc();
212         if (schemaInfoBuilder != null) {
213             buildSEIFactoryMap(schemaInfoBuilder, serviceRefType, mapping, handlerInfos, serviceQName, soapVersion, seiPortNameToFactoryMap, seiClassNameToFactoryMap, classloader);
214         }
215         return new AxisServiceReference(serviceInterface.getName(), seiPortNameToFactoryMap, seiClassNameToFactoryMap);
216     }
217
218     public void buildSEIFactoryMap(SchemaInfoBuilder schemaInfoBuilder, GerServiceRefType serviceRefType, JavaWsdlMappingType mapping, List JavaDoc handlerInfos, QName JavaDoc serviceQName, SOAPConstants soapVersion, Map JavaDoc seiPortNameToFactoryMap, Map JavaDoc seiClassNameToFactoryMap, ClassLoader JavaDoc classLoader) throws DeploymentException {
219         Map JavaDoc exceptionMap = WSDescriptorParser.getExceptionMap(mapping);
220
221         Definition definition = schemaInfoBuilder.getDefinition();
222         //check for consistency
223
if (definition.getServices().size() == 0) {
224             //partial wsdl
225
if (serviceRefType == null || !serviceRefType.isSetServiceCompletion()) {
226                 throw new DeploymentException("Partial wsdl, but no service completion supplied");
227             }
228             GerServiceCompletionType serviceCompletion = serviceRefType.getServiceCompletion();
229             String JavaDoc serviceLocalName = serviceCompletion.getServiceName().trim();
230             String JavaDoc namespace = definition.getTargetNamespace();
231             serviceQName = new QName JavaDoc(namespace, serviceLocalName);
232             javax.wsdl.Service service = definition.createService();
233             service.setQName(serviceQName);
234             GerPortCompletionType[] portCompletions = serviceCompletion.getPortCompletionArray();
235             for (int i = 0; i < portCompletions.length; i++) {
236                 GerPortCompletionType portCompletion = portCompletions[i];
237                 GerPortType port = portCompletion.getPort();
238                 URL JavaDoc location = getLocation(port);
239                 String JavaDoc portName = port.getPortName().trim();
240                 String JavaDoc bindingName = portCompletion.getBindingName().trim();
241                 QName JavaDoc bindingQName = new QName JavaDoc(namespace, bindingName);
242                 Binding binding = definition.getBinding(bindingQName);
243                 if (binding == null) {
244                     throw new DeploymentException("No binding found with qname: " + bindingQName);
245                 }
246                 String JavaDoc credentialsName = port.isSetCredentialsName() ? port.getCredentialsName().trim() : null;
247                 mapBinding(binding, mapping, serviceQName, classLoader, soapVersion, schemaInfoBuilder, portName, location, handlerInfos, seiPortNameToFactoryMap, seiClassNameToFactoryMap, credentialsName, exceptionMap);
248
249             }
250         } else {
251             //full wsdl
252
if (serviceRefType != null && serviceRefType.isSetServiceCompletion()) {
253                 throw new DeploymentException("Full wsdl, but service completion supplied");
254             }
255             //organize the extra port info
256
Map JavaDoc portMap = new HashMap JavaDoc();
257             if (serviceRefType != null) {
258                 GerPortType[] ports = serviceRefType.getPortArray();
259                 for (int i = 0; i < ports.length; i++) {
260                     GerPortType port = ports[i];
261                     String JavaDoc portName = port.getPortName().trim();
262                     portMap.put(portName, port);
263                 }
264             }
265
266             //find the service we are working with
267
javax.wsdl.Service service = getService(serviceQName, schemaInfoBuilder.getDefinition());
268             if (serviceQName == null) {
269                 serviceQName = service.getQName();
270             }
271
272             Map JavaDoc wsdlPortMap = service.getPorts();
273             for (Iterator JavaDoc iterator = wsdlPortMap.entrySet().iterator(); iterator.hasNext();) {
274                 Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iterator.next();
275                 String JavaDoc portName = (String JavaDoc) entry.getKey();
276                 Port port = (Port) entry.getValue();
277
278                 GerPortType gerPort = (GerPortType) portMap.get(portName);
279
280                 URL JavaDoc location = gerPort == null ? getAddressLocation(port) : getLocation(gerPort);
281                 //skip non-soap ports
282
if (location == null) {
283                     continue;
284                 }
285                 String JavaDoc credentialsName = gerPort == null || gerPort.getCredentialsName() == null ? null : gerPort.getCredentialsName().trim();
286
287                 Binding binding = port.getBinding();
288
289                 mapBinding(binding, mapping, serviceQName, classLoader, soapVersion, schemaInfoBuilder, portName, location, handlerInfos, seiPortNameToFactoryMap, seiClassNameToFactoryMap, credentialsName, exceptionMap);
290             }
291         }
292     }
293
294     private void mapBinding(Binding binding, JavaWsdlMappingType mapping, QName JavaDoc serviceQName, ClassLoader JavaDoc classLoader, SOAPConstants soapVersion, SchemaInfoBuilder schemaInfoBuilder, String JavaDoc portName, URL JavaDoc location, List JavaDoc handlerInfos, Map JavaDoc seiPortNameToFactoryMap, Map JavaDoc seiClassNameToFactoryMap, String JavaDoc credentialsName, Map JavaDoc exceptionMap) throws DeploymentException {
295         Style portStyle = getStyle(binding);
296
297         PortType portType = binding.getPortType();
298
299         ServiceEndpointInterfaceMappingType[] endpointMappings = mapping.getServiceEndpointInterfaceMappingArray();
300
301         //port type corresponds to SEI
302
List JavaDoc operations = portType.getOperations();
303         OperationInfo[] operationInfos = new OperationInfo[operations.size()];
304         if (endpointMappings.length == 0) {
305             doLightweightMapping(serviceQName, portType, mapping, classLoader, operations, binding, portStyle, soapVersion, operationInfos, schemaInfoBuilder, portName, location, handlerInfos, seiPortNameToFactoryMap, seiClassNameToFactoryMap, credentialsName);
306         } else {
307             doHeavyweightMapping(serviceQName, portType, endpointMappings, classLoader, operations, binding, portStyle, soapVersion, exceptionMap, schemaInfoBuilder, mapping, operationInfos, portName, location, handlerInfos, seiPortNameToFactoryMap, seiClassNameToFactoryMap, credentialsName);
308         }
309     }
310
311     private URL JavaDoc getLocation(GerPortType port) throws DeploymentException {
312         String JavaDoc protocol = port.getProtocol().trim();
313         String JavaDoc host = port.getHost().trim();
314         int portNum = port.getPort();
315         String JavaDoc uri = port.getUri().trim();
316         String JavaDoc locationURIString = protocol + "://" + host + ":" + portNum + uri;
317         URL JavaDoc location;
318         try {
319             location = new URL JavaDoc(locationURIString);
320         } catch (MalformedURLException JavaDoc e) {
321             throw new DeploymentException("Could not construct web service location URL from " + locationURIString);
322         }
323         return location;
324     }
325
326     private javax.wsdl.Service getService(QName JavaDoc serviceQName, Definition definition) throws DeploymentException {
327         javax.wsdl.Service service;
328         if (serviceQName != null) {
329             service = definition.getService(serviceQName);
330             if (service == null) {
331                 throw new DeploymentException("No service wsdl for supplied service qname " + serviceQName);
332             }
333         } else {
334             Map JavaDoc services = definition.getServices();
335             if (services.size() > 1) {
336                 throw new DeploymentException("no serviceQName supplied, and there are " + services.size() + " services");
337             }
338             if (services.size() == 0) {
339                 throw new DeploymentException("No service in wsdl, and no service completion supplied!");
340             } else {
341                 service = (javax.wsdl.Service) services.values().iterator().next();
342             }
343         }
344         return service;
345     }
346
347     private Style getStyle(Binding binding) throws DeploymentException {
348         SOAPBinding soapBinding = (SOAPBinding) SchemaInfoBuilder.getExtensibilityElement(SOAPBinding.class, binding.getExtensibilityElements());
349 // String transportURI = soapBinding.getTransportURI();
350
String JavaDoc portStyleString = soapBinding.getStyle();
351         return Style.getStyle(portStyleString);
352     }
353
354     private URL JavaDoc getAddressLocation(Port port) throws DeploymentException {
355         SOAPAddress soapAddress;
356         try {
357             soapAddress = (SOAPAddress) SchemaInfoBuilder.getExtensibilityElement(SOAPAddress.class, port.getExtensibilityElements());
358         } catch (DeploymentException e) {
359             //a http: protocol REST service. Skip it.
360
return null;
361         }
362         String JavaDoc locationURIString = soapAddress.getLocationURI();
363         URL JavaDoc location;
364         try {
365             location = new URL JavaDoc(locationURIString);
366         } catch (MalformedURLException JavaDoc e) {
367             throw new DeploymentException("Could not construct web service location URL from " + locationURIString);
368         }
369         return location;
370     }
371
372     private void doHeavyweightMapping(QName JavaDoc serviceName, PortType portType, ServiceEndpointInterfaceMappingType[] endpointMappings, ClassLoader JavaDoc classLoader, List JavaDoc operations, Binding binding, Style portStyle, SOAPConstants soapVersion, Map JavaDoc exceptionMap, SchemaInfoBuilder schemaInfoBuilder, JavaWsdlMappingType mapping, OperationInfo[] operationInfos, String JavaDoc portName, URL JavaDoc location, List JavaDoc handlerInfos, Map JavaDoc seiPortNameToFactoryMap, Map JavaDoc seiClassNameToFactoryMap, String JavaDoc credentialsName) throws DeploymentException {
373         Class JavaDoc serviceEndpointInterface;
374         SEIFactory seiFactory;
375         //complete jaxrpc mapping file supplied
376
QName JavaDoc portTypeQName = portType.getQName();
377         ServiceEndpointInterfaceMappingType endpointMapping = WSDescriptorParser.getServiceEndpointInterfaceMapping(endpointMappings, portTypeQName);
378         String JavaDoc fqcn = endpointMapping.getServiceEndpointInterface().getStringValue();
379         try {
380             serviceEndpointInterface = classLoader.loadClass(fqcn);
381         } catch (ClassNotFoundException JavaDoc e) {
382             throw new DeploymentException("Could not load service endpoint interface", e);
383         }
384 // Class enhancedServiceEndpointClass = enhanceServiceEndpointInterface(serviceEndpointInterface, context, module, classLoader);
385

386         Collection JavaDoc operationDescs = new ArrayList JavaDoc();
387         ServiceEndpointMethodMappingType[] methodMappings = endpointMapping.getServiceEndpointMethodMappingArray();
388         int i = 0;
389         Set JavaDoc wrapperElementQNames = new HashSet JavaDoc();
390         JavaXmlTypeMappingType[] javaXmlTypeMappings = mapping.getJavaXmlTypeMappingArray();
391         boolean hasEncoded = false;
392         for (Iterator JavaDoc ops = operations.iterator(); ops.hasNext();) {
393             Operation operation = (Operation) ops.next();
394             String JavaDoc operationName = operation.getName();
395             //the obvious method seems to be buggy
396
// BindingOperation bindingOperation = binding.getBindingOperation(operationName, operation.getInput().getName(), operation.getOutput() == null ? null : operation.getOutput().getName());
397
BindingOperation bindingOperation = null;
398             List JavaDoc bops = binding.getBindingOperations();
399             for (Iterator JavaDoc iterator = bops.iterator(); iterator.hasNext();) {
400                 BindingOperation bindingOperation1 = (BindingOperation) iterator.next();
401                 if (bindingOperation1.getOperation().equals(operation)) {
402                     bindingOperation = bindingOperation1;
403                     break;
404                 }
405             }
406             if (bindingOperation == null) {
407                 throw new DeploymentException("No BindingOperation for operation: " + operationName + ", input: " + operation.getInput().getName() + ", output: " + (operation.getOutput() == null ? "<none>" : operation.getOutput().getName()));
408             }
409             ServiceEndpointMethodMappingType methodMapping = WSDescriptorParser.getMethodMappingForOperation(operationName, methodMappings);
410             HeavyweightOperationDescBuilder operationDescBuilder = new HeavyweightOperationDescBuilder(bindingOperation, mapping, methodMapping, portStyle, exceptionMap, schemaInfoBuilder, javaXmlTypeMappings, classLoader, serviceEndpointInterface);
411             OperationInfo operationInfo = operationDescBuilder.buildOperationInfo(soapVersion);
412             operationInfos[i++] = operationInfo;
413             operationDescs.add(operationInfo.getOperationDesc());
414             wrapperElementQNames.addAll(operationDescBuilder.getWrapperElementQNames());
415             hasEncoded |= operationDescBuilder.isEncoded();
416         }
417         HeavyweightTypeInfoBuilder builder = new HeavyweightTypeInfoBuilder(classLoader, schemaInfoBuilder.getSchemaTypeKeyToSchemaTypeMap(), wrapperElementQNames, operationDescs, hasEncoded);
418         List JavaDoc typeInfo = builder.buildTypeInfo(mapping);
419
420         seiFactory = createSEIFactory(serviceName, portName, serviceEndpointInterface.getName(), typeInfo, location, operationInfos, handlerInfos, credentialsName);
421         seiPortNameToFactoryMap.put(portName, seiFactory);
422         seiClassNameToFactoryMap.put(serviceEndpointInterface.getName(), seiFactory);
423     }
424
425     private void doLightweightMapping(QName JavaDoc serviceName, PortType portType, JavaWsdlMappingType mapping, ClassLoader JavaDoc classLoader, List JavaDoc operations, Binding binding, Style portStyle, SOAPConstants soapVersion, OperationInfo[] operationInfos, SchemaInfoBuilder schemaInfoBuilder, String JavaDoc portName, URL JavaDoc location, List JavaDoc handlerInfos, Map JavaDoc seiPortNameToFactoryMap, Map JavaDoc seiClassNameToFactoryMap, String JavaDoc credentialsName) throws DeploymentException {
426         Class JavaDoc serviceEndpointInterface;
427         SEIFactory seiFactory;
428         //lightweight jaxrpc mapping supplied
429
serviceEndpointInterface = getServiceEndpointInterfaceLightweight(portType, mapping, classLoader);
430 // Class enhancedServiceEndpointClass = enhanceServiceEndpointInterface(serviceEndpointInterface, context, module, classLoader);
431

432         int i = 0;
433         for (Iterator JavaDoc ops = operations.iterator(); ops.hasNext();) {
434             Operation operation = (Operation) ops.next();
435             Method JavaDoc method = WSDescriptorParser.getMethodForOperation(serviceEndpointInterface, operation);
436             BindingOperation bindingOperation = binding.getBindingOperation(operation.getName(), operation.getInput().getName(), operation.getOutput() == null ? null : operation.getOutput().getName());
437             operationInfos[i++] = buildOperationInfoLightweight(method, bindingOperation, portStyle, soapVersion);
438         }
439         LightweightTypeInfoBuilder builder = new LightweightTypeInfoBuilder(classLoader, schemaInfoBuilder.getSchemaTypeKeyToSchemaTypeMap(), Collections.EMPTY_SET);
440         List JavaDoc typeInfo = builder.buildTypeInfo(mapping);
441
442         seiFactory = createSEIFactory(serviceName, portName, serviceEndpointInterface.getName(), typeInfo, location, operationInfos, handlerInfos, credentialsName);
443         seiPortNameToFactoryMap.put(portName, seiFactory);
444         seiClassNameToFactoryMap.put(serviceEndpointInterface.getName(), seiFactory);
445     }
446
447     private Class JavaDoc getServiceEndpointInterfaceLightweight(PortType portType, JavaWsdlMappingType mappings, ClassLoader JavaDoc classLoader) throws DeploymentException {
448         QName JavaDoc portTypeQName = portType.getQName();
449         String JavaDoc portTypeNamespace = portTypeQName.getNamespaceURI();
450         String JavaDoc portTypePackage = WSDescriptorParser.getPackageFromNamespace(portTypeNamespace, mappings);
451         StringBuffer JavaDoc shortInterfaceName = new StringBuffer JavaDoc(portTypeQName.getLocalPart());
452         shortInterfaceName.setCharAt(0, Character.toUpperCase(shortInterfaceName.charAt(0)));
453         //TODO just use one buffer!
454
String JavaDoc fqcn = portTypePackage + "." + shortInterfaceName.toString();
455         try {
456             return classLoader.loadClass(fqcn);
457         } catch (ClassNotFoundException JavaDoc e) {
458             throw new DeploymentException("Could not load service endpoint interface type", e);
459         }
460     }
461
462
463     public SEIFactory createSEIFactory(QName JavaDoc serviceName, String JavaDoc portName, String JavaDoc enhancedServiceEndpointClassName, List JavaDoc typeInfo, URL JavaDoc location, OperationInfo[] operationInfos, List JavaDoc handlerInfoInfos, String JavaDoc credentialsName) throws DeploymentException {
464         List JavaDoc handlerInfos = buildHandlerInfosForPort(portName, handlerInfoInfos);
465         return new SEIFactoryImpl(serviceName, portName, enhancedServiceEndpointClassName, operationInfos, typeInfo, location, handlerInfos, credentialsName);
466     }
467
468     private List JavaDoc buildHandlerInfosForPort(String JavaDoc portName, List JavaDoc handlerInfoInfos) {
469         List JavaDoc handlerInfos = new ArrayList JavaDoc();
470         for (Iterator JavaDoc iterator = handlerInfoInfos.iterator(); iterator.hasNext();) {
471             HandlerInfoInfo handlerInfoInfo = (HandlerInfoInfo) iterator.next();
472             Set JavaDoc portNames = handlerInfoInfo.getPortNames();
473             if (portNames.isEmpty() || portNames.contains(portName)) {
474                 HandlerInfo JavaDoc handlerInfo = new HandlerInfo JavaDoc(handlerInfoInfo.getHandlerClass(), handlerInfoInfo.getHandlerConfig(), handlerInfoInfo.getSoapHeaders());
475                 handlerInfos.add(handlerInfo);
476
477                 //TODO what about the soap roles??
478
}
479         }
480         return handlerInfos;
481     }
482
483     public OperationInfo buildOperationInfoLightweight(Method JavaDoc method, BindingOperation bindingOperation, Style defaultStyle, SOAPConstants soapVersion) throws DeploymentException {
484         LightweightOperationDescBuilder operationDescBuilder = new LightweightOperationDescBuilder(bindingOperation, method);
485         return operationDescBuilder.buildOperationInfo(soapVersion);
486     }
487
488
489     public static final GBeanInfo GBEAN_INFO;
490
491     static {
492         GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(AxisBuilder.class, NameFactory.MODULE_BUILDER);
493         infoBuilder.addInterface(WebServiceBuilder.class);
494         infoBuilder.addAttribute("defaultEnvironment", Environment.class, true, true);
495
496         infoBuilder.setConstructor(new String JavaDoc[]{"defaultEnvironment"});
497
498         GBEAN_INFO = infoBuilder.getBeanInfo();
499     }
500
501     public static GBeanInfo getGBeanInfo() {
502         return GBEAN_INFO;
503     }
504
505 }
506
Popular Tags