sf logo

sf.qof.util
Class DelegatorFactory

java.lang.Object
  extended by sf.qof.util.DelegatorFactory

public class DelegatorFactory
extends Object

Factory class to create a delegator object for a given delegatee class.

The factory creates wrappers for each public non-final method of the delegatee class. Once any of these methods is called the delegatee factory is used to initialize the delegatee object. The delegatee class must have a default constructor.

The delegatee factory must implement a static initialize method with the first argument being the delegatee object and the other arguments matching the types of the constructorParameters:

 public class PersonDelegateeFactory {
   public static void initialize(Person personDelegatee, Integer id) {
     String name = getNameForId(id);
     personDelegatee.setName(name);
   }
 }
 
 // create a delegator for person and pass it the id of 1 
 Person person = DelegatorFactory<Person>(Person.class, 
      PersonDelegateeFactory.class, 1);
 // person is instanziated but not initialized
 // a call to getName() or any other public method of person for the first time
 // calls PersonDelegateeFactory.initialize(person, 1)
 String name = person.getName();
 // person is initialized now
 

Initialization of delegator objects is thread-safe.

DelegatorFactory can be used to implement lazy initialization of objects

The generated delegatee objects super class is the delegatee class.


Constructor Summary
DelegatorFactory()
           
 
Method Summary
static
<T> T
create(Class<T> delegateeClass, Class<?> delegateeFactory, Object... constructorParameters)
          Returns an instance of a delegator object for a delegatee class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegatorFactory

public DelegatorFactory()
Method Detail

create

public static <T> T create(Class<T> delegateeClass,
                           Class<?> delegateeFactory,
                           Object... constructorParameters)
Returns an instance of a delegator object for a delegatee class.

Type Parameters:
T - type of the delegatee object
Parameters:
delegateeClass - class of the delegatee object
delegateeFactory - factory to initialize the delegatee object
constructorParameters - parameters that are passed to the delegatee factory
Returns:
delegator object instance

sf logo

Copyright © 2007 brunella ltd. All Rights Reserved.