/** * Returns the {@link Gauge} matching the criteria from the injection point. * * @param <T> type of the {@code Gauge} * @param registry metric registry * @param ip injection point being resolved * @return requested gauge */ @Produces @VendorDefined @SuppressWarnings("unchecked") private <T> Gauge<T> produceGauge(MetricRegistry registry, InjectionPoint ip) { Metric metric = ip.getAnnotated().getAnnotation(Metric.class); return (Gauge<T>) registry.getGauges().entrySet().stream() .filter(entry -> entry.getKey().equals(metric.name())) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Could not produce Gauge for injection point " + ip.toString())) .getValue(); }
@Override public ResourceReferenceFactory<Object> registerResourceInjectionPoint(final InjectionPoint injectionPoint) { final String result = getResourceName(injectionPoint); if (isKnownNamespace(result) && injectionPoint.getAnnotated().isAnnotationPresent(Produces.class)) { validateResourceInjectionPointType(getManagedReferenceFactory(getBindInfo(result)), injectionPoint); } return new ResourceReferenceFactory<Object>() { @Override public ResourceReference<Object> createResource() { return new SimpleResourceReference<Object>(resolveResource(injectionPoint)); } }; }
@Produces @Dependent @PersistenceUnitName("any") // the value is nonbinding, thus 'any' is just a dummy parameter here public EntityManagerFactory createEntityManagerFactoryForUnit(InjectionPoint injectionPoint) { PersistenceUnitName unitNameAnnotation = injectionPoint.getAnnotated().getAnnotation(PersistenceUnitName.class); if (unitNameAnnotation == null) { LOG.warning("@PersisteneUnitName annotation could not be found at EntityManagerFactory injection point!"); return null; } String unitName = unitNameAnnotation.value(); Properties properties = persistenceConfigurationProvider.getEntityManagerFactoryConfiguration(unitName); EntityManagerFactory emf = Persistence.createEntityManagerFactory(unitName, properties); return emf; } }
public void collectConfigProducer(@Observes ProcessInjectionPoint<?, ?> pip) { ConfigProperty configProperty = pip.getInjectionPoint().getAnnotated().getAnnotation(ConfigProperty.class); if (configProperty != null) { InjectionPoint ip = pip.getInjectionPoint(); String fullPath = ip.getMember().getDeclaringClass().getName() + "." + getFieldName(ip); Type type = ip.getType();
@SuppressWarnings("unchecked") @ConfigurationValue("") @Dependent @Produces <T> Optional<T> produceOptionalConfigValue(InjectionPoint injectionPoint) { Type type = injectionPoint.getAnnotated().getBaseType(); final Class<T> valueType; if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; Type[] typeArguments = parameterizedType.getActualTypeArguments(); valueType = unwrapType(typeArguments[0]); } else { valueType = (Class<T>) String.class; } return Optional.ofNullable(resolve(injectionPoint, valueType)); }
@Inject public ParameterImpl(InjectionPoint ip) { if (ip.getAnnotated().isAnnotationPresent(Name.class)) { this.key = ip.getAnnotated().getAnnotation(Name.class).value(); } else { this.key = ip.getMember().getName(); } this.type = Reflections.getGenericTypeArgument(ip.getMember(), 0); this.viewScoped = ip.getAnnotated().isAnnotationPresent(ViewScoped.class); this.requestScoped = ip.getAnnotated().isAnnotationPresent(RequestScoped.class); this.sessionScoped = ip.getAnnotated().isAnnotationPresent(SessionScoped.class); }
public void collectConfigProducer(@Observes ProcessInjectionPoint<?, ?> pip) { ConfigProperty configProperty = pip.getInjectionPoint().getAnnotated().getAnnotation(ConfigProperty.class); if (configProperty != null) { injectionPoints.add(pip.getInjectionPoint()); } }
@Produces @Dependent protected ResourceBundle injectableResourceBundle(InjectionPoint injectionPoint) { Bundle bundle = getBundleClass(injectionPoint.getAnnotated().getAnnotations()); if(bundle != null) { Class bundleClass = bundle.value(); if(bundleClass != null && !Class.class.getName().equals(bundleClass.getName())) { return createDefaultResourceBundle().useBundle(bundleClass); } if(!"".equals(bundle.name())) { return createDefaultResourceBundle().useBundle(bundle.name()); } } return createDefaultResourceBundle(); }
if (ij.getAnnotated().getAnnotation(New.class) != null && ij.getQualifiers().size() > 1) { throw ValidatorLogger.LOG.newWithQualifiers(ij, Formats.formatAsStackTraceElement(ij)); if (ij.getType() instanceof TypeVariable<?>) { throw ValidatorLogger.LOG.injectionPointWithTypeVariable(ij, Formats.formatAsStackTraceElement(ij)); if (!(ij.getMember() instanceof Field) && ij.getAnnotated().isAnnotationPresent(Named.class) && ij.getAnnotated().getAnnotation(Named.class).value().equals("")) { throw ValidatorLogger.LOG.nonFieldInjectionPointCannotUseNamed(ij, Formats.formatAsStackTraceElement(ij)); if (ij.getAnnotated().isAnnotationPresent(Produces.class)) { if (bean != null) { throw BeanLogger.LOG.injectedFieldCannotBeProducer(ij.getAnnotated(), bean); checkScopeAnnotations(ij, beanManager.getServices().get(MetaAnnotationStore.class)); checkFacadeInjectionPoint(ij, Instance.class); checkFacadeInjectionPoint(ij, Event.class);
/** * Processing bean. * * @param event the event. */ public void processBean(@Observes ProcessBean<?> event) { ViewScoped viewScoped = event.getAnnotated().getAnnotation(ViewScoped.class); if (viewScoped != null && LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("Processing occurrence of @ViewScoped"); } }
@Produces @TypedMessageBundle Object produceTypedMessageBundle(InjectionPoint injectionPoint) { Annotated annotated = injectionPoint.getAnnotated(); if (annotated.isAnnotationPresent(Locale.class)) { return getBundle(getRawType(injectionPoint.getType()), toLocale(annotated.getAnnotation(Locale.class).value())); } else { return getBundle(getRawType(injectionPoint.getType())); } }
<T> void findEndpointsAndApplication(@Observes final ProcessBean<T> event) { final String typeName = event.getAnnotated().getBaseType().getTypeName(); if (classes == null && !skipScan && event.getAnnotated().isAnnotationPresent(Path.class) && !typeName.startsWith("org.apache.geronimo.microprofile.openapi.") && (packages == null || packages.stream().anyMatch(typeName::startsWith))) { endpoints.add(event.getBean()); } }
private boolean isInjectionPointPassivationCapable(InjectionPoint ij, Bean<?> resolvedBean, BeanManagerImpl beanManager) { if (!Beans.isPassivationCapableDependency(resolvedBean)) { if (((ij.getMember() instanceof Field) && ij.isTransient())) { return true; } if (ij.getAnnotated() instanceof AnnotatedParameter<?> && ij.getAnnotated().isAnnotationPresent(TransientReference.class)) { return true; } return false; } return true; }
protected String getVariableTypedName(InjectionPoint ip) { String variableName = ip.getAnnotated().getAnnotation(ProcessVariableTyped.class).value(); if (variableName.length() == 0) { variableName = ip.getMember().getName(); } return variableName; }
private void checkScopeAnnotations(InjectionPoint ij, MetaAnnotationStore metaAnnotationStore) { Annotated annotated = ij.getAnnotated(); if (annotated instanceof EnhancedAnnotated<?, ?>) { EnhancedAnnotated<?, ?> weldAnnotated = (EnhancedAnnotated<?, ?>) annotated; Set<Annotation> scopes = weldAnnotated.getMetaAnnotations(Scope.class); Set<Annotation> normalScopes = weldAnnotated.getMetaAnnotations(NormalScope.class); for (Annotation annotation : scopes) { logScopeOnInjectionPointWarning(ij, annotation); } for (Annotation annotation : normalScopes) { logScopeOnInjectionPointWarning(ij, annotation); } } else { for (Annotation annotation : annotated.getAnnotations()) { if (hasScopeMetaAnnotation(annotation)) { logScopeOnInjectionPointWarning(ij, annotation); } } } }
private void validateStatefulSessionBean(Annotated type) { assert type.getBaseType().equals(Cow.class); assert rawTypeSetMatches(type.getTypeClosure(), Cow.class, CowLocal.class, Object.class); assert type.getAnnotations().size() == 0; }
public static String getResourceName(InjectionPoint injectionPoint) { Resource resource = getResourceAnnotated(injectionPoint).getAnnotation(Resource.class); String mappedName = resource.mappedName(); if (!mappedName.equals("")) { if (injectionPoint.getMember() instanceof Field) { propertyName = injectionPoint.getMember().getName(); } else if (injectionPoint.getMember() instanceof Method) { propertyName = getPropertyName((Method) injectionPoint.getMember()); if (propertyName == null) {
public static <T> Optional<T> optionalConfigValue(InjectionPoint injectionPoint, Config config) { Type type = injectionPoint.getAnnotated().getBaseType(); final Class<T> valueType; valueType = resolveValueType(type); return Optional.ofNullable(getValue(injectionPoint, valueType, config)); }
private void addAnnotatedTypeIfNecessary(Annotated annotated) { if (annotated.isAnnotationPresent(ManagedProperty.class)) { Type type = annotated.getBaseType(); types.add(new ManagedPropertyInfo(type, annotated.getAnnotation(ManagedProperty.class).value())); } }
protected void postSpecialize() { // Override qualifiers and the bean name Set<Annotation> qualifiers = new HashSet<Annotation>(); for (Annotation qualifier : attributes().getQualifiers()) { // Don't include implicit javax.enterprise.inject.Default qualifier if (!qualifier.equals(DefaultLiteral.INSTANCE) || getAnnotated().isAnnotationPresent(Default.class)) { qualifiers.add(qualifier); } } String name = attributes().getName(); for (AbstractBean<?, ?> specializedBean : getSpecializedBeans()) { qualifiers.addAll(specializedBean.getQualifiers()); if (specializedBean.getName() != null) { name = specializedBean.getName(); } } setAttributes(new ImmutableBeanAttributes<T>(qualifiers, name, attributes())); }