/** * INTERNAL: * Returns the instantiation policy. */ @Override public InstantiationPolicy getInstantiationPolicy() { // Lazy initialize for XML deployment. if (instantiationPolicy == null) { setInstantiationPolicy(new InstantiationPolicy()); } return instantiationPolicy; }
/** * Return a new instance of the receiver's javaClass. */ public Object buildNewInstance() { return this.descriptor.getInstantiationPolicy().buildNewInstance(); }
/** * Initialize the method. * It is either a static on the descriptor class, or it is a non-static on the factory. */ protected void initializeMethod() throws DescriptorException { Class tempClass; if (this.getFactory() != null) { tempClass = this.getFactory().getClass(); } else if (this.getFactoryClass() == null) { tempClass = this.getDescriptor().getJavaClass(); } else { tempClass = this.getFactoryClass(); } this.setMethod(this.buildMethod(tempClass, this.getMethodName(), new Class[0])); }
/** * Build and return the default (zero-argument) constructor for the factory class. */ protected Constructor buildFactoryDefaultConstructor() throws DescriptorException { return this.buildDefaultConstructorFor(this.getFactoryClass()); }
/** * Return the default (zero-argument) constructor for the descriptor class. */ protected Constructor getDefaultConstructor() throws DescriptorException { // Lazy initialize, because the constructor cannot be serialized if (defaultConstructor == null) { this.setDefaultConstructor(this.buildDefaultConstructor()); } return defaultConstructor; }
protected Object buildFactory() throws DescriptorException { // If there is no factory class specified, there is no factory; // we will be using a static method defined by the descriptor class... if (this.getFactoryClass() == null) { return null; } // If there is a factory class specified but no factory method name, // instantiate the factory using the default constructor if (this.getFactoryMethodName() == null) { return this.buildFactoryUsingDefaultConstructor(); } // If both the factory class and the factory method name have been specified, // instantiate the factory by invoking the static factory method return this.buildFactoryUsingStaticMethod(); }
/** * If necessary, initialize the factory and the method. */ public void initialize(AbstractSession session) throws DescriptorException { if (this.isUsingDefaultConstructor()) { // May not have a constructor as may be abstract or interface so only lazy init. return; } try { // If the factory has been specified directly, do not overwrite it if (this.getFactory() == null) { this.setFactory(this.buildFactory()); } this.initializeMethod(); } catch (DescriptorException ex) { session.getIntegrityChecker().handleError(ex); } }
if (!descriptor.getInstantiationPolicy().isUsingDefaultConstructor()) { if (descriptor.getInstantiationPolicy().getFactoryClassName() != null) { if (descriptor.getInstantiationPolicy().getFactoryMethodName() != null) { method.addLine("descriptor.useFactoryInstantiationPolicy(" + descriptor.getInstantiationPolicy().getFactoryClassName() + ".class, \"" + descriptor.getInstantiationPolicy().getMethodName() + "\", \"" + descriptor.getInstantiationPolicy().getFactoryMethodName() + "\");"); } else { method.addLine("descriptor.useFactoryInstantiationPolicy(" + descriptor.getInstantiationPolicy().getFactoryClassName() + ".class, \"" + descriptor.getInstantiationPolicy().getMethodName() + "\");"); method.addLine("descriptor.useMethodInstantiationPolicy(\"" + descriptor.getInstantiationPolicy().getMethodName() + "\");");
/** * Build and return the factory, using the specified static method. */ protected Object buildFactoryUsingStaticMethod() throws DescriptorException { Method factoryMethod = this.buildMethod(this.getFactoryClass(), this.getFactoryMethodName(), new Class[0]); try { // it should be static and zero-argument... if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { return AccessController.doPrivileged(new PrivilegedMethodInvoker(factoryMethod, null, null)); } catch (PrivilegedActionException exception) { Exception throwableException = exception.getException(); if (throwableException instanceof IllegalAccessException) { throw DescriptorException.illegalAccessWhileMethodInstantiationOfFactory(getFactoryMethodName(), getDescriptor(), throwableException); } else { throw DescriptorException.targetInvocationWhileMethodInstantiationOfFactory(getFactoryMethodName(), getDescriptor(), throwableException); } } } else { return PrivilegedAccessHelper.invokeMethod(factoryMethod, null, null); } } catch (IllegalAccessException exception) { throw DescriptorException.illegalAccessWhileMethodInstantiationOfFactory(getFactoryMethodName(), getDescriptor(), exception); } catch (InvocationTargetException exception) { throw DescriptorException.targetInvocationWhileMethodInstantiationOfFactory(getFactoryMethodName(), getDescriptor(), exception); } catch (NullPointerException exception) { // Some JVMs will throw a NULL pointer exception here throw DescriptorException.nullPointerWhileMethodInstantiationOfFactory(getFactoryMethodName(), getDescriptor(), exception); } }
this.factoryClassName = defaultInstantiationPolicy.getFactoryClassName(); this.factoryClass = defaultInstantiationPolicy.getFactoryClass(); this.methodName = defaultInstantiationPolicy.getMethodName();
/** * INTERNAL: * Set the factory class name, used by the MW. */ public void useFactoryInstantiationPolicy(String factoryClassName, String methodName) { getInstantiationPolicy().useFactoryInstantiationPolicy(factoryClassName, methodName); }
isAbstract = Modifier.isAbstract(subClassToInstantiate.getModifiers()); if (!isAbstract) { InstantiationPolicy instantiationPolicy = new InstantiationPolicy(); instantiationPolicy.useFactoryInstantiationPolicy(new ConcreteSubclassFactory(subClassToInstantiate), "createConcreteSubclass"); descriptor.setInstantiationPolicy(instantiationPolicy); break;
public String toString() { String mName = null; if (this.isUsingDefaultConstructor()) { mName = "<CONSTRUCTOR>"; } else { mName = this.getMethodName(); } return Helper.getShortClassName(this) + "(" + mName + ")"; }
/** * Build and return the default (zero-argument) constructor for the descriptor class. */ protected Constructor buildDefaultConstructor() throws DescriptorException { return this.buildDefaultConstructorFor(this.getDescriptor().getJavaClass()); }
@Override public void convertClassNamesToClasses(ClassLoader loader) { super.convertClassNamesToClasses(loader); if(parameterTypes == null) { if(parameterTypeNames != null) { Class[] values = new Class[parameterTypeNames.length]; for(int i = 0; i < values.length; i++) { try{ if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { values[i] = AccessController.doPrivileged(new PrivilegedClassForName(parameterTypeNames[i], true, loader)); } catch (PrivilegedActionException exception) { throw ValidationException.classNotFoundWhileConvertingClassNames(parameterTypeNames[i], exception.getException()); } } else { values[i] = org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(parameterTypeNames[i], true, loader); } } catch (ClassNotFoundException exc){ throw ValidationException.classNotFoundWhileConvertingClassNames(factoryClassName, exc); } } this.parameterTypes = values; } } } protected void initializeMethod() throws DescriptorException {
/** * If no method name is specified, they we have to use the default (zero-argument) constructor. */ public boolean isUsingDefaultConstructor() { return this.getMethodName() == null; }
/** * Initialize the method. * It is either a static on the descriptor class, or it is a non-static on the factory. */ protected void initializeMethod() throws DescriptorException { Class tempClass; if (this.getFactory() == null) { tempClass = this.getDescriptor().getJavaClass(); } else { tempClass = this.getFactory().getClass(); } this.setMethod(this.buildMethod(tempClass, this.getMethodName(), new Class[0])); }
/** * If necessary, initialize the factory and the method. */ public void initialize(AbstractSession session) throws DescriptorException { if (this.isUsingDefaultConstructor()) { // May not have a constructor as may be abstract or interface so only lazy init. return; } try { this.initializeMethod(); if (!(Modifier.isStatic(getMethod().getModifiers()))) { // If the factory has been specified directly, do not overwrite it if (this.getFactory() == null) { this.setFactory(this.buildFactory()); } } } catch (DescriptorException ex) { session.getIntegrityChecker().handleError(ex); } }
if (!descriptor.getInstantiationPolicy().isUsingDefaultConstructor()) { if (descriptor.getInstantiationPolicy().getFactoryClassName() != null) { if (descriptor.getInstantiationPolicy().getFactoryMethodName() != null) { method.addLine("descriptor.useFactoryInstantiationPolicy(" + descriptor.getInstantiationPolicy().getFactoryClassName() + ".class, \"" + descriptor.getInstantiationPolicy().getMethodName() + "\", \"" + descriptor.getInstantiationPolicy().getFactoryMethodName() + "\");"); } else { method.addLine("descriptor.useFactoryInstantiationPolicy(" + descriptor.getInstantiationPolicy().getFactoryClassName() + ".class, \"" + descriptor.getInstantiationPolicy().getMethodName() + "\");"); method.addLine("descriptor.useMethodInstantiationPolicy(\"" + descriptor.getInstantiationPolicy().getMethodName() + "\");");
protected Object buildFactory() throws DescriptorException { // If there is no factory class specified, there is no factory; // we will be using a static method defined by the descriptor class... if (this.getFactoryClass() == null) { return null; } // If there is a factory class specified but no factory method name, // instantiate the factory using the default constructor if (this.getFactoryMethodName() == null) { return this.buildFactoryUsingDefaultConstructor(); } // If both the factory class and the factory method name have been specified, // instantiate the factory by invoking the static factory method return this.buildFactoryUsingStaticMethod(); }