|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsf.qof.util.DelegatorFactory
public class DelegatorFactory
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
|
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 |
---|
public DelegatorFactory()
Method Detail |
---|
public static <T> T create(Class<T> delegateeClass, Class<?> delegateeFactory, Object... constructorParameters)
T
- type of the delegatee objectdelegateeClass
- class of the delegatee objectdelegateeFactory
- factory to initialize the delegatee objectconstructorParameters
- parameters that are passed to the delegatee factory
|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |