|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.objectweb.asm.ClassAdapter
org.objectweb.easybeans.enhancer.injection.InjectionClassAdapter
public class InjectionClassAdapter
This class adds methods which will inject resources in the bean class.
Field Summary | |
---|---|
private ClassAnnotationMetadata |
classAnnotationMetadata
Metadata available by this adapter for a class. |
private static java.lang.String |
DATASOURCE_ITF
javax.sql.DataSource interface. |
private static java.lang.String |
ENTITYMANAGER_ITF
Entity Manager interface. |
private static java.lang.String |
ENTITYMANAGERFACTORY_ITF
Entity Manager Factory interface. |
private static java.lang.String |
EZB_EJBCONTEXT_DESC
EZBEJBContext type descriptor. |
static JMethod |
INJECTED_JMETHOD
JMethod object for injectedByEasyBeans. |
static java.lang.String |
INJECTED_METHOD
Injected method name. |
static java.lang.String[] |
INJECTED_METHODS
List of injected methods. |
static java.lang.String |
JAVA_LANG_OBJECT
Defines java.lang.Object class. |
private static int |
LENGTH
Replace length to create default JNDI names. |
private static JLog |
logger
Logger. |
private java.util.Map<java.lang.String,java.lang.Object> |
map
Map containing informations for enhancers. |
private static java.lang.String |
MESSAGEDRIVEN_CONTEXT
javax.ejb.MessageDrivenContext interface. |
private static java.lang.String |
ORB_ITF
org.omg.CORBA.ORB interface. |
private static java.lang.String |
QUEUE_ITF
javax.jms.Queue interface. |
private static java.lang.String |
QUEUECONNECTIONFACTORY_ITF
javax.jms.QueueConnectionFactory interface. |
private static java.lang.String |
SESSION_CONTEXT
javax.ejb.SessionContext interface. |
private boolean |
staticMode
Is that generated method is static (client case). |
private static java.lang.String |
TIMERSERVICE_ITF
javax.ejb.TimerService interface. |
private static java.lang.String |
TOPIC_ITF
javax.jms.Topic interface. |
private static java.lang.String |
TOPICCONNECTIONFACTORY_ITF
javax.jms.TopicConnectionFactory interface. |
private static java.lang.String |
USERTRANSACTION_ITF
javax.transaction.UserTransaction interface. |
Fields inherited from class org.objectweb.asm.ClassAdapter |
---|
cv |
Fields inherited from interface org.objectweb.asm.Opcodes |
---|
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6 |
Constructor Summary | |
---|---|
InjectionClassAdapter(ClassAnnotationMetadata classAnnotationMetadata,
org.objectweb.asm.ClassVisitor cv,
java.util.Map<java.lang.String,java.lang.Object> map,
boolean staticMode)
Constructor. |
Method Summary | |
---|---|
private boolean |
accessTest(int access,
int checkedAccess)
|
private void |
addCallEntityManagerFactoryHelper(JavaxPersistenceUnit javaxPersistenceUnit,
org.objectweb.asm.MethodVisitor mv)
Add a call to EntityManagerHelper class (PersistenceUnit): EntityManagerHelper.getEntityManagerFactory(getEasyBeansContext(), unitName). |
private void |
addCallEntityManagerHelper(JavaxPersistenceContext javaxPersistenceContext,
org.objectweb.asm.MethodVisitor mv)
Add a call to EntityManagerHelper class (PersistenceContext) : EntityManagerHelper.getEntityManager(getEasyBeansContext(), unitName, type of persistence). |
private void |
addCallGetEasyBeansContext(org.objectweb.asm.MethodVisitor mv,
java.lang.String castDesc)
Add a call to getEasyBeansContext() method in the given method visitor. |
private void |
addDefaultMethods()
Generated methods allowing to set a context and a factory. |
private void |
addInjectedMethod()
Generates the injectedByEasyBeans() method on the current class. |
private void |
bindClassEJB(JEjbEJB jEJB,
org.objectweb.asm.MethodVisitor mv)
Bind a ref for an EJB in ENC environment. |
private void |
bindClassPersistenceContext(JavaxPersistenceContext javaxPersistenceContext,
org.objectweb.asm.MethodVisitor mv)
Bind a ref for a PersistenceContext in ENC environment. |
private void |
bindClassPersistenceUnit(JavaxPersistenceUnit javaxPersistenceUnit,
org.objectweb.asm.MethodVisitor mv)
Bind a ref for a PersistenceUnit in ENC environment. |
private void |
bindResource(JAnnotationResource jAnnotationResource,
org.objectweb.asm.MethodVisitor mv)
Bind a ref for a Resource in ENC environment. |
private void |
callAttributeJndi(java.lang.String jndiName,
org.objectweb.asm.Type type,
org.objectweb.asm.MethodVisitor mv,
FieldAnnotationMetadata fieldMetaData,
java.lang.String className,
JNDILookupHelper.JndiType jndiType)
Generates a call to JNDILookupHelper class to get the java:comp/env name requested. |
private void |
callBindAttributeJndi(java.lang.String encName,
java.lang.String jndiName,
org.objectweb.asm.MethodVisitor mv,
FieldAnnotationMetadata fieldMetaData)
Generates a call to JNDIBinderHelper class to bind an object into the java:comp/env context. |
private void |
callBindLookupJndiRef(java.lang.String encName,
java.lang.String jndiName,
org.objectweb.asm.MethodVisitor mv)
Generates a call to JNDIBinderHelper class to link an object into the java:comp/env context. |
private void |
callJndi(java.lang.String jndiName,
org.objectweb.asm.Type type,
org.objectweb.asm.MethodVisitor mv,
java.lang.String className,
JNDILookupHelper.JndiType jndiType)
Generates a call to JNDILookupHelper class to get the java:comp/env name requested. |
private void |
callMethodJndiEnv(java.lang.String jndiName,
org.objectweb.asm.Type type,
org.objectweb.asm.MethodVisitor mv,
MethodAnnotationMetadata methodMetaData,
java.lang.String className,
JNDILookupHelper.JndiType jndiType)
Generates a call to JNDILookupHelper class to get the java:comp/env name requested. |
private void |
callSetterMethod(org.objectweb.asm.MethodVisitor mv,
java.lang.String className,
MethodAnnotationMetadata methodMetaData,
org.objectweb.asm.Type type)
Sets the value of a field. |
private void |
generateAttributesInjection(org.objectweb.asm.MethodVisitor mv)
Generates the calls to methods that will set the attributes value. |
private void |
generateBodyInjectedMethod(org.objectweb.asm.MethodVisitor mv)
Generates the body of the injectedByEasyBeans() method if any. Else, do nothing. |
private void |
generateClassInjection(org.objectweb.asm.MethodVisitor mv)
Generates the calls to populate ENC environment by using annotations on the class itself. |
private void |
generateSettersInjection(org.objectweb.asm.MethodVisitor mv)
Generates the calls to methods that will call the setters methods. |
private java.lang.String |
getJndiName(java.lang.String jndiName,
FieldAnnotationMetadata fieldAnnotationMetadata)
Ensures that jndiName is valid and return the default value if it is a null value. |
private java.lang.String |
getJndiName(java.lang.String jndiName,
MethodAnnotationMetadata methodMetaData)
Ensures that jndiName is valid and return the default value if it is a null value. |
private boolean |
isEnvEntry(org.objectweb.asm.Type type)
Return true if the given type is a type used in env-entry. |
private boolean |
isJNDIResourceInjection(java.lang.String itfName)
If the resource is a JNDI resource injection, return true. This is the case of DataSource, JMS Queues/Topics & JMS factories, etc. |
private int |
setField()
|
private void |
setField(org.objectweb.asm.MethodVisitor mv,
java.lang.String className,
FieldAnnotationMetadata fieldMetaData,
org.objectweb.asm.Type type)
Sets the value of a field. |
private void |
validateAccessFieldAnnotation(FieldAnnotationMetadata field)
Check that the annotation is not used on a final field or static field (except client mode). |
private void |
validateAccessMethodAnnotation(MethodAnnotationMetadata methodData)
Check that the annotation is not used on a final field or static field (except client mode). |
private org.objectweb.asm.Type |
validateSetterMethod(MethodAnnotationMetadata methodMetaData)
Ensure that this method is a valid setter method and return ASM type of the first arg of the method. |
void |
visitEnd()
Visits the end of the class. |
Methods inherited from class org.objectweb.asm.ClassAdapter |
---|
visit, visitAnnotation, visitAttribute, visitField, visitInnerClass, visitMethod, visitOuterClass, visitSource |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static JLog logger
private ClassAnnotationMetadata classAnnotationMetadata
private java.util.Map<java.lang.String,java.lang.Object> map
private boolean staticMode
private static final java.lang.String SESSION_CONTEXT
private static final java.lang.String MESSAGEDRIVEN_CONTEXT
private static final java.lang.String ORB_ITF
private static final java.lang.String DATASOURCE_ITF
private static final java.lang.String USERTRANSACTION_ITF
private static final java.lang.String QUEUE_ITF
private static final java.lang.String QUEUECONNECTIONFACTORY_ITF
private static final java.lang.String TOPIC_ITF
private static final java.lang.String TOPICCONNECTIONFACTORY_ITF
private static final java.lang.String ENTITYMANAGER_ITF
private static final java.lang.String ENTITYMANAGERFACTORY_ITF
private static final java.lang.String TIMERSERVICE_ITF
private static final java.lang.String EZB_EJBCONTEXT_DESC
public static final java.lang.String JAVA_LANG_OBJECT
public static final java.lang.String INJECTED_METHOD
public static final JMethod INJECTED_JMETHOD
public static final java.lang.String[] INJECTED_METHODS
private static final int LENGTH
Constructor Detail |
---|
public InjectionClassAdapter(ClassAnnotationMetadata classAnnotationMetadata, org.objectweb.asm.ClassVisitor cv, java.util.Map<java.lang.String,java.lang.Object> map, boolean staticMode)
classAnnotationMetadata
- object containing all attributes of the
classcv
- the class visitor to which this adapter must delegate calls.map
- a map allowing to give some objects to the adapter.staticMode
- - Is that generated method is static (client case).Method Detail |
---|
public void visitEnd()
visitEnd
in interface org.objectweb.asm.ClassVisitor
visitEnd
in class org.objectweb.asm.ClassAdapter
private void addDefaultMethods()
private void addInjectedMethod()
private void generateBodyInjectedMethod(org.objectweb.asm.MethodVisitor mv)
mv
- the method visitor object used to add some code.private void generateClassInjection(org.objectweb.asm.MethodVisitor mv)
mv
- the method visitor used to inject bytecode.private void generateAttributesInjection(org.objectweb.asm.MethodVisitor mv)
mv
- the method visitor used to inject bytecode.private void generateSettersInjection(org.objectweb.asm.MethodVisitor mv)
mv
- the method visitor used to inject bytecode.private org.objectweb.asm.Type validateSetterMethod(MethodAnnotationMetadata methodMetaData)
methodMetaData
- the metadata to check
private boolean isEnvEntry(org.objectweb.asm.Type type)
type
- an ASM type.
private void addCallGetEasyBeansContext(org.objectweb.asm.MethodVisitor mv, java.lang.String castDesc)
mv
- the method visitor on which instructions are addedcastDesc
- the cast to do.private void addCallEntityManagerHelper(JavaxPersistenceContext javaxPersistenceContext, org.objectweb.asm.MethodVisitor mv)
javaxPersistenceContext
- informations on the persistence contextmv
- the method visitor on which instructions are addedprivate void addCallEntityManagerFactoryHelper(JavaxPersistenceUnit javaxPersistenceUnit, org.objectweb.asm.MethodVisitor mv)
javaxPersistenceUnit
- informations on the persistence unitmv
- the method visitor on which instructions are addedprivate void callJndi(java.lang.String jndiName, org.objectweb.asm.Type type, org.objectweb.asm.MethodVisitor mv, java.lang.String className, JNDILookupHelper.JndiType jndiType)
jndiName
- the name to lookup.type
- the ASM typemv
- the method visitor to write code.className
- the name of the generated class.jndiType
- the type of access (registry, java:comp/env, etc)private void callAttributeJndi(java.lang.String jndiName, org.objectweb.asm.Type type, org.objectweb.asm.MethodVisitor mv, FieldAnnotationMetadata fieldMetaData, java.lang.String className, JNDILookupHelper.JndiType jndiType)
jndiName
- the name to lookup.type
- the ASM type.mv
- the method visitor to write code.fieldMetaData
- the metadata of the attribute.className
- the name of the generated class.jndiType
- the type of access (registry, java:comp/env, etc)private void setField(org.objectweb.asm.MethodVisitor mv, java.lang.String className, FieldAnnotationMetadata fieldMetaData, org.objectweb.asm.Type type)
mv
- the method visitor to useclassName
- the class which contains the attribute.fieldMetaData
- the metadata corresponding to the attributetype
- the ASM type of the attributeprivate void callSetterMethod(org.objectweb.asm.MethodVisitor mv, java.lang.String className, MethodAnnotationMetadata methodMetaData, org.objectweb.asm.Type type)
mv
- the method visitor to useclassName
- the class which contains the method.methodMetaData
- the metadata corresponding to the method *type
- the ASM type of the methodprivate void callMethodJndiEnv(java.lang.String jndiName, org.objectweb.asm.Type type, org.objectweb.asm.MethodVisitor mv, MethodAnnotationMetadata methodMetaData, java.lang.String className, JNDILookupHelper.JndiType jndiType)
jndiName
- the name to lookup.type
- the ASM type.mv
- the method visitor to write code.methodMetaData
- the metadata of the method.className
- the name of the generated class.jndiType
- the type of access (registry, java:comp/env, etc)private java.lang.String getJndiName(java.lang.String jndiName, FieldAnnotationMetadata fieldAnnotationMetadata)
jndiName
- to checkfieldAnnotationMetadata
- attribute's metadata
private java.lang.String getJndiName(java.lang.String jndiName, MethodAnnotationMetadata methodMetaData)
jndiName
- to checkmethodMetaData
- attribute's metadata
private void callBindAttributeJndi(java.lang.String encName, java.lang.String jndiName, org.objectweb.asm.MethodVisitor mv, FieldAnnotationMetadata fieldMetaData)
encName
- the name to bindjndiName
- the name to link to (LinkRef)mv
- the method visitor to write code.fieldMetaData
- the metadata of the attribute (that will be bound)private void callBindLookupJndiRef(java.lang.String encName, java.lang.String jndiName, org.objectweb.asm.MethodVisitor mv)
encName
- the name to bindjndiName
- the jndi name to use for the linkmv
- the method visitor to write code.private void bindClassEJB(JEjbEJB jEJB, org.objectweb.asm.MethodVisitor mv)
jEJB
- annotation to analyzemv
- the visitor on which write the bytecode.private void bindResource(JAnnotationResource jAnnotationResource, org.objectweb.asm.MethodVisitor mv)
jAnnotationResource
- annotation to analyzemv
- the visitor on which write the bytecode.private void bindClassPersistenceContext(JavaxPersistenceContext javaxPersistenceContext, org.objectweb.asm.MethodVisitor mv)
javaxPersistenceContext
- annotation to analyzemv
- the visitor on which write the bytecode.private void bindClassPersistenceUnit(JavaxPersistenceUnit javaxPersistenceUnit, org.objectweb.asm.MethodVisitor mv)
javaxPersistenceUnit
- annotation to analyzemv
- the visitor on which write the bytecode.private int setField()
private void validateAccessFieldAnnotation(FieldAnnotationMetadata field)
field
- the attribute to check.private void validateAccessMethodAnnotation(MethodAnnotationMetadata methodData)
methodData
- the method to check.private boolean accessTest(int access, int checkedAccess)
access
- the full access modified to checkcheckedAccess
- the access to check
private boolean isJNDIResourceInjection(java.lang.String itfName)
itfName
- the name of the interface to check.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |