use of javassist.ByteArrayClassPath in project motech by motech.
the class MDSConstructorImpl method buildInterfaces.
private void buildInterfaces(JavassistLoader loader, MdsJDOEnhancer enhancer, EntityDto entity) {
List<ClassData> interfaces = new LinkedList<>();
if (entity.isDDE()) {
Bundle declaringBundle = MdsBundleHelper.searchForBundle(bundleContext, entity);
try {
Class<?> definition = declaringBundle.loadClass(entity.getClassName());
for (Class interfaceClass : definition.getInterfaces()) {
String classpath = JavassistUtil.toClassPath(interfaceClass.getName());
URL classResource = declaringBundle.getResource(classpath);
if (classResource != null) {
try (InputStream in = classResource.openStream()) {
interfaces.add(new ClassData(interfaceClass.getName(), IOUtils.toByteArray(in), true));
}
}
}
} catch (ClassNotFoundException e) {
LOGGER.error("Class {} not found in {} bundle", entity.getClassName(), declaringBundle.getSymbolicName());
} catch (IOException ioExc) {
LOGGER.error("Could not load interface for {} class", entity.getClassName());
}
}
for (ClassData data : interfaces) {
try {
MDSClassLoader.getInstance().loadClass(data.getClassName());
} catch (ClassNotFoundException e) {
// interfaces should be defined in the MDS class loader only if it does not exist
MDSClassLoader.getInstance().safeDefineClass(data.getClassName(), data.getBytecode());
ByteArrayClassPath classPath = new ByteArrayClassPath(data.getClassName(), data.getBytecode());
MotechClassPool.getDefault().appendClassPath(classPath);
MotechClassPool.registerEnhancedClassData(data);
addClassData(loader, enhancer, data);
}
}
}
use of javassist.ByteArrayClassPath in project motech by motech.
the class MDSConstructorImpl method buildEnum.
private void buildEnum(JavassistLoader loader, MdsJDOEnhancer enhancer, ComboboxHolder holder) {
ClassData data = enumBuilder.build(holder);
ByteArrayClassPath classPath = new ByteArrayClassPath(data.getClassName(), data.getBytecode());
MotechClassPool.getDefault().appendClassPath(classPath);
MotechClassPool.registerEnhancedClassData(data);
// register with the classloader so that we avoid issues with the persistence manager
MDSClassLoader.getInstance().safeDefineClass(data.getClassName(), data.getBytecode());
addClassData(loader, enhancer, data);
}
use of javassist.ByteArrayClassPath in project motech by motech.
the class PristineBundleClassLoader method appendClassPath.
private void appendClassPath(String name, byte[] bytecode) {
LOGGER.debug("Appending class to Javassist classpath: " + name);
ByteArrayClassPath classPath = new ByteArrayClassPath(name, bytecode);
classPool.appendClassPath(classPath);
}
Aggregations