void processClaimValueInjections(@Observes ProcessInjectionPoint pip) { log.debugf("pipRaw: %s", pip.getInjectionPoint()); InjectionPoint ip = pip.getInjectionPoint(); if (ip.getAnnotated().isAnnotationPresent(Claim.class) && ip.getType() instanceof Class) { Class rawClass = (Class) ip.getType(); if (Modifier.isFinal(rawClass.getModifiers())) { Claim claim = ip.getAnnotated().getAnnotation(Claim.class); rawTypes.add(ip.getType()); rawTypeQualifiers.add(claim); log.debugf("+++ Added Claim raw type: %s", ip.getType()); Class declaringClass = ip.getMember().getDeclaringClass(); Annotation[] appScoped = declaringClass.getAnnotationsByType(ApplicationScoped.class); Annotation[] sessionScoped = declaringClass.getAnnotationsByType(SessionScoped.class); if ((appScoped != null && appScoped.length > 0) || (sessionScoped != null && sessionScoped.length > 0)) { String err = String.format("A raw type cannot be injected into application/session scope: IP=%s", ip); pip.addDefinitionError(new DeploymentException(err)); } } } }
public <T, X> void injectionPoints( final @Observes ProcessInjectionPoint<T, X> processInjectionPoint ) { final Type type = processInjectionPoint.getInjectionPoint().getType(); final Object mock = mockStore.findFor(type); if (mock == null) { return; } LOG.debug("Mocking injection point: {}", processInjectionPoint.getInjectionPoint()); final InjectionPoint original = processInjectionPoint.getInjectionPoint(); processInjectionPoint.setInjectionPoint(new ForwardingInjectionPoint() { @Override public Set<Annotation> getQualifiers() { final Set<Annotation> ret = new HashSet<>(super.getQualifiers()).stream() .filter(it -> !(it instanceof Default)) .collect(toSet()); ret.add(MOCKED); return ret; } @Override protected InjectionPoint delegate() { return original; } }); mockedInjectionPoints.add(original); }
@Test public void captureProducerTypes() { final ProcessInjectionPoint<?, ?> pip = mock(ProcessInjectionPoint.class); final InjectionPoint ip = mock(InjectionPoint.class); when(pip.getInjectionPoint()).thenReturn(ip); final Annotated annotated = mock(Annotated.class); when(ip.getAnnotated()).thenReturn(annotated); when(annotated.isAnnotationPresent(Body.class)).thenReturn(true); when(ip.getType()).thenReturn(COLLECTION.getClass()); @SuppressWarnings("unchecked") final InjectionTarget<Object> injectionTarget = mock(InjectionTarget.class); when(this.beanManager.createInjectionTarget(Mockito.any())).thenReturn(injectionTarget); final Member member = mock(Member.class); when(ip.getMember()).thenReturn(member); final List<Bean<?>> found = ReflectionUtil.get(this.extension, "found"); assertTrue(found.isEmpty()); this.extension.captureProducerTypes(pip, this.beanManager); assertEquals(1, found.size()); verify(pip, times(2)).getInjectionPoint(); verify(ip).getAnnotated(); verify(annotated).isAnnotationPresent(Body.class); verify(ip).getType(); verify(ip).getMember(); verify(member).getName(); verify(ip).getQualifiers(); verify(injectionTarget).getInjectionPoints(); verify(this.beanManager).createInjectionTarget(Mockito.any()); verifyNoMoreInteractions(pip, ip, annotated, injectionTarget, member); }
/** * Collect the types of all Provider injection points annotated with {@linkplain Claim}. * * @param pip - the injection point event information */ void processClaimProviderInjections(@Observes ProcessInjectionPoint<?, ? extends Provider> pip) { log.debugf("pip: %s", pip.getInjectionPoint()); final InjectionPoint ip = pip.getInjectionPoint(); if (ip.getAnnotated().isAnnotationPresent(Claim.class)) { Claim claim = ip.getAnnotated().getAnnotation(Claim.class); if (claim.value().length() == 0 && claim.standard() == Claims.UNKNOWN) { throw new DeploymentException("@Claim at: " + ip + " has no name or valid standard enum setting"); } boolean usesEnum = claim.standard() != Claims.UNKNOWN; final String claimName = usesEnum ? claim.standard().name() : claim.value(); log.debugf("Checking Provider Claim(%s), ip: %s", claimName, ip); ClaimIP claimIP = claims.get(claimName); Type matchType = ip.getType(); Type actualType = ((ParameterizedType) matchType).getActualTypeArguments()[0]; // Don't add Optional as this is handled specially if (!optionalOrJsonValue(actualType)) { rawTypes.add(actualType); } else if (!actualType.getTypeName().startsWith("javax.json.Json")) { // Validate that this is not an Optional<JsonValue> Type innerType = ((ParameterizedType) actualType).getActualTypeArguments()[0]; if (!innerType.getTypeName().startsWith("javax.json.Json")) { providerOptionalTypes.add(actualType); providerQualifiers.add(claim); } } rawTypeQualifiers.add(claim); ClaimIPType key = new ClaimIPType(claimName, actualType); if (claimIP == null) { claimIP = new ClaimIP(actualType, actualType, false, claim); claimIP.setProviderSite(true); claims.put(key, claimIP); } claimIP.getInjectionPoints().add(ip); log.debugf("+++ Added Provider Claim(%s) ip: %s", claimName, ip); } }
private void cdiEventEndpoints(@Observes ProcessInjectionPoint<?, CdiEventEndpoint> pip, BeanManager manager) { InjectionPoint ip = pip.getInjectionPoint(); Type type = ip.getType() instanceof ParameterizedType ? ((ParameterizedType) ip.getType()).getActualTypeArguments()[0] : Object.class; String uri = eventEndpointUri(type, ip.getQualifiers()); cdiEventEndpoints.put(uri, new CdiEventEndpoint<>(uri, type, ip.getQualifiers(), manager)); }
<K, V> void processInjectionPoint(@Observes ProcessInjectionPoint<K, V> pip) { logger.info("finished the scanning process"); processInjectionPoint++; }
public void collectConfigProducer(@Observes ProcessInjectionPoint<?, ?> pip) { ConfigProperty configProperty = pip.getInjectionPoint().getAnnotated().getAnnotation(ConfigProperty.class); if (configProperty != null) { injectionPoints.add(pip.getInjectionPoint()); } }
public void locateInjections(@Observes ProcessInjectionPoint<?, ReactorEvent<?,?>> pip) { eventTypes.add(pip.getInjectionPoint()); }
/** * * @param pip * @param beanManager */ public void captureProducerTypes(@Observes final ProcessInjectionPoint<?, ?> pip, BeanManager beanManager) { if (pip.getInjectionPoint().getAnnotated().isAnnotationPresent(Body.class)) { found.add(createBeanAdapter(pip.getInjectionPoint(), beanManager)); } }
@SuppressWarnings("rawtypes") void processAsyncReferenceInjectionPoints(@Observes ProcessInjectionPoint<?, ? extends AsyncReference> event) { asyncReferenceQualifiers.addAll(event.getInjectionPoint().getQualifiers()); }
<T, X extends EventScheduler> void processEventSchedulerInjectionPoint( @Observes final ProcessInjectionPoint<T, X> processInjectionPoint, final BeanManager beanManager) { InjectionPoint injectionPoint = processInjectionPoint.getInjectionPoint(); eventSchedulerInfos.add(EventSchedulerInfo.of(injectionPoint)); }
<T, X> void logLifecycleEvent(@Observes ProcessInjectionPoint<T, X> event) { LOGGER.info("ProcessInjectionPoint: injectionPoint=" + event.getInjectionPoint()); }
public void alterSubscriptionPublishInjectionPoints(@Observes ProcessInjectionPoint processInjectionPoint) { final InjectionPoint injectionPoint = processInjectionPoint.getInjectionPoint(); logger.info("Looking at injection point: " + injectionPoint); if (injectionPoint.getType() instanceof Class && SubscriptionPublisher.class.isAssignableFrom((Class) injectionPoint.getType())) { logger.info("Re-writing injection point type from {} to {} on bean {}", injectionPoint.getType(), SubscriptionPublisher.class, injectionPoint.getBean()); final Bean<?> bean = injectionPoint.getBean(); InjectionPoint newInjectionPoint = new InjectionPoint() { @Override public Type getType() { return SubscriptionPublisher.class; } @Override public Set<Annotation> getQualifiers() { return injectionPoint.getQualifiers(); } @Override public Bean<?> getBean() { return bean; } @Override public Member getMember() { return injectionPoint.getMember(); } @Override public Annotated getAnnotated() { return injectionPoint.getAnnotated(); } @Override public boolean isDelegate() { return injectionPoint.isDelegate(); } @Override public boolean isTransient() { return injectionPoint.isTransient(); } }; processInjectionPoint.setInjectionPoint(newInjectionPoint); } }
/** * Event generated by the container to process an injection point. Is called for every point defined in the * container. During this phase, we check for any @ServiceReference qualifiers and create a bean for it. * That bean is later added during another phase of the container construction. * * @param event The injection point event * @param <T> The injection point type * @param <X> The bean class declaring the point */ public <T, X> void processInjectionPoints(@Observes ProcessInjectionPoint<T, X> event) { TrackerBean bean = processInjectionPoint(event.getInjectionPoint(), (e) -> event.addDefinitionError(e)); if (bean != null) { beans.add(bean); } }