OPENJPA-2133: Fix to allow custom mappings to be found by an applicable class loader.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1332313 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Heath Thomann 2012-04-30 17:44:20 +00:00
parent d5a324f802
commit 7642e7e249
2 changed files with 16 additions and 4 deletions

View File

@ -546,7 +546,7 @@ public class MappingRepository extends MetaDataRepository {
strat = JavaTypes.classForName(name, cls, strat = JavaTypes.classForName(name, cls,
AccessController.doPrivileged( AccessController.doPrivileged(
J2DoPrivHelper.getClassLoaderAction( J2DoPrivHelper.getClassLoaderAction(
ClassStrategy.class))); ClassStrategy.class)),false);
ClassStrategy strategy = ClassStrategy strategy =
(ClassStrategy) AccessController.doPrivileged( (ClassStrategy) AccessController.doPrivileged(
J2DoPrivHelper.newInstanceAction(strat)); J2DoPrivHelper.newInstanceAction(strat));
@ -579,7 +579,7 @@ public class MappingRepository extends MetaDataRepository {
try { try {
Class<?> c = JavaTypes.classForName(name, field, Class<?> c = JavaTypes.classForName(name, field,
AccessController.doPrivileged( AccessController.doPrivileged(
J2DoPrivHelper.getClassLoaderAction(FieldStrategy.class))); J2DoPrivHelper.getClassLoaderAction(FieldStrategy.class)),false);
if (FieldStrategy.class.isAssignableFrom(c)) { if (FieldStrategy.class.isAssignableFrom(c)) {
FieldStrategy strat = (FieldStrategy) FieldStrategy strat = (FieldStrategy)
AccessController.doPrivileged( AccessController.doPrivileged(
@ -653,7 +653,7 @@ public class MappingRepository extends MetaDataRepository {
discrim.getClassMapping(), discrim.getClassMapping(),
AccessController.doPrivileged( AccessController.doPrivileged(
J2DoPrivHelper.getClassLoaderAction( J2DoPrivHelper.getClassLoaderAction(
DiscriminatorStrategy.class))); DiscriminatorStrategy.class)),false);
DiscriminatorStrategy strategy = (DiscriminatorStrategy) DiscriminatorStrategy strategy = (DiscriminatorStrategy)
AccessController.doPrivileged( AccessController.doPrivileged(
J2DoPrivHelper.newInstanceAction(strat)); J2DoPrivHelper.newInstanceAction(strat));
@ -719,7 +719,7 @@ public class MappingRepository extends MetaDataRepository {
version.getClassMapping(), version.getClassMapping(),
AccessController.doPrivileged( AccessController.doPrivileged(
J2DoPrivHelper.getClassLoaderAction( J2DoPrivHelper.getClassLoaderAction(
VersionStrategy.class))); VersionStrategy.class)),false);
} catch (Exception e) { } catch (Exception e) {
throw new MetaDataException(_loc.get("bad-version-strategy", throw new MetaDataException(_loc.get("bad-version-strategy",
version.getClassMapping(), name), e); version.getClassMapping(), name), e);

View File

@ -187,6 +187,18 @@ public class JavaTypes {
loader); loader);
} }
/**
* Check the given name against the same set of standard packages used
* when parsing metadata.
*
* @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, ClassMetaData context, ClassLoader loader, boolean mustExist) {
return classForName(name, context, context.getDescribedType(), null,
loader, mustExist);
}
/** /**
* 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.