Class InstantiationPolicy
- java.lang.Object
-
- org.eclipse.persistence.internal.core.descriptors.CoreInstantiationPolicy
-
- org.eclipse.persistence.internal.descriptors.InstantiationPolicy
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
- Direct Known Subclasses:
PersistenceObjectInstantiationPolicy
public class InstantiationPolicy extends CoreInstantiationPolicy implements java.lang.Cloneable, java.io.Serializable
Purpose: Allows customization of how an object is created/instantiated.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...
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected ClassDescriptordescriptorBackpointer to descriptor.protected java.lang.ObjectfactoryThe object factory.protected java.lang.ClassfactoryClassThe class of the factory.protected java.lang.StringfactoryClassNameprotected java.lang.StringfactoryMethodNameStatic method invoked on the factoryClass to get the factory instance.protected java.lang.reflect.MethodmethodThe method is resolved during initialization, and it is not serialized.protected java.lang.StringmethodNameThe 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 Summary
Constructors Constructor Description InstantiationPolicy()Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.reflect.ConstructorbuildDefaultConstructor()Build and return the default (zero-argument) constructor for the descriptor class.protected java.lang.reflect.ConstructorbuildDefaultConstructorFor(java.lang.Class javaClass)Build and return the default (zero-argument) constructor for the specified class.protected java.lang.ObjectbuildFactory()protected java.lang.reflect.ConstructorbuildFactoryDefaultConstructor()Build and return the default (zero-argument) constructor for the factory class.protected java.lang.ObjectbuildFactoryUsingDefaultConstructor()Build and return the factory, using its default constructor.protected java.lang.ObjectbuildFactoryUsingStaticMethod()Build and return the factory, using the specified static method.protected java.lang.reflect.MethodbuildMethod(java.lang.Class methodClass, java.lang.String methodName, java.lang.Class[] methodParameterTypes)Build the specified method.java.lang.ObjectbuildNewInstance()Build and return a new instance, using the appropriate mechanism.protected java.lang.ObjectbuildNewInstanceUsingDefaultConstructor()Build and return a new instance, using the default (zero-argument) constructor.protected java.lang.ObjectbuildNewInstanceUsingFactory()Build and return a new instance, using the factory.java.lang.Objectclone()INTERNAL: Clones the InstantiationPolicyvoidconvertClassNamesToClasses(java.lang.ClassLoader classLoader)INTERNAL: Convert all the class-name-based settings in this InstantiationPolicy to actual class-based settings.protected java.lang.reflect.ConstructorgetDefaultConstructor()Return the default (zero-argument) constructor for the descriptor class.protected ClassDescriptorgetDescriptor()java.lang.ObjectgetFactory()java.lang.ClassgetFactoryClass()java.lang.StringgetFactoryClassName()java.lang.StringgetFactoryMethodName()protected java.lang.reflect.MethodgetMethod()java.lang.StringgetMethodName()voidinitialize(AbstractSession session)If necessary, initialize the factory and the method.protected voidinitializeMethod()Initialize the method.booleanisUsingDefaultConstructor()If no method name is specified, they we have to use the default (zero-argument) constructor.protected voidsetDefaultConstructor(java.lang.reflect.Constructor defaultConstructor)voidsetDescriptor(ClassDescriptor descriptor)protected voidsetFactory(java.lang.Object factory)protected voidsetFactoryClass(java.lang.Class factoryClass)protected voidsetFactoryClassName(java.lang.String factoryClassName)protected voidsetFactoryMethodName(java.lang.String factoryMethodName)protected voidsetMethod(java.lang.reflect.Method method)voidsetMethodName(java.lang.String methodName)java.lang.StringtoString()voiduseDefaultConstructorInstantiationPolicy()voiduseFactoryInstantiationPolicy(java.lang.Class factoryClass, java.lang.String methodName)voiduseFactoryInstantiationPolicy(java.lang.Class factoryClass, java.lang.String methodName, java.lang.String factoryMethodName)voiduseFactoryInstantiationPolicy(java.lang.Object factory, java.lang.String methodName)voiduseFactoryInstantiationPolicy(java.lang.String factoryClassName, java.lang.String methodName)voiduseFactoryInstantiationPolicy(java.lang.String factoryClassName, java.lang.String methodName, java.lang.String factoryMethodName)voiduseMethodInstantiationPolicy(java.lang.String staticMethodName)
-
-
-
Field Detail
-
methodName
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.
-
method
protected transient java.lang.reflect.Method method
The method is resolved during initialization, and it is not serialized.
-
factoryClass
protected java.lang.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
protected java.lang.String factoryClassName
-
factoryMethodName
protected java.lang.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.
-
factory
protected java.lang.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.
-
descriptor
protected ClassDescriptor descriptor
Backpointer to descriptor.
-
-
Method Detail
-
buildNewInstance
public java.lang.Object buildNewInstance() throws DescriptorExceptionBuild and return a new instance, using the appropriate mechanism.- Specified by:
buildNewInstancein classCoreInstantiationPolicy- Throws:
DescriptorException
-
buildNewInstanceUsingDefaultConstructor
protected java.lang.Object buildNewInstanceUsingDefaultConstructor() throws DescriptorExceptionBuild and return a new instance, using the default (zero-argument) constructor.- Throws:
DescriptorException
-
buildNewInstanceUsingFactory
protected java.lang.Object buildNewInstanceUsingFactory() throws DescriptorExceptionBuild 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.- Throws:
DescriptorException
-
clone
public java.lang.Object clone()
INTERNAL: Clones the InstantiationPolicy- Overrides:
clonein classjava.lang.Object
-
getDefaultConstructor
protected java.lang.reflect.Constructor getDefaultConstructor() throws DescriptorExceptionReturn the default (zero-argument) constructor for the descriptor class.- Throws:
DescriptorException
-
buildDefaultConstructor
protected java.lang.reflect.Constructor buildDefaultConstructor() throws DescriptorExceptionBuild and return the default (zero-argument) constructor for the descriptor class.- Throws:
DescriptorException
-
buildDefaultConstructorFor
protected java.lang.reflect.Constructor buildDefaultConstructorFor(java.lang.Class javaClass) throws DescriptorExceptionBuild and return the default (zero-argument) constructor for the specified class.- Throws:
DescriptorException
-
getDescriptor
protected ClassDescriptor getDescriptor()
-
getFactoryMethodName
public java.lang.String getFactoryMethodName()
-
getFactory
public java.lang.Object getFactory()
-
getFactoryClass
public java.lang.Class getFactoryClass()
-
getFactoryClassName
public java.lang.String getFactoryClassName()
-
getMethod
protected java.lang.reflect.Method getMethod()
-
getMethodName
public java.lang.String getMethodName()
-
initialize
public void initialize(AbstractSession session) throws DescriptorException
If necessary, initialize the factory and the method.- Throws:
DescriptorException
-
buildFactory
protected java.lang.Object buildFactory() throws DescriptorException- Throws:
DescriptorException
-
buildFactoryUsingDefaultConstructor
protected java.lang.Object buildFactoryUsingDefaultConstructor() throws DescriptorExceptionBuild and return the factory, using its default constructor.- Throws:
DescriptorException
-
buildFactoryDefaultConstructor
protected java.lang.reflect.Constructor buildFactoryDefaultConstructor() throws DescriptorExceptionBuild and return the default (zero-argument) constructor for the factory class.- Throws:
DescriptorException
-
buildFactoryUsingStaticMethod
protected java.lang.Object buildFactoryUsingStaticMethod() throws DescriptorExceptionBuild and return the factory, using the specified static method.- Throws:
DescriptorException
-
initializeMethod
protected void initializeMethod() throws DescriptorExceptionInitialize the method. It is either a static on the descriptor class, or it is a non-static on the factory.- Throws:
DescriptorException
-
buildMethod
protected java.lang.reflect.Method buildMethod(java.lang.Class methodClass, java.lang.String methodName, java.lang.Class[] methodParameterTypes) throws DescriptorExceptionBuild the specified method.- Throws:
DescriptorException
-
isUsingDefaultConstructor
public boolean isUsingDefaultConstructor()
If no method name is specified, they we have to use the default (zero-argument) constructor.
-
setDefaultConstructor
protected void setDefaultConstructor(java.lang.reflect.Constructor defaultConstructor)
-
setDescriptor
public void setDescriptor(ClassDescriptor descriptor)
-
setFactoryMethodName
protected void setFactoryMethodName(java.lang.String factoryMethodName)
-
setFactory
protected void setFactory(java.lang.Object factory)
-
setFactoryClass
protected void setFactoryClass(java.lang.Class factoryClass)
-
setFactoryClassName
protected void setFactoryClassName(java.lang.String factoryClassName)
-
setMethod
protected void setMethod(java.lang.reflect.Method method)
-
setMethodName
public void setMethodName(java.lang.String methodName)
-
convertClassNamesToClasses
public void convertClassNamesToClasses(java.lang.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.- Parameters:
classLoader-
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
useDefaultConstructorInstantiationPolicy
public void useDefaultConstructorInstantiationPolicy()
-
useFactoryInstantiationPolicy
public void useFactoryInstantiationPolicy(java.lang.Class factoryClass, java.lang.String methodName)
-
useFactoryInstantiationPolicy
public void useFactoryInstantiationPolicy(java.lang.Class factoryClass, java.lang.String methodName, java.lang.String factoryMethodName)
-
useFactoryInstantiationPolicy
public void useFactoryInstantiationPolicy(java.lang.String factoryClassName, java.lang.String methodName)- Specified by:
useFactoryInstantiationPolicyin classCoreInstantiationPolicy
-
useFactoryInstantiationPolicy
public void useFactoryInstantiationPolicy(java.lang.String factoryClassName, java.lang.String methodName, java.lang.String factoryMethodName)
-
useFactoryInstantiationPolicy
public void useFactoryInstantiationPolicy(java.lang.Object factory, java.lang.String methodName)
-
useMethodInstantiationPolicy
public void useMethodInstantiationPolicy(java.lang.String staticMethodName)
-
-