Package org.objectweb.asm

Examples of org.objectweb.asm.ClassWriter


    public byte[] generate(Class<? extends Throwable> exceptionClass) {
        String className = getFaultBeanName(exceptionClass);
       
      // The reflection code here allows for toleration of older versions of ASM.     
      ClassWriter cw;
      try {      
        Constructor<ClassWriter> c = ClassWriter.class.getConstructor(new Class[] {int.class});
        Field f = ClassWriter.class.getField("COMPUTE_MAXS");
        cw = c.newInstance(f.get(null));
      } catch ( Exception ex ) {
View Full Code Here


                             String name,
                             BeanProperty[] properties,
                             GeneratedClassLoader classLoader) {
     
      // The reflection code here allows for toleration of older versions of ASM.
      ClassWriter cw;
      try {      
        Constructor<ClassWriter> c = ClassWriter.class.getConstructor(new Class[] {int.class});
        Field f = ClassWriter.class.getField("COMPUTE_MAXS");
        cw = c.newInstance(f.get(null));
      } catch ( Exception ex ) {
View Full Code Here

     * Generates a proxy class.
     * @param spec the proxied service specification
     * @return the byte[] for the generated proxy class.
     */
    public static byte[] dumpProxy(Class spec) {
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        String internalClassName = Type.getInternalName(spec); // Specification class internal name.
        String[] itfs = new String[0];
        String parent = "java/lang/Object";
        if (spec.isInterface()) {
          itfs = new String[] {internalClassName}// Implemented interface.
        } else {
          parent = internalClassName;
        }
        String className = internalClassName + "$$Proxy"; // Unique name.

        // Turn around the VM changes (FELIX-2716) about java.* classes.
        if (className.startsWith("java/")) {
          className = "$" + className;
        }

        Method[] methods = spec.getMethods(); // Method to delegate

        cw.visit(Opcodes.V1_3, Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, className, null, parent, itfs);
        addDependencyField(cw);

        // We try to call super() on the parent, however this should not be used as proxing does work only for interface.
        generateConstructor(cw, className, parent);

        // For each method, create the delegator code.
        for (int i = 0; i < methods.length; i++) {
            if ((methods[i].getModifiers() & (Modifier.STATIC | Modifier.FINAL)) == 0) {
                generateDelegator(cw, methods[i], className, internalClassName);
            }
        }

        cw.visitEnd();

        return cw.toByteArray();

    }
View Full Code Here

            Thread.currentThread().setContextClassLoader(resourceLoader.getClassLoader());
           
            // Create an XSD helper
            XSDHelper xsdHelper = SDOUtil.createXSDHelper(typeHelper);
           
            ClassWriter cw = new ClassWriter(false);

            // Generate the interface
            interfaceName = interfaceName.replace('.', '/');
            cw.visit(V1_5, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE, interfaceName, null, "java/lang/Object", EMPTY_STRINGS);

            // Generate methods from the WSDL operations
            for (Operation operation : (List<Operation>) portType.getOperations()) {
               
                //FIXME Workaround for TUSCANY-170, we will need to make this consistent with the algorithm used by Axis2 WSDL2Java
                // to generate method names from operations names
                //String methodName = XMLNameUtil.getJavaNameFromXMLName(operation.getName(), false);
                String methodName = operation.getName();
               
                // FIXME later we may want to wwitch to use the Axis2 WSDL2Java (not to generate the Java source,
                // just to figure the WSDL to Java mapping)
               
                // Derive the method signature from the input message part (and check if it's a doc-wrapped or doc-bare operation)
                List<Class> inputTypes=new ArrayList<Class>();
                boolean wrapped = false;
                if (operation.getInput() != null && operation.getInput().getMessage()!=null && !operation.getInput().getMessage().getParts().isEmpty()) {
                    QName qname=((Part)operation.getInput().getMessage().getParts().values().iterator().next()).getElementName();
                    if (qname!=null) {
                        Property property = xsdHelper.getGlobalProperty(qname.getNamespaceURI(), qname.getLocalPart(), true);
                        commonj.sdo.Type type = property.getType();
                        if (property.getName().equals(operation.getName())) {
                            String localName = xsdHelper.getLocalName(type);
                            if (localName.indexOf("_._")!=-1) {
                                for (Property param : (List<Property>)type.getProperties()) {
                                    Class inputType = param.getType().getInstanceClass();
                                    if (inputType == null)
                                        inputType = Object.class;
                                    inputTypes.add(inputType);
                                }
                                wrapped=true;
                            }
                        }

                        // Bare doc style
                        if (!wrapped) {
                            Class inputType = type.getInstanceClass();
                            if (inputType == null)
                                inputType = Object.class;
                            inputTypes.add(inputType);
                        }
                       
                    } else {
                        // FIXME only support elements for now
                    }
                }
               
                // Derive the return type from the output message part (also support doc-wrapped and doc-bare here)
                Class outputType=Void.class;
                if (operation.getOutput() != null && operation.getOutput().getMessage()!=null && !operation.getOutput().getMessage().getParts().isEmpty()) {
                    QName qname=((Part)operation.getOutput().getMessage().getParts().values().iterator().next()).getElementName();
                    if (qname!=null) {
                        Property property = xsdHelper.getGlobalProperty(qname.getNamespaceURI(), qname.getLocalPart(), true);
                        commonj.sdo.Type type = property.getType();
                        if (wrapped) {
                            if (!type.getProperties().isEmpty()) {
                                outputType=((Property)type.getProperties().get(0)).getType().getInstanceClass();
                                if (outputType==null)
                                    outputType=Object.class;
                            }
                        } else {
                            outputType = type.getInstanceClass();
                            if (outputType==null)
                                outputType=Object.class;
                        }
                    } else {
                        // FIXME only support elements for now
                    }
                }

                // FIXME integrate XSD to Java type mapping here
                StringBuffer inputSignature=new StringBuffer();
                for (Class inputType : inputTypes) {
                    inputSignature.append(Type.getDescriptor(inputType));
                }
                String outputSignature = Type.getDescriptor(outputType);

                cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, methodName, '(' + inputSignature.toString() + ')' + outputSignature, null, null).visitEnd();
            }

            // Generate the bytecodes
            cw.visitEnd();
            byte[] bytes = cw.toByteArray();

            // Add the class to the resource loader

            return resourceLoader.addClass(bytes);
           
View Full Code Here

*/
public class BytecodeInterfaceGenerator implements SDOTypeVisitor {
    private final ClassWriter cw;

    public BytecodeInterfaceGenerator() {
        cw = new ClassWriter(false);
    }
View Full Code Here

      log.error( "Unable to read class", e );
      throw new HibernateException( "Unable to read class: " + e.getMessage() );
    }

    String[] names = ClassNameReader.getClassInfo( reader );
    ClassWriter w = new DebuggingClassWriter( true );
    ClassTransformer t = getClassTransformer( names );
    if ( t != null ) {
      if ( log.isDebugEnabled() ) {
        log.debug( "Enhancing " + className );
      }
      ByteArrayOutputStream out;
      byte[] result;
      try {
        reader = new ClassReader( new ByteArrayInputStream( classfileBuffer ) );
        new TransformingClassGenerator(
            new ClassReaderGenerator( reader, attributes(), skipDebug() ), t
        ).generateClass( w );
        out = new ByteArrayOutputStream();
        out.write( w.toByteArray() );
        result = out.toByteArray();
        out.close();
      }
      catch (Exception e) {
        log.error( "Unable to transform class", e );
View Full Code Here

    return new MyClassLoader().defineClass(generationContext.getClassName().replace('/', '.'), cw.toByteArray());
  }

  private void startClass() {

    cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    cv = new TraceClassVisitor(cw, new PrintWriter(System.out));
    //cv = new CheckClassAdapter(cv);
    cv.visit(V1_6, ACC_PUBLIC + ACC_SUPER, generationContext.getClassName(), null,
        "java/lang/Object", new String[] { "org/renjin/compiler/CompiledBody" });
  }
View Full Code Here

    compileMain();
  }
 
  private void compileMain() {

    ClassWriter cw = new ClassWriter(0);
    FieldVisitor fv;
    MethodVisitor mv;
    AnnotationVisitor av0;
   
    cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, "RProgram", null, "java/lang/Object", new String[] { });
   
    writeConstructor(cw);
    writeMainMethod(cw);
   
  }
View Full Code Here

  private static final int ENVIRONMENT = 2;


  public static byte[] compile(String packageName, Environment packageEnvironment) {

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, CompiledNames.loaderClassName(packageName), null,
        "java/lang/Object", new String[] { "org/renjin/compiler/runtime/PackageLoader" });

    writeInit(cw);
    writeLoadMethod(cw, packageName, packageEnvironment);
   
    return cw.toByteArray();
  }
View Full Code Here

    className = "Jit" + System.identityHashCode(this);
  }

  public JittedComputation compile(DeferredNode node)  {
    long startTime = System.nanoTime();
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    cv = cw;
//    if(DeferredGraph.DEBUG) {
//      cv = new TraceClassVisitor(cw, new PrintWriter(System.out));
//    }
    //cv = new CheckClassAdapter(cv);
    cv.visit(V1_6, ACC_PUBLIC + ACC_SUPER, className, null, "java/lang/Object",
            new String[]{"org/renjin/compiler/pipeline/JittedComputation"});

    writeConstructor();
    writeCompute(node);

    cv.visitEnd();

    byte[] classBytes = cw.toByteArray();
    long compileTime = System.nanoTime() - startTime;

    Class jitClass = new MyClassLoader().defineClass(className, classBytes);

    long loadTime = System.nanoTime() - startTime - compileTime;
View Full Code Here

TOP

Related Classes of org.objectweb.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.