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

    1   /**
    2    *
    3    * Licensed to the Apache Software Foundation (ASF) under one or more
    4    * contributor license agreements.  See the NOTICE file distributed with
    5    * this work for additional information regarding copyright ownership.
    6    * The ASF licenses this file to You under the Apache License, Version 2.0
    7    * (the "License"); you may not use this file except in compliance with
    8    * 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, software
   13    *  distributed under the License is distributed on an "AS IS" BASIS,
   14    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15    *  See the License for the specific language governing permissions and
   16    *  limitations under the License.
   17    */
   18   package org.apache.geronimo.openejb;
   19   
   20   import java.lang.reflect.Method;
   21   import java.util.Set;
   22   import java.util.concurrent.atomic.AtomicReference;
   23   
   24   import javax.ejb.EJBHome;
   25   import javax.ejb.EJBLocalHome;
   26   import javax.ejb.EJBObject;
   27   import javax.naming.Context;
   28   import javax.naming.NamingException;
   29   import javax.security.auth.Subject;
   30   import javax.security.auth.login.LoginException;
   31   
   32   import org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator;
   33   import org.apache.geronimo.management.EJB;
   34   import org.apache.geronimo.security.jacc.RunAsSource;
   35   import org.apache.openejb.BeanType;
   36   import org.apache.openejb.Container;
   37   import org.apache.openejb.InterfaceType;
   38   import org.apache.openejb.core.CoreDeploymentInfo;
   39   import org.apache.openejb.core.ivm.EjbObjectProxyHandler;
   40   import org.apache.openejb.core.transaction.TransactionType;
   41   
   42   public class EjbDeployment implements EJB, EjbDeploymentIdAccessor {
   43       private final String objectName;
   44       protected final String deploymentId;
   45       private final String ejbName;
   46   
   47       private final String homeInterfaceName;
   48       private final String remoteInterfaceName;
   49       private final String localHomeInterfaceName;
   50       private final String localInterfaceName;
   51       private final String serviceEndpointInterfaceName;
   52       private final String beanClassName;
   53       private final ClassLoader classLoader;
   54   
   55       private final boolean securityEnabled;
   56       private final Subject defaultSubject;
   57       private final Subject runAs;
   58   
   59       private final Context componentContext;
   60   
   61       // connector stuff
   62       private final Set unshareableResources;
   63       private final Set applicationManagedSecurityResources;
   64       private final TrackedConnectionAssociator trackedConnectionAssociator;
   65   
   66       protected final OpenEjbSystem openEjbSystem;
   67   
   68       protected AtomicReference<CoreDeploymentInfo> deploymentInfo = new AtomicReference<CoreDeploymentInfo>();
   69   
   70       private Context javaCompSubContext;
   71   
   72       public EjbDeployment() throws LoginException {
   73           this(null, null, null, null, null, null, null, null, null, null,
   74                false, null, null, null, null, null, null, null, null);
   75       }
   76   
   77       public EjbDeployment(String objectName,
   78               String deploymentId,
   79               String ejbName,
   80               String homeInterfaceName,
   81               String remoteInterfaceName,
   82               String localHomeInterfaceName,
   83               String localInterfaceName,
   84               String serviceEndpointInterfaceName,
   85               String beanClassName,
   86               ClassLoader classLoader,
   87               boolean securityEnabled,
   88               String defaultRole,
   89               String runAsRole,
   90               RunAsSource runAsSource,
   91               Context componentContext,
   92               Set unshareableResources,
   93               Set applicationManagedSecurityResources,
   94               TrackedConnectionAssociator trackedConnectionAssociator,
   95               OpenEjbSystem openEjbSystem) throws LoginException {
   96           this.objectName = objectName;
   97           this.deploymentId = deploymentId;
   98           this.ejbName = ejbName;
   99           this.homeInterfaceName = homeInterfaceName;
  100           this.remoteInterfaceName = remoteInterfaceName;
  101           this.localHomeInterfaceName = localHomeInterfaceName;
  102           this.localInterfaceName = localInterfaceName;
  103           this.serviceEndpointInterfaceName = serviceEndpointInterfaceName;
  104           this.beanClassName = beanClassName;
  105           this.classLoader = classLoader;
  106           this.securityEnabled = securityEnabled;
  107           if (runAsSource == null) {
  108               runAsSource = RunAsSource.NULL;
  109           }
  110           this.defaultSubject = defaultRole == null? runAsSource.getDefaultSubject(): runAsSource.getSubjectForRole(defaultRole);
  111           this.runAs = runAsSource.getSubjectForRole(runAsRole);
  112           this.componentContext = componentContext;
  113           this.unshareableResources = unshareableResources;
  114           this.applicationManagedSecurityResources = applicationManagedSecurityResources;
  115           this.trackedConnectionAssociator = trackedConnectionAssociator;
  116           this.openEjbSystem = openEjbSystem;
  117       }
  118   
  119       public CoreDeploymentInfo getDeploymentInfo() {
  120           return deploymentInfo.get();
  121       }
  122   
  123       public String getDeploymentId() {
  124           return deploymentId;
  125       }
  126   
  127       public String getEjbName() {
  128           return ejbName;
  129       }
  130   
  131       public String getHomeInterfaceName() {
  132           return homeInterfaceName;
  133       }
  134   
  135       public String getRemoteInterfaceName() {
  136           return remoteInterfaceName;
  137       }
  138   
  139       public String getLocalHomeInterfaceName() {
  140           return localHomeInterfaceName;
  141       }
  142   
  143       public String getLocalInterfaceName() {
  144           return localInterfaceName;
  145       }
  146   
  147       public String getServiceEndpointInterfaceName() {
  148           return serviceEndpointInterfaceName;
  149       }
  150   
  151       public String getBeanClassName() {
  152           return beanClassName;
  153       }
  154   
  155       public ClassLoader getClassLoader() {
  156           return classLoader;
  157       }
  158   
  159       public boolean isSecurityEnabled() {
  160           return securityEnabled;
  161       }
  162   
  163       public Subject getDefaultSubject() {
  164           return defaultSubject;
  165       }
  166   
  167       public Subject getRunAs() {
  168           return runAs;
  169       }
  170   
  171       public Context getComponentContext() {
  172           return javaCompSubContext;
  173       }
  174   
  175       public Set getUnshareableResources() {
  176           return unshareableResources;
  177       }
  178   
  179       public Set getApplicationManagedSecurityResources() {
  180           return applicationManagedSecurityResources;
  181       }
  182   
  183       public TrackedConnectionAssociator getTrackedConnectionAssociator() {
  184           return trackedConnectionAssociator;
  185       }
  186   
  187       public EJBHome getEJBHome() {
  188           return getDeploymentInfo().getEJBHome();
  189       }
  190   
  191       public EJBLocalHome getEJBLocalHome() {
  192           return getDeploymentInfo().getEJBLocalHome();
  193       }
  194   
  195       public Object getBusinessLocalHome() {
  196           return getDeploymentInfo().getBusinessLocalHome();
  197       }
  198   
  199       public Object getBusinessRemoteHome() {
  200           return getDeploymentInfo().getBusinessRemoteHome();
  201       }
  202   
  203       public EJBObject getEjbObject(Object primaryKey) {
  204           return (EJBObject) EjbObjectProxyHandler.createProxy(getDeploymentInfo(), primaryKey, InterfaceType.EJB_HOME);
  205       }
  206   
  207       public Class getHomeInterface() {
  208           return getDeploymentInfo().getHomeInterface();
  209       }
  210   
  211       public Class getRemoteInterface() {
  212           return getDeploymentInfo().getRemoteInterface();
  213       }
  214   
  215       public Class getLocalHomeInterface() {
  216           return getDeploymentInfo().getLocalHomeInterface();
  217       }
  218   
  219       public Class getLocalInterface() {
  220           return getDeploymentInfo().getLocalInterface();
  221       }
  222   
  223       public Class getBeanClass() {
  224           return getDeploymentInfo().getBeanClass();
  225       }
  226   
  227       public Class getBusinessLocalInterface() {
  228           return getDeploymentInfo().getBusinessLocalInterface();
  229       }
  230   
  231       public Class getBusinessRemoteInterface() {
  232           return getDeploymentInfo().getBusinessRemoteInterface();
  233       }
  234   
  235       public Class getMdbInterface() {
  236           return getDeploymentInfo().getMdbInterface();
  237       }
  238   
  239       public Class getServiceEndpointInterface() {
  240           return getDeploymentInfo().getServiceEndpointInterface();
  241       }
  242   
  243       public BeanType getComponentType() {
  244           return getDeploymentInfo().getComponentType();
  245       }
  246   
  247       public Container getContainer() {
  248           return getDeploymentInfo().getContainer();
  249       }
  250   
  251       public boolean isBeanManagedTransaction() {
  252           return getDeploymentInfo().isBeanManagedTransaction();
  253       }
  254   
  255       public TransactionType getTransactionType(Method method) {
  256             return getDeploymentInfo().getTransactionType(method);
  257       }
  258       
  259       public String getObjectName() {
  260           return objectName;
  261       }
  262   
  263       public boolean isStateManageable() {
  264           return true;
  265       }
  266   
  267       public boolean isStatisticsProvider() {
  268           return false;
  269       }
  270   
  271       public boolean isEventProvider() {
  272           return true;
  273       }
  274   
  275       protected EjbDeployment initialize(CoreDeploymentInfo deploymentInfo) {
  276           try {
  277               javaCompSubContext = (Context) deploymentInfo.getJndiEnc().lookup("java:comp");
  278               if (componentContext != null) {
  279                   javaCompSubContext.bind("geronimo", componentContext);
  280               }
  281   
  282               deploymentInfo.set(EjbDeployment.class, this);
  283   
  284               this.deploymentInfo.set(deploymentInfo);
  285   
  286               return this;
  287           } catch (NamingException e) {
  288               throw new IllegalStateException("Unable to complete EjbDeployment initialization", e);
  289           }
  290       }
  291   
  292       protected void destroy() {
  293           CoreDeploymentInfo info = deploymentInfo.getAndSet(null);
  294           if (info != null) {
  295               info.set(EjbDeployment.class, null);
  296           }
  297       }
  298   }

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