public class InstantiationPolicy extends Object implements Cloneable, 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 Object |
factory
The object factory.
|
protected Class |
factoryClass
The class of the factory.
|
protected String |
factoryClassName |
protected String |
factoryMethodName
Static method invoked on the factoryClass to get the factory instance.
|
protected Method |
method
The method is resolved during initialization, and it is not serialized.
|
protected 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 Constructor |
buildDefaultConstructor()
Build and return the default (zero-argument) constructor for the descriptor class.
|
protected Constructor |
buildDefaultConstructorFor(Class javaClass)
Build and return the default (zero-argument) constructor for the specified class.
|
protected Object |
buildFactory() |
protected Constructor |
buildFactoryDefaultConstructor()
Build and return the default (zero-argument) constructor for the factory class.
|
protected Object |
buildFactoryUsingDefaultConstructor()
Build and return the factory, using its default constructor.
|
protected Object |
buildFactoryUsingStaticMethod()
Build and return the factory, using the specified static method.
|
protected Method |
buildMethod(Class methodClass,
String methodName,
Class[] methodParameterTypes)
Build the specified method.
|
Object |
buildNewInstance()
Build and return a new instance, using the appropriate mechanism.
|
protected Object |
buildNewInstanceUsingDefaultConstructor()
Build and return a new instance, using the default (zero-argument) constructor.
|
protected Object |
buildNewInstanceUsingFactory()
Build and return a new instance, using the factory.
|
Object |
clone()
INTERNAL:
Clones the InstantiationPolicy
|
void |
convertClassNamesToClasses(ClassLoader classLoader)
INTERNAL:
Convert all the class-name-based settings in this InstantiationPolicy to actual class-based
settings.
|
protected Constructor |
getDefaultConstructor()
Return the default (zero-argument) constructor for the descriptor class.
|
protected ClassDescriptor |
getDescriptor() |
Object |
getFactory() |
Class |
getFactoryClass() |
String |
getFactoryClassName() |
String |
getFactoryMethodName() |
protected Method |
getMethod() |
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(Constructor defaultConstructor) |
void |
setDescriptor(ClassDescriptor descriptor) |
protected void |
setFactory(Object factory) |
protected void |
setFactoryClass(Class factoryClass) |
protected void |
setFactoryClassName(String factoryClassName) |
protected void |
setFactoryMethodName(String factoryMethodName) |
protected void |
setMethod(Method method) |
void |
setMethodName(String methodName) |
String |
toString() |
void |
useDefaultConstructorInstantiationPolicy() |
void |
useFactoryInstantiationPolicy(Class factoryClass,
String methodName) |
void |
useFactoryInstantiationPolicy(Class factoryClass,
String methodName,
String factoryMethodName) |
void |
useFactoryInstantiationPolicy(Object factory,
String methodName) |
void |
useFactoryInstantiationPolicy(String factoryClassName,
String methodName) |
void |
useFactoryInstantiationPolicy(String factoryClassName,
String methodName,
String factoryMethodName) |
void |
useMethodInstantiationPolicy(String staticMethodName) |
protected String methodName
protected transient Method method
protected Class factoryClass
protected String factoryClassName
protected String factoryMethodName
protected Object factory
protected ClassDescriptor descriptor
public Object buildNewInstance() throws DescriptorException
DescriptorException
protected Object buildNewInstanceUsingDefaultConstructor() throws DescriptorException
DescriptorException
protected Object buildNewInstanceUsingFactory() throws DescriptorException
DescriptorException
public Object clone()
protected Constructor getDefaultConstructor() throws DescriptorException
DescriptorException
protected Constructor buildDefaultConstructor() throws DescriptorException
DescriptorException
protected Constructor buildDefaultConstructorFor(Class javaClass) throws DescriptorException
DescriptorException
protected ClassDescriptor getDescriptor()
public String getFactoryMethodName()
public Object getFactory()
public Class getFactoryClass()
public String getFactoryClassName()
protected Method getMethod()
public String getMethodName()
public void initialize(AbstractSession session) throws DescriptorException
DescriptorException
protected Object buildFactory() throws DescriptorException
DescriptorException
protected Object buildFactoryUsingDefaultConstructor() throws DescriptorException
DescriptorException
protected Constructor buildFactoryDefaultConstructor() throws DescriptorException
DescriptorException
protected Object buildFactoryUsingStaticMethod() throws DescriptorException
DescriptorException
protected void initializeMethod() throws DescriptorException
DescriptorException
protected Method buildMethod(Class methodClass, String methodName, Class[] methodParameterTypes) throws DescriptorException
DescriptorException
public boolean isUsingDefaultConstructor()
protected void setDefaultConstructor(Constructor defaultConstructor)
public void setDescriptor(ClassDescriptor descriptor)
protected void setFactoryMethodName(String factoryMethodName)
protected void setFactory(Object factory)
protected void setFactoryClass(Class factoryClass)
protected void setFactoryClassName(String factoryClassName)
protected void setMethod(Method method)
public void setMethodName(String methodName)
public void convertClassNamesToClasses(ClassLoader classLoader)
classLoader
- public void useDefaultConstructorInstantiationPolicy()
public void useFactoryInstantiationPolicy(Class factoryClass, String methodName)
public void useFactoryInstantiationPolicy(Class factoryClass, String methodName, String factoryMethodName)
public void useFactoryInstantiationPolicy(String factoryClassName, String methodName)
public void useFactoryInstantiationPolicy(String factoryClassName, String methodName, String factoryMethodName)
public void useFactoryInstantiationPolicy(Object factory, String methodName)
public void useMethodInstantiationPolicy(String staticMethodName)
Copyright © 2022. All rights reserved.