/** * Records metric producer fields defined by the application. Ignores producers * with non-default qualifiers and library producers. * * @param ppf Producer field. */ private void recordProducerFields(@Observes ProcessProducerField<? extends org.eclipse.microprofile.metrics.Metric, ?> ppf) { LOGGER.log(Level.FINE, () -> "### recordProducerFields " + ppf.getBean().getBeanClass()); if (!MetricProducer.class.equals(ppf.getBean().getBeanClass())) { Metric metric = ppf.getAnnotatedProducerField().getAnnotation(Metric.class); if (metric != null) { Optional<? extends Annotation> hasQualifier = ppf.getAnnotatedProducerField() .getAnnotations() .stream() .filter(annotation -> annotation.annotationType().isAnnotationPresent(Qualifier.class)) .findFirst(); // Ignore producers with non-default qualifiers if (!hasQualifier.isPresent() || hasQualifier.get() instanceof Default) { producers.put(ppf.getBean(), ppf.getAnnotatedProducerField()); } } } }
@Override public ConfigProgram introspectField(AnnotatedField<?> field) { EJB ejb = field.getAnnotation(EJB.class); return generateContext(field, ejb); }
public OSGiServiceAnnotatedField(final AnnotatedField<? super T> field) { logger.debug("Creation of a new CDIOSGiAnnotatedField wrapping {}", field); this.field = field; filter = FilterGenerator.makeFilter(filter, field.getAnnotations()); annotations.add(filter); //annotations.add(new AnnotationLiteral<OSGiService>() {}); annotations.add(new OSGiServiceAnnotation( field.getJavaMember().getAnnotation(OSGiService.class).value())); if (field.getAnnotation(Required.class) != null) { annotations.add(new AnnotationLiteral<Required>() { }); } for (Annotation annotation : field.getAnnotations()) { if (!annotation.annotationType().isAnnotationPresent(Qualifier.class)) { annotations.add(annotation); } } logger.debug("New OSGiServiceAnnotatedField constructed {}", this); }
@Override public ConfigProgram introspectField(AnnotatedField<?> field) { DataSourceDefinition db = field.getAnnotation(DataSourceDefinition.class); return generateProgram(field, db); }
/** * Records metric producer fields defined by the application. Ignores producers * with non-default qualifiers and library producers. * * @param ppf Producer field. */ private void recordProducerFields(@Observes ProcessProducerField<? extends org.eclipse.microprofile.metrics.Metric, ?> ppf) { LOGGER.log(Level.FINE, () -> "### recordProducerFields " + ppf.getBean().getBeanClass()); if (!MetricProducer.class.equals(ppf.getBean().getBeanClass())) { Metric metric = ppf.getAnnotatedProducerField().getAnnotation(Metric.class); if (metric != null) { Optional<? extends Annotation> hasQualifier = ppf.getAnnotatedProducerField() .getAnnotations() .stream() .filter(annotation -> annotation.annotationType().isAnnotationPresent(Qualifier.class)) .findFirst(); // Ignore producers with non-default qualifiers if (!hasQualifier.isPresent() || hasQualifier.get() instanceof Default) { producers.put(ppf.getBean(), ppf.getAnnotatedProducerField()); } } } }
@Override public ConfigProgram introspectField(AnnotatedField<?> field) { Resource resource = field.getAnnotation(Resource.class); Field javaField = field.getJavaMember(); String loc = getLocation(javaField); String jndiName = javaField.getDeclaringClass().getName() + "/" + javaField.getName(); Class<?> bindType = javaField.getType(); ValueGenerator gen = generateContext(loc, bindType, jndiName, resource); bindJndi(javaField, gen); return new FieldGeneratorProgram(field.getJavaMember(), gen); }
private <T> boolean processAnnotatedField(AnnotatedField<? super T> field, Class<T> token, boolean classHasEncodedAnnotation, Map<AnnotatedField<? super T>, PatchInformation> fieldToPatchInfoMap) { boolean mustPatch = false; for (Annotation annotation : field.getAnnotations()) { if (knownParameterQualifiers.contains(annotation.annotationType())) { boolean mustAddInjectAnnotation = !field.isAnnotationPresent(Inject.class); if (field.isAnnotationPresent(Encoded.class) || classHasEncodedAnnotation || mustAddInjectAnnotation || field.isAnnotationPresent(DefaultValue.class)) { mustPatch = true; } Set<DiscoveredParameter> discovered = discoveredParameterMap.get(annotation.annotationType()); if (discovered != null) { boolean encoded = field.isAnnotationPresent(Encoded.class) || classHasEncodedAnnotation; DefaultValue defaultValue = field.getAnnotation(DefaultValue.class); DiscoveredParameter parameter = new DiscoveredParameter(annotation, field.getBaseType(), defaultValue, encoded); discovered.add(parameter); LOGGER.fine(" recorded " + parameter); fieldToPatchInfoMap.put(field, new PatchInformation(parameter, getSyntheticQualifierFor(parameter), mustAddInjectAnnotation)); } } } return mustPatch; }
@Override public ConfigProgram introspectField(AnnotatedField<?> field) { PersistenceUnit pUnit = field.getAnnotation(PersistenceUnit.class); Field javaField = field.getJavaMember(); if (! javaField.getType().isAssignableFrom(EntityManagerFactory.class)) { throw new ConfigException(L.l("{0}: @PersistenceUnit field must be assignable from EntityManagerFactory.", getLocation(javaField))); } return generateContext(field, pUnit); }
private <T> boolean processAnnotatedField(AnnotatedField<? super T> field, Class<T> token, boolean classHasEncodedAnnotation, Map<AnnotatedField<? super T>, PatchInformation> fieldToPatchInfoMap) { boolean mustPatch = false; for (Annotation annotation : field.getAnnotations()) { if (knownParameterQualifiers.contains(annotation.annotationType())) { boolean mustAddInjectAnnotation = !field.isAnnotationPresent(Inject.class); if (field.isAnnotationPresent(Encoded.class) || classHasEncodedAnnotation || mustAddInjectAnnotation || field.isAnnotationPresent(DefaultValue.class)) { mustPatch = true; } Set<DiscoveredParameter> discovered = discoveredParameterMap.get(annotation.annotationType()); if (discovered != null) { boolean encoded = field.isAnnotationPresent(Encoded.class) || classHasEncodedAnnotation; DefaultValue defaultValue = field.getAnnotation(DefaultValue.class); DiscoveredParameter parameter = new DiscoveredParameter(annotation, field.getBaseType(), defaultValue, encoded); discovered.add(parameter); LOGGER.fine(" recorded " + parameter); fieldToPatchInfoMap.put(field, new PatchInformation(parameter, getSyntheticQualifierFor(parameter), mustAddInjectAnnotation)); } } } return mustPatch; }
private void metricProducerField(@Observes ProcessProducerField<? extends Metric, ?> ppf) { if (ppf.getAnnotatedProducerField().getAnnotation(org.eclipse.microprofile.metrics.annotation.Metric.class) != null) { Field member = ppf.getAnnotatedProducerField().getJavaMember(); Class<?> bean = member.getDeclaringClass(); Metadata metadata = AnnotationMetadata.buildMetadata(bean, member, org.eclipse.microprofile.metrics.annotation.Metric.class); producerMembers.add(new ProducerMemberRegistration(ppf.getBean(), ppf.getAnnotatedProducerField(), metadata)); } }
private <T> boolean processAnnotatedField(AnnotatedField<? super T> field, Class<T> token, boolean classHasEncodedAnnotation, Map<AnnotatedField<? super T>, PatchInformation> fieldToPatchInfoMap) { boolean mustPatch = false; for (Annotation annotation : field.getAnnotations()) { if (knownParameterQualifiers.contains(annotation.annotationType())) { boolean mustAddInjectAnnotation = !field.isAnnotationPresent(Inject.class); if (field.isAnnotationPresent(Encoded.class) || classHasEncodedAnnotation || mustAddInjectAnnotation || field.isAnnotationPresent(DefaultValue.class)) { mustPatch = true; } Set<DiscoveredParameter> discovered = discoveredParameterMap.get(annotation.annotationType()); if (discovered != null) { boolean encoded = field.isAnnotationPresent(Encoded.class) || classHasEncodedAnnotation; DefaultValue defaultValue = field.getAnnotation(DefaultValue.class); DiscoveredParameter parameter = new DiscoveredParameter(annotation, field.getBaseType(), defaultValue, encoded); discovered.add(parameter); LOGGER.fine(" recorded " + parameter); fieldToPatchInfoMap.put(field, new PatchInformation(parameter, getSyntheticQualifierFor(parameter), mustAddInjectAnnotation)); } } } return mustPatch; }
private void validateWebServiceRef( AnnotatedField annotatedField ) { WebServiceRef webServiceRef = annotatedField.getAnnotation(WebServiceRef.class); if ( webServiceRef != null ) { if ( javax.xml.ws.Service.class.isAssignableFrom(annotatedField.getJavaMember().getType())) { return; } if ( annotatedField.getJavaMember().getType().isInterface() ) { Class serviceClass = webServiceRef.value(); if ( serviceClass != null ) { if ( ! javax.xml.ws.Service.class.isAssignableFrom(serviceClass)) { throw new DefinitionException( "The type of the injection point " + annotatedField.getJavaMember().getName() + " is an interface: " + annotatedField.getJavaMember().getType().getName() + ". The @WebSreviceRef value of " + serviceClass + " is not assignable from " + javax.xml.ws.Service.class.getName()); } } } else { throw new DefinitionException( "The type of the injection point " + annotatedField.getJavaMember().getName() + " is " + annotatedField.getJavaMember().getType().getName() + ". This type is invalid for a field annotated with @WebSreviceRef"); } } }
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 (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) { } } } }
private void validateResourceProducer( Class annotatedClass, AnnotatedField annotatedField, List<InjectionCapable> injectionResources ) { Resource resourceAnnotation = annotatedField.getAnnotation(Resource.class); if ( resourceAnnotation != null ) { String lookupName = getLookupName(annotatedClass,
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; }
@Override public ConfigProgram introspectField(AnnotatedField<?> field) { PersistenceContext pContext = field.getAnnotation(PersistenceContext.class); PersistenceContextType type = pContext.type(); Field javaField = field.getJavaMember(); String location = getLocation(javaField); if (! javaField.getType().isAssignableFrom(EntityManager.class)) { throw new ConfigException(L.l("{0}: @PersistenceContext field must be assignable from EntityManager.", getLocation(javaField))); } ValueGenerator gen; if (PersistenceContextType.EXTENDED.equals(type)) gen = generateExtendedContext(location, pContext); else gen = generateTransactionContext(location, pContext); return new FieldGeneratorProgram(javaField, gen); } // InjectIntrospector.introspect(_injectProgramList, field);
public <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat) { boolean modified = false; AnnotatedType<T> annotatedType = pat.getAnnotatedType(); AnnotatedTypeBuilder<T> builder = new AnnotatedTypeBuilder<T>().readFromType(annotatedType); for (AnnotatedField field : annotatedType.getFields()) { Context context = field.getAnnotation(Context.class); if (context != null) { builder.addToField(field, new AnnotationLiteral<Inject>() {}); builder.addToField(field, new AnnotationLiteral<JaxRsQualifier>() {}); modified = true; } } if (modified) { pat.setAnnotatedType(builder.create()); } }
public <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat) { boolean modified = false; AnnotatedType<T> annotatedType = pat.getAnnotatedType(); AnnotatedTypeBuilder<T> builder = new AnnotatedTypeBuilder<T>().readFromType(annotatedType); for (AnnotatedField field : annotatedType.getFields()) { Context context = field.getAnnotation(Context.class); if (context != null) { builder.addToField(field, new AnnotationLiteral<Inject>() { }); builder.addToField(field, new AnnotationLiteral<JaxRsQualifier>() { }); modified = true; } } if (modified) { pat.setAnnotatedType(builder.create()); } }
public <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat) { boolean modified = false; AnnotatedType<T> annotatedType = pat.getAnnotatedType(); AnnotatedTypeBuilder<T> builder = new AnnotatedTypeBuilder<T>().readFromType(annotatedType); for (AnnotatedField field : annotatedType.getFields()) { Context context = field.getAnnotation(Context.class); if (context != null) { builder.addToField(field, new AnnotationLiteral<Inject>() { }); builder.addToField(field, new AnnotationLiteral<JaxRsQualifier>() { }); modified = true; } } if (modified) { pat.setAnnotatedType(builder.create()); } }
EJB ejb = field.getAnnotation(EJB.class); if (ejb != null) { modified = true; Produces produces = field.getAnnotation(Produces.class); if (produces == null) { builder.addToField(field, new AnnotationLiteral<Inject>(){private static final long serialVersionUID = 1L;});