com.tzavellas.dyndelegate
Class DynamicDelegateFactory

java.lang.Object
  extended by com.tzavellas.dyndelegate.DynamicDelegateFactory

public class DynamicDelegateFactory
extends Object

A Dynamic Delegate for Session Beans.

This class dynamically creates a Business Delegate for a Session EJB. The delegate will implement the specified interface. When a method is called on the delegate the corresponding method on the client interface of bean will be invoked. Any exception that may be thrown from the invocation will be converted and re-thrown according to the ThrowableConverter of this class.

To use this class your EJBs must implement the Business Interface EJB design pattern (see the EJB Design Patterns book by Floyd Marinescu). In this pattern your EJB's bean class and client interface (local or remote), both implement a common "Business Interface" that defines the business methods.

When creating a dynamic delegate for an EJB, supply as the delegate interface the Business Interface of your bean. The business interface usually does not throw any EJB specific exceptions (like RemoteException and EJBException) and does not have any dependency on the EJB APIs.

This work is based on the "EJB best practices: The dynamic delegate" article by Brett McLaughlin and on the Spring Framework EJB Access classes found at the org.springframework.ejb.access package.

Author:
Spiros Tzavellas
See Also:
ThrowableConverter, EJBHomeFactory, EJB best practices: The dynamic delegate, The Business Interface design pattern, Spring Framework

Constructor Summary
DynamicDelegateFactory()
          Construct a DynamicDelegateFactory with an EJBExceptionConverter and a SimpleEJBHomeFactory.
DynamicDelegateFactory(ThrowableConverter exceptionConverter, EJBHomeFactory homeFactory)
          Construct a DynamicDelegateFactory using the specified ThrowableConverter and EJBHomeFactory.
 
Method Summary
protected  Object createDelegate(String jndiName, Class homeInterface, Class businnessInterface, Object[] createArgs, boolean isRemote)
          Dynamically create a Business Delegate.
 Object createLocalDelegate(String jndiName, Class homeInterface, Class businnessInterface)
          Dynamically create a Business Delegate for an EJB with local access.
 Object createLocalDelegate(String jndiName, Class homeInterface, Class businnessInterface, Object[] createArgs)
          Dynamically create a Business Delegate for an EJB with local access.
 Object createRemoteDelegate(String jndiName, Class homeInterface, Class businnessInterface)
          Dynamically create a Business Delegate for an EJB with remote access.
 Object createRemoteDelegate(String jndiName, Class homeInterface, Class businnessInterface, Object[] createArgs)
          Dynamically create a Business Delegate for an EJB with remote access.
 Object getBean(Object delegate)
          Get the EJB that the specified Business Delegate proxies.
 void remove(Object delegate)
          Remove the EJB behind the specified dynamic delegate object.
 void setExceptionConverter(ThrowableConverter exceptionConverter)
          Set the ThrowableConverter to use with this factory.
 void setHomeFactory(EJBHomeFactory homeFactory)
          Set the EJBHomeFactory to use with this factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicDelegateFactory

public DynamicDelegateFactory(ThrowableConverter exceptionConverter,
                              EJBHomeFactory homeFactory)
Construct a DynamicDelegateFactory using the specified ThrowableConverter and EJBHomeFactory.

See Also:
ThrowableConverter, EJBHomeFactory

DynamicDelegateFactory

public DynamicDelegateFactory()
Construct a DynamicDelegateFactory with an EJBExceptionConverter and a SimpleEJBHomeFactory.

See Also:
EJBExceptionConverter, SimpleEJBHomeFactory
Method Detail

setExceptionConverter

public void setExceptionConverter(ThrowableConverter exceptionConverter)
Set the ThrowableConverter to use with this factory.


setHomeFactory

public void setHomeFactory(EJBHomeFactory homeFactory)
Set the EJBHomeFactory to use with this factory.


createRemoteDelegate

public Object createRemoteDelegate(String jndiName,
                                   Class homeInterface,
                                   Class businnessInterface)
Dynamically create a Business Delegate for an EJB with remote access.

Parameters:
jndiName - the JNDI name to lookup the EJB.
homeInterface - the class of the home interface of the EJB that the created delegate will proxy
businnessInterface - the interface that the created delegate will implement
Returns:
a Business Delegate object for the EJB bound to the specified JNDI name implementing the specified interface.

createRemoteDelegate

public Object createRemoteDelegate(String jndiName,
                                   Class homeInterface,
                                   Class businnessInterface,
                                   Object[] createArgs)
Dynamically create a Business Delegate for an EJB with remote access.

Parameters:
jndiName - the JNDI name to lookup the EJB.
homeInterface - the class of the home interface of the EJB that the created delegate will proxy
businnessInterface - the interface that the created delegate will implement
createArgs - the arguments of the create method in the EJB's home interface
Returns:
a Business Delegate object for the EJB bound to the specified JNDI name implementing the specified interface.

createLocalDelegate

public Object createLocalDelegate(String jndiName,
                                  Class homeInterface,
                                  Class businnessInterface)
Dynamically create a Business Delegate for an EJB with local access.

Parameters:
jndiName - the JNDI name to lookup the EJB.
homeInterface - the class of the home interface of the EJB that the created delegate will proxy
businnessInterface - the interface that the created delegate will implement
Returns:
a Business Delegate object for the EJB bound to the specified JNDI name implementing the specified interface.

createLocalDelegate

public Object createLocalDelegate(String jndiName,
                                  Class homeInterface,
                                  Class businnessInterface,
                                  Object[] createArgs)
Dynamically create a Business Delegate for an EJB with local access.

Parameters:
jndiName - the JNDI name to lookup the EJB.
homeInterface - the class of the home interface of the EJB that the created delegate will proxy
businnessInterface - the interface that the created delegate will implement
createArgs - the arguments of the create method in the EJB's home interface
Returns:
a Business Delegate object for the EJB bound to the specified JNDI name implementing the specified interface.

createDelegate

protected Object createDelegate(String jndiName,
                                Class homeInterface,
                                Class businnessInterface,
                                Object[] createArgs,
                                boolean isRemote)
Dynamically create a Business Delegate.

Parameters:
jndiName - the JNDI name to lookup the EJB.
homeInterface - the class of the home interface of the EJB that the created delegate will proxy
businnessInterface - the interface that the created delegate will implement
createArgs - the arguments of the create method in the EJB's home interface
isRemote - the access of the EJB (remote or local)
Returns:
a Business Delegate object for the EJB bound to the specified JNDI name implementing the specified interface.

getBean

public Object getBean(Object delegate)
               throws IllegalArgumentException
Get the EJB that the specified Business Delegate proxies.

Parameters:
delegate - a dynamic Business Delegate object generated with this class.
Returns:
a reference of the bean's client interface (local or remote).
Throws:
IllegalArgumentException - if the parameter is not a dynamic delegate generated with this class.

remove

public void remove(Object delegate)
            throws IllegalArgumentException
Remove the EJB behind the specified dynamic delegate object.

Since this method calls remove() on the bean's client interface, you cannot invoke methods on the specified delegate object after this method is invoked.

Parameters:
delegate - the delegate that proxies the bean that we want to remove.
Throws:
IllegalArgumentException - if the parameter is not a dynamic delegate generated with this class.


Copyright © 2005-2009 spiros.blog(). All Rights Reserved.