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

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
   10    *  http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied.  See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.
   18    */
   19   
   20   
   21   package org.apache.geronimo.corba.deployment;
   22   
   23   import java.net.URI;
   24   import java.util.Map;
   25   import java.util.Collections;
   26   
   27   import javax.xml.namespace.QName;
   28   
   29   import org.apache.geronimo.common.DeploymentException;
   30   import org.apache.geronimo.gbean.AbstractName;
   31   import org.apache.geronimo.gbean.AbstractNameQuery;
   32   import org.apache.geronimo.gbean.GBeanData;
   33   import org.apache.geronimo.gbean.GBeanInfo;
   34   import org.apache.geronimo.gbean.GBeanInfoBuilder;
   35   import org.apache.geronimo.j2ee.deployment.Module;
   36   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   37   import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
   38   import org.apache.geronimo.kernel.GBeanNotFoundException;
   39   import org.apache.geronimo.kernel.repository.Environment;
   40   import org.apache.geronimo.naming.deployment.AbstractNamingBuilder;
   41   import org.apache.geronimo.naming.deployment.ENCConfigBuilder;
   42   import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
   43   import org.apache.geronimo.corba.TSSLinkGBean;
   44   import org.apache.geronimo.corba.xbeans.csiv2.tss.TSSTssDocument;
   45   import org.apache.xmlbeans.QNameSet;
   46   import org.apache.xmlbeans.XmlObject;
   47   import org.apache.xmlbeans.XmlString;
   48   
   49   /**
   50    * @version $Rev: 882783 $ $Date: 2009-11-20 15:30:26 -0800 (Fri, 20 Nov 2009) $
   51    */
   52   public class TSSLinkBuilder extends AbstractNamingBuilder {
   53       private static final String TSS_NAMESPACE = TSSTssDocument.type.getDocumentElementName().getNamespaceURI();
   54       private static final QName TSS_LINK_QNAME = new QName(TSS_NAMESPACE, "tss-link");
   55       private static final QName TSS_QNAME = new QName(TSS_NAMESPACE, "tss");
   56       private static final QName JNDI_NAME_QNAME = new QName(TSS_NAMESPACE, "jndi-name");
   57   
   58       public TSSLinkBuilder() {
   59       }
   60   
   61       public TSSLinkBuilder(Environment defaultEnvironment) {
   62           super(defaultEnvironment);
   63       }
   64   
   65       protected boolean willMergeEnvironment(XmlObject specDD, XmlObject plan) {
   66           return true;
   67   //        return hasTssLinks(plan);
   68       }
   69   
   70   //    static boolean hasTssLinks(XmlObject plan) {
   71   //        return plan != null && (plan.selectChildren(TSS_LINK_QNAME).length > 0 ||
   72   //                plan.selectChildren(TSS_QNAME).length > 0);
   73   //    }
   74   
   75       public void buildNaming(XmlObject specDD, XmlObject plan, Module module, Map componentContext) throws DeploymentException {
   76           if (plan == null) {
   77               return;
   78           }
   79   
   80           AbstractName ejbName = getGBeanName(componentContext);
   81   
   82           String[] tssLinks = toStringArray(plan.selectChildren(TSS_LINK_QNAME));
   83           XmlObject[] tsss = plan.selectChildren(TSS_QNAME);
   84           String[] jndiNames = toStringArray(plan.selectChildren(JNDI_NAME_QNAME));
   85           AbstractNameQuery ejbModuleName = NameFactory.newTypeNameQuery(module.getEarContext().getConfigID(), NameFactory.EJB_MODULE, module.getName());
   86           for (int i = 0; i < tssLinks.length; i++) {
   87               String tssLink = tssLinks[i];
   88               URI moduleURI = module.getModuleURI();
   89               String moduleString = moduleURI == null ? null : moduleURI.toString();
   90               AbstractNameQuery tssBeanName = ENCConfigBuilder.buildAbstractNameQuery(null, moduleString, tssLink, NameFactory.EJB_MODULE, NameFactory.EJB_MODULE);
   91               try {
   92                   module.getEarContext().findGBean(tssBeanName);
   93               } catch (GBeanNotFoundException e) {
   94                   tssBeanName = ENCConfigBuilder.buildAbstractNameQuery(null, null, tssLink, null, NameFactory.EJB_MODULE);
   95                   try {
   96                       module.getEarContext().findGBean(tssBeanName);
   97                   } catch (GBeanNotFoundException e1) {
   98                       throw new DeploymentException("No tss bean found", e);
   99                   }
  100               }
  101               AbstractName tssLinkName = module.getEarContext().getNaming().createChildName(ejbName, "tssLink" + i, "TSSLink");
  102               GBeanData tssLinkData = new GBeanData(tssLinkName, TSSLinkGBean.GBEAN_INFO);
  103               tssLinkData.setAttribute("jndiNames", jndiNames);
  104               tssLinkData.setReferencePattern("EJB", ejbName);
  105               tssLinkData.setReferencePattern("TSSBean", tssBeanName);
  106               tssLinkData.addDependency(ejbModuleName);
  107               try {
  108                   module.getEarContext().addGBean(tssLinkData);
  109               } catch (GBeanAlreadyExistsException e) {
  110                   throw new DeploymentException("tss link gbean already present", e);
  111               }
  112           }
  113           for (int i = 0; i < tsss.length; i++) {
  114               GerPatternType tss = (GerPatternType) tsss[i];
  115               AbstractNameQuery tssBeanName = ENCConfigBuilder.buildAbstractNameQuery(tss, NameFactory.CORBA_TSS, NameFactory.EJB_MODULE, null);
  116               AbstractName tssLinkName = module.getEarContext().getNaming().createChildName(ejbName, "tssRef" + i, "TSSLink");
  117               GBeanData tssLinkData = new GBeanData(tssLinkName, TSSLinkGBean.GBEAN_INFO);
  118               tssLinkData.setAttribute("jndiNames", jndiNames);
  119               tssLinkData.setReferencePattern("EJB", ejbName);
  120               tssLinkData.setReferencePattern("TSSBean", tssBeanName);
  121               tssLinkData.addDependency(ejbModuleName);
  122               try {
  123                   module.getEarContext().addGBean(tssLinkData);
  124               } catch (GBeanAlreadyExistsException e) {
  125                   throw new DeploymentException("tss link gbean already present", e);
  126               }
  127           }
  128   
  129       }
  130   
  131       public QNameSet getSpecQNameSet() {
  132           return QNameSet.EMPTY;
  133       }
  134   
  135       public QNameSet getPlanQNameSet() {
  136           return QNameSet.singleton(TSS_LINK_QNAME);
  137       }
  138   
  139       private String[] toStringArray(XmlObject[] xmlObjects) {
  140           String[] result = new String[xmlObjects.length];
  141           for (int i = 0; i < result.length; i++) {
  142               // toString() and xmlText() insert tags around the value, which
  143               // is most definitely NOT what we want.
  144               result[i] = ((XmlString)xmlObjects[i]).getStringValue();
  145           }
  146           return result;
  147       }
  148   
  149       public static final GBeanInfo GBEAN_INFO;
  150   
  151       static {
  152           GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(TSSLinkBuilder.class, NameFactory.MODULE_BUILDER); //TODO decide what type this should be
  153           infoBuilder.addAttribute("defaultEnvironment", Environment.class, true, true);
  154   
  155           infoBuilder.setConstructor(new String[] {"defaultEnvironment"});
  156   
  157           GBEAN_INFO = infoBuilder.getBeanInfo();
  158       }
  159   
  160       public static GBeanInfo getGBeanInfo() {
  161           return GBEAN_INFO;
  162       }
  163   
  164   }
  165   
  166   

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