mirror of https://github.com/apache/openjpa.git
Classloader used to generate dynamic implementaion of managed interface uses interfaces' classloader as parent
git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@502326 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
862cd158ed
commit
a11158d51a
|
@ -48,11 +48,9 @@ class InterfaceImplGenerator {
|
||||||
private final MetaDataRepository _repos;
|
private final MetaDataRepository _repos;
|
||||||
private final Map _impls = new WeakHashMap();
|
private final Map _impls = new WeakHashMap();
|
||||||
private final Project _project = new Project();
|
private final Project _project = new Project();
|
||||||
private final BCClassLoader _loader = new BCClassLoader(_project);
|
|
||||||
|
|
||||||
// distinct project / loader for enhanced version of class
|
// distinct project / loader for enhanced version of class
|
||||||
private final Project _enhProject = new Project();
|
private final Project _enhProject = new Project();
|
||||||
private final BCClassLoader _enhLoader = new BCClassLoader(_enhProject);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor. Supply repository.
|
* Constructor. Supply repository.
|
||||||
|
@ -73,6 +71,8 @@ class InterfaceImplGenerator {
|
||||||
if (impl != null)
|
if (impl != null)
|
||||||
return impl;
|
return impl;
|
||||||
|
|
||||||
|
ClassLoader parentLoader = iface.getClassLoader();
|
||||||
|
BCClassLoader loader = new BCClassLoader(_project, parentLoader);
|
||||||
BCClass bc = _project.loadClass(getClassName(meta));
|
BCClass bc = _project.loadClass(getClassName(meta));
|
||||||
bc.declareInterface(iface);
|
bc.declareInterface(iface);
|
||||||
ClassMetaData sup = meta.getPCSuperclassMetaData();
|
ClassMetaData sup = meta.getPCSuperclassMetaData();
|
||||||
|
@ -88,14 +88,14 @@ class InterfaceImplGenerator {
|
||||||
// first load the base class as the enhancer requires the class
|
// first load the base class as the enhancer requires the class
|
||||||
// to be available
|
// to be available
|
||||||
try {
|
try {
|
||||||
meta.setInterfaceImpl(Class.forName(bc.getName(), true, _loader));
|
meta.setInterfaceImpl(Class.forName(bc.getName(), true, loader));
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
throw new InternalException(_loc.get("interface-load"), t).
|
throw new InternalException(_loc.get("interface-load", iface,
|
||||||
setFatal(true);
|
loader), t).setFatal(true);
|
||||||
}
|
}
|
||||||
// copy the BCClass into the enhancer project.
|
// copy the BCClass into the enhancer project.
|
||||||
bc = _enhProject.loadClass(new ByteArrayInputStream(bc.toByteArray()),
|
bc = _enhProject.loadClass(new ByteArrayInputStream(bc.toByteArray()),
|
||||||
_loader);
|
loader);
|
||||||
PCEnhancer enhancer = new PCEnhancer(_repos.getConfiguration(), bc,
|
PCEnhancer enhancer = new PCEnhancer(_repos.getConfiguration(), bc,
|
||||||
meta);
|
meta);
|
||||||
|
|
||||||
|
@ -103,12 +103,13 @@ class InterfaceImplGenerator {
|
||||||
if (result != PCEnhancer.ENHANCE_PC)
|
if (result != PCEnhancer.ENHANCE_PC)
|
||||||
throw new InternalException(_loc.get("interface-badenhance",
|
throw new InternalException(_loc.get("interface-badenhance",
|
||||||
iface)).setFatal(true);
|
iface)).setFatal(true);
|
||||||
|
BCClassLoader enhLoader = new BCClassLoader(_enhProject, parentLoader);
|
||||||
try{
|
try{
|
||||||
// load the class for real.
|
// load the class for real.
|
||||||
impl = Class.forName(bc.getName(), true, _enhLoader);
|
impl = Class.forName(bc.getName(), true, enhLoader);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
throw new InternalException(_loc.get("interface-load2"), t).
|
throw new InternalException(_loc.get("interface-load2", iface,
|
||||||
setFatal(true);
|
enhLoader), t).setFatal(true);
|
||||||
}
|
}
|
||||||
// cache the generated impl.
|
// cache the generated impl.
|
||||||
_impls.put(iface, impl);
|
_impls.put(iface, impl);
|
||||||
|
|
|
@ -294,3 +294,8 @@ scanning-zip-stream-url: Scanning jar in stream from URL "{0}" for persistent \
|
||||||
scanning-resource: Scanning resource "{0}" for persistent types.
|
scanning-resource: Scanning resource "{0}" for persistent types.
|
||||||
scan-found-names: Scan of "{1}" found persistent types {0}.
|
scan-found-names: Scan of "{1}" found persistent types {0}.
|
||||||
parse-found-names: parsePersistentTypeNames() found {0}.
|
parse-found-names: parsePersistentTypeNames() found {0}.
|
||||||
|
interface-load: Dynamic implementation of managed "{0}" can not be defined \
|
||||||
|
using classloader "{1}". See nested exception for details.
|
||||||
|
interface-load2: Enhanced dynamic implementaion of managed "{0}" can not be \
|
||||||
|
defined using classloader "{1}". See nested exception for details.
|
||||||
|
interface-badenhance: Dynamic implementaion of "{0}" can not be enhanced.
|
Loading…
Reference in New Issue