Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**********************************************************************
Copyright (c) 2007 Andy Jefferson and others. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Contributors:
...
**********************************************************************/
package org.datanucleus.enhancer.asm.method;
import org.datanucleus.enhancer.ClassEnhancer;
import org.datanucleus.enhancer.asm.ASMClassEnhancer;
import org.datanucleus.enhancer.asm.ASMClassMethod;
import org.datanucleus.enhancer.asm.ASMUtils;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
/**
* Method to generate the method "jdoReplaceDetachedState" using ASM.
*
* public final synchronized void jdoReplaceDetachedState()
* {
* if (jdoStateManager == null)
* throw new IllegalStateException("state manager is null");
* this.jdoDetachedState = this.jdoStateManager.replacingDetachedState(this, jdoDetachedState);
* }
*
*/
public class JdoReplaceDetachedState extends ASMClassMethod
{
public static JdoReplaceDetachedState getInstance(ClassEnhancer enhancer)
{
return new JdoReplaceDetachedState(enhancer, enhancer.getReplaceDetachedStateMethodName(),
Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_SYNCHRONIZED,
null, null, null);
}
/**
* Constructor.
* @param enhancer ClassEnhancer
* @param name Name of method
* @param access Access type
* @param returnType Return type
* @param argTypes Argument types
* @param argNames Argument names
*/
public JdoReplaceDetachedState(ClassEnhancer enhancer, String name, int access,
Object returnType, Object[] argTypes, String[] argNames)
{
super(enhancer, name, access, returnType, argTypes, argNames);
}
/**
* Method to add the contents of the class method.
*/
public void execute()
{
visitor.visitCode();
Label startLabel = new Label();
visitor.visitLabel(startLabel);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(),
enhancer.getStateManagerFieldName(), enhancer.getStateManagerDescriptor());
Label l1 = new Label();
visitor.visitJumpInsn(Opcodes.IFNONNULL, l1);
visitor.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalStateException");
visitor.visitInsn(Opcodes.DUP);
visitor.visitLdcInsn("state manager is null");
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalStateException",
"", "(Ljava/lang/String;)V");
visitor.visitInsn(Opcodes.ATHROW);
visitor.visitLabel(l1);
if (ASMClassEnhancer.useFrames())
{
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
}
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(),
enhancer.getStateManagerFieldName(), enhancer.getStateManagerDescriptor());
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(),
enhancer.getDetachedStateFieldName(), "[" + ASMUtils.CD_Object);
visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, enhancer.getStateManagerAsmClassName(), "replacingDetachedState",
"(L" + enhancer.getDetachableAsmClassName() + ";[" + ASMUtils.CD_Object + ")[" + ASMUtils.CD_Object);
visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(),
enhancer.getDetachedStateFieldName(), "[" + ASMUtils.CD_Object);
visitor.visitInsn(Opcodes.RETURN);
Label endLabel = new Label();
visitor.visitLabel(endLabel);
visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
visitor.visitMaxs(4, 1);
visitor.visitEnd();
}
}