Search in sources :

Example 26 with MethodVisitor

use of org.apache.xbean.asm5.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.asm5.MethodVisitor)

Example 27 with MethodVisitor

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

the class Cmp2Generator method createCmrGetter.

/**
 * Create a getter method for the CMR field.  This
 * will used the accessor object initialized into the
 * name + "Cmr" field that was already generated and
 * initialized at object creation.  The accessor
 * object manages the object relationship.
 *
 * @param cmrField The field we're generating.
 */
private void createCmrGetter(final CmrField cmrField) {
    // no back reference.  We don't generate a getter method for this
    if (cmrField.isSynthetic()) {
        return;
    }
    final String methodName = getterName(cmrField.getName());
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, methodName, "()" + cmrField.getProxyDescriptor(), null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, implClassName, cmrField.getName() + "Cmr", cmrField.getAccessorDescriptor());
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, implClassName, cmrField.getName(), cmrField.getDescriptor());
    // return this.${cmrField.name}Cmr.get(this.${cmdField.name});
    // this takes the value stored in the CMR field (which might be a single value or
    // a Set or Collection), and hands it to the appropriate accessor.
    mv.visitMethodInsn(INVOKEVIRTUAL, cmrField.getAccessorInternalName(), "get", cmrField.getCmrStyle().getGetterDescriptor(), false);
    // to the target class before returning.
    if (cmrField.getCmrStyle() == CmrStyle.SINGLE) {
        mv.visitTypeInsn(CHECKCAST, cmrField.getProxyType().getInternalName());
    }
    mv.visitInsn(ARETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
Also used : MethodVisitor(org.apache.xbean.asm5.MethodVisitor)

Example 28 with MethodVisitor

use of org.apache.xbean.asm5.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.asm5.Type)

Example 29 with MethodVisitor

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

the class Cmp2Generator method createOpenEJB_deleted.

private void createOpenEJB_deleted() {
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "OpenEJB_deleted", "()V", null, null);
    mv.visitCode();
    /* if (deleted) return; */
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, implClassName, DELETED, "Z");
    final Label notDeleted = new Label();
    mv.visitJumpInsn(IFEQ, notDeleted);
    mv.visitInsn(RETURN);
    mv.visitLabel(notDeleted);
    // deleted = true;
    mv.visitVarInsn(ALOAD, 0);
    mv.visitInsn(ICONST_1);
    mv.visitFieldInsn(PUTFIELD, implClassName, DELETED, "Z");
    for (final CmrField cmrField : cmrFields) {
        // ${cmrField.accessor}.delete(${cmrField.name});
        createOpenEJB_deleted(mv, cmrField);
    }
    // return;
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
Also used : Label(org.apache.xbean.asm5.Label) MethodVisitor(org.apache.xbean.asm5.MethodVisitor)

Example 30 with MethodVisitor

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

the class PostCreateGenerator method createEjbPostCreate.

/**
 * Generate an ejbPostCreatexxxx method corresponding
 * to an ejbCreatexxxx method definition.  These provided
 * methods are just empty stubs.
 *
 * @param ejbPostCreateName The name we're creating under.
 * @param ejbCreate         The matching ejbCreate method.  The post create method
 *                          will match this one in terms of method signature.
 */
public void createEjbPostCreate(final String ejbPostCreateName, final Method ejbCreate) {
    final String methodDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getArgumentTypes(ejbCreate));
    final MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, ejbPostCreateName, methodDescriptor, null, null);
    mv.visitCode();
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(0, ejbCreate.getParameterTypes().length + 1);
    mv.visitEnd();
}
Also used : MethodVisitor(org.apache.xbean.asm5.MethodVisitor)

Aggregations

MethodVisitor (org.apache.xbean.asm5.MethodVisitor)28 Label (org.apache.xbean.asm5.Label)7 MethodVisitor (jodd.asm5.MethodVisitor)6 ClassWriter (org.apache.xbean.asm5.ClassWriter)6 Method (java.lang.reflect.Method)3 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 EmptyClassVisitor (jodd.asm.EmptyClassVisitor)2 EmptyMethodVisitor (jodd.asm.EmptyMethodVisitor)2 Type (org.apache.xbean.asm5.Type)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 MethodAdapter (jodd.asm.MethodAdapter)1 FieldVisitor (jodd.asm5.FieldVisitor)1 Label (jodd.asm5.Label)1 ProxettaException (jodd.proxetta.ProxettaException)1 ProxyGenerationException (org.apache.openejb.util.proxy.ProxyGenerationException)1