Search in sources :

Example 26 with MethodVisitor

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

the class Cmp2Generator method createOpenEJB_addCmr.

private void createOpenEJB_addCmr() {
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "OpenEJB_addCmr", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;", null, null);
    mv.visitCode();
    // if (deleted) return null;
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, implClassName, DELETED, "Z");
    final Label notDeleted = new Label();
    mv.visitJumpInsn(IFEQ, notDeleted);
    mv.visitInsn(ACONST_NULL);
    mv.visitInsn(ARETURN);
    mv.visitLabel(notDeleted);
    for (final CmrField cmrField : cmrFields) {
        // if ("${cmrField.name}".equals(name)) {
        // ${cmrField.name}.add((${cmrField.type})value);
        // return null;
        // }
        // 
        // OR
        // 
        // if ("${cmrField.name}".equals(name)) {
        // Object oldValue = ${cmrField.name};
        // ${cmrField.name} = (${cmrField.type}) bean;
        // return oldValue;
        // }
        createOpenEJB_addCmr(mv, cmrField);
    }
    // throw new IllegalArgumentException("Unknown cmr field " + name + " on entity bean of type " + getClass().getName());
    mv.visitTypeInsn(NEW, "java/lang/IllegalArgumentException");
    mv.visitInsn(DUP);
    mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
    mv.visitInsn(DUP);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false);
    mv.visitLdcInsn("Unknown cmr field ");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
    mv.visitLdcInsn(" on entity bean of type ");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;", false);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IllegalArgumentException", "<init>", "(Ljava/lang/String;)V", false);
    mv.visitInsn(ATHROW);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
Also used : Label(org.apache.xbean.asm9.Label) MethodVisitor(org.apache.xbean.asm9.MethodVisitor)

Example 27 with MethodVisitor

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

the class Cmp1Generator method createConstructor.

/**
 * Create a default constructor for our bean super
 * class.  This is just a forwarding constructor that
 * calls the superclass (the bean implementation class)
 * default constructor.
 */
private void createConstructor() {
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, beanClassName, "<init>", "()V", false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
Also used : MethodVisitor(org.apache.xbean.asm9.MethodVisitor)

Example 28 with MethodVisitor

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

the class Cmp2Generator method createOpenEJB_isDeleted.

private void createOpenEJB_isDeleted() {
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "OpenEJB_isDeleted", "()Z", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, implClassName, DELETED, "Z");
    mv.visitInsn(IRETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
Also used : MethodVisitor(org.apache.xbean.asm9.MethodVisitor)

Example 29 with MethodVisitor

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

the class Cmp2Generator method createEjbLoad.

public void createEjbLoad() {
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "ejbLoad", "()V", null, null);
    mv.visitCode();
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 1);
    mv.visitEnd();
}
Also used : MethodVisitor(org.apache.xbean.asm9.MethodVisitor)

Example 30 with MethodVisitor

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

the class Cmp2Generator method initCmrFields.

/**
 * Initialize the CMR fields associated with a CMR
 * definition.  This initializes two fields per CMR
 * defined field:  1)  The CMR field itself (which might
 * be initialized to an instance of a defined type) and 2)
 * the appropriate CMD accessor that handles the
 * different types of relationship.
 *
 * @param mv       The method context we're initializing in.
 * @param cmrField The CMR field to process.
 */
private void initCmrFields(final MethodVisitor mv, final CmrField cmrField) {
    // this.${cmrField.name} = new ${cmrField.initialValueType}();
    final Type initialValueType = cmrField.getInitialValueType();
    if (initialValueType != null) {
        mv.visitVarInsn(ALOAD, 0);
        mv.visitTypeInsn(NEW, initialValueType.getInternalName());
        mv.visitInsn(DUP);
        mv.visitMethodInsn(INVOKESPECIAL, initialValueType.getInternalName(), "<init>", "()V", false);
        mv.visitFieldInsn(PUTFIELD, implClassName, cmrField.getName(), cmrField.getDescriptor());
    }
    // this.${cmrField.name}Cmr = new ${cmrField.accessorType}<${cmrField.type}, ${cmrField.proxyType}>(this,
    // ${cmrField.name},
    // ${cmrField.type},
    // ${cmrField.relatedName});
    mv.visitVarInsn(ALOAD, 0);
    mv.visitTypeInsn(NEW, cmrField.getAccessorInternalName());
    mv.visitInsn(DUP);
    // arg0: EntityBean source = this
    mv.visitVarInsn(ALOAD, 0);
    // arg1: String sourceProperty - "b"
    mv.visitLdcInsn(cmrField.getName());
    // arg2: Class<Bean> relatedType = BBean_BBean
    mv.visitLdcInsn(cmrField.getType());
    // arg3: String relatedProperty
    if (cmrField.getRelatedName() != null) {
        mv.visitLdcInsn(cmrField.getRelatedName());
    } else {
        mv.visitInsn(ACONST_NULL);
    }
    // invoke
    mv.visitMethodInsn(INVOKESPECIAL, cmrField.getAccessorInternalName(), "<init>", "(Ljavax/ejb/EntityBean;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/String;)V", false);
    // bCmr = result
    mv.visitFieldInsn(PUTFIELD, implClassName, cmrField.getName() + "Cmr", cmrField.getAccessorDescriptor());
}
Also used : Type(org.apache.xbean.asm9.Type)

Aggregations

MethodVisitor (org.apache.xbean.asm9.MethodVisitor)30 Label (org.apache.xbean.asm9.Label)7 MethodVisitor (jodd.asm5.MethodVisitor)6 MethodVisitor (org.apache.xbean.asm6.MethodVisitor)6 ClassWriter (org.apache.xbean.asm9.ClassWriter)6 Method (java.lang.reflect.Method)5 Type (org.apache.xbean.asm9.Type)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 ZipEntry (java.util.zip.ZipEntry)2 EmptyClassVisitor (jodd.asm.EmptyClassVisitor)2 EmptyMethodVisitor (jodd.asm.EmptyMethodVisitor)2 ProxyGenerationException (org.apache.openejb.util.proxy.ProxyGenerationException)2 AnnotationVisitor (org.apache.xbean.asm6.AnnotationVisitor)2 ClassWriter (org.apache.xbean.asm6.ClassWriter)2 AnnotationVisitor (org.apache.xbean.asm9.AnnotationVisitor)2