OPENJPA-311

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@564688 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2007-08-10 17:33:08 +00:00
parent 8ba0483bf7
commit 99ecf9564b
1 changed files with 21 additions and 6 deletions

View File

@ -50,12 +50,9 @@ public class GeneratedClasses {
if (l2 == null)
return l1;
for (ClassLoader p = (ClassLoader) AccessController.doPrivileged(
J2DoPrivHelper.getParentAction(l1)); p != null;
p = (ClassLoader) AccessController.doPrivileged(
J2DoPrivHelper.getParentAction(p)))
if (p == l2)
if(canLoad(l1, c2)) {
return l1;
}
return l2;
}
@ -74,4 +71,22 @@ public class GeneratedClasses {
throw new GeneralException(bc.getName()).setCause(t);
}
}
/**
* Return true if the given loader will load the same version of a given
* class.
*
* @param loader Classloader to use.
* @param clazz Expected class.
* @return true if loader.load(clazz.getName()) == clazz. Otherwise false.
*/
private static boolean canLoad(ClassLoader loader, Class clazz) {
Class loaded = null;
try {
loaded = loader.loadClass(clazz.getName());
} catch (ClassNotFoundException e) {
// Rely on caller to handle return value = false.
}
return clazz == loaded;
}
}