Search in sources :

Example 1 with ClassVisitor

use of org.apache.xbean.asm9.ClassVisitor in project tomee by apache.

the class AnnotationFinder method readClassDef.

private void readClassDef(String className, final ClassVisitor visitor) {
    classes++;
    if (!className.endsWith(".class")) {
        className = className.replace('.', '/') + ".class";
    }
    try {
        final URL resource = classLoader.getResource(className);
        if (resource != null) {
            InputStream in = resource.openStream();
            in = new BufferedInputStream(in);
            try {
                final ClassReader classReader = new ClassReader(in);
                classReader.accept(visitor, ASM_FLAGS);
            } finally {
                in.close();
            }
        } else {
            new Exception("Could not load " + className).printStackTrace();
        }
    } catch (final IOException e) {
        e.printStackTrace();
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) ClassReader(org.apache.xbean.asm9.ClassReader) IOException(java.io.IOException) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 2 with ClassVisitor

use of org.apache.xbean.asm9.ClassVisitor in project tomee by apache.

the class DynamicSubclass method copyMethodAnnotations.

public static void copyMethodAnnotations(final Class<?> classToProxy, final Map<String, MethodVisitor> visitors) throws ProxyGenerationException {
    // Move all the annotations onto the newly implemented methods
    // Ensures CDI and JAX-RS and JAX-WS still work
    Class clazz = classToProxy;
    while (clazz != null && !clazz.equals(Object.class)) {
        try {
            final ClassReader classReader = new ClassReader(readClassFile(clazz));
            final ClassVisitor copyMethodAnnotations = new CopyMethodAnnotations(visitors);
            classReader.accept(copyMethodAnnotations, ClassReader.SKIP_CODE);
        } catch (final IOException e) {
            throw new ProxyGenerationException(e);
        }
        clazz = clazz.getSuperclass();
    }
}
Also used : ProxyGenerationException(org.apache.openejb.util.proxy.ProxyGenerationException) ClassReader(org.apache.xbean.asm9.ClassReader) ClassVisitor(org.apache.xbean.asm9.ClassVisitor) IOException(java.io.IOException)

Example 3 with ClassVisitor

use of org.apache.xbean.asm9.ClassVisitor in project tomee by apache.

the class DynamicSubclass method copyClassAnnotations.

private static void copyClassAnnotations(final Class<?> clazz, final ClassVisitor newClass) throws ProxyGenerationException {
    try {
        final ClassReader classReader = new ClassReader(readClassFile(clazz));
        final ClassVisitor visitor = new CopyClassAnnotations(newClass);
        classReader.accept(visitor, ClassReader.SKIP_CODE);
    } catch (final IOException e) {
        throw new ProxyGenerationException(e);
    }
}
Also used : ProxyGenerationException(org.apache.openejb.util.proxy.ProxyGenerationException) ClassReader(org.apache.xbean.asm9.ClassReader) ClassVisitor(org.apache.xbean.asm9.ClassVisitor) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)3 ClassReader (org.apache.xbean.asm9.ClassReader)3 ProxyGenerationException (org.apache.openejb.util.proxy.ProxyGenerationException)2 ClassVisitor (org.apache.xbean.asm9.ClassVisitor)2 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 JarInputStream (java.util.jar.JarInputStream)1