}
IJAnnotationResource jAnnotationResource = methodMetaData.getJAnnotationResource();
// @Resource annotation
if (jAnnotationResource != null) {
Type typeInterface = validateSetterMethod(methodMetaData);
String itfName = typeInterface.getClassName();
// Set default name if not present.
jAnnotationResource.setName(getJndiName(jAnnotationResource.getName(), methodMetaData));
// Update annotation value with data set on the class
updateAnnotationResource(jAnnotationResource);
// Get lookup / Mapped Name
String lookupName = jAnnotationResource.getLookup();
String mappedName = jAnnotationResource.getMappedName();
// Use MessageDestinationLink if present !
String messageDestinationLink = jAnnotationResource.getMessageDestinationLink();
if (messageDestinationLink != null) {
try {
mappedName = this.containerJNDIResolver.getMessageDestinationJNDIUniqueName(messageDestinationLink);
} catch (EZBJNDIResolverException e) {
throw new IllegalStateException("No JNDI name found when analyzing @Resource annotation '"
+ jAnnotationResource + "' for the class '" + this.classAnnotationMetadata.getClassName()
+ "'.", e);
}
}
// Env-Entry
if (isEnvEntry(typeInterface)) {
JndiType type = JAVA_COMP_ENV;
// Lookup name exists ?
if (lookupName == null) {
lookupName = jAnnotationResource.getName();
}
if (lookupName.startsWith("java:")) {
type = JAVA;
}
callMethodJndiEnv(lookupName, typeInterface, mv, methodMetaData,
this.classAnnotationMetadata.getClassName(), type);
} else if (USERTRANSACTION_ITF.equals(itfName)) {
callMethodJndiEnv("UserTransaction", typeInterface, mv, methodMetaData,
this.classAnnotationMetadata.getClassName(), JAVA_COMP);
callBindLookupJndiRef(jAnnotationResource.getName(), "java:comp/UserTransaction", mv);
} else if (TIMERSERVICE_ITF.equals(itfName)) {
// add call to : setterMethod(getEasyBeansContext().getInternalTimerService());
mv.visitVarInsn(ALOAD, 0);
addCallGetEasyBeansContext(mv, null);
mv.visitMethodInsn(INVOKEINTERFACE, "org/ow2/easybeans/api/container/EZBEJBContext",
"getInternalTimerService", "()Ljavax/ejb/TimerService;");
mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), methodMetaData.getMethodName(),
"(Ljavax/ejb/TimerService;)V");
callBindLookupJndiRef(jAnnotationResource.getName(), "java:comp/TimerService", mv);
} else if (SESSION_CONTEXT.equals(itfName)) {
// add call to : setterMethod(getEasyBeansContext());
mv.visitVarInsn(ALOAD, 0);
addCallGetEasyBeansContext(mv, "javax/ejb/SessionContext");
mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), methodMetaData.getMethodName(),
"(Ljavax/ejb/SessionContext;)V");
// Define the type (if missing)
jAnnotationResource.setType(SESSION_CONTEXT);
bindResource(jAnnotationResource, mv);
} else if (MESSAGEDRIVEN_CONTEXT.equals(itfName)) {
// add call to : setterMethod(getEasyBeansContext());
mv.visitVarInsn(ALOAD, 0);
addCallGetEasyBeansContext(mv, "javax/ejb/MessageDrivenContext");
mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), methodMetaData.getMethodName(),
"(Ljavax/ejb/MessageDrivenContext;)V");
// Define the type (if missing)
jAnnotationResource.setType(MESSAGEDRIVEN_CONTEXT);
bindResource(jAnnotationResource, mv);
} else if (EJBCONTEXT.equals(itfName)) {
// add call to : setterMethod(getEasyBeansContext());
mv.visitVarInsn(ALOAD, 0);
addCallGetEasyBeansContext(mv, "javax/ejb/EJBContext");
mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), methodMetaData.getMethodName(),
"(Ljavax/ejb/EJBContext;)V");
// Define the type (if missing)
jAnnotationResource.setType(EJBCONTEXT);
bindResource(jAnnotationResource, mv);
} else if (ORB_ITF.equals(itfName)) {
callMethodJndiEnv("ORB", typeInterface, mv, methodMetaData,
this.classAnnotationMetadata.getClassName(), JAVA_COMP);
callBindLookupJndiRef(jAnnotationResource.getName(), "java:comp/ORB", mv);
} else if (URL_ITF.equals(itfName)) {
// Bind object in java:comp/env
callBindLookupURLRef(jAnnotationResource.getName(), mappedName, mv);
// Get JNDI value from registry and call setter method
callMethodJndiEnv(jAnnotationResource.getName(), typeInterface, mv, methodMetaData,
this.classAnnotationMetadata.getClassName(), JAVA_COMP_ENV);
} else if (lookupName != null && !lookupName.equals("")) {
JndiType type = REGISTRY;
// Lookup name ?
if (lookupName.startsWith("java:")) {
type = JAVA;
}
callMethodJndiEnv(lookupName, typeInterface, mv, methodMetaData,
this.classAnnotationMetadata.getClassName(), type);
} else if (mappedName != null && !mappedName.equals("")) {
// Get JNDI value from registry and call setter method
callMethodJndiEnv(mappedName, typeInterface, mv, methodMetaData,
this.classAnnotationMetadata.getClassName(), REGISTRY);
// Then bind attribute in ENC
callBindLookupJndiRef(jAnnotationResource.getName(), mappedName, mv);
}
}
// @EJB annotation
IJEjbEJB jEjb = methodMetaData.getJEjbEJB();
if (jEjb != null) {
logger.debug("Add injection for EJB on method {0} of class {1}", methodMetaData.getMethodName(),
this.classAnnotationMetadata.getClassName());
Type typeInterface = validateSetterMethod(methodMetaData);
String itfName = typeInterface.getClassName();
// ejbName ?
String beanName = jEjb.getBeanName();
// JNDI name
String jndiName = null;
// Mapped Name ? if not null, use it as JNDI name
String mappedName = jEjb.getMappedName();
if (mappedName != null && !mappedName.equals("")) {
jndiName = mappedName;
}
// JNDI name still null, ask the JNDI resolver
if (jndiName == null) {
try {
jndiName = this.containerJNDIResolver.getEJBJNDIUniqueName(itfName, beanName);
} catch (EZBJNDIResolverException e) {
logger.error("Cannot find JNDI Name on class {0} for interface {1} and beanName {2}. Result = {3}",
this.classAnnotationMetadata.getClassName(), itfName, beanName);
}
}
// Not null, bind it
if (jndiName != null) {
logger.debug("Asking jndi name on class {0} for interface {1} and beanName {2}. Result = {3}",
this.classAnnotationMetadata.getClassName(), itfName, beanName, jndiName);
callMethodJndiEnv(jndiName, typeInterface, mv, methodMetaData, this.classAnnotationMetadata
.getClassName(), REGISTRY);
// get enc name (or the default name) and bind result
String encName = getJndiName(jEjb.getName(), methodMetaData);
callBindLookupJndiRef(encName, jndiName, mv);
}
}
// @PersistenceContext annotation
if (methodMetaData.isPersistenceContext()) {
Type typeInterface = validateSetterMethod(methodMetaData);
String itfName = typeInterface.getClassName();
// Check that arg of the method is EntityManager
if (!ENTITYMANAGER_ITF.equals(itfName)) {
throw new IllegalStateException(
"Trying to applied @PersistenceContext on an invalid method in the class '"
+ this.classAnnotationMetadata.getClassName() + "', method = " + methodMetaData);
}
logger.debug("Add injection for PersistenceContext on method {0} of class {1}", methodMetaData
.getMethodName(), this.classAnnotationMetadata.getClassName());
IJavaxPersistenceContext javaxPersistenceContext = methodMetaData.getJavaxPersistenceContext();
// add
// setterName(EntityManagerHelper.getEntityManager(getEasyBeansContext(),
// "myUnitName", PersistenceContextType.EXTENDED);
mv.visitVarInsn(ALOAD, 0);
// call em helper
addCallEntityManagerHelper(javaxPersistenceContext, mv);
// call setter method
mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), methodMetaData
.getMethodName(), "(Ljavax/persistence/EntityManager;)V");
// bind value in ENC environment
javaxPersistenceContext.setName(getJndiName(javaxPersistenceContext.getName(), methodMetaData));
bindClassPersistenceContext(javaxPersistenceContext, mv);
}
// @PersistenceUnit annotation
if (methodMetaData.isPersistenceUnit()) {
Type typeInterface = validateSetterMethod(methodMetaData);
String itfName = typeInterface.getClassName();
// Check that attribute is EntityManager
if (!ENTITYMANAGERFACTORY_ITF.equals(itfName)) {
throw new IllegalStateException(
"Trying to applied @PersistenceUnit on an invalid method in the class '"
+ this.classAnnotationMetadata.getClassName() + "', method = " + methodMetaData);
}
logger.debug("Add injection for PersistenceUnit on on method {0} of class {1}", methodMetaData
.getMethodName(), this.classAnnotationMetadata.getClassName());
IJavaxPersistenceUnit javaxPersistenceUnit = methodMetaData.getJavaxPersistenceUnit();
// add
// setterName(EntityManagerHelper.getEntityManagerFactory(getEasyBeansContext(),
// "myUnitName"));
mv.visitVarInsn(ALOAD, 0);
// get EMF
addCallEntityManagerFactoryHelper(javaxPersistenceUnit, mv);
// call setter method
mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), methodMetaData
.getMethodName(), "(Ljavax/persistence/EntityManagerFactory;)V");
// Bind value in JNDI
javaxPersistenceUnit.setName(getJndiName(javaxPersistenceUnit.getName(), methodMetaData));
bindClassPersistenceUnit(javaxPersistenceUnit, mv);
}
// @WebServiceRef annotation
IJaxwsWebServiceRef jWebServiceRef = methodMetaData.getJaxwsWebServiceRef();
if (jWebServiceRef != null) {
Type typeInterface = validateSetterMethod(methodMetaData);
// Validate
validateAccessMethodAnnotation(methodMetaData);
// Perform a java:comp/env lookup