use of javax.ejb.EJB in project Payara by payara.
the class EJBsHandler method processAnnotation.
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, ResourceContainerContext[] rcContexts) throws AnnotationProcessorException {
EJBs ejbsAnnotation = (EJBs) ainfo.getAnnotation();
EJB[] ejbAnnotations = ejbsAnnotation.value();
if (ejbAnnotations.length == 0) {
String localizedMsg = localStrings.getLocalString("enterprise.deployment.annotation.handlers.emptyEJBs", "No @EJB elements in @EJBs on " + ainfo.getAnnotatedElement(), new Object[] { ejbsAnnotation, ainfo.getAnnotatedElement() });
logger.log(Level.WARNING, localizedMsg);
}
List<HandlerProcessingResult> results = new ArrayList<HandlerProcessingResult>();
for (EJB ejb : ejbAnnotations) {
results.add(processEJB(ainfo, rcContexts, ejb));
}
return getOverallProcessingResult(results);
}
use of javax.ejb.EJB in project tomee by apache.
the class TestClient method processFieldInjections.
protected final void processFieldInjections() {
Object home = null;
ClassFinder finder = null;
List<Field> fieldList = null;
finder = new ClassFinder(getClassPath());
fieldList = finder.findAnnotatedFields(EJB.class);
for (final Iterator fields = fieldList.iterator(); fields.hasNext(); ) {
final Field field = (Field) fields.next();
final EJB ejbAnnotation = field.getAnnotation(EJB.class);
if ((ejbAnnotation.name() != null) && (ejbAnnotation.name() != "") && (ejbAnnotation.beanInterface() != null)) {
try {
home = initialContext.lookup(ejbAnnotation.name());
// home = ejbAnnotation.beanInterface().cast(home;
home = cast(home, ejbAnnotation.beanInterface());
field.setAccessible(true);
field.set(this, home);
} catch (final Exception ex) {
// TODO - MNour : Needs better exception handling
ex.printStackTrace();
}
}
}
}
use of javax.ejb.EJB in project tomee by apache.
the class LegacyAnnotationProcessor method processAnnotations.
/**
* Inject resources in specified instance.
* @param instance
* @throws java.lang.IllegalAccessException
* @throws java.lang.reflect.InvocationTargetException
* @throws javax.naming.NamingException
*/
public void processAnnotations(final Object instance) throws IllegalAccessException, InvocationTargetException, NamingException {
if (context == null) {
// No resource injection
return;
}
Class<?> clazz = instance.getClass();
while (clazz != null) {
// Initialize fields annotations
final Field[] fields = clazz.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
if (fields[i].isAnnotationPresent(Resource.class)) {
final Resource annotation = fields[i].getAnnotation(Resource.class);
lookupFieldResource(context, instance, fields[i], annotation.name(), clazz);
}
if (fields[i].isAnnotationPresent(EJB.class)) {
final EJB annotation = fields[i].getAnnotation(EJB.class);
lookupFieldResource(context, instance, fields[i], annotation.name(), clazz);
}
if (fields[i].isAnnotationPresent(WebServiceRef.class)) {
final WebServiceRef annotation = fields[i].getAnnotation(WebServiceRef.class);
lookupFieldResource(context, instance, fields[i], annotation.name(), clazz);
}
if (fields[i].isAnnotationPresent(PersistenceContext.class)) {
final PersistenceContext annotation = fields[i].getAnnotation(PersistenceContext.class);
lookupFieldResource(context, instance, fields[i], annotation.name(), clazz);
}
if (fields[i].isAnnotationPresent(PersistenceUnit.class)) {
final PersistenceUnit annotation = fields[i].getAnnotation(PersistenceUnit.class);
lookupFieldResource(context, instance, fields[i], annotation.name(), clazz);
}
}
// Initialize methods annotations
final Method[] methods = clazz.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
if (methods[i].isAnnotationPresent(Resource.class)) {
final Resource annotation = methods[i].getAnnotation(Resource.class);
lookupMethodResource(context, instance, methods[i], annotation.name(), clazz);
}
if (methods[i].isAnnotationPresent(EJB.class)) {
final EJB annotation = methods[i].getAnnotation(EJB.class);
lookupMethodResource(context, instance, methods[i], annotation.name(), clazz);
}
if (methods[i].isAnnotationPresent(WebServiceRef.class)) {
final WebServiceRef annotation = methods[i].getAnnotation(WebServiceRef.class);
lookupMethodResource(context, instance, methods[i], annotation.name(), clazz);
}
if (methods[i].isAnnotationPresent(PersistenceContext.class)) {
final PersistenceContext annotation = methods[i].getAnnotation(PersistenceContext.class);
lookupMethodResource(context, instance, methods[i], annotation.name(), clazz);
}
if (methods[i].isAnnotationPresent(PersistenceUnit.class)) {
final PersistenceUnit annotation = methods[i].getAnnotation(PersistenceUnit.class);
lookupMethodResource(context, instance, methods[i], annotation.name(), clazz);
}
}
clazz = clazz.getSuperclass();
}
}
use of javax.ejb.EJB in project Payara by payara.
the class InjectionServicesImpl method getLookupName.
/**
* Returns the JNDI name to lookup
* <p>
* This calls getJndiName with the appropriate arguments for the annotation type
* @param annotatedClass
* @param annotatedField
* @param injectionResources
* @return
*/
private String getLookupName(Class annotatedClass, AnnotatedField annotatedField, List<InjectionCapable> injectionResources) {
String lookupName = null;
if (annotatedField.isAnnotationPresent(Resource.class)) {
Resource resource = annotatedField.getAnnotation(Resource.class);
lookupName = getJndiName(resource.lookup(), resource.mappedName(), resource.name());
} else if (annotatedField.isAnnotationPresent(EJB.class)) {
EJB ejb = annotatedField.getAnnotation(EJB.class);
lookupName = getJndiName(ejb.lookup(), ejb.mappedName(), ejb.name());
} else if (annotatedField.isAnnotationPresent(WebServiceRef.class)) {
WebServiceRef webServiceRef = annotatedField.getAnnotation(WebServiceRef.class);
lookupName = getJndiName(webServiceRef.lookup(), webServiceRef.mappedName(), webServiceRef.name());
} else if (annotatedField.isAnnotationPresent(PersistenceUnit.class)) {
PersistenceUnit persistenceUnit = annotatedField.getAnnotation(PersistenceUnit.class);
lookupName = getJndiName(persistenceUnit.unitName(), null, persistenceUnit.name());
} else if (annotatedField.isAnnotationPresent(PersistenceContext.class)) {
PersistenceContext persistenceContext = annotatedField.getAnnotation(PersistenceContext.class);
lookupName = getJndiName(persistenceContext.unitName(), null, persistenceContext.name());
}
if (lookupName == null || lookupName.trim().length() == 0) {
lookupName = getComponentEnvName(annotatedClass, annotatedField.getJavaMember().getName(), injectionResources);
}
return lookupName;
}
use of javax.ejb.EJB in project Payara by payara.
the class InjectionServicesImpl method validateEjbProducer.
/**
* @param annotatedClass
* @param annotatedField
* @param injectionResources
*/
private void validateEjbProducer(Class annotatedClass, AnnotatedField annotatedField, List<InjectionCapable> injectionResources) {
EJB ejbAnnotation = annotatedField.getAnnotation(EJB.class);
if (ejbAnnotation != null) {
String lookupName = getLookupName(annotatedClass, annotatedField, injectionResources);
EjbDescriptor foundEjb = null;
Collection<EjbDescriptor> ejbs = deployment.getDeployedEjbs();
for (EjbDescriptor oneEjb : ejbs) {
String jndiName = oneEjb.getJndiName();
if (jndiName.isEmpty()) {
jndiName = oneEjb.getName();
}
if (lookupName.contains(jndiName)) {
foundEjb = oneEjb;
break;
}
}
if (foundEjb != null) {
String className = foundEjb.getEjbImplClassName();
try {
Class clazz = Class.forName(className, false, annotatedClass.getClassLoader());
validateResourceClass(annotatedField, clazz);
} catch (ClassNotFoundException ignore) {
}
}
}
}
Aggregations