Search in sources :

Example 1 with ByteArrayClassPath

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);
        }
    }
}
Also used : ByteArrayClassPath(javassist.ByteArrayClassPath) ClassData(org.motechproject.mds.domain.ClassData) Bundle(org.osgi.framework.Bundle) InputStream(java.io.InputStream) CtClass(javassist.CtClass) IOException(java.io.IOException) LinkedList(java.util.LinkedList) URL(java.net.URL)

Example 2 with ByteArrayClassPath

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);
}
Also used : ByteArrayClassPath(javassist.ByteArrayClassPath) ClassData(org.motechproject.mds.domain.ClassData)

Example 3 with ByteArrayClassPath

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);
}
Also used : ByteArrayClassPath(javassist.ByteArrayClassPath)

Aggregations

ByteArrayClassPath (javassist.ByteArrayClassPath)3 ClassData (org.motechproject.mds.domain.ClassData)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 LinkedList (java.util.LinkedList)1 CtClass (javassist.CtClass)1 Bundle (org.osgi.framework.Bundle)1