Package net.sf.cglib.asm

Examples of net.sf.cglib.asm.ClassWriter


        }
    }

    private static byte[] generateGenericInterface(Class serviceInterface) {
        String interfazeName = serviceInterface.getCanonicalName();
        ClassWriter cw = new ClassWriter(false);

        cw.visit(Constants.V1_5,
                 Constants.ACC_PUBLIC + Constants.ACC_ABSTRACT + Constants.ACC_INTERFACE,
                 interfazeName.replace('.',
                                       '/'),
                 "java/lang/Object",
                 null,
                 serviceInterface.getSimpleName() + ".java");

        StringBuffer argsAndReturn = new StringBuffer("(");
        Method[] methods = serviceInterface.getMethods();
        for (int count = 0; count < methods.length; ++count) {
            argsAndReturn = new StringBuffer("(");
            Class[] paramTypes = methods[count].getParameterTypes();
            Class returnType = methods[count].getReturnType();

            for (int paramCount = 0; paramCount < paramTypes.length; ++paramCount) {
                argsAndReturn.append(Type.getType(Object.class));
            }
            argsAndReturn.append(")");
            argsAndReturn.append(Type.getType(Object.class));

            Class[] exceptionTypes = methods[count].getExceptionTypes();
            String[] exceptions = new String[exceptionTypes.length];
            for (int excCount = 0; excCount < exceptionTypes.length; ++excCount) {
                exceptions[excCount] = exceptionTypes[excCount].getName();
                exceptions[excCount] = exceptions[excCount].replace('.',
                                                                    '/');
            }

            CodeVisitor cv = cw.visitMethod(Constants.ACC_PUBLIC + Constants.ACC_ABSTRACT,
                                            methods[count].getName(),
                                            argsAndReturn.toString(),
                                            exceptions,
                                            null);
            cw.visitEnd();
        }

        cw.visitEnd();

        return cw.toByteArray();
    }
View Full Code Here


/*     */
/*     */   public byte[] preProcess(byte[] b)
/*     */   {
/*     */     try
/*     */     {
/*  40 */       ClassWriter w = new ClassWriter(true) { private boolean flag;
/*     */
/*  43 */         public void visit(int version, int access, String name, String superName, String[] interfaces, String sourceFile) { super.visit(version, access, name, superName, interfaces, sourceFile);
/*  44 */           this.flag = name.equals("java/lang/ClassLoader"); }
/*     */
/*     */         public CodeVisitor visitMethod(int access, String name, String desc, String[] exceptions, Attribute attrs) {
/*  47 */           CodeVisitor v = super.visitMethod(access, name, desc, exceptions, attrs);
/*  48 */           if (this.flag) {
/*  49 */             v = new AsmClassLoaderPreProcessor.PreProcessingVisitor(v, access, desc);
/*     */           }
/*  51 */           return v;
/*     */         }
/*     */       };
/*  54 */       new ClassReader(b).accept(w, false);
/*  55 */       return w.toByteArray();
/*     */     } catch (Exception e) {
/*  57 */       System.err.println("failed to patch ClassLoader:");
/*  58 */       e.printStackTrace();
/*  59 */     }return b;
/*     */   }
View Full Code Here

/*  86 */       throw new ClassNotFoundException(name + ":" + e.getMessage());
/*     */     }
/*     */     try
/*     */     {
/*     */       ClassReader r;
/*  90 */       ClassWriter w = new DebuggingClassWriter(true);
/*  91 */       getGenerator(r).generateClass(w);
/*  92 */       byte[] b = w.toByteArray();
/*  93 */       Class c = super.defineClass(name, b, 0, b.length, DOMAIN);
/*  94 */       postProcess(c);
/*  95 */       return c;
/*     */     } catch (RuntimeException e) {
/*  97 */       throw e;
View Full Code Here

/*    */   implements GeneratorStrategy
/*    */ {
/* 21 */   public static final DefaultGeneratorStrategy INSTANCE = new DefaultGeneratorStrategy();
/*    */
/*    */   public byte[] generate(ClassGenerator cg) throws Exception {
/* 24 */     ClassWriter cw = getClassWriter();
/* 25 */     transform(cg).generateClass(cw);
/* 26 */     return transform(cw.toByteArray());
/*    */   }
View Full Code Here

/*     */   private void processClassFile(File file)
/*     */     throws Exception, FileNotFoundException, IOException, MalformedURLException
/*     */   {
/*  86 */     ClassReader reader = getClassReader(file);
/*  87 */     String[] name = ClassNameReader.getClassInfo(reader);
/*  88 */     ClassWriter w = new DebuggingClassWriter(true);
/*  89 */     ClassTransformer t = getClassTransformer(name);
/*  90 */     if (t != null)
/*     */     {
/*  92 */       if (this.verbose) {
/*  93 */         log("processing " + file.toURL());
/*     */       }
/*  95 */       new TransformingClassGenerator(new ClassReaderGenerator(getClassReader(file), attributes(), skipDebug()), t).generateClass(w);
/*     */
/*  98 */       FileOutputStream fos = new FileOutputStream(file);
/*     */       try {
/* 100 */         fos.write(w.toByteArray());
/*     */       } finally {
/* 102 */         fos.close();
/*     */       }
/*     */     }
/*     */   }
View Full Code Here

/*     */   private byte[] process(byte[] bytes)
/*     */     throws Exception
/*     */   {
/* 224 */     ClassReader reader = new ClassReader(new ByteArrayInputStream(bytes));
/* 225 */     String[] name = ClassNameReader.getClassInfo(reader);
/* 226 */     ClassWriter w = new DebuggingClassWriter(true);
/* 227 */     ClassTransformer t = getClassTransformer(name);
/* 228 */     if (t != null) {
/* 229 */       if (this.verbose) {
/* 230 */         log("processing " + name[0]);
/*     */       }
/* 232 */       new TransformingClassGenerator(new ClassReaderGenerator(new ClassReader(new ByteArrayInputStream(bytes)), attributes(), skipDebug()), t).generateClass(w);
/*     */
/* 235 */       ByteArrayOutputStream out = new ByteArrayOutputStream();
/* 236 */       out.write(w.toByteArray());
/* 237 */       return out.toByteArray();
/*     */     }
/* 239 */     return bytes;
/*     */   }
View Full Code Here

/*    */     try
/*    */     {
/* 31 */       ClassTransformer t = getClassTransformer(name);
/* 32 */       if (t == null)
/* 33 */         return abyte;
/* 34 */       ClassWriter w = new DebuggingClassWriter(true);
/* 35 */       ClassGenerator gen = new ClassReaderGenerator(new ClassReader(abyte), false);
/* 36 */       gen = new TransformingClassGenerator(gen, t);
/* 37 */       gen.generateClass(w);
/* 38 */       return w.toByteArray(); } catch (Exception e) {
/*    */     }
/* 40 */     throw new CodeGenerationException(e);
/*    */   }
View Full Code Here

TOP

Related Classes of net.sf.cglib.asm.ClassWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.