Top Description Fields Constructors Methods
org.eclipse.persistence.internal.descriptors

public Class InstantiationPolicy

extends CoreInstantiationPolicy
implements Cloneable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Cloneable
Known Direct Subclasses
org.eclipse.persistence.internal.descriptors.PersistenceObjectInstantiationPolicy, org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceRuntimeXMLProject_11_1_1.StoredProcedureArgumentInstantiationPolicy, org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceRuntimeXMLProject_11_1_1.ObjectTypeFieldAssociationInstantiationPolicy, org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceRuntimeXMLProject_11_1_1.ObjectRelationalDatabaseFieldInstantiationPolicy
Imports
java.io.Serializable, java.lang.reflect.Constructor, .InvocationTargetException, .Method, .Modifier, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.exceptions.DescriptorException, .ValidationException, org.eclipse.persistence.internal.core.descriptors.CoreInstantiationPolicy, org.eclipse.persistence.internal.helper.Helper, org.eclipse.persistence.internal.security.PrivilegedAccessHelper, org.eclipse.persistence.internal.sessions.AbstractSession

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...

Field Summary

Modifier and TypeField and Description
private transient Constructor<T>
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.

Constructor Summary

AccessConstructor and Description
public
InstantiationPolicy()

Default constructor

Method Summary

Modifier and TypeMethod and Description
protected Constructor<T>
buildDefaultConstructor()

Build and return the default (zero-argument) constructor for the descriptor class.

protected Constructor<T>
buildDefaultConstructorFor(final Class<?> javaClass)

Build and return the default (zero-argument) constructor for the specified class.

protected Object
protected Constructor<T>
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.

public Object
buildNewInstance()

Implements abstract org.eclipse.persistence.internal.core.descriptors.CoreInstantiationPolicy.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.

public Object
clone()

Overrides java.lang.Object.clone.

INTERNAL: Clones the InstantiationPolicy
public void
convertClassNamesToClasses(final ClassLoader classLoader)

INTERNAL: Convert all the class-name-based settings in this InstantiationPolicy to actual class-based settings.

protected Constructor<T>
getDefaultConstructor()

Return the default (zero-argument) constructor for the descriptor class.

protected ClassDescriptor
public Object
public Class<?>
public String
public String
protected Method
public String
public void
initialize(AbstractSession session)

If necessary, initialize the factory and the method.

protected void
initializeMethod()

Initialize the method.

public boolean
isUsingDefaultConstructor()

If no method name is specified, they we have to use the default (zero-argument) constructor.

protected void
setDefaultConstructor(Constructor<T> defaultConstructor)

public void
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)

public void
setMethodName(String methodName)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public void
public void
useFactoryInstantiationPolicy(Class<?> factoryClass, String methodName)

public void
useFactoryInstantiationPolicy(Class<?> factoryClass, String methodName, String factoryMethodName)

public void
public void
useFactoryInstantiationPolicy(String factoryClassName, String methodName, String factoryMethodName)

public void
public void

Field Detail

defaultConstructorback to summary
private transient Constructor<T> defaultConstructor

Must be transient because java.lang.Constructor is not serializable.

descriptorback to summary
protected ClassDescriptor descriptor

Backpointer to descriptor.

factoryback 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.

factoryClassback 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.

factoryClassNameback to summary
protected String factoryClassName
factoryMethodNameback 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.

methodback to summary
protected transient Method method

The method is resolved during initialization, and it is not serialized.

methodNameback 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.

Constructor Detail

InstantiationPolicyback to summary
public InstantiationPolicy()

Default constructor

Method Detail

buildDefaultConstructorback to summary
protected Constructor<T> buildDefaultConstructor() throws DescriptorException

Build and return the default (zero-argument) constructor for the descriptor class.

buildDefaultConstructorForback to summary
protected Constructor<T> buildDefaultConstructorFor(final Class<?> javaClass) throws DescriptorException

Build and return the default (zero-argument) constructor for the specified class.

