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 |
|---|---|
| private transient Constructor | defaultConstructor
Must be transient because java.lang.Constructor is not serializable. |
| protected ClassDescriptor | descriptor
Backpointer to descriptor. |
| protected Object | factory
The object factory. |
| protected Class | factoryClass
The class of the factory. |
| protected String | |
| protected String | factoryMethodName
Static method invoked on the factoryClass to get the factory instance. |
| protected transient 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. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected Constructor | buildDefaultConstructor()
Build and return the default (zero-argument) constructor for the descriptor class. |
| protected Constructor | buildDefaultConstructorFor(final Class<?> javaClass)
Build and return the default (zero-argument) constructor for the specified class. |
| protected Object | |
| protected Constructor | buildFactoryDefaultConstructor()
Build and return the default (zero-argument) constructor for the factory class. |
| protected Object | |
| protected Object | |
| protected Method | buildMethod(Class<?> methodClass, String methodName, Class<?>[] methodParameterTypes)
Build the specified method. |
| public Object | buildNewInstance()
Implements abstract org. |
| protected Object | buildNewInstanceUsingDefaultConstructor()
Build and return a new instance, using the default (zero-argument) constructor. |
| protected Object | |
| public Object | |
| public void | convertClassNamesToClasses(final ClassLoader classLoader)
INTERNAL: Convert all the class-name-based settings in this InstantiationPolicy to actual class-based settings. |
| protected Constructor | |
| protected ClassDescriptor | |
| public Object | |
| public Class | |
| public String | |
| public String | |
| protected Method | |
| public String | |
| public void | |
| protected void | |
| public boolean | isUsingDefaultConstructor()
If no method name is specified, they we have to use the default (zero-argument) constructor. |
| protected void | |
| public void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| public void | |
| public String | |
| public void | |
| public void | |
| public void | |
| public void | useFactoryInstantiationPolicy(String factoryClassName, String methodName)
Implements abstract org. |
| public void | |
| public void | |
| public void |
| defaultConstructor | back to summary |
|---|---|
| private transient Constructor<T> defaultConstructor Must be transient because java.lang.Constructor is not serializable. | |
| descriptor | back to summary |
|---|---|
| protected ClassDescriptor descriptor Backpointer to descriptor. | |
| factory | back to summary |
|---|---|
| protected Object factory The object factory. This can be specified directly by the client, or it can be built dynamically using the the factoryClass and, optionally, the factoryMethodName. | |
| factoryClass | back to summary |
|---|---|
| protected Class<?> factoryClass The class of the factory. The factory is instantiated by either invoking this class's default (zero-argument) constructor or the factoryMethod specified below. | |
| factoryClassName | back to summary |
|---|---|
| protected String factoryClassName | |
| factoryMethodName | back to summary |
|---|---|
| protected String factoryMethodName Static method invoked on the factoryClass to get the factory instance. If this is null, the factory class's default (zero-argument) constructor is invoked. | |
| method | back to summary |
|---|---|
| protected transient Method method The method is resolved during initialization, and it is not serialized. | |
| methodName | back to summary |
|---|---|
| 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. | |
| InstantiationPolicy | back to summary |
|---|---|
| public InstantiationPolicy() Default constructor | |
| buildDefaultConstructor | back to summary |
|---|---|
| protected Constructor Build and return the default (zero-argument) constructor for the descriptor class. | |
| buildDefaultConstructorFor | back to summary |
|---|---|
| protected Constructor Build and return the default (zero-argument) constructor for the specified class. | |
| buildFactory | back to summary |
|---|---|
| protected Object buildFactory() throws DescriptorException | |
| buildFactoryDefaultConstructor | back to summary |
|---|---|
| protected Constructor Build and return the default (zero-argument) constructor for the factory class. | |
| buildFactoryUsingDefaultConstructor | back to summary |
|---|---|
| protected Object buildFactoryUsingDefaultConstructor() throws DescriptorException Build and return the factory, using its default constructor. | |
| buildFactoryUsingStaticMethod | back to summary |
|---|---|
| protected Object buildFactoryUsingStaticMethod() throws DescriptorException Build and return the factory, using the specified static method. | |
| buildMethod | back to summary |
|---|---|
| protected Method buildMethod(Class<?> methodClass, String methodName, Class<?>[] methodParameterTypes) throws DescriptorException Build the specified method. | |
| buildNewInstance | back to summary |
|---|---|
| public Object buildNewInstance() throws DescriptorException Implements abstract org. Build and return a new instance, using the appropriate mechanism.
| |
| buildNewInstanceUsingDefaultConstructor | back to summary |
|---|---|
| protected Object buildNewInstanceUsingDefaultConstructor() throws DescriptorException Build and return a new instance, using the default (zero-argument) constructor. | |
| buildNewInstanceUsingFactory | back to summary |
|---|---|
| protected Object buildNewInstanceUsingFactory() throws DescriptorException Build and return a new instance, using the factory. The factory can be null, in which case the method is a static method defined by the descriptor class. | |
| clone | back to summary |
|---|---|
| public Object clone() Overrides java. INTERNAL: Clones the InstantiationPolicy
| |
| convertClassNamesToClasses | back to summary |
|---|---|
| public void convertClassNamesToClasses(final ClassLoader classLoader) INTERNAL: Convert all the class-name-based settings in this InstantiationPolicy to actual class-based settings. This method is used when converting a project that has been built with class names to a project with classes. | |
| getDefaultConstructor | back to summary |
|---|---|
| protected Constructor Return the default (zero-argument) constructor for the descriptor class. | |
| getDescriptor | back to summary |
|---|---|
| protected ClassDescriptor getDescriptor() | |
| getFactory | back to summary |
|---|---|
| public Object getFactory() | |
| getFactoryClass | back to summary |
|---|---|
| public Class | |
| getFactoryClassName | back to summary |
|---|---|
| public String getFactoryClassName() | |
| getFactoryMethodName | back to summary |
|---|---|
| public String getFactoryMethodName() | |
| getMethod | back to summary |
|---|---|
| protected Method getMethod() | |
| getMethodName | back to summary |
|---|---|
| public String getMethodName() | |
| initialize | back to summary |
|---|---|
| public void initialize(AbstractSession session) throws DescriptorException If necessary, initialize the factory and the method. | |
| initializeMethod | back to summary |
|---|---|
| protected void initializeMethod() throws DescriptorException Initialize the method. It is either a static on the descriptor class, or it is a non-static on the factory. | |
| isUsingDefaultConstructor | back to summary |
|---|---|
| public boolean isUsingDefaultConstructor() If no method name is specified, they we have to use the default (zero-argument) constructor. | |
| setDefaultConstructor | back to summary |
|---|---|
| protected void setDefaultConstructor(Constructor<T> defaultConstructor) | |
| setDescriptor | back to summary |
|---|---|
| public void setDescriptor(ClassDescriptor descriptor) | |
| setFactory | back to summary |
|---|---|
| protected void setFactory(Object factory) | |
| setFactoryClass | back to summary |
|---|---|
| protected void setFactoryClass(Class<?> factoryClass) | |
| setFactoryClassName | back to summary |
|---|---|
| protected void setFactoryClassName(String factoryClassName) | |
| setFactoryMethodName | back to summary |
|---|---|
| protected void setFactoryMethodName(String factoryMethodName) | |
| setMethod | back to summary |
|---|---|
| protected void setMethod(Method method) | |
| setMethodName | back to summary |
|---|---|
| public void setMethodName(String methodName) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| useDefaultConstructorInstantiationPolicy | back to summary |
|---|---|
| public void useDefaultConstructorInstantiationPolicy() | |
| useFactoryInstantiationPolicy | back to summary |
|---|---|
| public void useFactoryInstantiationPolicy(Class<?> factoryClass, String methodName) | |
| useFactoryInstantiationPolicy | back to summary |
|---|---|
| public void useFactoryInstantiationPolicy(Class<?> factoryClass, String methodName, String factoryMethodName) | |
| useFactoryInstantiationPolicy | back to summary |
|---|---|
| public void useFactoryInstantiationPolicy(String factoryClassName, String methodName) Implements abstract org.
| |
| useFactoryInstantiationPolicy | back to summary |
|---|---|
| public void useFactoryInstantiationPolicy(String factoryClassName, String methodName, String factoryMethodName) | |
| useFactoryInstantiationPolicy | back to summary |
|---|---|
| public void useFactoryInstantiationPolicy(Object factory, String methodName) | |
| useMethodInstantiationPolicy | back to summary |
|---|---|
| public void useMethodInstantiationPolicy(String staticMethodName) | |