| Method from org.jboss.ejb.plugins.local.BaseLocalProxyFactory Detail: |
public void create() throws Exception {
BeanMetaData metaData = container.getBeanMetaData();
localJndiName = metaData.getLocalJndiName();
}
|
public void destroy() {
if(beanMethodInvokerMap != null)
{
beanMethodInvokerMap.clear();
}
if(homeMethodInvokerMap != null)
{
homeMethodInvokerMap.clear();
}
MarshalledInvocation.removeHashes(localHomeClass);
MarshalledInvocation.removeHashes(localClass);
container = null;
}
|
public EJBLocalHome getEJBLocalHome() {
if(home == null)
{
EJBProxyFactoryContainer cic = (EJBProxyFactoryContainer) container;
InvocationHandler handler = new LocalHomeProxy(localJndiName, this);
ClassLoader loader = ClassLoaderAction.UTIL.get(cic.getLocalHomeClass());
Class[] interfaces = {cic.getLocalHomeClass()};
home = (EJBLocalHome) Proxy.newProxyInstance(loader,
interfaces,
handler);
}
return home;
}
|
public EJBLocalObject getEntityEJBLocalObject(Object id) {
return getEntityEJBLocalObject(id, false);
}
|
public EJBLocalObject getEntityEJBLocalObject(Object id,
boolean create) {
EJBLocalObject result = null;
if(id != null)
{
final Transaction tx = cache.getTransaction();
if(tx == null)
{
result = createEJBLocalObject(id);
}
else
{
Map map = (Map) cache.get(tx);
if(create)
{
result = createEJBLocalObject(id);
map.put(id, result);
}
else
{
result = (EJBLocalObject) map.get(id);
if(result == null)
{
result = createEJBLocalObject(id);
map.put(id, result);
}
}
}
}
return result;
}
|
public Object getEntityEJBObject(Object id) {
return getEntityEJBLocalObject(id);
}
|
public Collection getEntityLocalCollection(Collection ids) {
ArrayList list = new ArrayList(ids.size());
Iterator iter = ids.iterator();
while(iter.hasNext())
{
final Object nextId = iter.next();
list.add(getEntityEJBLocalObject(nextId));
}
return list;
}
|
public String getJndiName() {
return localJndiName;
}
|
public Constructor getProxyClassConstructor() {
if(proxyClassConstructor == null)
{
}
return proxyClassConstructor;
}
|
public EJBLocalObject getStatefulSessionEJBLocalObject(Object id) {
InvocationHandler handler =
new StatefulSessionProxy(localJndiName, id, this);
try
{
return (EJBLocalObject) proxyClassConstructor.newInstance(new Object[]{handler});
}
catch(Exception ex)
{
throw new NestedRuntimeException(ex);
}
}
|
public EJBLocalObject getStatelessSessionEJBLocalObject() {
if(statelessObject == null)
{
EJBProxyFactoryContainer cic = (EJBProxyFactoryContainer) container;
InvocationHandler handler =
new StatelessSessionProxy(localJndiName, this);
ClassLoader loader = ClassLoaderAction.UTIL.get(cic.getLocalClass());
Class[] interfaces = {cic.getLocalClass()};
statelessObject = (EJBLocalObject) Proxy.newProxyInstance(loader,
interfaces,
handler);
}
return statelessObject;
}
|
Transaction getTransaction() throws SystemException {
if(transactionManager == null)
{
return null;
}
return transactionManager.getTransaction();
}
Return the transaction associated with the current thread.
Returns null if the transaction manager was never
set, or if no transaction is associated with the current thread. |
public Object invoke(Object id,
Method m,
Object[] args) throws Exception {
// Set the right context classloader
ClassLoader oldCl = TCLAction.UTIL.getContextClassLoader();
boolean setCl = !oldCl.equals(container.getClassLoader());
if(setCl)
{
TCLAction.UTIL.setContextClassLoader(container.getClassLoader());
}
container.pushENC();
SecurityActions sa = SecurityActions.UTIL.getSecurityActions();
try
{
LocalEJBInvocation invocation = new LocalEJBInvocation(id,
m,
args,
getTransaction(),
sa.getPrincipal(),
sa.getCredential());
invocation.setType(InvocationType.LOCAL);
return container.invoke(invocation);
}
catch(AccessException ae)
{
throw new AccessLocalException(ae.getMessage(), ae);
}
catch(NoSuchObjectException nsoe)
{
throw new NoSuchObjectLocalException(nsoe.getMessage(), nsoe);
}
catch(TransactionRequiredException tre)
{
throw new TransactionRequiredLocalException(tre.getMessage());
}
catch(TransactionRolledbackException trbe)
{
throw new TransactionRolledbackLocalException(trbe.getMessage(), trbe);
}
finally
{
container.popENC();
if(setCl)
{
TCLAction.UTIL.setContextClassLoader(oldCl);
}
}
}
Invoke a local interface method. |
public Object invokeHome(Method m,
Object[] args) throws Exception {
// Set the right context classloader
ClassLoader oldCl = TCLAction.UTIL.getContextClassLoader();
boolean setCl = !oldCl.equals(container.getClassLoader());
if(setCl)
{
TCLAction.UTIL.setContextClassLoader(container.getClassLoader());
}
container.pushENC();
SecurityActions sa = SecurityActions.UTIL.getSecurityActions();
try
{
LocalEJBInvocation invocation = new LocalEJBInvocation(null,
m,
args,
getTransaction(),
sa.getPrincipal(),
sa.getCredential());
invocation.setType(InvocationType.LOCALHOME);
return container.invoke(invocation);
}
catch(AccessException ae)
{
throw new AccessLocalException(ae.getMessage(), ae);
}
catch(NoSuchObjectException nsoe)
{
throw new NoSuchObjectLocalException(nsoe.getMessage(), nsoe);
}
catch(TransactionRequiredException tre)
{
throw new TransactionRequiredLocalException(tre.getMessage());
}
catch(TransactionRolledbackException trbe)
{
throw new TransactionRolledbackLocalException(trbe.getMessage(), trbe);
}
finally
{
container.popENC();
if(setCl)
{
TCLAction.UTIL.setContextClassLoader(oldCl);
}
}
}
Invoke a Home interface method. |
public void setContainer(Container con) {
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
// ContainerService implementation -------------------------------
this.container = con;
}
|
public void start() throws Exception {
BeanMetaData metaData = container.getBeanMetaData();
EJBProxyFactoryContainer invokerContainer =
(EJBProxyFactoryContainer) container;
localHomeClass = invokerContainer.getLocalHomeClass();
localClass = invokerContainer.getLocalClass();
if(localHomeClass == null || localClass == null)
{
log.debug(metaData.getEjbName()
+
" cannot be Bound, doesn't " +
"have local and local home interfaces");
return;
}
// this is faster than newProxyInstance
Class[] intfs = {localClass};
Class proxyClass = Proxy.getProxyClass(ClassLoaderAction.UTIL.get(localClass), intfs);
final Class[] constructorParams =
{InvocationHandler.class};
proxyClassConstructor = proxyClass.getConstructor(constructorParams);
Context iniCtx = new InitialContext();
String beanName = metaData.getEjbName();
// Set the transaction manager and transaction propagation
// context factory of the GenericProxy class
transactionManager =
(TransactionManager) iniCtx.lookup("java:/TransactionManager");
// Create method mappings for container invoker
Method[] methods = localClass.getMethods();
beanMethodInvokerMap = new HashMap();
for(int i = 0; i < methods.length; i++)
{
long hash = MarshalledInvocation.calculateHash(methods[i]);
beanMethodInvokerMap.put(new Long(hash), methods[i]);
}
methods = localHomeClass.getMethods();
homeMethodInvokerMap = new HashMap();
for(int i = 0; i < methods.length; i++)
{
long hash = MarshalledInvocation.calculateHash(methods[i]);
homeMethodInvokerMap.put(new Long(hash), methods[i]);
}
// bind that referance to my name
Util.rebind(iniCtx, localJndiName, getEJBLocalHome());
invokerMap.put(localJndiName, this);
log.info("Bound EJB LocalHome '" + beanName + "' to jndi '" + localJndiName + "'");
}
|
public void stop() {
// Clean up the home proxy binding
try
{
if(invokerMap.remove(localJndiName) == this)
{
log.info("Unbind EJB LocalHome '" + container.getBeanMetaData().getEjbName() + "' from jndi '" + localJndiName + "'");
InitialContext ctx = new InitialContext();
ctx.unbind(localJndiName);
}
}
catch(Exception ignore)
{
}
}
|