Home » geronimo-2.2-source-release » org.apache.geronimo.corba.deployment » [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.corba.deployment;
   19   
   20   import java.net.URI;
   21   import java.net.URISyntaxException;
   22   import java.util.HashMap;
   23   import java.util.Map;
   24   import javax.naming.Reference;
   25   import javax.xml.namespace.QName;
   26   
   27   import org.apache.geronimo.common.DeploymentException;
   28   import org.apache.geronimo.gbean.AbstractNameQuery;
   29   import org.apache.geronimo.gbean.GBeanInfo;
   30   import org.apache.geronimo.gbean.GBeanInfoBuilder;
   31   import org.apache.geronimo.j2ee.deployment.Module;
   32   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   33   import org.apache.geronimo.kernel.GBeanNotFoundException;
   34   import org.apache.geronimo.kernel.config.Configuration;
   35   import org.apache.geronimo.kernel.repository.Environment;
   36   import org.apache.geronimo.openejb.deployment.EjbRefBuilder;
   37   import org.apache.geronimo.schema.NamespaceElementConverter;
   38   import org.apache.geronimo.xbeans.geronimo.naming.GerEjbRefDocument;
   39   import org.apache.geronimo.xbeans.geronimo.naming.GerEjbRefType;
   40   import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
   41   import org.apache.geronimo.xbeans.javaee.EjbRefType;
   42   import org.apache.geronimo.corba.proxy.CORBAProxyReference;
   43   import org.apache.xmlbeans.QNameSet;
   44   import org.apache.xmlbeans.XmlObject;
   45   
   46   /**
   47    * Installs ejb refs that use corba transport into jndi context.
   48    * Such ejb refs are determined by the nscorbaloc element in the openejb ejb plan.
   49    *  
   50    * @version $Revision: 549455 $ $Date: 2007-06-21 05:12:27 -0700 (Thu, 21 Jun 2007) $
   51    */
   52   public class OpenEjbCorbaRefBuilder extends EjbRefBuilder {
   53   
   54       private static final QName GER_EJB_REF_QNAME = GerEjbRefDocument.type.getDocumentElementName();
   55       private static final QNameSet GER_EJB_REF_QNAME_SET = QNameSet.singleton(GER_EJB_REF_QNAME);
   56       private static final NamespaceElementConverter OPENEJB_CONVERTER = new NamespaceElementConverter(GER_EJB_REF_QNAME.getNamespaceURI());
   57   
   58       private static final QName GER_NS_CORBA_LOC_QNAME = new QName(GER_EJB_REF_QNAME.getNamespaceURI(), "ns-corbaloc");
   59       private static final QNameSet GER_NS_CORBA_LOC_QNAME_SET = QNameSet.singleton(GER_NS_CORBA_LOC_QNAME);
   60   
   61       private final QNameSet ejbRefQNameSet;
   62   
   63       public OpenEjbCorbaRefBuilder(Environment defaultEnvironment, String[] eeNamespaces) throws URISyntaxException {
   64           super(defaultEnvironment, new String[0], null, -1);
   65           ejbRefQNameSet = buildQNameSet(eeNamespaces, "ejb-ref");
   66       }
   67   
   68       @Override
   69       public QNameSet getSpecQNameSet() {
   70           return ejbRefQNameSet;
   71       }
   72   
   73       @Override
   74       public QNameSet getPlanQNameSet() {
   75           return GER_NS_CORBA_LOC_QNAME_SET;
   76       }
   77   
   78   
   79       protected boolean willMergeEnvironment(XmlObject specDD, XmlObject plan)  {
   80   //        return hasCssRefs(plan);
   81           return true;
   82       }
   83   
   84   //    static boolean hasCssRefs(XmlObject plan) throws DeploymentException {
   85   //        XmlObject[] refs = plan == null ? NO_REFS : convert(plan.selectChildren(GER_EJB_REF_QNAME_SET), OPENEJB_CONVERTER, GerEjbRefType.type);
   86   //        for (int i = 0; i < refs.length; i++) {
   87   //            GerEjbRefType ref = (GerEjbRefType) refs[i];
   88   //            if (ref.isSetNsCorbaloc()) {
   89   //                return true;
   90   //            }
   91   //        }
   92   //        return false;
   93   //    }
   94   
   95       public void buildNaming(XmlObject specDD, XmlObject plan, Module module, Map componentContext) throws DeploymentException {
   96           XmlObject[] ejbRefsUntyped = convert(specDD.selectChildren(ejbRefQNameSet), JEE_CONVERTER, EjbRefType.type);
   97           XmlObject[] gerEjbRefsUntyped = plan == null ? NO_REFS : convert(plan.selectChildren(GER_EJB_REF_QNAME_SET), OPENEJB_CONVERTER, GerEjbRefType.type);
   98           Map ejbRefMap = mapEjbRefs(gerEjbRefsUntyped);
   99           ClassLoader cl = module.getEarContext().getClassLoader();
  100   
  101           for (XmlObject anEjbRefsUntyped : ejbRefsUntyped) {
  102               EjbRefType ejbRef = (EjbRefType) anEjbRefsUntyped;
  103   
  104               String ejbRefName = getStringValue(ejbRef.getEjbRefName());
  105               addInjections(ejbRefName, ejbRef.getInjectionTargetArray(), componentContext);
  106               GerEjbRefType remoteRef = (GerEjbRefType) ejbRefMap.get(ejbRefName);
  107   
  108               Reference ejbReference = addEJBRef(module, ejbRef, remoteRef, cl);
  109               if (ejbReference != null) {
  110                   getJndiContextMap(componentContext).put(ENV + ejbRefName, ejbReference);
  111               }
  112           }
  113       }
  114   
  115       private Reference addEJBRef(Module module, EjbRefType ejbRef, GerEjbRefType remoteRef, ClassLoader cl) throws DeploymentException {
  116           Reference ejbReference = null;
  117           if (remoteRef != null && remoteRef.isSetNsCorbaloc()) {
  118               String refName = getStringValue(ejbRef.getEjbRefName());
  119               String home = getStringValue(ejbRef.getHome());
  120               String remote = getStringValue(ejbRef.getRemote());
  121   
  122               verifyInterfaces(refName, module.getModuleURI(), cl, remote, home);
  123   
  124               try {
  125                   // create the cssBean query
  126                   AbstractNameQuery cssBean;
  127                   if (remoteRef.isSetCssLink()) {
  128                       String cssLink = remoteRef.getCssLink().trim();
  129                       cssBean = buildAbstractNameQuery(null, null, cssLink, NameFactory.CORBA_CSS, NameFactory.EJB_MODULE);
  130                   } else {
  131                       GerPatternType css = remoteRef.getCss();
  132                       cssBean = buildAbstractNameQuery(css, NameFactory.CORBA_CSS, NameFactory.EJB_MODULE, null);
  133                   }
  134   
  135                   // verify the cssBean query is valid
  136                   try {
  137                       module.getEarContext().findGBean(cssBean);
  138                   } catch (GBeanNotFoundException e) {
  139                       throw new DeploymentException("Could not find css bean matching " + cssBean + " from configuration " + module.getConfigId(), e);
  140                   }
  141   
  142                   // create ref
  143                   ejbReference = new CORBAProxyReference(module.getConfigId(), cssBean, new URI(remoteRef.getNsCorbaloc().trim()), remoteRef.getName().trim(), home);
  144               } catch (URISyntaxException e) {
  145                   throw new DeploymentException("Could not construct CORBA NameServer URI: " + remoteRef.getNsCorbaloc(), e);
  146               }
  147           }
  148           return ejbReference;
  149       }
  150   
  151       private void verifyInterfaces(String refName, URI moduleURI, ClassLoader cl, String remote, String home) throws DeploymentException {
  152           try {
  153               assureInterface(remote, "javax.ejb.EJBObject", "Remote", cl);
  154           } catch (DeploymentException e) {
  155               throw new DeploymentException("Error processing 'remote' element for EJB Reference '" + refName + "' for module '" + moduleURI + "': " + e.getMessage(), e);
  156           }
  157           try {
  158               assureInterface(home, "javax.ejb.EJBHome", "Home", cl);
  159           } catch (DeploymentException e) {
  160               throw new DeploymentException("Error processing 'home' element for EJB Reference '" + refName + "' for module '" + moduleURI + "': " + e.getMessage(), e);
  161           }
  162       }
  163   
  164       private static Map mapEjbRefs(XmlObject[] refs) {
  165           Map refMap = new HashMap();
  166           if (refs != null) {
  167               for (int i = 0; i < refs.length; i++) {
  168                   GerEjbRefType ref = (GerEjbRefType) refs[i];
  169                   refMap.put(ref.getRefName().trim(), ref);
  170               }
  171           }
  172           return refMap;
  173       }
  174   
  175   
  176       public static final GBeanInfo GBEAN_INFO;
  177   
  178       static {
  179           GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(OpenEjbCorbaRefBuilder.class, NameFactory.MODULE_BUILDER); //TODO decide what type this should be
  180           infoBuilder.addAttribute("eeNamespaces", String[].class, true, true);
  181           infoBuilder.addAttribute("defaultEnvironment", Environment.class, true, true);
  182   
  183           infoBuilder.setConstructor(new String[]{"defaultEnvironment", "eeNamespaces"});
  184   
  185           GBEAN_INFO = infoBuilder.getBeanInfo();
  186       }
  187   
  188       public static GBeanInfo getGBeanInfo() {
  189           return GBEAN_INFO;
  190       }
  191   
  192   }

Home » geronimo-2.2-source-release » org.apache.geronimo.corba.deployment » [javadoc | source]