Methods Summary |
---|
protected java.lang.reflect.Constructor | buildDefaultConstructor()Build and return the default (zero-argument) constructor for the descriptor class.
return this.buildDefaultConstructorFor(this.getDescriptor().getJavaClass());
|
protected java.lang.reflect.Constructor | buildDefaultConstructorFor(java.lang.Class javaClass)Build and return the default (zero-argument) constructor for the specified class.
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
try {
return (Constructor)AccessController.doPrivileged(new PrivilegedGetDeclaredConstructorFor(javaClass, new Class[0], true));
} catch (PrivilegedActionException exception) {
throw DescriptorException.noSuchMethodWhileInitializingInstantiationPolicy(javaClass.getName() + ".<Default Constructor>", getDescriptor(), exception.getException());
}
} else {
return PrivilegedAccessHelper.getDeclaredConstructorFor(javaClass, new Class[0], true);
}
} catch (NoSuchMethodException exception) {
throw DescriptorException.noSuchMethodWhileInitializingInstantiationPolicy(javaClass.getName() + ".<Default Constructor>", getDescriptor(), exception);
}
|
protected java.lang.Object | buildFactory()
// 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 java.lang.reflect.Constructor | buildFactoryDefaultConstructor()Build and return the default (zero-argument) constructor for the factory class.
return this.buildDefaultConstructorFor(this.getFactoryClass());
|
protected java.lang.Object | buildFactoryUsingDefaultConstructor()Build and return the factory, using its default constructor.
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
try {
return AccessController.doPrivileged(new PrivilegedInvokeConstructor(this.buildFactoryDefaultConstructor(), (Object[])null));
} catch (PrivilegedActionException exception) {
Exception throwableException = exception.getException();
if (throwableException instanceof InvocationTargetException){
throw DescriptorException.targetInvocationWhileConstructorInstantiationOfFactory(this.getDescriptor(), throwableException);
} else if (throwableException instanceof IllegalAccessException){
throw DescriptorException.illegalAccessWhileConstructorInstantiationOfFactory(this.getDescriptor(), throwableException);
} else {
throw DescriptorException.instantiationWhileConstructorInstantiationOfFactory(this.getDescriptor(), throwableException);
}
}
} else {
return PrivilegedAccessHelper.invokeConstructor(this.buildFactoryDefaultConstructor(), (Object[])null);
}
} catch (InvocationTargetException exception) {
throw DescriptorException.targetInvocationWhileConstructorInstantiationOfFactory(this.getDescriptor(), exception);
} catch (IllegalAccessException exception) {
throw DescriptorException.illegalAccessWhileConstructorInstantiationOfFactory(this.getDescriptor(), exception);
} catch (InstantiationException exception) {
throw DescriptorException.instantiationWhileConstructorInstantiationOfFactory(this.getDescriptor(), exception);
} catch (NoSuchMethodError exception) {
// This exception is not documented but gets thrown.
throw DescriptorException.noSuchMethodWhileConstructorInstantiationOfFactory(this.getDescriptor(), exception);
} catch (NullPointerException exception) {
// Some JVMs will throw a NULL pointer exception here
throw DescriptorException.nullPointerWhileConstructorInstantiationOfFactory(this.getDescriptor(), exception);
}
|
protected java.lang.Object | buildFactoryUsingStaticMethod()Build and return the factory, using the specified static method.
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 java.lang.reflect.Method | buildMethod(java.lang.Class methodClass, java.lang.String methodName, java.lang.Class[] methodParameterTypes)Build the specified method.
try {
return Helper.getDeclaredMethod(methodClass, methodName, methodParameterTypes);
} catch (NoSuchMethodException exception) {
throw DescriptorException.noSuchMethodWhileInitializingInstantiationPolicy(methodClass.getName() + "." + methodName, this.getDescriptor(), exception);
} catch (SecurityException exception) {
throw DescriptorException.securityWhileInitializingInstantiationPolicy(methodClass.getName() + "." + methodName, this.getDescriptor(), exception);
}
|
public java.lang.Object | buildNewInstance()Build and return a new instance, using the appropriate mechanism.
if (this.isUsingDefaultConstructor()) {
return this.buildNewInstanceUsingDefaultConstructor();
} else {
return this.buildNewInstanceUsingFactory();
}
|
protected java.lang.Object | buildNewInstanceUsingDefaultConstructor()Build and return a new instance, using the default (zero-argument) constructor.
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
try {
return AccessController.doPrivileged(new PrivilegedInvokeConstructor(this.getDefaultConstructor(), (Object[])null));
} catch (PrivilegedActionException exception) {
Exception throwableException = exception.getException();
if (throwableException instanceof InvocationTargetException){
throw DescriptorException.targetInvocationWhileConstructorInstantiationOfFactory(this.getDescriptor(), throwableException);
} else if (throwableException instanceof IllegalAccessException){
throw DescriptorException.illegalAccessWhileConstructorInstantiationOfFactory(this.getDescriptor(), throwableException);
} else {
throw DescriptorException.instantiationWhileConstructorInstantiationOfFactory(this.getDescriptor(), throwableException);
}
}
} else {
return PrivilegedAccessHelper.invokeConstructor(this.getDefaultConstructor(), (Object[])null);
}
} catch (InvocationTargetException exception) {
throw DescriptorException.targetInvocationWhileConstructorInstantiation(this.getDescriptor(), exception);
} catch (IllegalAccessException exception) {
throw DescriptorException.illegalAccessWhileConstructorInstantiation(this.getDescriptor(), exception);
} catch (InstantiationException exception) {
throw DescriptorException.instantiationWhileConstructorInstantiation(this.getDescriptor(), exception);
} catch (NoSuchMethodError exception) {
// This exception is not documented but gets thrown.
throw DescriptorException.noSuchMethodWhileConstructorInstantiation(this.getDescriptor(), exception);
} catch (NullPointerException exception) {
// Some JVMs will throw a NULL pointer exception here
throw DescriptorException.nullPointerWhileConstructorInstantiation(this.getDescriptor(), exception);
}
|
protected java.lang.Object | buildNewInstanceUsingFactory()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.
try {
// If the method is static, the first argument is ignored and can be null
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
try {
return AccessController.doPrivileged(new PrivilegedMethodInvoker(this.getMethod(), this.getFactory(), new Object[0]));
} catch (PrivilegedActionException exception) {
Exception throwableException = exception.getException();
if (throwableException instanceof IllegalAccessException) {
throw DescriptorException.illegalAccessWhileMethodInstantiation(this.getMethod().toString(), this.getDescriptor(), throwableException);
} else {
throw DescriptorException.targetInvocationWhileMethodInstantiation(this.getMethod().toString(), this.getDescriptor(), throwableException);
}
}
} else {
return PrivilegedAccessHelper.invokeMethod(this.getMethod(), this.getFactory(), new Object[0]);
}
} catch (IllegalAccessException exception) {
throw DescriptorException.illegalAccessWhileMethodInstantiation(this.getMethod().toString(), this.getDescriptor(), exception);
} catch (InvocationTargetException exception) {
throw DescriptorException.targetInvocationWhileMethodInstantiation(this.getMethod().toString(), this.getDescriptor(), exception);
} catch (NullPointerException exception) {
// Some JVMs will throw a NULL pointer exception here
throw DescriptorException.nullPointerWhileMethodInstantiation(this.getMethod().toString(), this.getDescriptor(), exception);
}
|
public java.lang.Object | clone()INTERNAL:
Clones the InstantiationPolicy
try {
// clones itself
return super.clone();
} catch (Exception exception) {
;
}
return null;
|
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.
if (factoryClassName == null){
return;
}
Class factoryClass = null;
try{
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
try {
factoryClass = (Class)AccessController.doPrivileged(new PrivilegedClassForName(factoryClassName, true, classLoader));
} catch (PrivilegedActionException exception) {
throw ValidationException.classNotFoundWhileConvertingClassNames(factoryClassName, exception.getException());
}
} else {
factoryClass = oracle.toplink.essentials.internal.security.PrivilegedAccessHelper.getClassForName(factoryClassName, true, classLoader);
}
} catch (ClassNotFoundException exc){
throw ValidationException.classNotFoundWhileConvertingClassNames(factoryClassName, exc);
}
setFactoryClass(factoryClass);
|
protected java.lang.reflect.Constructor | getDefaultConstructor()Return the default (zero-argument) constructor for the descriptor class.
// Lazy initialize, because the constructor cannot be serialized
if (defaultConstructor == null) {
this.setDefaultConstructor(this.buildDefaultConstructor());
}
return defaultConstructor;
|
protected oracle.toplink.essentials.descriptors.ClassDescriptor | getDescriptor()
return descriptor;
|
public java.lang.Object | getFactory()
return factory;
|
public java.lang.Class | getFactoryClass()
return factoryClass;
|
public java.lang.String | getFactoryClassName()
if ((factoryClassName == null) && (factoryClass != null)) {
factoryClassName = factoryClass.getName();
}
return factoryClassName;
|
public java.lang.String | getFactoryMethodName()
return factoryMethodName;
|
protected java.lang.reflect.Method | getMethod()
return method;
|
public java.lang.String | getMethodName()
return methodName;
|
public void | initialize(oracle.toplink.essentials.internal.sessions.AbstractSession session)If necessary, initialize the factory and the method.
if (this.isUsingDefaultConstructor()) {
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);
}
|
protected void | initializeMethod()Initialize the method.
It is either a static on the descriptor class, or it is a non-static on the factory.
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]));
|
public boolean | isUsingDefaultConstructor()If no method name is specified, they we have to use the default (zero-argument) constructor.
return this.getMethodName() == null;
|
protected void | setDefaultConstructor(java.lang.reflect.Constructor defaultConstructor)
this.defaultConstructor = defaultConstructor;
|
public void | setDescriptor(oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
this.descriptor = descriptor;
|
protected void | setFactory(java.lang.Object factory)
this.factory = factory;
|
protected void | setFactoryClass(java.lang.Class factoryClass)
this.factoryClass = factoryClass;
|
protected void | setFactoryClassName(java.lang.String factoryClassName)
this.factoryClassName = factoryClassName;
|
protected void | setFactoryMethodName(java.lang.String factoryMethodName)
this.factoryMethodName = factoryMethodName;
|
protected void | setMethod(java.lang.reflect.Method method)
this.method = method;
|
public void | setMethodName(java.lang.String methodName)
this.methodName = methodName;
|
public java.lang.String | toString()
String mName = null;
if (this.isUsingDefaultConstructor()) {
mName = "<CONSTRUCTOR>";
} else {
mName = this.getMethodName();
}
return Helper.getShortClassName(this) + "(" + mName + ")";
|
public void | useDefaultConstructorInstantiationPolicy()
setMethodName(null);
setFactory(null);
setFactoryClass(null);
setFactoryClassName(null);
setFactoryMethodName(null);
|
public void | useFactoryInstantiationPolicy(java.lang.Class factoryClass, java.lang.String methodName)
setMethodName(methodName);
setFactory(null);
setFactoryClass(factoryClass);
setFactoryClassName(factoryClass.getName());
setFactoryMethodName(null);
|
public void | useFactoryInstantiationPolicy(java.lang.Class factoryClass, java.lang.String methodName, java.lang.String factoryMethodName)
setMethodName(methodName);
setFactory(null);
setFactoryClass(factoryClass);
setFactoryClassName(factoryClass.getName());
setFactoryMethodName(factoryMethodName);
|
public void | useFactoryInstantiationPolicy(java.lang.String factoryClassName, java.lang.String methodName)
setMethodName(methodName);
setFactory(null);
setFactoryClass(null);
setFactoryClassName(factoryClassName);
setFactoryMethodName(null);
|
public void | useFactoryInstantiationPolicy(java.lang.String factoryClassName, java.lang.String methodName, java.lang.String factoryMethodName)
setMethodName(methodName);
setFactory(null);
setFactoryClass(null);
setFactoryClassName(factoryClassName);
setFactoryMethodName(factoryMethodName);
|
public void | useFactoryInstantiationPolicy(java.lang.Object factory, java.lang.String methodName)
setMethodName(methodName);
setFactory(factory);
setFactoryClass(null);
setFactoryClassName(null);
setFactoryMethodName(null);
|
public void | useMethodInstantiationPolicy(java.lang.String staticMethodName)
setMethodName(staticMethodName);
setFactory(null);
setFactoryClass(null);
setFactoryClassName(null);
setFactoryMethodName(null);
|