mirror of https://github.com/apache/openjpa.git
OPENJPA-758: Added code to check the ClassResolver to get a class loader when attempting to load a ValueHandler or FieldStrategy.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1155394 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
529827b0fb
commit
3598a2d8eb
|
@ -1228,7 +1228,7 @@ public class MappingRepository extends MetaDataRepository {
|
||||||
try {
|
try {
|
||||||
Class<?> c = JavaTypes.classForName(name, val,
|
Class<?> c = JavaTypes.classForName(name, val,
|
||||||
AccessController.doPrivileged(
|
AccessController.doPrivileged(
|
||||||
J2DoPrivHelper.getClassLoaderAction(FieldStrategy.class)));
|
J2DoPrivHelper.getClassLoaderAction(FieldStrategy.class)),false);
|
||||||
Object o = AccessController.doPrivileged(
|
Object o = AccessController.doPrivileged(
|
||||||
J2DoPrivHelper.newInstanceAction(c));
|
J2DoPrivHelper.newInstanceAction(c));
|
||||||
Configurations.configureInstance(o, getConfiguration(), props);
|
Configurations.configureInstance(o, getConfiguration(), props);
|
||||||
|
@ -1255,7 +1255,7 @@ public class MappingRepository extends MetaDataRepository {
|
||||||
try {
|
try {
|
||||||
Class<?> c = JavaTypes.classForName(name, val,
|
Class<?> c = JavaTypes.classForName(name, val,
|
||||||
AccessController.doPrivileged(
|
AccessController.doPrivileged(
|
||||||
J2DoPrivHelper.getClassLoaderAction(ValueHandler.class)));
|
J2DoPrivHelper.getClassLoaderAction(ValueHandler.class)),false);
|
||||||
if (ValueHandler.class.isAssignableFrom(c)) {
|
if (ValueHandler.class.isAssignableFrom(c)) {
|
||||||
ValueHandler vh = (ValueHandler) AccessController.doPrivileged(
|
ValueHandler vh = (ValueHandler) AccessController.doPrivileged(
|
||||||
J2DoPrivHelper.newInstanceAction(c));
|
J2DoPrivHelper.newInstanceAction(c));
|
||||||
|
|
|
@ -205,12 +205,38 @@ public class JavaTypes {
|
||||||
context.getFieldMetaData().getDeclaringType(), context, loader);
|
context.getFieldMetaData().getDeclaringType(), context, loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to load a class using the provided loader. Optionally tries the
|
||||||
|
* configuration's ClassResolver if the supplied loader cannot find the class.
|
||||||
|
*
|
||||||
|
* @param name Name of the class to load.
|
||||||
|
* @param context
|
||||||
|
* @param loader ClassLoader to use. If null, the configuration's ClassResolver will be used.
|
||||||
|
* @param mustExist Whether the supplied loader <b>must</b> be able to load the class. If true no attempt to use a
|
||||||
|
* different classloader will be made. If false the ClassResolver from the configuration will be used.
|
||||||
|
*/
|
||||||
|
public static Class<?> classForName(String name, ValueMetaData context,
|
||||||
|
ClassLoader loader, boolean mustExist) {
|
||||||
|
return classForName(name,
|
||||||
|
context.getFieldMetaData().getDefiningMetaData(),
|
||||||
|
context.getFieldMetaData().getDeclaringType(), context, loader, mustExist);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OJ-758: Delegates to the final classForName. This is needed
|
||||||
|
* to maintain the existing code path prior to OJ-758.
|
||||||
|
*/
|
||||||
|
private static Class<?> classForName(String name, ClassMetaData meta,
|
||||||
|
Class<?> dec, ValueMetaData vmd, ClassLoader loader) {
|
||||||
|
return classForName(name, meta, dec, vmd, loader, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the given name against the same set of standard packages used
|
* Check the given name against the same set of standard packages used
|
||||||
* when parsing metadata.
|
* when parsing metadata.
|
||||||
*/
|
*/
|
||||||
private static Class<?> classForName(String name, ClassMetaData meta, Class<?> dec, ValueMetaData vmd,
|
private static Class<?> classForName(String name, ClassMetaData meta, Class<?> dec, ValueMetaData vmd,
|
||||||
ClassLoader loader) {
|
ClassLoader loader, boolean mustExist) {
|
||||||
// special case for PersistenceCapable and Object
|
// special case for PersistenceCapable and Object
|
||||||
if ("PersistenceCapable".equals(name)
|
if ("PersistenceCapable".equals(name)
|
||||||
|| "javax.jdo.PersistenceCapable".equals(name)) // backwards compatibility
|
|| "javax.jdo.PersistenceCapable".equals(name)) // backwards compatibility
|
||||||
|
@ -232,9 +258,21 @@ public class JavaTypes {
|
||||||
pkg = Strings.getPackageName(vmd.getDeclaredType());
|
pkg = Strings.getPackageName(vmd.getDeclaredType());
|
||||||
cls = CFMetaDataParser.classForName(name, pkg, runtime, loader);
|
cls = CFMetaDataParser.classForName(name, pkg, runtime, loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//OJ-758 start: If the class is still null, as a last/final attempt to
|
||||||
|
//load the class, check with the ClassResolver to get a loader
|
||||||
|
//and use it to attempt to load the class.
|
||||||
|
if (cls == null && !mustExist){
|
||||||
|
loader = rep.getConfiguration().getClassResolverInstance().
|
||||||
|
getClassLoader(dec, meta.getEnvClassLoader());
|
||||||
|
cls = CFMetaDataParser.classForName(name, pkg, runtime, loader);
|
||||||
|
}
|
||||||
|
//OJ-758 end
|
||||||
|
|
||||||
if (cls == null)
|
if (cls == null)
|
||||||
throw new MetaDataException(_loc.get("bad-class", name,
|
throw new MetaDataException(_loc.get("bad-class", name,
|
||||||
(vmd == null) ? (Object) meta : (Object) vmd));
|
(vmd == null) ? (Object) meta : (Object) vmd));
|
||||||
|
|
||||||
return cls;
|
return cls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue