java.lang.Object
org.eclipse.persistence.internal.core.descriptors.CoreInstantiationPolicy
org.eclipse.persistence.internal.descriptors.InstantiationPolicy
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
MultiArgInstantiationPolicy, PersistenceObjectInstantiationPolicy, SDOType.TypeInstantiationPolicy

public class InstantiationPolicy extends CoreInstantiationPolicy implements Cloneable, 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:
  • Field Details

    • methodName

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

      protected transient Method method
      The method is resolved during initialization, and it is not serialized.
    • factoryClass

      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

      protected String factoryClassName
    • factoryMethodName

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

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

      protected ClassDescriptor descriptor
      Backpointer to descriptor.
  • Constructor Details

    • InstantiationPolicy

      public InstantiationPolicy()
      Default constructor
  • Method Details

    • buildNewInstance

      public Object buildNewInstance() throws DescriptorException
      Build and return a new instance, using the appropriate mechanism.
      Specified by:
      buildNewInstance in class CoreInstantiationPolicy
      Throws:
      DescriptorException
    • buildNewInstanceUsingDefaultConstructor

      protected Object buildNewInstanceUsingDefaultConstructor() throws DescriptorException
      Build and return a new instance, using the default (zero-argument) constructor.
      Throws:
      DescriptorException
    • buildNewInstanceUsingFactory

      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.
      Throws:
      DescriptorException
    • clone

      public Object clone()
      INTERNAL: Clones the InstantiationPolicy
      Overrides:
      clone in class Object
    • getDefaultConstructor

      protected Constructor getDefaultConstructor() throws DescriptorException
      Return the default (zero-argument) constructor for the descriptor class.
      Throws:
      DescriptorException
    • buildDefaultConstructor

      protected Constructor buildDefaultConstructor() throws DescriptorException
      Build and return the default (zero-argument) constructor for the descriptor class.
      Throws:
      DescriptorException
    • buildDefaultConstructorFor

      protected Constructor buildDefaultConstructorFor(Class<?> javaClass) throws DescriptorException
      Build and return the default (zero-argument) constructor for the specified class.
      Throws:
      DescriptorException
    • getDescriptor

      protected ClassDescriptor getDescriptor()
    • getFactoryMethodName

      public String getFactoryMethodName()
    • getFactory

      public Object getFactory()
    • getFactoryClass

      public Class<?> getFactoryClass()
    • getFactoryClassName

      public String getFactoryClassName()
    • getMethod

      protected Method getMethod()
    • getMethodName

      public String getMethodName()
    • initialize

      public void initialize(AbstractSession session) throws DescriptorException
      If necessary, initialize the factory and the method.
      Throws:
      DescriptorException
    • buildFactory

      protected Object buildFactory() throws DescriptorException
      Throws:
      DescriptorException
    • buildFactoryUsingDefaultConstructor

      protected Object buildFactoryUsingDefaultConstructor() throws DescriptorException
      Build and return the factory, using its default constructor.
      Throws:
      DescriptorException
    • buildFactoryDefaultConstructor

      protected Constructor buildFactoryDefaultConstructor() throws DescriptorException
      Build and return the default (zero-argument) constructor for the factory class.
      Throws:
      DescriptorException
    • buildFactoryUsingStaticMethod

      protected Object buildFactoryUsingStaticMethod() throws DescriptorException
      Build and return the factory, using the specified static method.
      Throws:
      DescriptorException
    • initializeMethod

      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.
      Throws:
      DescriptorException
    • buildMethod

      protected Method buildMethod(Class<?> methodClass, String methodName, Class<?>[] methodParameterTypes) throws DescriptorException
      Build 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(Constructor defaultConstructor)
    • setDescriptor

      public void setDescriptor(ClassDescriptor descriptor)
    • setFactoryMethodName

      protected void setFactoryMethodName(String factoryMethodName)
    • setFactory

      protected void setFactory(Object factory)
    • setFactoryClass

      protected void setFactoryClass(Class<?> factoryClass)
    • setFactoryClassName

      protected void setFactoryClassName(String factoryClassName)
    • setMethod

      protected void setMethod(Method method)
    • setMethodName

      public void setMethodName(String methodName)
    • convertClassNamesToClasses

      public void convertClassNamesToClasses(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.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • useDefaultConstructorInstantiationPolicy

      public void useDefaultConstructorInstantiationPolicy()
    • useFactoryInstantiationPolicy

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

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

      public void useFactoryInstantiationPolicy(String factoryClassName, String methodName)
      Specified by:
      useFactoryInstantiationPolicy in class CoreInstantiationPolicy
    • useFactoryInstantiationPolicy

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

      public void useFactoryInstantiationPolicy(Object factory, String methodName)
    • useMethodInstantiationPolicy

      public void useMethodInstantiationPolicy(String staticMethodName)