public class InstantiationPolicy
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
So, here is how it works:
If there is no method specified
- all the other settings are ignored and
- the descriptor class's default constructor is invoked.
If a factory is specified
- the factoryClass and factoryClassMethod are ignored and
- the method is invoked on the factory.
If neither a factory nor a factoryClass are specified
- the factoryClassMethod is ignored and
- the method is invoked on the descriptor class (as a static).
If only the factoryClass is specified
- the factory is created by invoking the factoryClass' default (zero-argument) constructor and
- the method is invoked on the resulting factory.
If both the factoryClass and the factoryClassMethod are specified
- the factory is created by invoking the factoryClassMethod on the factoryClass (as a static) and
- the method is invoked on the resulting factory.
The only thing we can't support in the current configuration is invoking a static on some, client-specified, factoryClass to build new instances of the descriptor class; and it's debatable whether that is desirable...
It might be reasonable to rework this into a number of different classes that implement an interface...
Modifier and Type | Field and Description |
---|---|
protected ClassDescriptor |
descriptor
Backpointer to descriptor.
|
protected java.lang.Object |
factory
The object factory.
|
protected java.lang.Class |
factoryClass
The class of the factory.
|
protected java.lang.String |
factoryClassName |
protected java.lang.String |
factoryMethodName
Static method invoked on the factoryClass to get the factory instance.
|
protected java.lang.reflect.Method |
method
The method is resolved during initialization, and it is not serialized.
|
protected java.lang.String |
methodName
The method invoked on either the descriptor class (in which case it is static) or
the factory (in which case it is not static) to build a new instance of the descriptor class.
|
Constructor and Description |
---|
InstantiationPolicy()
Default constructor
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.reflect.Constructor |
buildDefaultConstructor()
Build and return the default (zero-argument) constructor for the descriptor class.
|
protected java.lang.reflect.Constructor |
buildDefaultConstructorFor(java.lang.Class javaClass)
Build and return the default (zero-argument) constructor for the specified class.
|
protected java.lang.Object |
buildFactory() |
protected java.lang.reflect.Constructor |
buildFactoryDefaultConstructor()
Build and return the default (zero-argument) constructor for the factory class.
|
protected java.lang.Object |
buildFactoryUsingDefaultConstructor()
Build and return the factory, using its default constructor.
|
protected java.lang.Object |
buildFactoryUsingStaticMethod()
Build and return the factory, using the specified static method.
|
protected java.lang.reflect.Method |
buildMethod(java.lang.Class methodClass,
java.lang.String methodName,
java.lang.Class[] methodParameterTypes)
Build the specified method.
|
java.lang.Object |
buildNewInstance()
Build and return a new instance, using the appropriate mechanism.
|
protected java.lang.Object |
buildNewInstanceUsingDefaultConstructor()
Build and return a new instance, using the default (zero-argument) constructor.
|
protected java.lang.Object |
buildNewInstanceUsingFactory()
Build and return a new instance, using the factory.
|
java.lang.Object |
clone()
INTERNAL:
Clones the InstantiationPolicy
|
void |
convertClassNamesToClasses(java.lang.ClassLoader classLoader)
INTERNAL:
Convert all the class-name-based settings in this InstantiationPolicy to actual class-based
settings.
|
protected java.lang.reflect.Constructor |
getDefaultConstructor()
Return the default (zero-argument) constructor for the descriptor class.
|
protected ClassDescriptor |
getDescriptor() |
java.lang.Object |
getFactory() |
java.lang.Class |
getFactoryClass() |
java.lang.String |
getFactoryClassName() |
java.lang.String |
getFactoryMethodName() |
protected java.lang.reflect.Method |
getMethod() |
java.lang.String |
getMethodName() |
void |
initialize(AbstractSession session)
If necessary, initialize the factory and the method.
|
protected void |
initializeMethod()
Initialize the method.
|
boolean |
isUsingDefaultConstructor()
If no method name is specified, they we have to use the default (zero-argument) constructor.
|
protected void |
setDefaultConstructor(java.lang.reflect.Constructor defaultConstructor) |
void |
setDescriptor(ClassDescriptor descriptor) |
protected void |
setFactory(java.lang.Object factory) |
protected void |
setFactoryClass(java.lang.Class factoryClass) |
protected void |
setFactoryClassName(java.lang.String factoryClassName) |
protected void |
setFactoryMethodName(java.lang.String factoryMethodName) |
protected void |
setMethod(java.lang.reflect.Method method) |
void |
setMethodName(java.lang.String methodName) |
java.lang.String |
toString() |
void |
useDefaultConstructorInstantiationPolicy() |
void |
useFactoryInstantiationPolicy(java.lang.Class factoryClass,
java.lang.String methodName) |
void |
useFactoryInstantiationPolicy(java.lang.Class factoryClass,
java.lang.String methodName,
java.lang.String factoryMethodName) |
void |
useFactoryInstantiationPolicy(java.lang.Object factory,
java.lang.String methodName) |
void |
useFactoryInstantiationPolicy(java.lang.String factoryClassName,
java.lang.String methodName) |
void |
useFactoryInstantiationPolicy(java.lang.String factoryClassName,
java.lang.String methodName,
java.lang.String factoryMethodName) |
void |
useMethodInstantiationPolicy(java.lang.String staticMethodName) |
protected java.lang.String methodName
protected transient java.lang.reflect.Method method
protected java.lang.Class factoryClass
protected java.lang.String factoryClassName
protected java.lang.String factoryMethodName
protected java.lang.Object factory
protected ClassDescriptor descriptor
public java.lang.Object buildNewInstance() throws DescriptorException
DescriptorException
protected java.lang.Object buildNewInstanceUsingDefaultConstructor() throws DescriptorException
DescriptorException
protected java.lang.Object buildNewInstanceUsingFactory() throws DescriptorException
DescriptorException
public java.lang.Object clone()
clone
in class java.lang.Object
protected java.lang.reflect.Constructor getDefaultConstructor() throws DescriptorException
DescriptorException
protected java.lang.reflect.Constructor buildDefaultConstructor() throws DescriptorException
DescriptorException
protected java.lang.reflect.Constructor buildDefaultConstructorFor(java.lang.Class javaClass) throws DescriptorException
DescriptorException
protected ClassDescriptor getDescriptor()
public java.lang.String getFactoryMethodName()
public java.lang.Object getFactory()
public java.lang.Class getFactoryClass()
public java.lang.String getFactoryClassName()
protected java.lang.reflect.Method getMethod()
public java.lang.String getMethodName()
public void initialize(AbstractSession session) throws DescriptorException
DescriptorException
protected java.lang.Object buildFactory() throws DescriptorException
DescriptorException
protected java.lang.Object buildFactoryUsingDefaultConstructor() throws DescriptorException
DescriptorException
protected java.lang.reflect.Constructor buildFactoryDefaultConstructor() throws DescriptorException
DescriptorException
protected java.lang.Object buildFactoryUsingStaticMethod() throws DescriptorException
DescriptorException
protected void initializeMethod() throws DescriptorException
DescriptorException
protected java.lang.reflect.Method buildMethod(java.lang.Class methodClass, java.lang.String methodName, java.lang.Class[] methodParameterTypes) throws DescriptorException
DescriptorException
public boolean isUsingDefaultConstructor()
protected void setDefaultConstructor(java.lang.reflect.Constructor defaultConstructor)
public void setDescriptor(ClassDescriptor descriptor)
protected void setFactoryMethodName(java.lang.String factoryMethodName)
protected void setFactory(java.lang.Object factory)
protected void setFactoryClass(java.lang.Class factoryClass)
protected void setFactoryClassName(java.lang.String factoryClassName)
protected void setMethod(java.lang.reflect.Method method)
public void setMethodName(java.lang.String methodName)
public void convertClassNamesToClasses(java.lang.ClassLoader classLoader)
classLoader
- public java.lang.String toString()
toString
in class java.lang.Object
public void useDefaultConstructorInstantiationPolicy()
public void useFactoryInstantiationPolicy(java.lang.Class factoryClass, java.lang.String methodName)
public void useFactoryInstantiationPolicy(java.lang.Class factoryClass, java.lang.String methodName, java.lang.String factoryMethodName)
public void useFactoryInstantiationPolicy(java.lang.String factoryClassName, java.lang.String methodName)
public void useFactoryInstantiationPolicy(java.lang.String factoryClassName, java.lang.String methodName, java.lang.String factoryMethodName)
public void useFactoryInstantiationPolicy(java.lang.Object factory, java.lang.String methodName)
public void useMethodInstantiationPolicy(java.lang.String staticMethodName)