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(); }
protected void initEjbAnnotatedDependency(Field field) throws NamingException { EJB annotation = field.getAnnotation(EJB.class); if (annotation == null) { return; } String name = annotation.beanName(); if (name == null || name.equals("")) { name = field.getName(); } inject(field, name); }
String beanNameOrName(EJB ejb) { if (!ejb.name().isEmpty()) { return ejb.name(); } else { return ejb.beanName(); } }
/** * 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()); }
/** * {@link EJB}アノテーションで指定されたセッションビーンを取得するOGNL式を返します。 * * @param ejb * {@link EJB}アノテーション * @return {@link EJB}アノテーションで指定されたセッションビーンを取得するOGNL式 */ protected String getExpression(final EJB ejb) { String name = ejb.beanName(); if (StringUtil.isEmpty(name)) { name = ejb.name(); } return name.replace('/', '.'); } }
/** * 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()); }
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)) { ejbRefEncInjector(ref.mappedName(), encName, method.getName().substring(0), method.getParameterTypes()[0], ref.beanName(), "@EJB", container); if (isIgnoreDependency(container, ref)) log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName); else ejbRefDependency(ref.mappedName(), ref.beanName(), container, method.getParameterTypes()[0], "@EJB", encName); } super.handleMethodAnnotations(method, container, injectors); } }
if (ref.beanName().equals("") && memberType == null) throw new RuntimeException("For deployment " + container.getIdentifier() + "not enough information for @EJB. Please fill out the beanName and/or businessInterface attributes"); if (ref.beanName().equals("")) rtn = (EJBContainer) container.resolveEjbContainer(ref.beanName(), businessInterface);
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(); }
/** * フィールドからコンポーネントの名前を解決します。 * * @param filed * フィールド * @return コンポーネント名 */ protected String resolveComponentName(final Field filed) { if (testContext.isEjb3Enabled()) { final EJB ejb = filed.getAnnotation(EJB.class); if (ejb != null) { if (!StringUtil.isEmpty(ejb.beanName())) { return ejb.beanName(); } else if (!StringUtil.isEmpty(ejb.name())) { return ejb.name(); } } } return normalizeName(filed.getName()); }
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); } }
private ViewDescription getViewDescription(EJB ejb, InjectionPoint injectionPoint) { final Set<ViewDescription> viewService; if (ejb.beanName().isEmpty()) { if (ejb.beanInterface() != Object.class) { viewService = applicationDescription.getComponentsForViewName(ejb.beanInterface().getName(), deploymentRoot); } else { viewService = applicationDescription.getComponentsForViewName(getType(injectionPoint.getType()).getName(), deploymentRoot); } } else { if (ejb.beanInterface() != Object.class) { viewService = applicationDescription.getComponents(ejb.beanName(), ejb.beanInterface().getName(), deploymentRoot); } else { viewService = applicationDescription.getComponents(ejb.beanName(), getType(injectionPoint.getType()).getName(), deploymentRoot); } } if (injectionPoint.getAnnotated().isAnnotationPresent(Produces.class)) { if (viewService.isEmpty()) { throw WeldLogger.ROOT_LOGGER.ejbNotResolved(ejb, injectionPoint.getMember()); } else if (viewService.size() > 1) { throw WeldLogger.ROOT_LOGGER.moreThanOneEjbResolved(ejb, injectionPoint.getMember(), viewService); } } else { if (viewService.isEmpty()) { return null; } else if (viewService.size() > 1) { return null; } } return viewService.iterator().next(); }
/** * 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()); }
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); } }
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; }