1 17 18 package org.apache.geronimo.axis.builder; 19 20 import java.net.URI ; 21 import java.net.URISyntaxException ; 22 import java.util.ArrayList ; 23 import java.util.HashMap ; 24 import java.util.HashSet ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.Set ; 28 29 import javax.xml.namespace.QName ; 30 31 import org.apache.geronimo.common.DeploymentException; 32 import org.apache.geronimo.gbean.GBeanInfo; 33 import org.apache.geronimo.gbean.GBeanInfoBuilder; 34 import org.apache.geronimo.j2ee.deployment.HandlerInfoInfo; 35 import org.apache.geronimo.j2ee.deployment.Module; 36 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 37 import org.apache.geronimo.kernel.ClassLoading; 38 import org.apache.geronimo.kernel.config.Configuration; 39 import org.apache.geronimo.kernel.repository.Environment; 40 import org.apache.geronimo.naming.deployment.AbstractNamingBuilder; 41 import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefDocument; 42 import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType; 43 import org.apache.geronimo.xbeans.j2ee.ParamValueType; 44 import org.apache.geronimo.xbeans.j2ee.PortComponentRefType; 45 import org.apache.geronimo.xbeans.j2ee.ServiceRefHandlerType; 46 import org.apache.geronimo.xbeans.j2ee.ServiceRefType; 47 import org.apache.geronimo.xbeans.j2ee.XsdQNameType; 48 import org.apache.xmlbeans.QNameSet; 49 import org.apache.xmlbeans.XmlObject; 50 51 54 public class AxisServiceRefBuilder extends AbstractNamingBuilder { 55 private final QNameSet serviceRefQNameSet; 56 private static final QName GER_SERVICE_REF_QNAME = GerServiceRefDocument.type.getDocumentElementName(); 57 private static final QNameSet GER_SERVICE_REF_QNAME_SET = QNameSet.singleton(GER_SERVICE_REF_QNAME); 58 59 private final AxisBuilder axisBuilder; 60 61 public AxisServiceRefBuilder(Environment defaultEnvironment, String [] eeNamespaces, AxisBuilder axisBuilder) { 62 super(defaultEnvironment); 63 this.axisBuilder = axisBuilder; 64 serviceRefQNameSet = buildQNameSet(eeNamespaces, "service-ref"); 65 } 66 67 protected boolean willMergeEnvironment(XmlObject specDD, XmlObject plan) { 68 return specDD.selectChildren(serviceRefQNameSet).length > 0; 69 } 70 71 public void buildNaming(XmlObject specDD, XmlObject plan, Configuration localConfiguration, Configuration remoteConfiguration, Module module, Map componentContext) throws DeploymentException { 72 XmlObject[] serviceRefsUntyped = convert(specDD.selectChildren(serviceRefQNameSet), J2EE_CONVERTER, ServiceRefType.type); 73 XmlObject[] gerServiceRefsUntyped = plan == null? NO_REFS: plan.selectChildren(GER_SERVICE_REF_QNAME_SET); 74 Map serviceRefMap = mapServiceRefs(gerServiceRefsUntyped); 75 ClassLoader cl = module.getEarContext().getClassLoader(); 76 77 for (int i = 0; i < serviceRefsUntyped.length; i++) { 78 ServiceRefType serviceRef = (ServiceRefType) serviceRefsUntyped[i]; 79 String name = getStringValue(serviceRef.getServiceRefName()); 80 GerServiceRefType serviceRefType = (GerServiceRefType) serviceRefMap.get(name); 81 String serviceInterfaceName = getStringValue(serviceRef.getServiceInterface()); 83 assureInterface(serviceInterfaceName, "javax.xml.rpc.Service", "[Web]Service", cl); 84 Class serviceInterface; 85 try { 86 serviceInterface = cl.loadClass(serviceInterfaceName); 87 } catch (ClassNotFoundException e) { 88 throw new DeploymentException("Could not load service interface class: " + serviceInterfaceName, e); 89 } 90 URI wsdlURI = null; 91 if (serviceRef.isSetWsdlFile()) { 92 try { 93 wsdlURI = new URI (serviceRef.getWsdlFile().getStringValue().trim()); 94 } catch (URISyntaxException e) { 95 throw new DeploymentException("could not construct wsdl uri from " + serviceRef.getWsdlFile().getStringValue(), e); 96 } 97 } 98 URI jaxrpcMappingURI = null; 99 if (serviceRef.isSetJaxrpcMappingFile()) { 100 try { 101 jaxrpcMappingURI = new URI (getStringValue(serviceRef.getJaxrpcMappingFile())); 102 } catch (URISyntaxException e) { 103 throw new DeploymentException("Could not construct jaxrpc mapping uri from " + serviceRef.getJaxrpcMappingFile(), e); 104 } 105 } 106 QName serviceQName = null; 107 if (serviceRef.isSetServiceQname()) { 108 serviceQName = serviceRef.getServiceQname().getQNameValue(); 109 } 110 Map portComponentRefMap = new HashMap (); 111 PortComponentRefType[] portComponentRefs = serviceRef.getPortComponentRefArray(); 112 if (portComponentRefs != null) { 113 for (int j = 0; j < portComponentRefs.length; j++) { 114 PortComponentRefType portComponentRef = portComponentRefs[j]; 115 String portComponentLink = getStringValue(portComponentRef.getPortComponentLink()); 116 String serviceEndpointInterfaceType = getStringValue(portComponentRef.getServiceEndpointInterface()); 117 assureInterface(serviceEndpointInterfaceType, "java.rmi.Remote", "ServiceEndpoint", cl); 118 Class serviceEndpointClass; 119 try { 120 serviceEndpointClass = cl.loadClass(serviceEndpointInterfaceType); 121 } catch (ClassNotFoundException e) { 122 throw new DeploymentException("could not load service endpoint class " + serviceEndpointInterfaceType, e); 123 } 124 portComponentRefMap.put(serviceEndpointClass, portComponentLink); 125 } 126 } 127 ServiceRefHandlerType[] handlers = serviceRef.getHandlerArray(); 128 List handlerInfos = buildHandlerInfoList(handlers, cl); 129 130 Object ref = axisBuilder.createService(serviceInterface, wsdlURI, jaxrpcMappingURI, serviceQName, portComponentRefMap, handlerInfos, serviceRefType, module, cl); 132 getJndiContextMap(componentContext).put(ENV + name, ref); 133 } 134 135 } 136 137 public QNameSet getSpecQNameSet() { 138 return serviceRefQNameSet; 139 } 140 141 public QNameSet getPlanQNameSet() { 142 return GER_SERVICE_REF_QNAME_SET; 143 } 144 145 146 private static List buildHandlerInfoList(ServiceRefHandlerType[] handlers, ClassLoader classLoader) throws DeploymentException { 147 List handlerInfos = new ArrayList (); 148 for (int i = 0; i < handlers.length; i++) { 149 ServiceRefHandlerType handler = handlers[i]; 150 org.apache.geronimo.xbeans.j2ee.String[] portNameArray = handler.getPortNameArray(); 151 List portNames = new ArrayList (); 152 for (int j = 0; j < portNameArray.length; j++) { 153 portNames.add(portNameArray[j].getStringValue().trim()); 154 155 } 156 String handlerClassName = handler.getHandlerClass().getStringValue().trim(); 158 Class handlerClass; 159 try { 160 handlerClass = ClassLoading.loadClass(handlerClassName, classLoader); 161 } catch (ClassNotFoundException e) { 162 throw new DeploymentException("Could not load handler class", e); 163 } 164 Map config = new HashMap (); 165 ParamValueType[] paramValues = handler.getInitParamArray(); 166 for (int j = 0; j < paramValues.length; j++) { 167 ParamValueType paramValue = paramValues[j]; 168 String paramName = paramValue.getParamName().getStringValue().trim(); 169 String paramStringValue = paramValue.getParamValue().getStringValue().trim(); 170 config.put(paramName, paramStringValue); 171 } 172 XsdQNameType[] soapHeaderQNames = handler.getSoapHeaderArray(); 173 QName [] headerQNames = new QName [soapHeaderQNames.length]; 174 for (int j = 0; j < soapHeaderQNames.length; j++) { 175 XsdQNameType soapHeaderQName = soapHeaderQNames[j]; 176 headerQNames[j] = soapHeaderQName.getQNameValue(); 177 } 178 Set soapRoles = new HashSet (); 179 for (int j = 0; j < handler.getSoapRoleArray().length; j++) { 180 String soapRole = handler.getSoapRoleArray(j).getStringValue().trim(); 181 soapRoles.add(soapRole); 182 } 183 HandlerInfoInfo handlerInfoInfo = new HandlerInfoInfo(new HashSet (portNames), handlerClass, config, headerQNames, soapRoles); 184 handlerInfos.add(handlerInfoInfo); 185 } 186 return handlerInfos; 187 } 188 189 190 private static Map mapServiceRefs(XmlObject[] refs) { 191 Map refMap = new HashMap (); 192 if (refs != null) { 193 for (int i = 0; i < refs.length; i++) { 194 GerServiceRefType ref = (GerServiceRefType) refs[i].copy().changeType(GerServiceRefType.type); 195 String serviceRefName = ref.getServiceRefName().trim(); 196 refMap.put(serviceRefName, ref); 197 } 198 } 199 return refMap; 200 } 201 202 public static final GBeanInfo GBEAN_INFO; 203 204 static { 205 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(AxisServiceRefBuilder.class, NameFactory.MODULE_BUILDER); 206 infoBuilder.addAttribute("defaultEnvironment", Environment.class, true, true); 207 infoBuilder.addAttribute("eeNamespaces", String [].class, true, true); 208 infoBuilder.addReference("AxisBuilder", AxisBuilder.class, NameFactory.MODULE_BUILDER); 209 210 infoBuilder.setConstructor(new String [] {"defaultEnvironment", "eeNamespaces", "AxisBuilder"}); 211 212 GBEAN_INFO = infoBuilder.getBeanInfo(); 213 } 214 215 public static GBeanInfo getGBeanInfo() { 216 return GBEAN_INFO; 217 } 218 } 219 | Popular Tags |