Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016,2017] [Payara Foundation and/or its affiliates]
package com.sun.ejb.containers;
import com.sun.ejb.*;
import com.sun.ejb.codegen.EjbOptionalIntfGenerator;
import com.sun.ejb.codegen.ServiceInterfaceGenerator;
import com.sun.ejb.containers.interceptors.InterceptorManager;
import com.sun.ejb.containers.interceptors.SystemInterceptorProxy;
import com.sun.ejb.containers.util.MethodMap;
import com.sun.ejb.monitoring.probes.EjbCacheProbeProvider;
import com.sun.ejb.monitoring.probes.EjbMonitoringProbeProvider;
import com.sun.ejb.monitoring.probes.EjbTimedObjectProbeProvider;
import com.sun.ejb.monitoring.stats.*;
import com.sun.ejb.portable.EJBMetaDataImpl;
import com.sun.ejb.spi.container.OptionalLocalInterfaceProvider;
import com.sun.enterprise.admin.monitor.callflow.CallFlowInfo;
import com.sun.enterprise.admin.monitor.callflow.ComponentType;
import com.sun.enterprise.container.common.spi.JCDIService;
import com.sun.enterprise.container.common.spi.JavaEEContainer;
import com.sun.enterprise.container.common.spi.util.ComponentEnvManager;
import com.sun.enterprise.container.common.spi.util.IndirectlySerializable;
import com.sun.enterprise.container.common.spi.util.InjectionManager;
import com.sun.enterprise.deployment.*;
import com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType;
import com.sun.enterprise.deployment.util.TypeUtil;
import com.sun.enterprise.deployment.xml.RuntimeTagNames;
import com.sun.enterprise.security.SecurityManager;
import com.sun.enterprise.transaction.api.JavaEETransaction;
import com.sun.enterprise.transaction.api.JavaEETransactionManager;
import com.sun.enterprise.util.LocalStringManagerImpl;
import com.sun.enterprise.util.Utility;
import fish.payara.nucleus.requesttracing.RequestTracingService;
import fish.payara.nucleus.requesttracing.domain.RequestEvent;
import org.glassfish.api.invocation.ComponentInvocation;
import org.glassfish.api.invocation.InvocationManager;
import org.glassfish.api.naming.GlassfishNamingManager;
import org.glassfish.deployment.common.DeploymentException;
import org.glassfish.deployment.common.Descriptor;
import org.glassfish.ejb.LogFacade;
import org.glassfish.ejb.api.EjbEndpointFacade;
import org.glassfish.ejb.deployment.descriptor.*;
import org.glassfish.ejb.deployment.descriptor.EjbDescriptor;
import org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor;
import org.glassfish.ejb.spi.EjbContainerInterceptor;
import org.glassfish.ejb.spi.WSEjbEndpointRegistry;
import org.glassfish.enterprise.iiop.api.GlassFishORBHelper;
import org.glassfish.enterprise.iiop.api.ProtocolManager;
import org.glassfish.enterprise.iiop.api.RemoteReferenceFactory;
import org.glassfish.enterprise.iiop.spi.EjbContainerFacade;
import org.glassfish.flashlight.provider.ProbeProviderFactory;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.internal.api.Globals;
import org.glassfish.logging.annotation.LogMessageInfo;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.*;
import javax.interceptor.AroundConstruct;
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.transaction.*;
import static com.sun.enterprise.deployment.MethodDescriptor.EJB_WEB_SERVICE;
import java.io.Serializable;
import java.lang.reflect.*;
import java.rmi.AccessException;
import java.rmi.RemoteException;
import java.util.*;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.enterprise.inject.Vetoed;
/**
* This class implements part of the com.sun.ejb.Container interface.
* It implements the container's side of the EJB-to-Container
* contract definweed by the EJB 2.0 spec.
* It contains code shared by SessionBeans, EntityBeans and MessageDrivenBeans.
* Its subclasses provide the remaining implementation of the
* container functionality.
*
*/
public abstract class BaseContainer implements Container, EjbContainerFacade, JavaEEContainer {
public enum ContainerType {
STATELESS, STATEFUL, SINGLETON, MESSAGE_DRIVEN, ENTITY, READ_ONLY
};
protected static final Logger _logger = LogFacade.getLogger();
@LogMessageInfo(
message = "The feature {0} requires Full Java EE Profile to be supported",
level = "WARNING")
private static final String WARN_FEATURE_REQUIRES_FULL_PROFILE = "AS-EJB-00053";
@LogMessageInfo(
message = "Portable JNDI names for EJB {0}: {1}",
level = "INFO")
private static final String PORTABLE_JNDI_NAMES = "AS-EJB-00054";
@LogMessageInfo(
message = "Glassfish-specific (Non-portable) JNDI names for EJB {0}: {1}",
level = "INFO")
private static final String GLASSFISH_SPECIFIC_JNDI_NAMES = "AS-EJB-00055";
@LogMessageInfo(
message = "A system exception occurred during an invocation on EJB {0}, method: {1}",
level = "WARNING")
private static final String SYSTEM_EXCEPTION = "AS-EJB-00056";
@LogMessageInfo(
message = "Error while creating enterprise bean context for {0} during jacc callback",
level = "WARNING")
private static final String CONTEXT_FAILURE_JACC = "AS-EJB-00057";
@LogMessageInfo(
message = "Attempt to override reserved ejb interface method [{0}] in [{1}]. Override will be ignored.",
level = "WARNING")
private static final String ILLEGAL_EJB_INTERFACE_OVERRIDE = "AS-EJB-00058";
@LogMessageInfo(
message = "Bean class for ejb [{0}] does not define a method corresponding to [{1}] interface method [{2}]",
level = "WARNING")
private static final String BEAN_CLASS_METHOD_NOT_FOUND = "AS-EJB-00059";
@LogMessageInfo(
message = "keepstate is true and will not create new auto timers during deployment.",
level = "INFO")
private static final String KEEPSTATE_IS_TRUE = "AS-EJB-00060";
@LogMessageInfo(
message = "Failed to initialize the interceptor",
level = "SEVERE",
cause = "Error during initializing the interceptor",
action = "Try to restart the server")
private static final String FAILED_TO_INITIALIZE_INTERCEPTOR = "AS-EJB-00061";
@LogMessageInfo(
message = "[**BaseContainer**] Could not create MonitorRegistryMediator. [{0}]",
level = "SEVERE",
cause = "Fail to create MonitorRegistryMediator",
action = "Check the exception stack")
private static final String COULD_NOT_CREATE_MONITORREGISTRYMEDIATOR = "AS-EJB-00062";
@LogMessageInfo(
message = "Internal Error",
level = "WARNING",
cause = "Error during invoke the ejb application",
action = "Trying to invoke the ejb application"
)
private static final String INTERNAL_ERROR = "AS-EJB-00052";
protected static final Class[] NO_PARAMS = new Class[] {};
protected Object[] logParams = null;
protected ContainerType containerType;
private RequestTracingService requestTracing;
// constants for EJB(Local)Home/EJB(Local)Object methods,
// used in authorizeRemoteMethod and authorizeLocalMethod
private static final int EJB_INTF_METHODS_LENGTH = 16;
static final int EJBHome_remove_Handle = 0;
static final int EJBHome_remove_Pkey = 1;
static final int EJBHome_getEJBMetaData = 2;
static final int EJBHome_getHomeHandle = 3;
static final int EJBLocalHome_remove_Pkey = 4;
static final int EJBObject_getEJBHome = 5;
protected static final int EJBObject_getPrimaryKey = 6; //TODO - move related to entity-container
static final int EJBObject_remove = 7;
static final int EJBObject_getHandle = 8;
static final int EJBObject_isIdentical = 9;
static final int EJBLocalObject_getEJBLocalHome = 10;
protected static final int EJBLocalObject_getPrimaryKey = 11; //TODO - move related to entity-container
static final int EJBLocalObject_remove = 12;
static final int EJBLocalObject_isIdentical = 13;
static final int EJBHome_create = 14;
static final int EJBLocalHome_create = 15;
// true if home method, false if component intf method.
// Used for setting info on invocation object during authorization.
private static final boolean[] EJB_INTF_METHODS_INFO =
{ true, true, true, true, true,
false, false, false, false, false,
false, false, false, false,
true, true };
private static final byte HOME_KEY = (byte)0xff;
private static final byte[] homeInstanceKey = {HOME_KEY};
protected static final String SINGLETON_BEAN_POOL_PROP = "singleton-bean-pool";
protected ClassLoader loader = null;
protected Class> ejbClass = null;
protected Class sfsbSerializedClass = null;
protected Method ejbPassivateMethod = null;
protected Method ejbActivateMethod = null;
protected Method ejbRemoveMethod = null;
private Method ejbTimeoutMethod = null;
protected Class webServiceEndpointIntf = null;
// true if exposed as a web service endpoint.
protected boolean isWebServiceEndpoint = false;
private boolean isTimedObject_ = false;
/*****************************************
* Data members for Local views *
*****************************************/
// True if bean has a LocalHome/Local view
// OR a Local business view OR both.
protected boolean isLocal=false;
// True if bean exposes a local home view
protected boolean hasLocalHomeView=false;
// True if bean exposes a local business view
protected boolean hasLocalBusinessView=false;
protected boolean hasOptionalLocalBusinessView = false;
protected Class ejbGeneratedOptionalLocalBusinessIntfClass;
//
// Data members for LocalHome/Local view
//
// LocalHome interface written by developer
protected Class localHomeIntf = null;
// Local interface written by developer
private Class localIntf = null;
// Client reference to ejb local home
protected EJBLocalHome ejbLocalHome;
// Implementation of ejb local home. May or may not be the same
// object as ejbLocalHome, for example in the case of dynamic proxies.
protected EJBLocalHomeImpl ejbLocalHomeImpl;
// Constructor used to instantiate ejb local object proxy.
private Constructor ejbLocalObjectProxyCtor;
//
// Data members for 3.x Local business view
//
// Internal interface describing operation used to create an
// instance of a local business object. (GenericEJBLocalHome)
protected Class localBusinessHomeIntf = null;
protected Class ejbOptionalLocalBusinessHomeIntf = null;
// Local business interface written by developer
protected Set localBusinessIntfs = new HashSet();
// Client reference to internal local business home interface.
// This is only seen by internal ejb code that instantiates local
// business objects during lookups.
protected GenericEJBLocalHome ejbLocalBusinessHome;
protected GenericEJBLocalHome ejbOptionalLocalBusinessHome;
// Implementation of internal local business home interface.
protected EJBLocalHomeImpl ejbLocalBusinessHomeImpl;
// Implementation of internal local business home interface.
protected EJBLocalHomeImpl ejbOptionalLocalBusinessHomeImpl;
// Constructor used to instantiate local business object proxy.
private Constructor ejbLocalBusinessObjectProxyCtor;
// Constructor used to instantiate local business object proxy.
private Constructor ejbOptionalLocalBusinessObjectProxyCtor;
private Collection interceptors = null;
/*****************************************
* Data members for Remote views *
*****************************************/
// True if bean has a RemoteHome/Remote view
// OR a Remote business view OR both.
protected boolean isRemote=false;
// True if bean exposes a RemoteHome view
protected boolean hasRemoteHomeView=false;
// True if bean exposes a Remote Business view.
protected boolean hasRemoteBusinessView=false;
//
// Data members for RemoteHome/Remote view
//
// Home interface written by developer.
protected Class homeIntf = null;
// Remote interface written by developer.
protected Class remoteIntf = null;
// Container implementation of EJB Home. May or may not be the same
// object as ejbHome, for example in the case of dynamic proxies.
protected EJBHomeImpl ejbHomeImpl;
// EJB Home reference used by ORB Tie within server to deliver
// invocation.
protected EJBHome ejbHome;
// Client reference to EJB Home.
protected EJBHome ejbHomeStub;
// Remote interface proxy class
private Class ejbObjectProxyClass;
// Remote interface proxy constructor.
private Constructor ejbObjectProxyCtor;
// RemoteReference Factory for RemoteHome view
protected RemoteReferenceFactory remoteHomeRefFactory = null;
//
// Data members for 3.x Remote business view
//
// Internal interface describing operation used to create an
// instance of a remote business object.
protected Class remoteBusinessHomeIntf = null;
// Container implementation of internal EJB Business Home. May or may
// not be same object as ejbRemoteBusinessHome, for example in the
// case of dynamic proxies.
protected EJBHomeImpl ejbRemoteBusinessHomeImpl;
// EJB Remote Business Home reference used by ORB Tie within server
// to deliver invocation.
protected EJBHome ejbRemoteBusinessHome;
// Client reference to internal Remote EJB Business Home. This is
// only seen by internal EJB code that instantiates remote business
// objects during lookups.
protected EJBHome ejbRemoteBusinessHomeStub;
// Holds information such as remote reference factory that are associated
// with a particular remote business interface
protected Map remoteBusinessIntfInfo
= new HashMap();
//
// END -- Data members for Remote views
//
protected EJBMetaData metadata = null;
protected final SecurityManager securityManager;
protected boolean isSession;
protected boolean isStatelessSession;
protected boolean isStatefulSession;
protected boolean isMessageDriven;
protected boolean isSingleton;
protected EjbDescriptor ejbDescriptor;
protected String componentId; // unique id for java:comp namespace lookup
protected Map invocationInfoMap = new HashMap();
protected Map scheduleIds =
new HashMap();
Map> schedules =
new HashMap>();
// Need a separate map for web service methods since it's possible for
// an EJB Remote interface to be a subtype of the Service Endpoint
// Interface. In that case, it's ambiguous to do a lookup based only
// on a java.lang.reflect.Method
protected Map webServiceInvocationInfoMap = new HashMap();
// optimized method map for proxies to resolve invocation info
private MethodMap proxyInvocationInfoMap;
protected Method[] ejbIntfMethods;
protected InvocationInfo[] ejbIntfMethodInfo;
protected Properties envProps;
protected boolean isBeanManagedTran=false;
protected boolean debugMonitorFlag = false;
private static LocalStringManagerImpl localStrings =
new LocalStringManagerImpl(BaseContainer.class);
private ThreadLocal threadLocalContext = new ThreadLocal();
protected static final int CONTAINER_INITIALIZING = -1;
protected static final int CONTAINER_STARTED = 0;
protected static final int CONTAINER_STOPPED = 1;
protected static final int CONTAINER_UNDEPLOYED = 3;
protected static final int CONTAINER_ON_HOLD = 4;
protected int containerState = CONTAINER_INITIALIZING;
protected HashMap methodMonitorMap;
protected boolean monitorOn = false;
protected EjbMonitoringStatsProvider ejbProbeListener;
protected EjbMonitoringProbeProvider ejbProbeNotifier;
protected EjbTimedObjectStatsProvider timerProbeListener;
protected EjbTimedObjectProbeProvider timerProbeNotifier;
protected EjbPoolStatsProvider poolProbeListener;
protected EjbCacheProbeProvider cacheProbeNotifier;
protected EjbCacheStatsProvider cacheProbeListener;
protected EjbThreadPoolExecutorStatsProvider executorProbeListener;
protected ContainerInfo containerInfo;
private String _debugDescription;
//protected Agent callFlowAgent;
protected CallFlowInfo callFlowInfo;
protected InterceptorManager interceptorManager;
// the order must be the same as CallbackType and getPre30LifecycleMethodNames
private static final Class[] lifecycleCallbackAnnotationClasses = {
AroundConstruct.class,
PostConstruct.class, PreDestroy.class,
PrePassivate.class, PostActivate.class
};
private Set monitoredGeneratedClasses = new HashSet();
protected InvocationManager invocationManager;
protected InjectionManager injectionManager;
protected GlassfishNamingManager namingManager;
protected JavaEETransactionManager transactionManager;
private EjbInvocationFactory invFactory;
private ProtocolManager protocolMgr;
protected EjbContainerUtil ejbContainerUtilImpl = EjbContainerUtilImpl.getInstance();
protected EjbOptionalIntfGenerator optIntfClassLoader;
private Set publishedPortableGlobalJndiNames = new HashSet();
private Set publishedNonPortableGlobalJndiNames = new HashSet();
private Set publishedInternalGlobalJndiNames = new HashSet();
private Map jndiInfoMap = new HashMap();
private String optIntfClassName;
// Used to track whether we've done the base container cleanup (JNDI entries, etc.)
// Only. Not applicable to concrete containers.
private boolean baseContainerCleanupDone = false;
// True if there is at least one asynchronous method exposed from the bean.
private boolean hasAsynchronousInvocations = false;
// Information about a web service ejb endpoint. Used as a conduit
// between webservice runtime and ejb container. Contains a Remote
// servant used by jaxrpc to call web service business method.
private WebServiceEndpoint webServiceEndpoint;
//The Webservices Ejb Endpoint Registry contract
// used to register and unregister ejb webservices endpoints
private WSEjbEndpointRegistry wsejbEndpointRegistry;
protected EJBContainerStateManager containerStateManager;
protected EJBContainerTransactionManager containerTransactionManager;
private JCDIService jcdiService;
/**
* This constructor is called from ContainerFactoryImpl when an
* EJB Jar is deployed.
*/
protected BaseContainer(ContainerType type, EjbDescriptor ejbDesc, ClassLoader loader, SecurityManager sm)
throws Exception
{
this.containerType = type;
this.securityManager = sm;
this.requestTracing = Globals.getDefaultHabitat().getService(RequestTracingService.class);
try {
this.loader = loader;
this.ejbDescriptor = ejbDesc;
//this.callFlowAgent = ejbContainerUtilImpl.getCallFlowAgent();
logParams = new Object[1];
logParams[0] = ejbDesc.getName();
invocationManager = ejbContainerUtilImpl.getInvocationManager();
injectionManager = ejbContainerUtilImpl.getInjectionManager();
namingManager = ejbContainerUtilImpl.getGlassfishNamingManager();
transactionManager = ejbContainerUtilImpl.getTransactionManager();
// get Class objects for creating new EJBs
ejbClass = loader.loadClass(ejbDescriptor.getEjbImplClassName());
containerStateManager = new EJBContainerStateManager(this);
containerTransactionManager = new EJBContainerTransactionManager(this, ejbDesc);
isBeanManagedTran = ejbDescriptor.getTransactionType().equals("Bean");
if( ejbDescriptor instanceof EjbSessionDescriptor)
{
isSession = true;
EjbSessionDescriptor sd = (EjbSessionDescriptor) ejbDescriptor;
if( !sd.isSessionTypeSet() ) {
throw new RuntimeException(localStrings.getLocalString(
"ejb.session_type_not_set",
"Invalid ejb Descriptor. Session type not set for {0}: {1}",
sd.getName(), sd));
}
if (sd.isSingleton()) {
isSingleton = true;
} else {
isStatelessSession = sd.isStateless();
isStatefulSession = !isStatelessSession;
if( isStatefulSession ) {
/**
* If bean class isn't explicitly marked Serializable, generate
* a subclass that is. We do this with a generator that uses
* ASM directly instead of the CORBA codegen library since none
* of the corba .jars are part of the Web Profile.
*/
if( !Serializable.class.isAssignableFrom(ejbClass) ) {
sfsbSerializedClass = EJBUtils.loadGeneratedSerializableClass(ejbClass.getClassLoader(),
ejbClass.getName());
}
}
}
hasAsynchronousInvocations = sd.hasAsynchronousMethods();
}
if ( ejbDescriptor.isRemoteInterfacesSupported() ||
ejbDescriptor.isRemoteBusinessInterfacesSupported() ) {
assertFullProfile("exposes a Remote client view");
initializeProtocolManager();
}
if ( ejbDescriptor.isRemoteInterfacesSupported() ) {
isRemote = true;
hasRemoteHomeView = true;
String homeClassName = ejbDescriptor.getHomeClassName();
homeIntf = loader.loadClass(homeClassName);
remoteIntf = loader.loadClass(ejbDescriptor.getRemoteClassName());
String id = Long.toString(ejbDescriptor.getUniqueId()) + "_RHome";
remoteHomeRefFactory = getProtocolManager().getRemoteReferenceFactory(this, true, id);
}
if( ejbDescriptor.isRemoteBusinessInterfacesSupported() ) {
isRemote = true;
hasRemoteBusinessView = true;
remoteBusinessHomeIntf = EJBUtils.loadGeneratedGenericEJBHomeClass(loader);
for(String next : ejbDescriptor.getRemoteBusinessClassNames()) {
// The generated remote business interface and the
// client wrapper for the business interface are
// produced dynamically. The following call must be
// made before any EJB 3.0 Remote business interface
// runtime behavior is needed for a particular
// classloader.
EJBUtils.loadGeneratedRemoteBusinessClasses(loader, next);
String nextGen = EJBUtils.getGeneratedRemoteIntfName(next);
Class genRemoteIntf = loader.loadClass(nextGen);
RemoteBusinessIntfInfo info = new RemoteBusinessIntfInfo();
info.generatedRemoteIntf = genRemoteIntf;
info.remoteBusinessIntf = loader.loadClass(next);
// One remote reference factory for each remote
// business interface. Id must be unique across
// all ejb containers.
String id = Long.toString(ejbDescriptor.getUniqueId())
+ "_RBusiness" + "_" + genRemoteIntf.getName();
info.referenceFactory = getProtocolManager().
getRemoteReferenceFactory(this, false, id);
remoteBusinessIntfInfo.put(genRemoteIntf.getName(), info);
addToGeneratedMonitoredMethodInfo(nextGen, genRemoteIntf);
}
}
if ( ejbDescriptor.isLocalInterfacesSupported() ) {
// initialize class objects for LocalHome/LocalIntf etc.
isLocal = true;
hasLocalHomeView = true;
String localHomeClassName = ejbDescriptor.getLocalHomeClassName();
localHomeIntf = loader.loadClass(localHomeClassName);
localIntf = loader.loadClass (ejbDescriptor.getLocalClassName());
}
if( ejbDescriptor.isLocalBusinessInterfacesSupported() ) {
isLocal = true;
hasLocalBusinessView = true;
localBusinessHomeIntf = GenericEJBLocalHome.class;
for(String next : ejbDescriptor.getLocalBusinessClassNames() ) {
Class clz = loader.loadClass(next);
localBusinessIntfs.add(clz);
addToGeneratedMonitoredMethodInfo(next, clz);
}
}
if( ejbDescriptor.isLocalBean() ) {
isLocal = true;
hasOptionalLocalBusinessView = true;
ejbOptionalLocalBusinessHomeIntf = GenericEJBLocalHome.class;
Class clz = loader.loadClass(ejbDescriptor.getEjbClassName());
addToGeneratedMonitoredMethodInfo(ejbDescriptor.getEjbClassName(), clz);
this.optIntfClassName = EJBUtils.getGeneratedOptionalInterfaceName(ejbClass.getName());
optIntfClassLoader = new EjbOptionalIntfGenerator(loader);
((EjbOptionalIntfGenerator) optIntfClassLoader).generateOptionalLocalInterface(ejbClass, optIntfClassName);
ejbGeneratedOptionalLocalBusinessIntfClass = optIntfClassLoader.loadClass(optIntfClassName);
}
if( isStatelessSession || isSingleton ) {
EjbBundleDescriptorImpl bundle = ejbDescriptor.getEjbBundleDescriptor();
WebServicesDescriptor webServices = bundle.getWebServices();
Collection endpoints = webServices.getEndpointsImplementedBy(ejbDescriptor);
// JSR 109 doesn't require support for a single ejb
// implementing multiple port ex.
if( endpoints.size() == 1 ) {
assertFullProfile("is a Web Service Endpoint");
webServiceEndpointIntf = loader.loadClass
(ejbDescriptor.getWebServiceEndpointInterfaceName());
isWebServiceEndpoint = true;
}
}
try{
// get Method objects for ejbPassivate/Activate/ejbRemove
ejbPassivateMethod = ejbClass.getMethod("ejbPassivate", NO_PARAMS);
ejbActivateMethod = ejbClass.getMethod("ejbActivate", NO_PARAMS);
ejbRemoveMethod = ejbClass.getMethod("ejbRemove", NO_PARAMS);
} catch(NoSuchMethodException nsme) {
// ignore. Will happen for EJB 3.0 session beans
}
if ( ejbDescriptor.isTimedObject() ) {
warnIfNotFullProfile("use of persistent EJB Timer Service");
MethodDescriptor ejbTimeoutMethodDesc =
ejbDescriptor.getEjbTimeoutMethod();
// Can be a @Timeout or @Schedule or TimedObject
if (ejbTimeoutMethodDesc != null) {
Method method = ejbTimeoutMethodDesc.getMethod(ejbDescriptor);
processEjbTimeoutMethod(method);
ejbTimeoutMethod = method;
}
for (ScheduledTimerDescriptor schd : ejbDescriptor.getScheduledTimerDescriptors()) {
Method method = schd.getTimeoutMethod().getMethod(ejbDescriptor);
if (method == null) {
// This should've been caught in EjbBundleValidator
throw new EJBException(localStrings.getLocalString(
"ejb.no_timeout_method",
"Class {0} does not define timeout method {1}",
ejbClass.getName(), schd.getTimeoutMethod().getFormattedString()));
}
if( _logger.isLoggable(Level.FINE) ) {
_logger.log(Level.FINE, "... processing " + method );
}
processEjbTimeoutMethod(method);
List list = schedules.get(method);
if (list == null) {
list = new ArrayList();
schedules.put(method, list);
}
list.add(schd);
}
}
if( isTimedObject_ ) {
if( !isStatefulSession ) {
// EJBTimerService should be accessed only if needed
// not to cause it to be loaded if it's not used.
EJBTimerService timerService = EJBTimerService.getEJBTimerService();
if( timerService != null ) {
timerService.timedObjectCount();
}
} else {
isTimedObject_ = false;
throw new EJBException(localStrings.getLocalString(
"ejb.stateful_cannot_be_timed_object",
"EJB {0} is invalid. Stateful session ejbs cannot be Timed Objects",
ejbDescriptor.getName()));
}
}
preInitialize(ejbDesc, loader);
initializeEjbInterfaceMethods();
if( needSystemInterceptorProxy() ) {
addSystemInterceptorProxy();
}
// NOTE : InterceptorManager initialization delayed until transition to START state.
addLocalRemoteInvocationInfo();
addWSOrTimedObjectInvocationInfo();
initializeInvocationInfo();
setupEnvironment();
ServiceLocator services = ejbContainerUtilImpl.getServices();
jcdiService = services.getService(JCDIService.class);
initEjbInterceptors();
} catch (Exception ex) {
_logger.log(Level.FINE, "Exception creating BaseContainer : [{0}]", logParams);
_logger.log(Level.FINE,"", ex);
throw ex;
}
_debugDescription = "ejbName: " + ejbDescriptor.getName()
+ "; containerId: " + ejbDescriptor.getUniqueId();
_logger.log(Level.FINE, "Instantiated container for: "
+ _debugDescription);
}
protected ProtocolManager getProtocolManager() {
return protocolMgr;
}
public ContainerType getContainerType() {
return containerType;
}
protected void doEJBHomeRemove(Object pk, Method m, boolean isLocal)
throws RemoteException, RemoveException {
throw new UnsupportedOperationException(localStrings.getLocalString(
"ejb.ejbhome_remove_on_nonentity",
"EJBHome.remove() called on non entity container"));
}
private void addToGeneratedMonitoredMethodInfo(String qualifiedClassName,
Class generatedClass) {
monitoredGeneratedClasses.add(generatedClass);
}
protected void initializeProtocolManager() {
try {
GlassFishORBHelper orbHelper = ejbContainerUtilImpl.getORBHelper();
protocolMgr = orbHelper.getProtocolManager();
} catch(Throwable t) {
throw new RuntimeException("IIOP Protocol Manager initialization failed. " +
"Possible cause is that ORB is not available in this " +
((ejbContainerUtilImpl.isEmbeddedServer())?
"embedded container, or server instance is running and required ports are in use" :
"container")
, t );
}
}
protected void preInitialize(EjbDescriptor ejbDesc, ClassLoader loader) {
//Overridden in sub classes
}
public void checkUserTransactionLookup(ComponentInvocation inv)
throws javax.naming.NameNotFoundException {
if (! this.isBeanManagedTran) {
throw new javax.naming.NameNotFoundException(
localStrings.getLocalString("ejb.ut_lookup_not_allowed",
"Lookup of java:comp/UserTransaction not allowed for Container managed Transaction beans"));
}
}
protected final void createCallFlowAgent(ComponentType compType) {
this.callFlowInfo = new CallFlowInfoImpl(
this, ejbDescriptor, compType);
}
public String toString() {
return _debugDescription;
}
public final void setStartedState() {
if( containerState == CONTAINER_STARTED ) {
return;
}
// NOTE : we used to initialize interceptor manager in the ctor but we need to delay
// the initialization to account for the possiblity of a 299-enabled app. In
// that case, the 299-defined ejb interceptors are not added until the
// deployment load() phase. That's ok, as long as everything is initialized
// before any bean instances are created or any ejb invocations take place.
// Therefore, moving the initialization to the point that we transition into the
// ejb container START state.
try {
initializeInterceptorManager();
for(Object o : invocationInfoMap.values()) {
InvocationInfo next = (InvocationInfo) o;
setInterceptorChain(next);
}
for(Object o : this.webServiceInvocationInfoMap.values()) {
InvocationInfo next = (InvocationInfo) o;
setInterceptorChain(next);
}
} catch(Exception e) {
throw new RuntimeException(e);
}
containerState = CONTAINER_STARTED;
}
private void setInterceptorChain(InvocationInfo info) {
if( info.aroundMethod != null ) {
if (info.isEjbTimeout) {
MethodDescriptor md = new MethodDescriptor(info.aroundMethod, MethodDescriptor.TIMER_METHOD);
info.interceptorChain =
interceptorManager.getAroundTimeoutChain(md, info.aroundMethod);
} else {
MethodDescriptor md = new MethodDescriptor(info.aroundMethod, MethodDescriptor.EJB_BEAN);
info.interceptorChain =
interceptorManager.getAroundInvokeChain(md, info.aroundMethod);
}
}
}
public final void setStoppedState() {
containerState = CONTAINER_STOPPED;
}
public final boolean isStopped() {
return containerState == CONTAINER_STOPPED;
}
public final void setUndeployedState() {
containerState = CONTAINER_UNDEPLOYED;
}
public final boolean isUndeployed() {
return (containerState == CONTAINER_UNDEPLOYED);
}
public final boolean isTimedObject() {
return isTimedObject_;
}
public final boolean isLocalObject() {
return isLocal;
}
public final boolean isRemoteObject() {
return isRemote;
}
public final ClassLoader getContainerClassLoader() {
return loader;
}
public final ClassLoader getClassLoader() {
return loader;
}
public final String getUseThreadPoolId() {
return ejbDescriptor.getIASEjbExtraDescriptors().getUseThreadPoolId();
}
public final boolean getPassByReference() {
return ejbDescriptor.getIASEjbExtraDescriptors().getPassByReference();
}
protected final long getContainerId() {
return ejbDescriptor.getUniqueId();
}
public final long getApplicationId() {
return ejbDescriptor.getApplication().getUniqueId();
}
public final EjbDescriptor getEjbDescriptor() {
return ejbDescriptor;
}
/**
* Method defined on JavaEEContainer
*/
public final Descriptor getDescriptor() {
return getEjbDescriptor();
}
public final EJBMetaData getEJBMetaData() {
return metadata;
}
public final UserTransaction getUserTransaction() {
return containerTransactionManager.getUserTransaction();
}
public boolean isHAEnabled() {
return false;
}
/**
* EJB spec makes a distinction between access to the UserTransaction
* object itself and access to its methods. getUserTransaction covers
* the first check and this method covers the second. It is called
* by the UserTransaction implementation to verify access.
*/
public boolean userTransactionMethodsAllowed(ComponentInvocation inv) {
// Overridden by containers that allowed BMT;
return false;
}
public final EJBHome getEJBHomeStub() {
return ejbHomeStub;
}
public final EJBHome getEJBHome() {
return ejbHome;
}
/**
* Return an object that implements ejb's local home interface.
* If dynamic proxies are being used, this is the proxy itself,
* it can't be directly cast to an EJBLocalHomeImpl.
*/
public final EJBLocalHome getEJBLocalHome() {
return ejbLocalHome;
}
/**
* Return an object that implements ejb's local business home interface.
*/
public final GenericEJBLocalHome getEJBLocalBusinessHome(String clientViewClassName) {
return isLocalBeanClass(clientViewClassName)
? ejbOptionalLocalBusinessHome
: ejbLocalBusinessHome;
}
boolean isLocalBeanClass(String className) {
return hasOptionalLocalBusinessView &&
( className.equals(ejbClass.getName()) ||
className.equals(ejbGeneratedOptionalLocalBusinessIntfClass.getName()) );
}
public final Class getEJBClass() {
return ejbClass;
}
public final SecurityManager getSecurityManager() {
return securityManager;
}
final Properties getEnvironmentProperties() {
return envProps;
}
/**
* Create an EJBObject reference from the instanceKey
* Called from EJBObjectOutputStream.SerializableRemoteRef
* during deserialization of a remote-ref
* @param instanceKey instanceKey of the ejbobject
* @param generatedRemoteBusinessIntf non-null, this is a remote business view and the param
* is the name of the generated remote business interface.
* Otherwise, this is for the RemoteHome view
*/
public java.rmi.Remote createRemoteReferenceWithId
(byte[] instanceKey, String generatedRemoteBusinessIntf) {
final Thread currentThread = Thread.currentThread();
final ClassLoader previousClassLoader =
currentThread.getContextClassLoader();
final ClassLoader myClassLoader = loader;
try {
if(System.getSecurityManager() == null) {
currentThread.setContextClassLoader(myClassLoader);
} else {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public java.lang.Object run() {
currentThread.setContextClassLoader(myClassLoader);
return null;
}
});
}
java.rmi.Remote remoteRef = null;
if( generatedRemoteBusinessIntf == null ) {
remoteRef = remoteHomeRefFactory.createRemoteReference
(instanceKey);
} else {
RemoteReferenceFactory remoteBusinessRefFactory =
remoteBusinessIntfInfo.get(generatedRemoteBusinessIntf).
referenceFactory;
remoteRef = remoteBusinessRefFactory.createRemoteReference
(instanceKey);
}
return remoteRef;
} finally {
if(System.getSecurityManager() == null) {
currentThread.setContextClassLoader(previousClassLoader);
} else {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public java.lang.Object run() {
currentThread.setContextClassLoader(previousClassLoader);
return null;
}
});
}
}
}
private void assertFullProfile(String description) {
if( ejbContainerUtilImpl.isEJBLite() ) {
throw new RuntimeException(localStrings.getLocalString(
"ejb.assert_full_profile",
"Invalid application. EJB {0} {1}. This feature is not part of the EJB 3.1 Lite API",
ejbDescriptor.getName(), description));
}
}
private void warnIfNotFullProfile(String description) {
if( ejbContainerUtilImpl.isEJBLite() ) {
_logger.log(Level.WARNING, WARN_FEATURE_REQUIRES_FULL_PROFILE, description);
}
}
/**
* Called from the ContainerFactory during initialization.
*/
protected void initializeHome()
throws Exception
{
if( isWebServiceEndpoint ) {
EjbBundleDescriptorImpl bundle =
ejbDescriptor.getEjbBundleDescriptor();
WebServicesDescriptor webServices = bundle.getWebServices();
Collection myEndpoints =
webServices.getEndpointsImplementedBy(ejbDescriptor);
// An ejb can only be exposed through 1 web service endpoint
Iterator iter = myEndpoints.iterator();
webServiceEndpoint =
(com.sun.enterprise.deployment.WebServiceEndpoint) iter.next();
Class serviceEndpointIntfClass =
loader.loadClass(webServiceEndpoint.getServiceEndpointInterface());
if (!serviceEndpointIntfClass.isInterface()) {
ServiceInterfaceGenerator generator = new ServiceInterfaceGenerator(loader, ejbClass);
serviceEndpointIntfClass = EJBUtils.generateSEI(generator, generator.getGeneratedClass(),
loader, this.ejbClass);
if (serviceEndpointIntfClass==null) {
throw new RuntimeException(localStrings.getLocalString(
"ejb.error_generating_sei",
"Error in generating service endpoint interface class for EJB class {0}", this.ejbClass));
}
}
Class tieClass=null;
WebServiceInvocationHandler invocationHandler =
new WebServiceInvocationHandler(ejbClass, webServiceEndpoint, serviceEndpointIntfClass,
ejbContainerUtilImpl,webServiceInvocationInfoMap);
invocationHandler.setContainer(this);
Object servant = (Object) Proxy.newProxyInstance
(loader, new Class[] { serviceEndpointIntfClass },
invocationHandler);
// starting in 2.0, there is no more generated Ties
if (webServiceEndpoint.getTieClassName()!=null) {
tieClass = loader.loadClass(webServiceEndpoint.getTieClassName());
}
// Create a facade for container services to be used by web services runtime.
EjbEndpointFacade endpointFacade =
new EjbEndpointFacadeImpl(this, ejbContainerUtilImpl);
wsejbEndpointRegistry = Globals.getDefaultHabitat().getService(
WSEjbEndpointRegistry.class);
if (wsejbEndpointRegistry != null ) {
wsejbEndpointRegistry.registerEndpoint(webServiceEndpoint,endpointFacade,servant,tieClass);
} else {
throw new DeploymentException(localStrings.getLocalString(
"ejb.no_webservices_module",
"EJB-based Webservice endpoint is detected but there is no webservices module installed to handle it"));
}
}
Map intfsForPortableJndi = new HashMap();
// Root of portable global JNDI name for this bean
String javaGlobalName = getJavaGlobalJndiNamePrefix();
if (isRemote) {
boolean disableNonPortableJndiName = false;
Boolean disableInDD = ejbDescriptor.getEjbBundleDescriptor().getDisableNonportableJndiNames();
if(disableInDD != null) { // explicitly set in glassfish-ejb-jar.xml
disableNonPortableJndiName = disableInDD;
} else {
String disableInServer = ejbContainerUtilImpl.getEjbContainer().
getPropertyValue(RuntimeTagNames.DISABLE_NONPORTABLE_JNDI_NAMES);
disableNonPortableJndiName = Boolean.valueOf(disableInServer);
}
String glassfishSpecificJndiName = null;
if (!disableNonPortableJndiName) {
// This is either the default glassfish-specific (non-portable)
// global JNDI name or the one specified via mappedName(), sun-ejb-jar.xml,
// etc.
glassfishSpecificJndiName = ejbDescriptor.getJndiName();
// If the explicitly specified name is the same as the portable name,
// don't register any of the glassfish-specific names to prevent
// clashes.
if ((glassfishSpecificJndiName != null)
&& (glassfishSpecificJndiName.equals("")
|| glassfishSpecificJndiName.equals(javaGlobalName))) {
glassfishSpecificJndiName = null;
}
}
if( hasRemoteHomeView ) {
this.ejbHomeImpl = instantiateEJBHomeImpl();
this.ejbHome = ejbHomeImpl.getEJBHome();
// Since some containers might create multiple EJBObjects for
// the same ejb, make sure we use the same Proxy class to
// instantiate all the proxy instances.
ejbObjectProxyClass =
Proxy.getProxyClass(loader, new Class[] { remoteIntf });
ejbObjectProxyCtor = ejbObjectProxyClass.
getConstructor(new Class[] { InvocationHandler.class });
//
// Make sure all Home/Remote interfaces conform to RMI-IIOP
// rules. Checking for conformance here keeps the exposed
// deployment/startup error behavior consistent since when
// rmic is used during codegen it makes equivalent checks and
// treats any validation problems as fatal errors.
//
// These same checks will be made when setTarget is called
// in POARemoteReferenceFactory.preinvoke, but that happens
// only when the actual invocation is made, so it's better to
// know at container initialization time if there is a problem.
//
getProtocolManager().validateTargetObjectInterfaces(this.ejbHome);
// Unlike the Home, each of the concrete containers are
// responsible for creating the EJBObjects, so just create
// a dummy EJBObjectImpl for validation purposes.
EJBObjectImpl dummyEJBObjectImpl = instantiateEJBObjectImpl();
EJBObject dummyEJBObject = (EJBObject)
dummyEJBObjectImpl.getEJBObject();
getProtocolManager().validateTargetObjectInterfaces(dummyEJBObject);
// Remotereference factory needs instances of
// Home and Remote to get repository Ids since it doesn't have
// stubs and ties. This must be done before any Home or Remote
// references are created.
remoteHomeRefFactory.setRepositoryIds(homeIntf, remoteIntf);
// get a remote ref for the EJBHome
ejbHomeStub = (EJBHome) remoteHomeRefFactory.createHomeReference(homeInstanceKey);
// Add 2.x Home for later portable JNDI name processing.
intfsForPortableJndi.put(ejbDescriptor.getHomeClassName(), ejbHomeStub);
// If there's a glassfish-specific JNDI name, any 2.x Home object is always
// regsitered under that name. This preserves backward compatibility since
// this was the original use of the jndi name.
if( glassfishSpecificJndiName != null ) {
JndiInfo jndiInfo = JndiInfo.newNonPortableRemote(glassfishSpecificJndiName, ejbHomeStub);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
}
if( hasRemoteBusinessView ) {
this.ejbRemoteBusinessHomeImpl =
instantiateEJBRemoteBusinessHomeImpl();
this.ejbRemoteBusinessHome =
ejbRemoteBusinessHomeImpl.getEJBHome();
// RMI-IIOP validation
getProtocolManager().validateTargetObjectInterfaces(this.ejbRemoteBusinessHome);
for(RemoteBusinessIntfInfo next :
remoteBusinessIntfInfo.values()) {
next.proxyClass = Proxy.getProxyClass
(loader, new Class[] { next.generatedRemoteIntf });
next.proxyCtor = next.proxyClass.
getConstructor(new Class[] { InvocationHandler.class });
// Remotereference factory needs instances of
// Home and Remote to get repository Ids since it
// doesn't have stubs and ties. This must be done before
// any Home or Remote references are created.
next.referenceFactory.setRepositoryIds
(remoteBusinessHomeIntf, next.generatedRemoteIntf);
// Create home stub from the remote reference factory
// associated with one of the remote business interfaces.
// It doesn't matter which remote reference factory is
// selected, so just do it the first time through the loop.
if( ejbRemoteBusinessHomeStub == null ) {
ejbRemoteBusinessHomeStub = (EJBHome) next.referenceFactory.
createHomeReference(homeInstanceKey);
}
}
EJBObjectImpl dummyEJBObjectImpl = instantiateRemoteBusinessObjectImpl();
// Internal jndi name under which remote business home is registered for
// glassfish-specific remote business JNDI names
String remoteBusinessHomeJndiName = null;
if( glassfishSpecificJndiName != null ) {
remoteBusinessHomeJndiName =
EJBUtils.getRemote30HomeJndiName(glassfishSpecificJndiName);
}
// Convenience location for common case of 3.0 session bean with only
// 1 remote business interface and no adapted remote home. Allows a
// stand-alone client to access 3.0 business interface by using simple
// jndi name. Each remote business interface is also always available
// at #. This is needed for the
// case where the bean has an adapted remote home and/or multiple business
// interfaces.
String simpleRemoteBusinessJndiName = null;
if( (glassfishSpecificJndiName != null) && !hasRemoteHomeView &&
remoteBusinessIntfInfo.size() == 1) {
simpleRemoteBusinessJndiName = glassfishSpecificJndiName;
}
// We need a separate name for the internal generated home object to
// support the portable global JNDI names for business interfaces.
// There won't necessarily be a glassfish-specific name specified so
// it's cleaner to just always use a separate ones.
String internalHomeJndiNameForPortableRemoteNames =
EJBUtils.getRemote30HomeJndiName(javaGlobalName);
for(RemoteBusinessIntfInfo next : remoteBusinessIntfInfo.values()) {
java.rmi.Remote dummyEJBObject = dummyEJBObjectImpl.
getEJBObject(next.generatedRemoteIntf.getName());
getProtocolManager().validateTargetObjectInterfaces(dummyEJBObject);
if( glassfishSpecificJndiName != null ) {
next.jndiName = EJBUtils.getRemoteEjbJndiName
(true, next.remoteBusinessIntf.getName(), glassfishSpecificJndiName);
Reference remoteBusRef = new Reference(next.remoteBusinessIntf.getName(),
new StringRefAddr("url", remoteBusinessHomeJndiName),
"com.sun.ejb.containers.RemoteBusinessObjectFactory", null);
// Glassfish-specific JNDI name for fully-qualified 3.0 Remote business interface.
JndiInfo jndiInfo = JndiInfo.newNonPortableRemote(next.jndiName, remoteBusRef);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
if( simpleRemoteBusinessJndiName != null ) {
Reference remoteBusRef = new Reference
(next.remoteBusinessIntf.getName(),
new StringRefAddr("url", remoteBusinessHomeJndiName),
"com.sun.ejb.containers.RemoteBusinessObjectFactory", null);
// Glassfish-specific JNDI name for simple 3.0 Remote business interface lookup.
// Applicable when the bean exposes only a single Remote 3.x client view.
JndiInfo jndiInfo = JndiInfo.newNonPortableRemote
(simpleRemoteBusinessJndiName, remoteBusRef);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
Reference remoteBusRef = new Reference(next.remoteBusinessIntf.getName(),
new StringRefAddr("url", internalHomeJndiNameForPortableRemoteNames),
"com.sun.ejb.containers.RemoteBusinessObjectFactory", null);
// Always register portable JNDI name for each remote business view
intfsForPortableJndi.put(next.remoteBusinessIntf.getName(), remoteBusRef);
}
if( remoteBusinessHomeJndiName != null ) {
// Glassfish-specific JNDI name for internal generated
// home object used by container
JndiInfo jndiInfo = JndiInfo.newNonPortableRemote
(remoteBusinessHomeJndiName, ejbRemoteBusinessHomeStub);
jndiInfo.setInternal(true);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
// Always registeer internal name for home in support of portable global
// remote business JNDI names.
JndiInfo jndiInfo = JndiInfo.newPortableRemote
(internalHomeJndiNameForPortableRemoteNames, ejbRemoteBusinessHomeStub);
jndiInfo.setInternal(true);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
// If there isn't any jndi name from the descriptor, set one so the
// lookup logic that depends on ejbDescriptor.getJndiName() will work.
if( glassfishSpecificJndiName == null ) {
ejbDescriptor.setJndiName(javaGlobalName);
}
}
}
if (isLocal) {
if( hasLocalHomeView ) {
this.ejbLocalHomeImpl = instantiateEJBLocalHomeImpl();
this.ejbLocalHome = ejbLocalHomeImpl.getEJBLocalHome();
// Since some containers might create multiple EJBLocalObjects
// for the same ejb, make sure we use the same Proxy class to
// instantiate all the proxy instances.
Class ejbLocalObjectProxyClass =
Proxy.getProxyClass(loader,
new Class[] { IndirectlySerializable.class,
localIntf });
ejbLocalObjectProxyCtor = ejbLocalObjectProxyClass.
getConstructor(new Class[] { InvocationHandler.class });
// Portable JNDI name for EJB 2.x LocalHome. We don't provide a
// glassfish-specific way of accessing Local EJBs.
JavaGlobalJndiNamingObjectProxy namingProxy =
new JavaGlobalJndiNamingObjectProxy(this, localHomeIntf.getName());
intfsForPortableJndi.put(localHomeIntf.getName(), namingProxy);
}
if( hasLocalBusinessView ) {
ejbLocalBusinessHomeImpl =
instantiateEJBLocalBusinessHomeImpl();
ejbLocalBusinessHome = (GenericEJBLocalHome)
ejbLocalBusinessHomeImpl.getEJBLocalHome();
Class[] proxyInterfaces =
new Class[ localBusinessIntfs.size() + 1 ];
proxyInterfaces[0] = IndirectlySerializable.class;
int index = 1;
for(Class next : localBusinessIntfs) {
proxyInterfaces[index] = next;
index++;
}
Class proxyClass = Proxy.getProxyClass(loader,proxyInterfaces);
ejbLocalBusinessObjectProxyCtor = proxyClass.
getConstructor(new Class[] { InvocationHandler.class });
for (Class next : localBusinessIntfs) {
// Portable JNDI name for EJB 3.x Local business interface.
// We don't provide a glassfish-specific way of accessing Local EJBs.
JavaGlobalJndiNamingObjectProxy namingProxy =
new JavaGlobalJndiNamingObjectProxy(this, next.getName());
intfsForPortableJndi.put(next.getName(), namingProxy);
}
}
if(hasOptionalLocalBusinessView) {
EJBLocalHomeImpl obj = instantiateEJBOptionalLocalBusinessHomeImpl();
ejbOptionalLocalBusinessHomeImpl = (EJBLocalHomeImpl) obj;
ejbOptionalLocalBusinessHome = (GenericEJBLocalHome)
ejbOptionalLocalBusinessHomeImpl.getEJBLocalHome();
Class[] proxyInterfaces =
new Class[ 2 ];
proxyInterfaces[0] = IndirectlySerializable.class;
String optionalIntfName = EJBUtils.getGeneratedOptionalInterfaceName(
ejbClass.getName());
proxyInterfaces[1] = ejbGeneratedOptionalLocalBusinessIntfClass =
optIntfClassLoader.loadClass(optionalIntfName);
Class proxyClass = Proxy.getProxyClass(loader,proxyInterfaces);
ejbOptionalLocalBusinessObjectProxyCtor = proxyClass.
getConstructor(new Class[] { InvocationHandler.class });
// Portable JNDI name for no-interface view.
// We don't provide a glassfish-specific way of accessing the
// no-interface view of a session bean.
JavaGlobalJndiNamingObjectProxy namingProxy =
new JavaGlobalJndiNamingObjectProxy(this, ejbClass.getName());
intfsForPortableJndi.put(ejbClass.getName(), namingProxy);
}
}
for(Map.Entry entry : intfsForPortableJndi.entrySet()) {
String intf = entry.getKey();
String fullyQualifiedJavaGlobalName = javaGlobalName + "!" + intf;
Object namingProxy = entry.getValue();
boolean local = (namingProxy instanceof JavaGlobalJndiNamingObjectProxy);
if (intfsForPortableJndi.size() == 1) {
JndiInfo jndiInfo = local ?
JndiInfo.newPortableLocal(javaGlobalName, namingProxy) :
JndiInfo.newPortableRemote(javaGlobalName, namingProxy);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
JndiInfo jndiInfo = local ?
JndiInfo.newPortableLocal(fullyQualifiedJavaGlobalName, namingProxy) :
JndiInfo.newPortableRemote(fullyQualifiedJavaGlobalName, namingProxy);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
for(Map.Entry entry : jndiInfoMap.entrySet()) {
JndiInfo jndiInfo = entry.getValue();
try {
jndiInfo.publish(this.namingManager);
if( jndiInfo.internal ) {
publishedInternalGlobalJndiNames.add(jndiInfo.name);
} else {
if( jndiInfo.portable ) {
publishedPortableGlobalJndiNames.add(jndiInfo.name);
} else {
publishedNonPortableGlobalJndiNames.add(jndiInfo.name);
}
}
} catch(Exception e) {
throw new RuntimeException(localStrings.getLocalString(
"ejb.error_binding_jndi_name",
"Error while binding JNDI name {0} for EJB {1}",
jndiInfo.name, this.ejbDescriptor.getName()), e);
}
}
if( !publishedPortableGlobalJndiNames.isEmpty() ) {
_logger.log(Level.INFO, PORTABLE_JNDI_NAMES, new Object[]{this.ejbDescriptor.getName(), publishedPortableGlobalJndiNames});
}
if( !publishedNonPortableGlobalJndiNames.isEmpty() ) {
_logger.log(Level.INFO, GLASSFISH_SPECIFIC_JNDI_NAMES, new Object[]{this.ejbDescriptor.getName(), publishedNonPortableGlobalJndiNames});
}
if( !publishedInternalGlobalJndiNames.isEmpty() ) {
_logger.log(Level.FINE, "Internal container JNDI names for EJB {0}: {1}", new Object[]{this.ejbDescriptor.getName(), publishedInternalGlobalJndiNames});
}
// set EJBMetaData
setEJBMetaData();
}
// default impl
protected void setEJBMetaData() throws Exception {
metadata = new EJBMetaDataImpl(ejbHomeStub, homeIntf, remoteIntf, isSession, isStatelessSession);
}
protected String getJavaGlobalJndiNamePrefix() {
String appName = null;
Application app = ejbDescriptor.getApplication();
if ( ! app.isVirtual() ) {
appName = ejbDescriptor.getApplication().getAppName();
}
EjbBundleDescriptorImpl ejbBundle = ejbDescriptor.getEjbBundleDescriptor();
String modName = ejbBundle.getModuleDescriptor().getModuleName();
String ejbName = ejbDescriptor.getName();
StringBuffer javaGlobalPrefix = new StringBuffer("java:global/");
if (appName != null) {
javaGlobalPrefix.append(appName);
javaGlobalPrefix.append("/");
}
javaGlobalPrefix.append(modName);
javaGlobalPrefix.append("/");
javaGlobalPrefix.append(ejbName);
return javaGlobalPrefix.toString();
}
public void createEjbInstance(Object[] params, EJBContextImpl ctx) throws Exception {
Object instance = _constructEJBInstance();
ctx.setEJB(instance);
}
protected EJBContextImpl createEjbInstanceAndContext() throws Exception {
EjbBundleDescriptorImpl ejbBundle = ejbDescriptor.getEjbBundleDescriptor();
JCDIService.JCDIInjectionContext