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(); }
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(); }
/** * 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); } }
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(); }
/** * 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); } }
/** * 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); } }
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() + "\");");
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() + "\");");
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() + "\");");