/** * Creates a new injection target which is able to delegate an injection to {@code delegate injection target} and inject * the fields that are Jersey-specific. The resolvers must be set later on. CDI will select its own constructor. * * @param delegate CDI specific injection target. * @param clazz class that will be scanned and injected. */ public JerseyInjectionTarget(BasicInjectionTarget<T> delegate, Class<T> clazz) { this(delegate, delegate.getBean(), clazz, null); }
/** * Looks at whether the DefaultInstantiator resolving a valid constructor does not met this case: * - No constructor with @Inject annotation is defined * - NoArgs constructor is defined * - Instantiator ignores JAX-RS valid constructor with multiple params * * @param it injection target containing instantiator with resolved constructor. * @param clazz class which analyzed constructor belongs to. * @param <T> type of the analyzed class. * @return {@code true} if no-arg constructor was selected while multi-params constructor exists. */ private static <T> boolean isNoArgConstructorCase(BasicInjectionTarget<T> it, Class<T> clazz) { if (!(it instanceof NonProducibleInjectionTarget)) { Instantiator<T> instantiator = it.getInstantiator(); Constructor<T> constructor = instantiator.getConstructor(); return constructor.getParameterCount() == 0 && clazz.getConstructors().length > 1; } return false; }
private void buildInterceptionModel(EnhancedAnnotatedType<T> annotatedType, AbstractInstantiator<T> instantiator) { new InterceptionModelInitializer<>(beanManager, annotatedType, annotatedType.getDeclaredEnhancedConstructor( instantiator.getConstructorInjectionPoint().getSignature()), getBean()).init(); }
public static <T> NonProducibleInjectionTarget<T> create(EnhancedAnnotatedType<T> type, Bean<T> bean, Injector<T> injector, LifecycleCallbackInvoker<T> invoker, BeanManagerImpl beanManager) { if (injector == null) { injector = DefaultInjector.of(type, bean, beanManager); } if (invoker == null) { invoker = DefaultLifecycleCallbackInvoker.of(type); } return new NonProducibleInjectionTarget<T>(type, bean, beanManager, injector, invoker); }
/** * Creates {@link InjectionTarget} for interceptors which do not have associated {@link Interceptor}. These interceptors are a * result of using {@link Interceptors} annotation directly on the target class. */ public static <T> BasicInjectionTarget<T> createNonCdiInterceptor(EnhancedAnnotatedType<T> type, BeanManagerImpl beanManager) { return new BasicInjectionTarget<T>(type, null, beanManager, DefaultInjector.of(type, null, beanManager), NoopLifecycleCallbackInvoker.<T>getInstance()); }
SubclassedComponentInstantiator.forInterceptedDecoratedBean(annotatedType, getBean(), delegate, beanManager)); setInstantiator(new SubclassDecoratorApplyingInstantiator<>( getBeanManager().getContextId(), getInstantiator(), getBean(), decorators)); setInstantiator(new InterceptorApplyingInstantiator<>( getInstantiator(), interceptionModel, getType()));
/** * Creates a new injection target which is able to delegate an injection to {@code delegate injection target} and inject * the fields that are Jersey-specific. This method accepts custom instantiator, if the instantiator is {@code null} * default one is created. * * @param annotatedType resolved type of the registered bean. * @param delegate CDI specific injection target. * @param bean bean which this injection target belongs to. * @param clazz class that will be scanned and injected. * @param resolvers all resolvers that can provide a valued for Jersey-specific injection. * @param instantiator default instantiator. */ public JerseyInjectionTarget(EnhancedAnnotatedType<T> annotatedType, BasicInjectionTarget<T> delegate, Bean<T> bean, Class<T> clazz, Collection<InjectionResolver> resolvers, Instantiator<T> instantiator) { super(annotatedType, bean, delegate.getBeanManager(), delegate.getInjector(), delegate.getLifecycleCallbackInvoker(), instantiator); this.bean = bean; this.enhancedAnnotatedType = annotatedType; this.clazz = clazz; this.resolvers = resolvers; this.injector = Values.lazy((Value<JerseyInstanceInjector<T>>) () -> new JerseyInstanceInjector<>(bean, this.resolvers)); }
private InterceptorBindings getInterceptorBindings(final String ejbName, final BeanManagerImpl manager) { InterceptorBindings retVal = null; if (ejbName != null) { retVal = interceptorSupport.getInterceptorBindings(ejbName, manager); } else { // This is a managed bean SlimAnnotatedType<?> type = (SlimAnnotatedType<?>) manager.createAnnotatedType(componentClass); if (!manager.getInterceptorModelRegistry().containsKey(type)) { EnhancedAnnotatedType<?> enhancedType = manager.getServices().get(ClassTransformer.class).getEnhancedAnnotatedType(type); InterceptionModelInitializer.of(manager, enhancedType, null).init(); } InterceptionModel model = manager.getInterceptorModelRegistry().get(type); if (model != null) { retVal = new InterceptorBindingsAdapter(manager.getInterceptorModelRegistry().get(type)); } } return retVal != null ? retVal : NullInterceptorBindings.INSTANCE; }
new JerseyConstructorInjectionPoint<>(constructor, bean, it.getBeanManager(), resolvers); InjectionTargetService injectionTargetService = it.getBeanManager().getServices().get(InjectionTargetService.class); injectionTargetService.addInjectionTargetToBeInitialized(jit.getEnhancedAnnotatedType(), jit); return jit;
public static <T> EnhancedAnnotatedType<T> createEnhancedAnnotatedType(BasicInjectionTarget<T> it) { return EnhancedAnnotatedTypeImpl.of( (SlimAnnotatedType<T>) it.getAnnotatedType(), ClassTransformer.instance(it.getBeanManager())); }
private void setupConstructorInterceptionInstantiator(InterceptionModel interceptionModel) { if (interceptionModel != null && interceptionModel.hasExternalConstructorInterceptors()) { setInstantiator(new ConstructorInterceptionInstantiator<>(getInstantiator(), interceptionModel, getType())); } }
private void initializeInterceptionModel(EnhancedAnnotatedType<T> annotatedType) { AbstractInstantiator<T> instantiator = (AbstractInstantiator<T>) getInstantiator(); if (instantiator.getConstructorInjectionPoint() == null) { return; // this is a non-producible InjectionTarget (only created to inject existing instances) } if (isInterceptionCandidate() && !beanManager.getInterceptorModelRegistry().containsKey(getType())) { buildInterceptionModel(annotatedType, instantiator); } }
beanManager.getServices().get(InjectionTargetService.class).validateProducer(injectionTarget);
@Override public void inject(T instance, CreationalContext<T> ctx) { /* * If an instance contains any fields which be injected by Jersey then Jersey attempts to inject them using annotations * retrieves from registered InjectionResolvers. */ try { injector.get().inject(instance); } catch (WebApplicationException wae) { throw wae; } catch (Throwable cause) { throw new InjectionException( "Exception occurred during Jersey/JAX-RS annotations processing in the class: " + clazz, cause); } /* * The rest of the fields (annotated by @Inject) are injected using CDI. */ super.inject(instance, ctx); }
public static <T> NonProducibleInjectionTarget<T> create(EnhancedAnnotatedType<T> type, Bean<T> bean, Injector<T> injector, LifecycleCallbackInvoker<T> invoker, BeanManagerImpl beanManager) { if (injector == null) { injector = DefaultInjector.of(type, bean, beanManager); } if (invoker == null) { invoker = DefaultLifecycleCallbackInvoker.of(type); } return new NonProducibleInjectionTarget<T>(type, bean, beanManager, injector, invoker); }
/** * Creates {@link InjectionTarget} for interceptors which do not have associated {@link Interceptor}. These interceptors are a * result of using {@link Interceptors} annotation directly on the target class. */ public static <T> BasicInjectionTarget<T> createNonCdiInterceptor(EnhancedAnnotatedType<T> type, BeanManagerImpl beanManager) { return new BasicInjectionTarget<T>(type, null, beanManager, DefaultInjector.of(type, null, beanManager), NoopLifecycleCallbackInvoker.<T>getInstance()); }
public static <T> NonProducibleInjectionTarget<T> create(EnhancedAnnotatedType<T> type, Bean<T> bean, Injector<T> injector, LifecycleCallbackInvoker<T> invoker, BeanManagerImpl beanManager) { if (injector == null) { injector = DefaultInjector.of(type, bean, beanManager); } if (invoker == null) { invoker = DefaultLifecycleCallbackInvoker.of(type); } return new NonProducibleInjectionTarget<T>(type, bean, beanManager, injector, invoker); }
/** * Creates {@link InjectionTarget} for interceptors which do not have associated {@link Interceptor}. These interceptors are a * result of using {@link Interceptors} annotation directly on the target class. */ public static <T> BasicInjectionTarget<T> createNonCdiInterceptor(EnhancedAnnotatedType<T> type, BeanManagerImpl beanManager) { return new BasicInjectionTarget<T>(type, null, beanManager, DefaultInjector.of(type, null, beanManager), NoopLifecycleCallbackInvoker.<T>getInstance()); }
public static <T> NonProducibleInjectionTarget<T> create(EnhancedAnnotatedType<T> type, Bean<T> bean, Injector<T> injector, LifecycleCallbackInvoker<T> invoker, BeanManagerImpl beanManager) { if (injector == null) { injector = DefaultInjector.of(type, bean, beanManager); } if (invoker == null) { invoker = DefaultLifecycleCallbackInvoker.of(type); } return new NonProducibleInjectionTarget<T>(type, bean, beanManager, injector, invoker); }
/** * Creates {@link InjectionTarget} for interceptors which do not have associated {@link Interceptor}. These interceptors are a * result of using {@link Interceptors} annotation directly on the target class. */ public static <T> BasicInjectionTarget<T> createNonCdiInterceptor(EnhancedAnnotatedType<T> type, BeanManagerImpl beanManager) { return new BasicInjectionTarget<T>(type, null, beanManager, DefaultInjector.of(type, null, beanManager), NoopLifecycleCallbackInvoker.<T>getInstance()); }