Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.naming.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.naming.deployment;
   19   
   20   import java.util.Arrays;
   21   import java.util.HashSet;
   22   import java.util.Map;
   23   import java.util.Set;
   24   
   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.GBeanData;
   30   import org.apache.geronimo.gbean.GBeanInfo;
   31   import org.apache.geronimo.gbean.GBeanInfoBuilder;
   32   import org.apache.geronimo.j2ee.deployment.Module;
   33   import org.apache.geronimo.j2ee.deployment.NamingBuilder;
   34   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   35   import org.apache.geronimo.kernel.ClassLoading;
   36   import org.apache.geronimo.kernel.GBeanNotFoundException;
   37   import org.apache.geronimo.naming.reference.GBeanReference;
   38   import org.apache.geronimo.xbeans.geronimo.naming.GerGbeanRefDocument;
   39   import org.apache.geronimo.xbeans.geronimo.naming.GerGbeanRefType;
   40   import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
   41   import org.apache.xmlbeans.QNameSet;
   42   import org.apache.xmlbeans.XmlObject;
   43   
   44   /**
   45    * @version $Rev: 535381 $ $Date: 2007-05-04 14:04:18 -0700 (Fri, 04 May 2007) $
   46    */
   47   public class GBeanRefBuilder extends AbstractNamingBuilder {
   48       private static final QName GBEAN_REF_QNAME = GerGbeanRefDocument.type.getDocumentElementName();
   49       private static final QNameSet GBEAN_REF_QNAME_SET = QNameSet.singleton(GBEAN_REF_QNAME);
   50   
   51       public void buildNaming(XmlObject specDD, XmlObject plan, Module module, Map componentContext) throws DeploymentException {
   52           if (plan == null) {
   53               return;
   54           }
   55           XmlObject[] gbeanRefsUntyped = plan.selectChildren(GBEAN_REF_QNAME_SET);
   56           for (XmlObject gbeanRefUntyped : gbeanRefsUntyped) {
   57               GerGbeanRefType gbeanRef = (GerGbeanRefType) gbeanRefUntyped.copy().changeType(GerGbeanRefType.type);
   58               if (gbeanRef == null) {
   59                   throw new DeploymentException("Could not read gbeanRef " + gbeanRefUntyped + " as the correct xml type");
   60               }
   61               GerPatternType[] gbeanLocatorArray = gbeanRef.getPatternArray();
   62   
   63               String[] interfaceTypesArray = gbeanRef.getRefTypeArray();
   64               Set<String> interfaceTypes = new HashSet<String>(Arrays.asList(interfaceTypesArray));
   65               Set<AbstractNameQuery> queries = new HashSet<AbstractNameQuery>();
   66               for (GerPatternType patternType : gbeanLocatorArray) {
   67                   AbstractNameQuery abstractNameQuery = ENCConfigBuilder.buildAbstractNameQuery(patternType, null, null, interfaceTypes);
   68                   queries.add(abstractNameQuery);
   69               }
   70   
   71               GBeanData gBeanData;
   72               try {
   73                   gBeanData = module.getEarContext().getConfiguration().findGBeanData(queries);
   74               } catch (GBeanNotFoundException e) {
   75                   throw new DeploymentException("Could not resolve reference at deploy time for queries " + queries, e);
   76               }
   77   
   78               if (interfaceTypes.isEmpty()) {
   79                   interfaceTypes.add(gBeanData.getGBeanInfo().getClassName());
   80               }
   81               ClassLoader cl = module.getEarContext().getClassLoader();
   82               Class gBeanType;
   83               try {
   84                   gBeanType = ClassLoading.loadClass(gBeanData.getGBeanInfo().getClassName(), cl);
   85               } catch (ClassNotFoundException e) {
   86                   throw new DeploymentException("Cannot load GBean class", e);
   87               }
   88   
   89               String refName = gbeanRef.getRefName();
   90   
   91               NamingBuilder.JNDI_KEY.get(componentContext).put(ENV + refName, new GBeanReference(module.getConfigId(), queries, gBeanType));
   92   
   93           }
   94       }
   95   
   96       public QNameSet getSpecQNameSet() {
   97           return QNameSet.EMPTY;
   98       }
   99   
  100       public QNameSet getPlanQNameSet() {
  101           return GBEAN_REF_QNAME_SET;
  102       }
  103   
  104       public static final GBeanInfo GBEAN_INFO;
  105   
  106       static {
  107           GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(GBeanRefBuilder.class, NameFactory.MODULE_BUILDER);
  108   
  109           GBEAN_INFO = infoBuilder.getBeanInfo();
  110       }
  111   
  112       public static GBeanInfo getGBeanInfo() {
  113           return GBEAN_INFO;
  114       }
  115   
  116   }

Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.naming.deployment » [javadoc | source]