String[] argNames = new String[] {"objPC"};
String fieldTypeDesc = Type.getDescriptor(mmd.getType());
mv.visitCode();
AbstractClassMetaData cmd = mmd.getAbstractClassMetaData();
if ((mmd.getJdoFieldFlag() & PersistenceCapable.MEDIATE_READ) == PersistenceCapable.MEDIATE_READ)
{
// MEDIATE_READ
Label startLabel = new Label();
mv.visitLabel(startLabel);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
Label l1 = new Label();
mv.visitJumpInsn(Opcodes.IFNULL, l1);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
mv.visitVarInsn(Opcodes.ALOAD, 0);
ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
if (cmd.getPersistenceCapableSuperclass() != null)
{
mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, "jdoInheritedFieldCount", "I");
mv.visitInsn(Opcodes.IADD);
}
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "javax/jdo/spi/StateManager",
"isLoaded", "(Ljavax/jdo/spi/PersistenceCapable;I)Z");
mv.visitJumpInsn(Opcodes.IFNE, l1);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
mv.visitVarInsn(Opcodes.ALOAD, 0);
ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
if (cmd.getPersistenceCapableSuperclass() != null)
{
mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, "jdoInheritedFieldCount", "I");
mv.visitInsn(Opcodes.IADD);
}
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName,
"jdoGet" + mmd.getName(), "()" + fieldTypeDesc);
String jdoMethodName = "get" + ASMUtils.getTypeNameForJDOMethod(mmd.getType()) + "Field";
String argTypeDesc = fieldTypeDesc;
if (jdoMethodName.equals("getObjectField"))
{
argTypeDesc = ASMUtils.CD_Object;
}
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "javax/jdo/spi/StateManager",
jdoMethodName, "(Ljavax/jdo/spi/PersistenceCapable;I" + argTypeDesc + ")" + argTypeDesc);
if (jdoMethodName.equals("getObjectField"))
{
// Cast any object fields to the correct type
mv.visitTypeInsn(Opcodes.CHECKCAST, mmd.getTypeName().replace('.', '/'));
}
ASMUtils.addReturnForType(mv, mmd.getType());
mv.visitLabel(l1);
Label l4 = new Label();
if (cmd.isDetachable())
{
// "if (objPC.jdoIsDetached() != false && ((BitSet) objPC.jdoDetachedState[2]).get(5) != true)"
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, "jdoIsDetached", "()Z");
mv.visitJumpInsn(Opcodes.IFEQ, l4);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
ClassEnhancer.FN_JdoDetachedState, "[Ljava/lang/Object;");
mv.visitInsn(Opcodes.ICONST_2);
mv.visitInsn(Opcodes.AALOAD);
mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
if (cmd.getPersistenceCapableSuperclass() != null)
{
mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, "jdoInheritedFieldCount", "I");
mv.visitInsn(Opcodes.IADD);
}
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/BitSet", "get", "(I)Z");
mv.visitJumpInsn(Opcodes.IFNE, l4);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
ClassEnhancer.FN_JdoDetachedState, "[Ljava/lang/Object;");
mv.visitInsn(Opcodes.ICONST_3);
mv.visitInsn(Opcodes.AALOAD);
mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
if (cmd.getPersistenceCapableSuperclass() != null)
{
mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, "jdoInheritedFieldCount", "I");
mv.visitInsn(Opcodes.IADD);
}
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/BitSet", "get", "(I)Z");
mv.visitJumpInsn(Opcodes.IFNE, l4);
// "throw new JDODetachedFieldAccessException(...)"
mv.visitTypeInsn(Opcodes.NEW, "javax/jdo/JDODetachedFieldAccessException");
mv.visitInsn(Opcodes.DUP);
mv.visitLdcInsn(LOCALISER.msg("Enhancer.DetachedPropertyAccess", mmd.getName()));
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "javax/jdo/JDODetachedFieldAccessException",
"<init>", "(Ljava/lang/String;)V");
mv.visitInsn(Opcodes.ATHROW);
}
mv.visitLabel(l4);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName,
"jdoGet" + mmd.getName(), "()" + fieldTypeDesc);
ASMUtils.addReturnForType(mv, mmd.getType());
Label endLabel = new Label();
mv.visitLabel(endLabel);
mv.visitLocalVariable(argNames[0], asmClassDesc, null, startLabel, endLabel, 0);
mv.visitMaxs(4, 1);
}
else if ((mmd.getJdoFieldFlag() & PersistenceCapable.CHECK_READ) == PersistenceCapable.CHECK_READ)
{
// CHECK_READ
Label startLabel = new Label();
mv.visitLabel(startLabel);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, ClassEnhancer.FN_Flag, "B");
Label l1 = new Label();
mv.visitJumpInsn(Opcodes.IFLE, l1);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
mv.visitJumpInsn(Opcodes.IFNULL, l1);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
mv.visitVarInsn(Opcodes.ALOAD, 0);
ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
if (cmd.getPersistenceCapableSuperclass() != null)
{
mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName,
ClassEnhancer.FN_JdoInheritedFieldCount, "I");
mv.visitInsn(Opcodes.IADD);
}
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "javax/jdo/spi/StateManager",
"isLoaded", "(Ljavax/jdo/spi/PersistenceCapable;I)Z");
mv.visitJumpInsn(Opcodes.IFNE, l1);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
ClassEnhancer.FN_StateManager, "Ljavax/jdo/spi/StateManager;");
mv.visitVarInsn(Opcodes.ALOAD, 0);
ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
if (cmd.getPersistenceCapableSuperclass() != null)
{
mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, ClassEnhancer.FN_JdoInheritedFieldCount, "I");
mv.visitInsn(Opcodes.IADD);
}
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, "jdoGet" + mmd.getName(), "()" + fieldTypeDesc);
String jdoMethodName = "get" + ASMUtils.getTypeNameForJDOMethod(mmd.getType()) + "Field";
String argTypeDesc = fieldTypeDesc;
if (jdoMethodName.equals("getObjectField"))
{
argTypeDesc = ASMUtils.CD_Object;
}
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "javax/jdo/spi/StateManager",
jdoMethodName, "(Ljavax/jdo/spi/PersistenceCapable;I" + argTypeDesc + ")" + argTypeDesc);
if (jdoMethodName.equals("getObjectField"))
{
// Cast any object fields to the correct type
mv.visitTypeInsn(Opcodes.CHECKCAST, mmd.getTypeName().replace('.', '/'));
}
ASMUtils.addReturnForType(mv, mmd.getType());
mv.visitLabel(l1);
Label l4 = new Label();
if (cmd.isDetachable())
{
// "if (objPC.jdoIsDetached() != false && ((BitSet) objPC.jdoDetachedState[2]).get(5) != true)"
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, ClassEnhancer.MN_JdoIsDetached, "()Z");
mv.visitJumpInsn(Opcodes.IFEQ, l4);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName,
ClassEnhancer.FN_JdoDetachedState, "[Ljava/lang/Object;");
mv.visitInsn(Opcodes.ICONST_2);
mv.visitInsn(Opcodes.AALOAD);
mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
ASMUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
if (cmd.getPersistenceCapableSuperclass() != null)
{
mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName,
ClassEnhancer.FN_JdoInheritedFieldCount, "I");
mv.visitInsn(Opcodes.IADD);
}