buildFactoryback to summary
protected Object buildFactory() throws DescriptorException
buildFactoryDefaultConstructorback to summary
protected Constructor<T> buildFactoryDefaultConstructor() throws DescriptorException

Build and return the default (zero-argument) constructor for the factory class.

buildFactoryUsingDefaultConstructorback to summary
protected Object buildFactoryUsingDefaultConstructor() throws DescriptorException

Build and return the factory, using its default constructor.

buildFactoryUsingStaticMethodback to summary
protected Object buildFactoryUsingStaticMethod() throws DescriptorException

Build and return the factory, using the specified static method.

buildMethodback to summary
protected Method buildMethod(Class<?> methodClass, String methodName, Class<?>[] methodParameterTypes) throws DescriptorException

Build the specified method.

buildNewInstanceback to summary
public Object buildNewInstance() throws DescriptorException

Implements abstract org.eclipse.persistence.internal.core.descriptors.CoreInstantiationPolicy.buildNewInstance.

Build and return a new instance, using the appropriate mechanism.

Annotations
@Override
buildNewInstanceUsingDefaultConstructorback to summary
protected Object buildNewInstanceUsingDefaultConstructor() throws DescriptorException

Build and return a new instance, using the default (zero-argument) constructor.

buildNewInstanceUsingFactoryback 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.

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

INTERNAL: Clones the InstantiationPolicy

Returns:Object

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@Override
convertClassNamesToClassesback 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.

getDefaultConstructorback to summary
protected Constructor<T> getDefaultConstructor() throws DescriptorException

Return the default (zero-argument) constructor for the descriptor class.

getDescriptorback to summary
protected ClassDescriptor getDescriptor()
getFactoryback to summary
public Object getFactory()
getFactoryClassback to summary
public Class<?> getFactoryClass()
getFactoryClassNameback to summary
public String getFactoryClassName()
getFactoryMethodNameback to summary
public String getFactoryMethodName()
getMethodback to summary
protected Method getMethod()
getMethodNameback to summary
public String getMethodName()
initializeback to summary
public void initialize(AbstractSession session) throws DescriptorException

If necessary, initialize the factory and the method.

initializeMethodback 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.

isUsingDefaultConstructorback to summary
public boolean isUsingDefaultConstructor()

If no method name is specified, they we have to use the default (zero-argument) constructor.

setDefaultConstructorback to summary
protected void setDefaultConstructor(Constructor<T> defaultConstructor)
setDescriptorback to summary
public void setDescriptor(ClassDescriptor descriptor)
setFactoryback to summary
protected void setFactory(Object factory)
setFactoryClassback to summary
protected void setFactoryClass(Class<?> factoryClass)
setFactoryClassNameback to summary
protected void setFactoryClassName(String factoryClassName)
setFactoryMethodNameback to summary
protected void setFactoryMethodName(String factoryMethodName)
setMethodback to summary
protected void setMethod(Method method)
setMethodNameback to summary
public void setMethodName(String methodName)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
useDefaultConstructorInstantiationPolicyback to summary
public void useDefaultConstructorInstantiationPolicy()
useFactoryInstantiationPolicyback to summary
public void useFactoryInstantiationPolicy(Class<?> factoryClass, String methodName)
useFactoryInstantiationPolicyback to summary
public void useFactoryInstantiationPolicy(Class<?> factoryClass, String methodName, String factoryMethodName)
useFactoryInstantiationPolicyback to summary
public void useFactoryInstantiationPolicy(String factoryClassName, String methodName)

Implements abstract org.eclipse.persistence.internal.core.descriptors.CoreInstantiationPolicy.useFactoryInstantiationPolicy.

Annotations
@Override
useFactoryInstantiationPolicyback to summary
public void useFactoryInstantiationPolicy(String factoryClassName, String methodName, String factoryMethodName)
useFactoryInstantiationPolicyback to summary
public void useFactoryInstantiationPolicy(Object factory, String methodName)
useMethodInstantiationPolicyback to summary
public void useMethodInstantiationPolicy(String staticMethodName)