Search in sources :

Example 6 with MethodVisitor

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

the class Cmp2Generator method createEjbRemove.

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

Example 7 with MethodVisitor

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

the class Cmp2Generator method createSetEntityContext.

public void createSetEntityContext() {
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "setEntityContext", "(Ljavax/ejb/EntityContext;)V", null, null);
    mv.visitCode();
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 2);
    mv.visitEnd();
}
Also used : MethodVisitor(org.apache.xbean.asm5.MethodVisitor)

Example 8 with MethodVisitor

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

the class Cmp2Generator method createOpenEJB_removeCmr.

//    private void createPrintln(MethodVisitor mv, String message) {
//        mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
//        mv.visitLdcInsn(message);
//        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
//    }
//    private void createPrintField(MethodVisitor mv, String fieldName, String descriptor) {
//        mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
//        mv.visitLdcInsn(fieldName + "=");
//        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "print", "(Ljava/lang/String;)V");
//
//        mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
//        mv.visitVarInsn(ALOAD, 0);
//        mv.visitFieldInsn(GETFIELD, implClassName, fieldName, descriptor);
//        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/Object;)V");
//    }
/**
     * Emit the remove logic for an individual CMR field.
     * Like the addCmr logic, each field is guarded by an
     * if test on the property name.
     *
     * @param mv
     * @param cmrField
     */
private void createOpenEJB_removeCmr(final MethodVisitor mv, final CmrField cmrField) {
    // if (${cmrField.name}.equals(arg1))
    mv.visitLdcInsn(cmrField.getName());
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
    // if not equal jump to end
    final Label end = new Label();
    mv.visitJumpInsn(IFEQ, end);
    // collection valued CMR field.  Remove the object from the collection. 
    if (cmrField.getCmrStyle() != CmrStyle.SINGLE) {
        // ${cmrField.name}.remove(arg2)
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, implClassName, cmrField.getName(), cmrField.getDescriptor());
        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEINTERFACE, cmrField.getCmrStyle().getCollectionType().getInternalName(), "remove", "(Ljava/lang/Object;)Z", true);
        mv.visitInsn(POP);
        // return;
        mv.visitInsn(RETURN);
    } else {
        // single valued, so just null out the field. 
        // this.${cmrField.name} = null;
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(ACONST_NULL);
        mv.visitFieldInsn(PUTFIELD, implClassName, cmrField.getName(), cmrField.getDescriptor());
        // return;
        mv.visitInsn(RETURN);
    }
    // end of if statement
    mv.visitLabel(end);
}
Also used : Label(org.apache.xbean.asm5.Label)

Example 9 with MethodVisitor

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

the class Cmp2Generator method createSetter.

/**
     * Generate a concrete setter field for a CMP field.
     * At this point, we're just generating a simple
     * accessor for the field, given the type.  The
     * JPA engine when it makes this implementation class
     * a managed class define whatever additional logic
     * might be required.
     *
     * @param cmpField The CMP field backing this setter method.
     */
private void createSetter(final CmpField cmpField) {
    final String methodName = setterName(cmpField.getName());
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, methodName, "(" + cmpField.getDescriptor() + ")V", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(cmpField.getType().getOpcode(ILOAD), 1);
    mv.visitFieldInsn(PUTFIELD, implClassName, cmpField.getName(), cmpField.getDescriptor());
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
Also used : MethodVisitor(org.apache.xbean.asm5.MethodVisitor)

Example 10 with MethodVisitor

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

the class Cmp2Generator method createUnsetEntityContext.

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

Aggregations

MethodVisitor (org.apache.xbean.asm5.MethodVisitor)27 Label (org.apache.xbean.asm5.Label)7 MethodVisitor (jodd.asm5.MethodVisitor)6 ClassWriter (org.apache.xbean.asm5.ClassWriter)5 Method (java.lang.reflect.Method)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 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)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