User: mnf999
Date: 01/12/18 23:22:27
Added: src/main/org/jboss/proxy/ejb/handle EntityHandleImpl.java
HomeHandleImpl.java StatefulHandleImpl.java
StatelessHandleImpl.java
Log:
the handle implementations, what is changed is that fact that the connector is now
detached from a given container but rather attached to the JMX node itself
Revision Changes Path
1.1 jboss/src/main/org/jboss/proxy/ejb/handle/EntityHandleImpl.java
Index: EntityHandleImpl.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.proxy.ejb.handle;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.rmi.ServerException;
import javax.naming.InitialContext;
import javax.ejb.Handle;
import javax.ejb.EJBObject;
import javax.ejb.EJBHome;
/**
* An EJB entity bean handle implementation.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
* @version $Revision: 1.1 $
*/
public class EntityHandleImpl
implements Handle
{
// Constants -----------------------------------------------------
/** Serial Version Identifier. */
//private static final long serialVersionUID = 1636103643167246469L;
// Attributes ----------------------------------------------------
/** The primary key of the entity bean. */
protected final Object id;
// The container
public String name;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
/**
* Construct a <tt>EntityHandleImpl</tt>.
*
* @param state The initial context state that will be used
* to restore the naming context or null to use
* a fresh InitialContext object.
* @param name JNDI name.
* @param id Primary key of the entity.
*/
public EntityHandleImpl( String name, Object id)
{
this.name=name;
this.id = id;
}
// Public --------------------------------------------------------
/**
* Handle implementation.
*
* @return <tt>EJBObject</tt> reference.
*
* @throws ServerException Could not get EJBObject.
* @throws RemoteException
*/
public EJBObject getEJBObject() throws RemoteException {
try {
EJBHome home = (EJBHome)new InitialContext().lookup(name);
Class type = home.getClass();
Method method = type.getMethod("findByPrimaryKey", new Class[]
{id.getClass()});
// call findByPrimary on the target
return (EJBObject)method.invoke(home, new Object[] {id});
}
catch (Exception e) {
throw new ServerException("Could not get EJBObject", e);
}
}
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
}
1.1 jboss/src/main/org/jboss/proxy/ejb/handle/HomeHandleImpl.java
Index: HomeHandleImpl.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.proxy.ejb.handle;
import javax.ejb.HomeHandle;
import javax.ejb.EJBHome;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.rmi.ServerException;
import java.rmi.RemoteException;
/*
import java.lang.reflect.Method;
*/
/**
* An EJB home handle implementation.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>.
* @version $Revision: 1.1 $
*/
public class HomeHandleImpl
implements HomeHandle
{
// Constants -----------------------------------------------------
/** Serial Version Identifier. */
// private static final long serialVersionUID = -6105191783910395296L;
// Attributes ----------------------------------------------------
public String jndiName;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
/**
* Construct a <tt>HomeHandleImpl</tt>.
*
* @param handle The initial context handle that will be used
* to restore the naming context or null to use
* a fresh InitialContext object.
* @param name JNDI name.
*/
public HomeHandleImpl(String jndiName)
{
this.jndiName = jndiName;
}
// Public --------------------------------------------------------
// Handle implementation -----------------------------------------
/**
* HomeHandle implementation.
*
* @return <tt>EJBHome</tt> reference.
*
* @throws ServerException Could not get EJBObject.
* @throws RemoteException
*/
public EJBHome getEJBHome() throws RemoteException
{
try
{
System.out.println(" GETTING THE HOME");
return (EJBHome) new InitialContext().lookup(jndiName);
}
catch (NamingException e) {
throw new ServerException("Could not get EJBHome", e);
}
}
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
}
1.1
jboss/src/main/org/jboss/proxy/ejb/handle/StatefulHandleImpl.java
Index: StatefulHandleImpl.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.proxy.ejb.handle;
import java.rmi.RemoteException;
import java.rmi.ServerException;
import java.rmi.MarshalledObject;
import java.lang.reflect.Method;
import java.util.Hashtable;
import javax.ejb.Handle;
import javax.ejb.EJBObject;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.jboss.invocation.Invoker;
import org.jboss.invocation.Invocation;
import org.jboss.invocation.MarshalledInvocation;
import org.jboss.security.SecurityAssociation;
/**
* An EJB stateful session bean handle.
*
* @author <a href="mailto:[EMAIL PROTECTED]>Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
* @version $Revision: 1.1 $
*/
public class StatefulHandleImpl
implements Handle
{
// Constants -----------------------------------------------------
/** Serial Version Identifier. */
// private static final long serialVersionUID = -2592509632957623102L;
// Static --------------------------------------------------------
/** A reference to {@link Handle#getEJBObject}. */
protected static final Method GET_EJB_OBJECT;
/**
* Initialize <tt>Handle</tt> method references.
*/
static {
try {
GET_EJB_OBJECT = Handle.class.getMethod("getEJBObject", new Class[0]);
}
catch (Exception e) {
e.printStackTrace();
throw new ExceptionInInitializerError(e);
}
}
// Attributes ----------------------------------------------------
/** The identity of the bean. */
public String jndiName;
public String server;
public Object id;
// Constructors --------------------------------------------------
/**
* Construct a <tt>StatefulHandleImpl</tt>.
*
* @param handle The initial context handle that will be used
* to restore the naming context or null to use
* a fresh InitialContext object.
* @param name JNDI name.
* @param id Identity of the bean.
*/
public StatefulHandleImpl(String jndiName, String server, Object id)
{
this.jndiName= jndiName;
this.server = server;
this.id = id;
}
// Public --------------------------------------------------------
/**
* Handle implementation.
*
* This differs from Stateless and Entity handles which just invoke standard
methods
* (<tt>create</tt> and <tt>findByPrimaryKey</tt> respectively) on the Home
interface (proxy).
* There is no equivalent option for stateful SBs, so a direct invocation on the
container has to
* be made to locate the bean by its id (the stateful SB container provides an
implementation of
* <tt>getEJBObject</tt>).
*
* This means the security context has to be set here just as it would be in the
Proxy.
*
* @return <tt>EJBObject</tt> reference.
*
* @throws ServerException Could not get EJBObject.
*/
public EJBObject getEJBObject() throws RemoteException {
try {
// Get the invoker to the target server (cluster or node)
Invoker invoker =
(Invoker) new InitialContext().lookup("invokers/"+server+"/jrmp");
Invocation invocation =
new Invocation(
null,
GET_EJB_OBJECT,
new Object[] {id},
//No transaction set up in here? it will get picked up in the proxy
null,
// fix for bug 474134 from Luke Taylor
SecurityAssociation.getPrincipal(),
SecurityAssociation.getCredential());
invocation.setContainer("J2EE:service=EJB,jndiName="+jndiName);
//It is a home invocation
invocation.setType("home");
// Get the invoker to the target server (cluster or node)
//Ship it
return (EJBObject) invoker.invoke(invocation);
}
catch (Exception e) {
throw new ServerException("Could not get EJBObject", e);
}
}
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
}
1.1
jboss/src/main/org/jboss/proxy/ejb/handle/StatelessHandleImpl.java
Index: StatelessHandleImpl.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.proxy.ejb.handle;
import java.rmi.RemoteException;
import java.rmi.ServerException;
import java.lang.reflect.Method;
import javax.naming.InitialContext;
import javax.ejb.Handle;
import javax.ejb.EJBObject;
import javax.ejb.EJBHome;
/**
* An EJB stateless session bean handle.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @version $Revision: 1.1 $
*/
public class StatelessHandleImpl
implements Handle
{
// Constants -----------------------------------------------------
/** Serial Version Identifier. */
//private static final long serialVersionUID = 4651553991845772180L;
// Attributes ----------------------------------------------------
public String jndiName;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
/**
* Construct a <tt>StatelessHandleImpl</tt>.
*
* @param handle The initial context handle that will be used
* to restore the naming context or null to use
* a fresh InitialContext object.
* @param name JNDI name.
*/
public StatelessHandleImpl(String jndiName)
{
this.jndiName = jndiName;
}
// Public --------------------------------------------------------
public EJBObject getEJBObject()
throws ServerException
{
try {
EJBHome home = (EJBHome) new InitialContext().lookup(jndiName);
Class type = home.getClass();
Method method = type.getMethod("create", new Class[0]);
return (EJBObject)method.invoke(home, new Object[0]);
}
catch (Exception e) {
throw new ServerException("Could not get EJBObject", e);
}
}
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development