|
Glassfish example source code file (EJBContextImpl.java)
The Glassfish EJBContextImpl.java source code
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2010 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.
*/
package com.sun.ejb.containers;
import com.sun.appserv.connectors.internal.api.ResourceHandle;
import com.sun.ejb.ComponentContext;
import com.sun.ejb.Container;
import com.sun.ejb.EjbInvocation;
import com.sun.enterprise.deployment.EjbDescriptor;
import com.sun.enterprise.deployment.RoleReference;
import com.sun.enterprise.transaction.api.JavaEETransaction;
import com.sun.enterprise.util.LocalStringManagerImpl;
import org.glassfish.api.invocation.ComponentInvocation;
import com.sun.enterprise.container.common.spi.JCDIService;
import javax.ejb.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.transaction.Status;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import java.lang.reflect.Method;
import java.security.Identity;
import java.security.Principal;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Implementation of javax.ejb.EJBContext for the J2EE Reference Implementation.
*
*/
public abstract class EJBContextImpl
implements EJBContext, ComponentContext, java.io.Serializable
{
private static final Logger _logger =
EjbContainerUtilImpl.getInstance().getLogger();
public enum BeanState {CREATED, POOLED, READY, INVOKING, INCOMPLETE_TX,
IN_PASSIVATE, PASSIVATED, IN_ACTIVATE, ACTIVATED, IN_REMOVE, DESTROYED}
private static LocalStringManagerImpl localStrings =
new LocalStringManagerImpl(EJBContextImpl.class);
private Object ejb;
// These are all transient to prevent serialization during passivation
// Note: all these will be initialized to default values during
// deserialization.
transient protected BaseContainer container;
transient protected Transaction transaction = null;
transient private Context initialContext = null;
transient private ArrayList resources;
transient private int concInvokeCount = 0;
// the EJBObject's client-side RMI stub
transient protected EJBObject ejbStub=null;
transient protected EJBObjectImpl ejbObjectImpl;
transient protected EJBObjectImpl ejbRemoteBusinessObjectImpl;
transient protected EJBLocalObjectImpl ejbLocalObjectImpl;
transient protected EJBLocalObjectImpl ejbLocalBusinessObjectImpl;
transient protected EJBLocalObjectImpl optionalEjbLocalBusinessObjectImpl;
transient private long lastTimeUsed;
transient protected BeanState state;
// true if the bean exposes a RemoteHome/Remote view
// (not 3.0 business view)
protected boolean isRemoteInterfaceSupported;
// true if the bean exposes a LocalHome/Localview
// (not 3.0 business view)
protected boolean isLocalInterfaceSupported;
// can't/doesn't set the context to DESTROYED until after calling ejbRemove
// but it needs a way to know if bean is being removed. Standardizing
// on the DESTROYED state doesn't help, since often times the container
// can't/doesn't set the context to DESTROYED until after calling ejbRemove
transient protected boolean inEjbRemove;
private Object[] interceptorInstances;
// TODO how to handle this for passivated SFSBs?
transient protected JCDIService.JCDIInjectionContext jcdiInjectionContext;
EJBContextImpl(Object ejb, BaseContainer container) {
this.ejb = ejb;
this.container = container;
state = BeanState.CREATED;
inEjbRemove = false;
isRemoteInterfaceSupported = container.isRemoteInterfaceSupported();
isLocalInterfaceSupported = container.isLocalInterfaceSupported();
}
public Transaction getTransaction() {
return transaction;
}
public void setTransaction(Transaction tr) {
transaction = tr;
}
void setEJBStub(EJBObject ejbStub) {
this.ejbStub = ejbStub;
}
void setEJBLocalObjectImpl(EJBLocalObjectImpl localObjectImpl) {
this.ejbLocalObjectImpl = localObjectImpl;
}
void setEJBLocalBusinessObjectImpl(EJBLocalObjectImpl localBusObjectImpl) {
this.ejbLocalBusinessObjectImpl = localBusObjectImpl;
}
void setOptionalEJBLocalBusinessObjectImpl(EJBLocalObjectImpl optionalLocalBusObjectImpl) {
this.optionalEjbLocalBusinessObjectImpl = optionalLocalBusObjectImpl;
}
void setEJBObjectImpl(EJBObjectImpl ejbo) {
this.ejbObjectImpl = ejbo;
}
EJBObjectImpl getEJBObjectImpl() {
return ejbObjectImpl;
}
void setEJBRemoteBusinessObjectImpl(EJBObjectImpl ejbo) {
this.ejbRemoteBusinessObjectImpl = ejbo;
}
EJBObjectImpl getEJBRemoteBusinessObjectImpl() {
return this.ejbRemoteBusinessObjectImpl;
}
EJBLocalObjectImpl getEJBLocalObjectImpl() {
return ejbLocalObjectImpl;
}
EJBLocalObjectImpl getEJBLocalBusinessObjectImpl() {
return ejbLocalBusinessObjectImpl;
}
EJBLocalObjectImpl getOptionalEJBLocalBusinessObjectImpl() {
return optionalEjbLocalBusinessObjectImpl;
}
void setContainer(BaseContainer container) {
this.container = container;
}
void setState(BeanState s) {
state = s;
}
boolean isTimedObject() {
return container.isTimedObject();
}
BeanState getState() {
return state;
}
void setInEjbRemove(boolean beingRemoved) {
inEjbRemove = beingRemoved;
}
boolean isInEjbRemove() {
return inEjbRemove;
}
void setJCDIInjectionContext(JCDIService.JCDIInjectionContext ctx) {
jcdiInjectionContext = ctx;
}
JCDIService.JCDIInjectionContext getJCDIInjectionContext() {
return jcdiInjectionContext;
}
/**
* Returns true if this context has NOT progressed past its initial
* state. The point at which this happens is container-specific.
*/
boolean isUnitialized() {
return (state == EJBContextImpl.BeanState.CREATED);
}
public long getLastTimeUsed() {
return lastTimeUsed;
}
void touch() {
lastTimeUsed = System.currentTimeMillis();
}
/**************************************************************************
The following are implementations of ComponentContext methods.
**************************************************************************/
/**
*
*/
public Object getEJB() {
return ejb;
}
public Container getContainer() {
return container;
}
/**
* Register a resource opened by the EJB instance
* associated with this Context.
*/
public void registerResource(ResourceHandle h) {
if ( resources == null )
resources = new ArrayList();
resources.add(h);
}
/**
* Unregister a resource from this Context.
*/
public void unregisterResource(ResourceHandle h) {
if ( resources == null )
resources = new ArrayList();
resources.remove(h);
}
/**
* Get all the resources associated with the context
*/
public List getResourceList() {
if (resources == null)
resources = new ArrayList(0);
return resources;
}
/**
* Get the number of concurrent invocations on this bean
* (could happen with re-entrant bean).
* Used by TM.
*/
public int getConcurrentInvokeCount() {
return concInvokeCount;
}
/**
* Increment the number of concurrent invocations on this bean
* (could happen with re-entrant bean).
* Used by TM.
*/
public synchronized void incrementConcurrentInvokeCount() {
concInvokeCount++;
}
/**
* Decrement the number of concurrent invocations on this bean
* (could happen with re-entrant bean).
* Used by TM.
*/
public synchronized void decrementConcurrentInvokeCount() {
concInvokeCount--;
}
/**************************************************************************
The following are implementations of EJBContext methods.
**************************************************************************/
/**
* This is a SessionContext/EntityContext method.
*/
public EJBObject getEJBObject()
throws IllegalStateException
{
if (ejbStub == null) {
throw new IllegalStateException("EJBObject not available");
}
return ejbStub;
}
/**
* This is a SessionContext/EntityContext method.
*/
public EJBLocalObject getEJBLocalObject()
throws IllegalStateException
{
if ( ejbLocalObjectImpl == null ) {
throw new IllegalStateException("EJBLocalObject not available");
}
// Have to convert EJBLocalObjectImpl to the client-view of
// EJBLocalObject
return (EJBLocalObject) ejbLocalObjectImpl.getClientObject();
}
/**
*
*/
public EJBHome getEJBHome() {
if (! isRemoteInterfaceSupported) {
throw new IllegalStateException("EJBHome not available");
}
return container.getEJBHomeStub();
}
/**
*
*/
public EJBLocalHome getEJBLocalHome() {
if (! isLocalInterfaceSupported) {
throw new IllegalStateException("EJBLocalHome not available");
}
return container.getEJBLocalHome();
}
/**
*
*/
public Properties getEnvironment() {
// This is deprecated, see EJB2.0 section 20.6.
return container.getEnvironmentProperties();
}
/**
* @deprecated
*/
public Identity getCallerIdentity() {
// This method is deprecated.
// see EJB2.0 section 21.2.5
throw new RuntimeException(
"getCallerIdentity() is deprecated, please use getCallerPrincipal().");
}
public Object lookup(String name) {
Object o = null;
if( name == null ) {
throw new IllegalArgumentException("Argument is null");
}
try {
if( initialContext == null ) {
initialContext = new InitialContext();
}
// if name starts with java: use it as is. Otherwise, treat it
// as relative to the private component namespace.
String lookupString = name.startsWith("java:") ?
name : "java:comp/env/" + name;
o = initialContext.lookup(lookupString);
} catch(Exception e) {
throw new IllegalArgumentException(e);
}
return o;
}
/**
*
*/
public Principal getCallerPrincipal() {
checkAccessToCallerSecurity();
com.sun.enterprise.security.SecurityManager sm = container.getSecurityManager();
return sm.getCallerPrincipal();
}
/**
* @return Returns the contextMetaData.
*/
public Map<String, Object> getContextData() {
Map<String, Object> contextData = (Map
Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish EJBContextImpl.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.