Home » geronimo-2.2-source-release » org.apache.geronimo.axis.builder » [javadoc | source]

    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   
   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.slf4j.Logger;
   32   import org.slf4j.LoggerFactory;
   33   import org.apache.geronimo.common.DeploymentException;
   34   import org.apache.geronimo.gbean.GBeanInfo;
   35   import org.apache.geronimo.gbean.GBeanInfoBuilder;
   36   import org.apache.geronimo.j2ee.deployment.HandlerInfoInfo;
   37   import org.apache.geronimo.j2ee.deployment.Module;
   38   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   39   import org.apache.geronimo.kernel.ClassLoading;
   40   import org.apache.geronimo.kernel.repository.Environment;
   41   import org.apache.geronimo.naming.deployment.AbstractNamingBuilder;
   42   import org.apache.geronimo.naming.deployment.ServiceRefBuilder;
   43   import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefDocument;
   44   import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType;
   45   import org.apache.geronimo.xbeans.javaee.ParamValueType;
   46   import org.apache.geronimo.xbeans.javaee.PortComponentRefType;
   47   import org.apache.geronimo.xbeans.javaee.ServiceRefHandlerType;
   48   import org.apache.geronimo.xbeans.javaee.ServiceRefType;
   49   import org.apache.geronimo.xbeans.javaee.XsdQNameType;
   50   import org.apache.xmlbeans.QNameSet;
   51   import org.apache.xmlbeans.XmlObject;
   52   
   53   /**
   54    * @version $Rev: 653782 $ $Date: 2008-05-06 07:10:14 -0700 (Tue, 06 May 2008) $
   55    */
   56   public class AxisServiceRefBuilder extends AbstractNamingBuilder implements ServiceRefBuilder {
   57       private static final Logger log = LoggerFactory.getLogger(AxisServiceRefBuilder.class);
   58       private final QNameSet serviceRefQNameSet;
   59       private static final QName GER_SERVICE_REF_QNAME = GerServiceRefDocument.type.getDocumentElementName();
   60       private static final QNameSet GER_SERVICE_REF_QNAME_SET = QNameSet.singleton(GER_SERVICE_REF_QNAME);
   61   
   62       private final AxisBuilder axisBuilder;
   63   
   64       public AxisServiceRefBuilder(Environment defaultEnvironment, String[] eeNamespaces, AxisBuilder axisBuilder) {
   65           super(defaultEnvironment);
   66           this.axisBuilder = axisBuilder;
   67           serviceRefQNameSet = buildQNameSet(eeNamespaces, "service-ref");
   68       }
   69   
   70       protected boolean willMergeEnvironment(XmlObject specDD, XmlObject plan) {
   71           return specDD.selectChildren(serviceRefQNameSet).length > 0;
   72       }
   73   
   74       public void buildNaming(XmlObject specDD, XmlObject plan, Module module, Map componentContext) throws DeploymentException {
   75           List<ServiceRefType> serviceRefsUntyped = convert(specDD.selectChildren(serviceRefQNameSet), JEE_CONVERTER, ServiceRefType.class, ServiceRefType.type);
   76           XmlObject[] gerServiceRefsUntyped = plan == null ? NO_REFS : plan.selectChildren(GER_SERVICE_REF_QNAME_SET);
   77           Map serviceRefMap = mapServiceRefs(gerServiceRefsUntyped);
   78   
   79           for (ServiceRefType serviceRef : serviceRefsUntyped) {
   80               String name = getStringValue(serviceRef.getServiceRefName());
   81               addInjections(name, serviceRef.getInjectionTargetArray(), componentContext);
   82               GerServiceRefType serviceRefType = (GerServiceRefType) serviceRefMap.get(name);
   83               serviceRefMap.remove(name);
   84               buildNaming(serviceRef, serviceRefType, module, componentContext);
   85           }
   86   
   87           if (serviceRefMap.size() > 0) {
   88               log.warn("Failed to build reference to service reference "+serviceRefMap.keySet()+" defined in plan file, reason - corresponding entry in deployment descriptor missing.");
   89           }
   90       }
   91   
   92       public void buildNaming(XmlObject serviceRef, GerServiceRefType gerServiceRefType, Module module, Map componentContext) throws DeploymentException {
   93           ServiceRefType serviceRefType =
   94                   (ServiceRefType) convert(serviceRef, JEE_CONVERTER, ServiceRefType.type);
   95           buildNaming(serviceRefType, gerServiceRefType, module, componentContext);
   96       }
   97   
   98       private void buildNaming(ServiceRefType serviceRef, GerServiceRefType serviceRefType, Module module, Map componentContext) throws DeploymentException {
   99           String name = getStringValue(serviceRef.getServiceRefName());
  100           ClassLoader cl = module.getEarContext().getClassLoader();
  101   
  102   //            Map credentialsNameMap = (Map) serviceRefCredentialsNameMap.get(name);
  103           String serviceInterfaceName = getStringValue(serviceRef.getServiceInterface());
  104           assureInterface(serviceInterfaceName, "javax.xml.rpc.Service", "[Web]Service", cl);
  105           Class serviceInterface;
  106           try {
  107               serviceInterface = cl.loadClass(serviceInterfaceName);
  108           } catch (ClassNotFoundException e) {
  109               throw new DeploymentException("Could not load service interface class: " + serviceInterfaceName, e);
  110           }
  111           URI wsdlURI = null;
  112           if (serviceRef.isSetWsdlFile()) {
  113               try {
  114                   wsdlURI = new URI(serviceRef.getWsdlFile().getStringValue().trim());
  115               } catch (URISyntaxException e) {
  116                   throw new DeploymentException("could not construct wsdl uri from " + serviceRef.getWsdlFile().getStringValue(), e);
  117               }
  118           }
  119           URI jaxrpcMappingURI = null;
  120           if (serviceRef.isSetJaxrpcMappingFile()) {
  121               try {
  122                   jaxrpcMappingURI = new URI(getStringValue(serviceRef.getJaxrpcMappingFile()));
  123               } catch (URISyntaxException e) {
  124                   throw new DeploymentException("Could not construct jaxrpc mapping uri from " + serviceRef.getJaxrpcMappingFile(), e);
  125               }
  126           }
  127           QName serviceQName = null;
  128           if (serviceRef.isSetServiceQname()) {
  129               serviceQName = serviceRef.getServiceQname().getQNameValue();
  130           }
  131           Map portComponentRefMap = new HashMap();
  132           PortComponentRefType[] portComponentRefs = serviceRef.getPortComponentRefArray();
  133           if (portComponentRefs != null) {
  134               for (int j = 0; j < portComponentRefs.length; j++) {
  135                   PortComponentRefType portComponentRef = portComponentRefs[j];
  136                   String portComponentLink = getStringValue(portComponentRef.getPortComponentLink());
  137                   String serviceEndpointInterfaceType = getStringValue(portComponentRef.getServiceEndpointInterface());
  138                   assureInterface(serviceEndpointInterfaceType, "java.rmi.Remote", "ServiceEndpoint", cl);
  139                   Class serviceEndpointClass;
  140                   try {
  141                       serviceEndpointClass = cl.loadClass(serviceEndpointInterfaceType);
  142                   } catch (ClassNotFoundException e) {
  143                       throw new DeploymentException("could not load service endpoint class " + serviceEndpointInterfaceType, e);
  144                   }
  145                   portComponentRefMap.put(serviceEndpointClass, portComponentLink);
  146               }
  147           }
  148           ServiceRefHandlerType[] handlers = serviceRef.getHandlerArray();
  149           List handlerInfos = buildHandlerInfoList(handlers, cl);
  150   
  151   //we could get a Reference or the actual serializable Service back.
  152           Object ref = axisBuilder.createService(serviceInterface, wsdlURI, jaxrpcMappingURI, serviceQName, portComponentRefMap, handlerInfos, serviceRefType, module, cl);
  153           getJndiContextMap(componentContext).put(ENV + name, ref);
  154       }
  155   
  156       public QNameSet getSpecQNameSet() {
  157           return serviceRefQNameSet;
  158       }
  159   
  160       public QNameSet getPlanQNameSet() {
  161           return GER_SERVICE_REF_QNAME_SET;
  162       }
  163   
  164   
  165       private static List buildHandlerInfoList(ServiceRefHandlerType[] handlers, ClassLoader classLoader) throws DeploymentException {
  166           List handlerInfos = new ArrayList();
  167           for (int i = 0; i < handlers.length; i++) {
  168               ServiceRefHandlerType handler = handlers[i];
  169               org.apache.geronimo.xbeans.javaee.String[] portNameArray = handler.getPortNameArray();
  170               List portNames = new ArrayList();
  171               for (int j = 0; j < portNameArray.length; j++) {
  172                   portNames.add(portNameArray[j].getStringValue().trim());
  173   
  174               }
  175   //            Set portNames = new HashSet(Arrays.asList(portNameArray));
  176               String handlerClassName = handler.getHandlerClass().getStringValue().trim();
  177               Class handlerClass;
  178               try {
  179                   handlerClass = ClassLoading.loadClass(handlerClassName, classLoader);
  180               } catch (ClassNotFoundException e) {
  181                   throw new DeploymentException("Could not load handler class", e);
  182               }
  183               Map config = new HashMap();
  184               ParamValueType[] paramValues = handler.getInitParamArray();
  185               for (int j = 0; j < paramValues.length; j++) {
  186                   ParamValueType paramValue = paramValues[j];
  187                   String paramName = paramValue.getParamName().getStringValue().trim();
  188                   String paramStringValue = paramValue.getParamValue().getStringValue().trim();
  189                   config.put(paramName, paramStringValue);
  190               }
  191               XsdQNameType[] soapHeaderQNames = handler.getSoapHeaderArray();
  192               QName[] headerQNames = new QName[soapHeaderQNames.length];
  193               for (int j = 0; j < soapHeaderQNames.length; j++) {
  194                   XsdQNameType soapHeaderQName = soapHeaderQNames[j];
  195                   headerQNames[j] = soapHeaderQName.getQNameValue();
  196               }
  197               Set soapRoles = new HashSet();
  198               for (int j = 0; j < handler.getSoapRoleArray().length; j++) {
  199                   String soapRole = handler.getSoapRoleArray(j).getStringValue().trim();
  200                   soapRoles.add(soapRole);
  201               }
  202               HandlerInfoInfo handlerInfoInfo = new HandlerInfoInfo(new HashSet(portNames), handlerClass, config, headerQNames, soapRoles);
  203               handlerInfos.add(handlerInfoInfo);
  204           }
  205           return handlerInfos;
  206       }
  207   
  208       private static Map mapServiceRefs(XmlObject[] refs) {
  209           Map refMap = new HashMap();
  210           if (refs != null) {
  211               for (int i = 0; i < refs.length; i++) {
  212                   GerServiceRefType ref = (GerServiceRefType) refs[i].copy().changeType(GerServiceRefType.type);
  213                   String serviceRefName = ref.getServiceRefName().trim();
  214                   refMap.put(serviceRefName, ref);
  215               }
  216           }
  217           return refMap;
  218       }
  219   
  220       // This is temporary
  221       private static String getStringValue(org.apache.geronimo.xbeans.j2ee.String string) {
  222           if (string == null) {
  223               return null;
  224           }
  225           String s = string.getStringValue();
  226           return s == null ? null : s.trim();
  227       }
  228   
  229       public static final GBeanInfo GBEAN_INFO;
  230   
  231       static {
  232           GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(AxisServiceRefBuilder.class, NameFactory.MODULE_BUILDER);
  233           infoBuilder.addInterface(ServiceRefBuilder.class);
  234           infoBuilder.addAttribute("defaultEnvironment", Environment.class, true, true);
  235           infoBuilder.addAttribute("eeNamespaces", String[].class, true, true);
  236           infoBuilder.addReference("AxisBuilder", AxisBuilder.class, NameFactory.MODULE_BUILDER);
  237   
  238           infoBuilder.setConstructor(new String[]{"defaultEnvironment", "eeNamespaces", "AxisBuilder"});
  239   
  240           GBEAN_INFO = infoBuilder.getBeanInfo();
  241       }
  242   
  243       public static GBeanInfo getGBeanInfo() {
  244           return GBEAN_INFO;
  245       }
  246   }

Home » geronimo-2.2-source-release » org.apache.geronimo.axis.builder » [javadoc | source]