public ResourceElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) { super(member, pd); Resource resource = ae.getAnnotation(Resource.class); String resourceName = resource.name(); Class<?> resourceType = resource.type(); 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)); } } else if (embeddedValueResolver != null) { resourceName = embeddedValueResolver.resolveStringValue(resourceName); } if (Object.class != resourceType) { checkResourceType(resourceType); } else { // No resource type specified... check field/method. resourceType = getResourceType(); } this.name = (resourceName != null ? resourceName : ""); this.lookupType = resourceType; String lookupValue = resource.lookup(); this.mappedName = (StringUtils.hasLength(lookupValue) ? lookupValue : resource.mappedName()); Lazy lazy = ae.getAnnotation(Lazy.class); this.lazyLookup = (lazy != null && lazy.value()); }
public ResourceElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) { super(member, pd); Resource resource = ae.getAnnotation(Resource.class); String resourceName = resource.name(); Class<?> resourceType = resource.type(); 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)); } } else if (embeddedValueResolver != null) { resourceName = embeddedValueResolver.resolveStringValue(resourceName); } if (Object.class != resourceType) { checkResourceType(resourceType); } else { // No resource type specified... check field/method. resourceType = getResourceType(); } this.name = (resourceName != null ? resourceName : ""); this.lookupType = resourceType; String lookupValue = resource.lookup(); this.mappedName = (StringUtils.hasLength(lookupValue) ? lookupValue : resource.mappedName()); Lazy lazy = ae.getAnnotation(Lazy.class); this.lazyLookup = (lazy != null && lazy.value()); }
protected String getResourceName(InjectionPoint injectionPoint) { Resource resource = getResourceAnnotated(injectionPoint).getAnnotation(Resource.class); String mappedName = resource.mappedName(); String lookup = resource.lookup(); if (!lookup.isEmpty()) { return lookup; } if (!mappedName.isEmpty()) { return mappedName; } String proposedName = ResourceInjectionUtilities.getResourceName(injectionPoint); return getEJBResourceName(injectionPoint, proposedName); }
private boolean isManagedBeanReference(Class<?> resourceTypeClass, Resource annotation) { // Check if this is @Resource managedBean injection. Handle two cases: // 1) @Resource managedBeanClass; or // 2) @Resource(lookup='...') managedBeanInterfaceClass; if (resourceTypeClass.isAnnotationPresent(ManagedBean.class) || (resourceTypeClass.isInterface() && annotation.lookup().length() != 0)) { return true; } return false; } }
private String getResourceName(InjectionPoint ip) { Resource resourceAnnotation = ip.getAnnotated().getAnnotation(Resource.class); String name = resourceAnnotation.mappedName(); if (name.trim().isEmpty()) { name = resourceAnnotation.lookup(); if (name.trim().isEmpty()) { name = "dummyName"; } } return name; }
@Override public Object resolveResource(InjectionPoint injectionPoint) { Resource resource = getResourceAnnotation(injectionPoint); if (resource == null) { throw new IllegalArgumentException("No @Resource annotation found on " + injectionPoint); } if (injectionPoint.getMember() instanceof Method && ((Method) injectionPoint.getMember()).getParameterTypes().length != 1) { throw new IllegalArgumentException( "Injection point represents a method which doesn't follow JavaBean conventions (must have exactly one parameter) " + injectionPoint); } String name; if (!resource.lookup().equals("")) { name = resource.lookup(); } else { name = getResourceName(injectionPoint); } return resources.get(name); }
@Override public Object resolveResource(InjectionPoint injectionPoint) { Resource resource = getResourceAnnotation(injectionPoint); if (resource == null) { throw new IllegalArgumentException("No @Resource annotation found on " + injectionPoint); } if (injectionPoint.getMember() instanceof Method && ((Method) injectionPoint.getMember()).getParameterTypes().length != 1) { throw new IllegalArgumentException( "Injection point represents a method which doesn't follow JavaBean conventions (must have exactly one parameter) " + injectionPoint); } String name; if (!resource.lookup().equals("")) { name = resource.lookup(); } else { name = getResourceName(injectionPoint); } return resources.get(name); }
/** * {@inheritDoc} */ @Nonnull protected <T> MembersInjector<T> createInjector( @Nonnull final TypeEncounter<T> typeEncounter, @Nonnull final Annotation annotation, @Nonnull final Field field ) { final Resource resource = (Resource) annotation; final String name = resource.name(); final String key = resource.lookup(); if ( !"".equals( key ) ) { return FieldBasedInjector.createFromEncounter( typeEncounter, key, field ); } else if ( !"".equals( name ) ) { return FieldBasedInjector.createFromEncounter( typeEncounter, name, field ); } else { return FieldBasedInjector.createFromEncounter( typeEncounter, field ); } } }
/** * Return the value of the "lookup" element of the @Resource annotation. * This method handles the case where the Resource class is an older * version before the lookup element was added; in that case access to * the lookup element will cause a NoSuchMethodError, which is caught * and ignored (with a warning message). * * @return the value of the lookup element */ private String getResourceLookupValue(Resource annotation, AnnotationInfo ainfo) { String lookupValue = ""; try { lookupValue = annotation.lookup(); } catch(NoSuchMethodError nsme) { // Probably means lib endorsed dir is not set and an older version // of Resource is being picked up from JDK. // Don't treat this as a fatal error. try { log(Level.WARNING, ainfo, localStrings.getLocalString( "enterprise.deployment.annotation.handlers.wrongresourceclass", "Incorrect @Resource annotation class definition - " + "missing lookup attribute")); } catch (AnnotationProcessorException ex) { } } return lookupValue; } }
/** * Return the value of the "lookup" element of the @Resource annotation. * This method handles the case where the Resource class is an older * version before the lookup element was added; in that case access to * the lookup element will cause a NoSuchMethodError, which is caught * and ignored (with a warning message). * * @return the value of the lookup element */ private String getResourceLookupValue(Resource annotation, AnnotationInfo ainfo) { String lookupValue = ""; try { lookupValue = annotation.lookup(); } catch(NoSuchMethodError nsme) { // Probably means lib endorsed dir is not set and an older version // of Resource is being picked up from JDK. // Don't treat this as a fatal error. try { log(Level.WARNING, ainfo, localStrings.getLocalString( "enterprise.deployment.annotation.handlers.wrongresourceclass", "Incorrect @Resource annotation class definition - " + "missing lookup attribute")); } catch (AnnotationProcessorException ex) { } } return lookupValue; } }
@Override protected String getResourceName(InjectionPoint injectionPoint) { Resource resource = injectionPoint.getAnnotated().getAnnotation(Resource.class); String mappedName = resource.mappedName(); String lookup = resource.lookup(); if (!lookup.isEmpty()) { return lookup; } if (!mappedName.isEmpty()) { return mappedName; } String proposedName = super.getResourceName(injectionPoint); return getEJBResourceName(injectionPoint, proposedName); }
public ResourceElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) { super(member, pd); Resource resource = ae.getAnnotation(Resource.class); String resourceName = resource.name(); Class<?> resourceType = resource.type(); 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)); } } else if (embeddedValueResolver != null) { resourceName = embeddedValueResolver.resolveStringValue(resourceName); } if (Object.class != resourceType) { checkResourceType(resourceType); } else { // No resource type specified... check field/method. resourceType = getResourceType(); } this.name = (resourceName != null ? resourceName : ""); this.lookupType = resourceType; String lookupValue = resource.lookup(); this.mappedName = (StringUtils.hasLength(lookupValue) ? lookupValue : resource.mappedName()); Lazy lazy = ae.getAnnotation(Lazy.class); this.lazyLookup = (lazy != null && lazy.value()); }
String lookup = annotation.lookup(); if (!lookup.isEmpty()) { messageDestinationRef.setLookupName(lookup);
String lookup = annotation.lookup(); if (!lookup.equals("")) { resourceRef.setLookupName(lookup);
String lookup = annotation.lookup(); if (!lookup.equals("")) { resourceEnvRef.setLookupName(lookup);
String lookup = annotation.lookup(); if (!lookup.equals("")) { envEntry.setLookupName(lookup);
resource.setDescription(annotation.description()); resource.setProperty(MAPPED_NAME_PROPERTY, annotation.mappedName()); resource.setLookupName(annotation.lookup()); service.setType(type); service.setDescription(annotation.description()); service.setLookupName(annotation.lookup()); resource.setProperty(MAPPED_NAME_PROPERTY, annotation.mappedName()); resource.setDescription(annotation.description()); resource.setLookupName(annotation.lookup()); resource.setUsage(annotation.mappedName()); resource.setDescription(annotation.description()); resource.setLookupName(annotation.lookup()); resource.setProperty(MAPPED_NAME_PROPERTY, annotation.mappedName()); resource.setDescription(annotation.description()); resource.setLookupName(annotation.lookup());
resource.setDescription(annotation.description()); resource.setProperty(MAPPED_NAME_PROPERTY, annotation.mappedName()); resource.setLookupName(annotation.lookup()); service.setType(type); service.setDescription(annotation.description()); service.setLookupName(annotation.lookup()); resource.setProperty(MAPPED_NAME_PROPERTY, annotation.mappedName()); resource.setDescription(annotation.description()); resource.setLookupName(annotation.lookup()); resource.setUsage(annotation.mappedName()); resource.setDescription(annotation.description()); resource.setLookupName(annotation.lookup()); resource.setProperty(MAPPED_NAME_PROPERTY, annotation.mappedName()); resource.setDescription(annotation.description()); resource.setLookupName(annotation.lookup());
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; }