public EjbRefElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) { super(member, pd); EJB resource = ae.getAnnotation(EJB.class); String resourceBeanName = resource.beanName(); String resourceName = resource.name(); this.isDefaultName = !StringUtils.hasLength(resourceName); if (this.isDefaultName) { resourceName = this.member.getName(); if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) { resourceName = Introspector.decapitalize(resourceName.substring(3)); } } Class<?> resourceType = resource.beanInterface(); if (Object.class != resourceType) { checkResourceType(resourceType); } else { // No resource type specified... check field/method. resourceType = getResourceType(); } this.beanName = resourceBeanName; this.name = resourceName; this.lookupType = resourceType; this.mappedName = resource.mappedName(); }
public EjbRefElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) { super(member, pd); EJB resource = ae.getAnnotation(EJB.class); String resourceBeanName = resource.beanName(); String resourceName = resource.name(); this.isDefaultName = !StringUtils.hasLength(resourceName); if (this.isDefaultName) { resourceName = this.member.getName(); if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) { resourceName = Introspector.decapitalize(resourceName.substring(3)); } } Class<?> resourceType = resource.beanInterface(); if (Object.class != resourceType) { checkResourceType(resourceType); } else { // No resource type specified... check field/method. resourceType = getResourceType(); } this.beanName = resourceBeanName; this.name = resourceName; this.lookupType = resourceType; this.mappedName = resource.mappedName(); }
/** * Constructs EjbReference. * * @param ejbAnnotation ejb annotation * @param type fall back type * @return ejb reference instance */ private EjbReference getEjbReference(final EJB ejbAnnotation, final Class<?> type) { String beanInterface = ejbAnnotation.beanInterface().getName(); if (java.lang.Object.class.getName().equals(beanInterface)) { beanInterface = type.getName(); } return new EjbReference(ejbAnnotation.beanName(), beanInterface, ejbAnnotation.mappedName()); }
/** * Constructs EjbReference. * * @param ejbAnnotation ejb annotation * @param type fall back type * @return ejb reference instance */ private EjbReference getEjbReference(final EJB ejbAnnotation, final Class<?> type) { String beanInterface = ejbAnnotation.beanInterface().getName(); if (java.lang.Object.class.getName().equals(beanInterface)) { beanInterface = type.getName(); } return new EjbReference(ejbAnnotation.beanName(), beanInterface, ejbAnnotation.mappedName()); }
/** * Constructs EjbReference. * * @param ejbAnnotation ejb annotation * @param type fall back type * @return ejb reference instance */ private EjbReference getEjbReference(final EJB ejbAnnotation, final Class<?> type) { String beanInterface = ejbAnnotation.beanInterface().getName(); if (java.lang.Object.class.getName().equals(beanInterface)) { beanInterface = type.getName(); } return new EjbReference(ejbAnnotation.beanName(), beanInterface, ejbAnnotation.mappedName()); }
protected final void processSetterInjections() { Object home = null; ClassFinder finder = null; List<Method> methodList = null; finder = new ClassFinder(getClassPath()); methodList = finder.findAnnotatedMethods(EJB.class); for(Iterator methods = methodList.iterator(); methods.hasNext();) { Method method = (Method) methods.next(); EJB ejbAnnotation = method.getAnnotation(EJB.class); if( (ejbAnnotation.name() != null) && (ejbAnnotation.name() != "") && (ejbAnnotation.beanInterface() != null)) { try { home = initialContext.lookup(ejbAnnotation.name()); // home = ejbAnnotation.beanInterface().cast(PortableRemoteObject.narrow(home, ejbAnnotation.beanInterface())); home = cast(home, ejbAnnotation.beanInterface()); method.setAccessible(true); method.invoke(this, new Object[] {home}); } catch(Exception ex) { // TODO - MNour : Needs better exception handling ex.printStackTrace(); } } } }
protected final void processFieldInjections() { Object home = null; ClassFinder finder = null; List<Field> fieldList = null; finder = new ClassFinder(getClassPath()); fieldList = finder.findAnnotatedFields(EJB.class); for(Iterator fields = fieldList.iterator(); fields.hasNext();) { Field field = (Field) fields.next(); 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(PortableRemoteObject.narrow(home, ejbAnnotation.beanInterface())); home = cast(home, ejbAnnotation.beanInterface()); field.setAccessible(true); field.set(this, home); } catch(Exception ex) { // TODO - MNour : Needs better exception handling ex.printStackTrace(); } } } }
protected final void processSetterInjections() { Object home = null; ClassFinder finder = null; List<Method> methodList = null; finder = new ClassFinder(getClassPath()); methodList = finder.findAnnotatedMethods(EJB.class); for(final Iterator methods = methodList.iterator(); methods.hasNext();) { final Method method = (Method) methods.next(); final EJB ejbAnnotation = method.getAnnotation(EJB.class); if( (ejbAnnotation.name() != null) && (ejbAnnotation.name() != "") && (ejbAnnotation.beanInterface() != null)) { try { home = initialContext.lookup(ejbAnnotation.name()); // home = ejbAnnotation.beanInterface().cast(PortableRemoteObject.narrow(home, ejbAnnotation.beanInterface())); home = cast(home, ejbAnnotation.beanInterface()); method.setAccessible(true); method.invoke(this, new Object[] {home}); } catch(final Exception ex) { // TODO - MNour : Needs better exception handling ex.printStackTrace(); } } } }
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(PortableRemoteObject.narrow(home, ejbAnnotation.beanInterface())); home = cast(home, ejbAnnotation.beanInterface()); field.setAccessible(true); field.set(this, home); } catch(final Exception ex) { // TODO - MNour : Needs better exception handling ex.printStackTrace(); } } } }
public EjbRefElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) { super(member, pd); EJB resource = ae.getAnnotation(EJB.class); String resourceBeanName = resource.beanName(); String resourceName = resource.name(); this.isDefaultName = !StringUtils.hasLength(resourceName); if (this.isDefaultName) { resourceName = this.member.getName(); if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) { resourceName = Introspector.decapitalize(resourceName.substring(3)); } } Class<?> resourceType = resource.beanInterface(); if (Object.class != resourceType) { checkResourceType(resourceType); } else { // No resource type specified... check field/method. resourceType = getResourceType(); } this.beanName = resourceBeanName; this.name = resourceName; this.lookupType = resourceType; this.mappedName = resource.mappedName(); }
private ConfigProgram generateContext(AnnotatedMethod<?> method, EJB ejb) throws ConfigException { String name = ejb.name(); Method javaMethod = method.getJavaMember(); String location = getLocation(javaMethod); Class<?> bindType = javaMethod.getParameterTypes()[0]; // ejb/2005 if (! Object.class.equals(ejb.beanInterface())) { bindType = ejb.beanInterface(); } ValueGenerator gen = bindGenerator(location, ejb, bindType); if (name != null && ! "".equals(name)) { bindJndi(name, gen, name); } bindJndi(javaMethod, gen); return new MethodGeneratorProgram(javaMethod, gen); }
protected void handleClassAnnotation(EJB ejb, Class<?> clazz, InjectionContainer container) { String encName = ejb.name(); if (encName == null || encName.equals("")) { throw new RuntimeException("JBoss requires the name of the @EJB in the @EJBs: " + clazz); } encName = "env/" + encName; if (container.getEncInjectors().containsKey(encName)) return; ejbRefEncInjector(ejb.mappedName(), encName, null, ejb.beanInterface(), ejb.beanName(), "@EJB", container); // handle dependencies if (isIgnoreDependency(container, ejb)) log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName); else ejbRefDependency(ejb.mappedName(), ejb.beanName(), container, ejb.beanInterface(), "@EJB", encName); }
protected void handleClassAnnotation(EJB ejb, Class<?> clazz, InjectionContainer container) { String encName = ejb.name(); if (encName == null || encName.equals("")) { throw new RuntimeException("JBoss requires the name of the @EJB in the @EJBs: " + clazz); } encName = "env/" + encName; if (container.getEncInjectors().containsKey(encName)) return; ejbRefEncInjector(ejb.mappedName(), encName, null, ejb.beanInterface(), ejb.beanName(), "@EJB", container); // handle dependencies if (isIgnoreDependency(container, ejb)) log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName); else ejbRefDependency(ejb.mappedName(), ejb.beanName(), container, ejb.beanInterface(), "@EJB", encName); }
public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors) { EJB ref = container.getAnnotation(EJB.class, method); if (ref != null) { if (!method.getName().startsWith("set")) throw new RuntimeException("@EJB can only be used with a set method: " + method); String encName = getEncName(ref, method); if (!container.getEncInjectors().containsKey(encName)) { Class<?> businessInterface = method.getParameterTypes()[0]; if (ref.beanInterface() != null && ref.beanInterface() != Object.class) { businessInterface = ref.beanInterface(); } ejbRefEncInjector(ref.mappedName(), encName, method.getName().substring(0), businessInterface, ref.beanName(), "@EJB", container); if (container.getAnnotation(IgnoreDependency.class, method) == null) { if (isIgnoreDependency(container, ref)) log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName); else ejbRefDependency(ref.mappedName(), ref.beanName(), container, businessInterface, "@EJB", encName); } } super.handleMethodAnnotations(method, container, injectors); } }
if (!ref.beanInterface().getName().equals(Object.class.getName())) businessInterface = ref.beanInterface();
private void introspectClass(String location, EJB ejb) { String name = ejb.name(); Class<?> bindType = ejb.beanInterface(); if ("".equals(name)) throw new ConfigException(L.l("{0}: @EJB name() attribute is required for @EJB on a class.", location)); if (Object.class.equals(bindType)) throw new ConfigException(L.l("{0}: @EJB beanInterface() attribute is required for @EJB on a class.", location)); ValueGenerator gen = bindGenerator(location, ejb, bindType); if (name != null && ! "".equals(name)) { bindJndi(name, gen, name); } }
public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors) { EJB ref = container.getAnnotation(EJB.class, field); if (ref != null) { String encName = getEncName(ref, field); if (!container.getEncInjectors().containsKey(encName)) { Class<?> businessInterface = field.getType(); if (ref.beanInterface() != null && ref.beanInterface() != Object.class) { businessInterface = ref.beanInterface(); } if (container.getAnnotation(IgnoreDependency.class, field) == null) { if (isIgnoreDependency(container, ref)) log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName); else ejbRefDependency(ref.mappedName(), ref.beanName(), container, businessInterface, "@EJB", encName); } ejbRefEncInjector(ref.mappedName(), encName, field.getName(), businessInterface, ref.beanName(), "@EJB", container); } super.handleFieldAnnotations(field, container, injectors); } }
/** * Create @EJB value meta data. * * @param annotation * @return @EJB metadata */ @Override protected ValueMetaData createValueMetaData(FieldInfo propInfo, EJB annotation) { // Get properties from the annotation String beanName = annotation.beanName(); String beanInterface = annotation.beanInterface().getName(); String mappedName = annotation.mappedName(); // Supply beanInterface from reflection if not explicitly-defined if (beanInterface == null || beanInterface.equals(Object.class.getName())) { String reflectType = propInfo.getType().getName(); beanInterface = reflectType; } // Create a reference EjbReference reference = new EjbReference(beanName, beanInterface, mappedName); log.debug("Found @EJB reference " + reference); // Return a new ValueMetaData w/ the reference return new AbstractEjbReferenceValueMetadata(this.getResolver(), reference, this.getNamingContext()); }
protected AnnotatedEJBReferenceMetaData createEJB(EJB annotation, E element) { AnnotatedEJBReferenceMetaData ref = new AnnotatedEJBReferenceMetaData(); if(annotation.name().length() > 0) ref.setEjbRefName(annotation.name()); else ref.setEjbRefName(getName(element)); if(annotation.beanInterface() != Object.class) ref.setBeanInterface(annotation.beanInterface()); else ref.setBeanInterface(getType(element)); if(annotation.description().length() > 0) { DescriptionImpl description = new DescriptionImpl(); description.setDescription(annotation.description()); DescriptionsImpl descriptions = new DescriptionsImpl(); descriptions.add(description); ref.setDescriptions(descriptions); } if(annotation.beanName().length() > 0) ref.setLink(annotation.beanName()); if(annotation.mappedName().length() > 0) ref.setMappedName(annotation.mappedName()); return ref; } }
protected AnnotatedEJBReferenceMetaData createEJB(EJB annotation, E element) { AnnotatedEJBReferenceMetaData ref = new AnnotatedEJBReferenceMetaData(); if(annotation.name().length() > 0) ref.setEjbRefName(annotation.name()); else ref.setEjbRefName(getName(element)); if(annotation.beanInterface() != Object.class) ref.setBeanInterface(annotation.beanInterface()); else ref.setBeanInterface(getType(element)); if(annotation.description().length() > 0) { DescriptionImpl description = new DescriptionImpl(); description.setDescription(annotation.description()); DescriptionsImpl descriptions = new DescriptionsImpl(); descriptions.add(description); ref.setDescriptions(descriptions); } if(annotation.beanName().length() > 0) ref.setLink(annotation.beanName()); if(annotation.mappedName().length() > 0) ref.setMappedName(annotation.mappedName()); String name = ProcessorUtils.getName(element); Set<ResourceInjectionTargetMetaData> injectionTargets = ProcessorUtils.getInjectionTargets(name, element); if(injectionTargets != null) ref.setInjectionTargets(injectionTargets); return ref; }