/** * 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); }
/** * 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)); }
public static <T> EnhancedAnnotatedType<T> createEnhancedAnnotatedType(BasicInjectionTarget<T> it) { return EnhancedAnnotatedTypeImpl.of( (SlimAnnotatedType<T>) it.getAnnotatedType(), ClassTransformer.instance(it.getBeanManager())); }
protected BasicInjectionTarget(EnhancedAnnotatedType<T> type, Bean<T> bean, BeanManagerImpl beanManager, Injector<T> injector, LifecycleCallbackInvoker<T> invoker, Instantiator<T> instantiator) { this.beanManager = beanManager; this.type = type.slim(); this.injector = injector; this.invoker = invoker; final Set<InjectionPoint> injectionPoints = new HashSet<InjectionPoint>(); checkType(type); this.injector.registerInjectionPoints(injectionPoints); if (instantiator != null) { this.instantiator = instantiator; } else { this.instantiator = initInstantiator(type, bean, beanManager, injectionPoints); } this.injectionPoints = ImmutableSet.copyOf(injectionPoints); checkDelegateInjectionPoints(); }
if (contextual instanceof ManagedBean<?> && !isInterceptorOrDecorator(contextual)) { ManagedBean<?> managedBean = (ManagedBean<?>) contextual; if (managedBean.getProducer() instanceof BasicInjectionTarget<?>) { BasicInjectionTarget<?> injectionTarget = (BasicInjectionTarget<?>) managedBean.getProducer(); if (!injectionTarget.getLifecycleCallbackInvoker().hasPreDestroyMethods() && !injectionTarget.hasInterceptors()) {
private boolean initHasPostConstructCallback(InjectionTarget<T> producer) { if (producer instanceof BasicInjectionTarget<?>) { BasicInjectionTarget<?> weldProducer = (BasicInjectionTarget<?>) producer; final InterceptionModel interceptors = getInterceptors(); if (interceptors == null || interceptors.getInterceptors(InterceptionType.POST_CONSTRUCT, null).isEmpty()) { if (!weldProducer.getLifecycleCallbackInvoker().hasPostConstructCallback()) { return false; } } } // otherwise we assume there is a post construct callback, just to be safe return true; } }
private BasicInjectionTarget<T> chooseInjectionTarget(EnhancedAnnotatedType<T> type, Bean<T> bean, boolean interceptor) { if (bean instanceof Decorator<?> || type.isAnnotationPresent(javax.decorator.Decorator.class)) { return new DecoratorInjectionTarget<T>(type, bean, manager); } NonProducibleInjectionTarget<T> nonProducible = InjectionTargets.createNonProducibleInjectionTarget(type, bean, manager); if(nonProducible != null) { return nonProducible; } if (bean instanceof SessionBean<?>) { return SessionBeanInjectionTarget.of(type, (SessionBean<T>) bean, manager); } if (bean instanceof Interceptor<?> || type.isAnnotationPresent(javax.interceptor.Interceptor.class)) { return BeanInjectionTarget.forCdiInterceptor(type, bean, manager); } if (interceptor) { return BasicInjectionTarget.createNonCdiInterceptor(type, manager); } return BeanInjectionTarget.createDefault(type, bean, manager); }
@Override public String toString() { StringBuilder result = new StringBuilder("InjectionTarget for "); if (getBean() == null) { result.append(getAnnotated()); } else { result.append(getBean()); } return result.toString(); }
private void validateInterceptors(BeanManagerImpl beanManager, AbstractClassBean<?> classBean) { InterceptionModel interceptionModel = beanManager.getInterceptorModelRegistry().get(classBean.getAnnotated()); if (interceptionModel != null) { Set<? extends InterceptorClassMetadata<?>> interceptors = interceptionModel.getAllInterceptors(); if (interceptors.size() > 0) { boolean passivationCapabilityCheckRequired = beanManager.isPassivatingScope(classBean.getScope()); beanManager = ((BasicInjectionTarget<?>) injectionTarget).getBeanManager();
private BasicInjectionTarget<T> buildInternal() { final Injector<T> injector = buildInjector(); final LifecycleCallbackInvoker<T> invoker = buildInvoker(); NonProducibleInjectionTarget<T> nonProducible = InjectionTargets.createNonProducibleInjectionTarget(type, bean, injector, invoker, manager); if (nonProducible != null) { return nonProducible; } if (!interceptorsEnabled && !decorationEnabled) { return BasicInjectionTarget.create(type, bean, manager, injector, invoker); } else if (interceptorsEnabled && decorationEnabled) { return new BeanInjectionTarget<T>(type, bean, manager, injector, invoker); } throw new IllegalStateException( "Unsupported combination: [interceptorsEnabled=" + interceptorsEnabled + ", decorationEnabled=" + decorationEnabled + "]"); }
public static <T> BasicInjectionTarget<T> createDefault(EnhancedAnnotatedType<T> type, Bean<T> bean, BeanManagerImpl beanManager, Instantiator<T> instantiator) { return new BasicInjectionTarget<T>(type, bean, beanManager, instantiator); }
.getDeclaredEnhancedConstructor(new ConstructorSignatureImpl(analyzer.getConstructor())); new JerseyConstructorInjectionPoint<>(constructor, bean, it.getBeanManager(), resolvers); InjectionTargetService injectionTargetService = it.getBeanManager().getServices().get(InjectionTargetService.class); injectionTargetService.addInjectionTargetToBeInitialized(jit.getEnhancedAnnotatedType(), jit); return jit;
@Override public AnnotatedType<T> getAnnotatedType() { return getAnnotated(); }
protected BasicInjectionTarget(EnhancedAnnotatedType<T> type, Bean<T> bean, BeanManagerImpl beanManager, Injector<T> injector, LifecycleCallbackInvoker<T> invoker, Instantiator<T> instantiator) { this.beanManager = beanManager; this.type = type.slim(); this.injector = injector; this.invoker = invoker; final Set<InjectionPoint> injectionPoints = new HashSet<InjectionPoint>(); checkType(type); this.injector.registerInjectionPoints(injectionPoints); if (instantiator != null) { this.instantiator = instantiator; } else { this.instantiator = initInstantiator(type, bean, beanManager, injectionPoints); } this.injectionPoints = ImmutableSet.copyOf(injectionPoints); checkDelegateInjectionPoints(); }
if (contextual instanceof ManagedBean<?> && !isInterceptorOrDecorator(contextual)) { ManagedBean<?> managedBean = (ManagedBean<?>) contextual; if (managedBean.getProducer() instanceof BasicInjectionTarget<?>) { BasicInjectionTarget<?> injectionTarget = (BasicInjectionTarget<?>) managedBean.getProducer(); if (!injectionTarget.getLifecycleCallbackInvoker().hasPreDestroyMethods() && !injectionTarget.hasInterceptors()) {
private boolean initHasPostConstructCallback(InjectionTarget<T> producer) { if (producer instanceof BasicInjectionTarget<?>) { BasicInjectionTarget<?> weldProducer = (BasicInjectionTarget<?>) producer; final InterceptionModel interceptors = getInterceptors(); if (interceptors == null || interceptors.getInterceptors(InterceptionType.POST_CONSTRUCT, null).isEmpty()) { if (!weldProducer.getLifecycleCallbackInvoker().hasPostConstructCallback()) { return false; } } } // otherwise we assume there is a post construct callback, just to be safe return true; } }
private BasicInjectionTarget<T> chooseInjectionTarget(EnhancedAnnotatedType<T> type, Bean<T> bean, boolean interceptor) { if (bean instanceof Decorator<?> || type.isAnnotationPresent(javax.decorator.Decorator.class)) { return new DecoratorInjectionTarget<T>(type, bean, manager); } NonProducibleInjectionTarget<T> nonProducible = InjectionTargets.createNonProducibleInjectionTarget(type, bean, manager); if (nonProducible != null) { return nonProducible; } if (bean instanceof SessionBean<?>) { return manager.getServices().get(EjbSupport.class).createSessionBeanInjectionTarget(type, (SessionBean<T>) bean, manager); } if (bean instanceof Interceptor<?> || type.isAnnotationPresent(javax.interceptor.Interceptor.class)) { return BeanInjectionTarget.forCdiInterceptor(type, bean, manager); } if (interceptor) { return BasicInjectionTarget.createNonCdiInterceptor(type, manager); } return BeanInjectionTarget.createDefault(type, bean, manager); }
@Override public String toString() { StringBuilder result = new StringBuilder("InjectionTarget for "); if (getBean() == null) { result.append(getAnnotated()); } else { result.append(getBean()); } return result.toString(); }
private void validateInterceptors(BeanManagerImpl beanManager, AbstractClassBean<?> classBean) { InterceptionModel interceptionModel = beanManager.getInterceptorModelRegistry().get(classBean.getAnnotated()); if (interceptionModel != null) { Set<? extends InterceptorClassMetadata<?>> interceptors = interceptionModel.getAllInterceptors(); if (interceptors.size() > 0) { boolean passivationCapabilityCheckRequired = beanManager.isPassivatingScope(classBean.getScope()); beanManager = ((BasicInjectionTarget<?>) injectionTarget).getBeanManager();
private BasicInjectionTarget<T> buildInternal() { final Injector<T> injector = buildInjector(); final LifecycleCallbackInvoker<T> invoker = buildInvoker(); NonProducibleInjectionTarget<T> nonProducible = InjectionTargets.createNonProducibleInjectionTarget(type, bean, injector, invoker, manager); if (nonProducible != null) { return nonProducible; } if (!interceptorsEnabled && !decorationEnabled) { return BasicInjectionTarget.create(type, bean, manager, injector, invoker); } else if (interceptorsEnabled && decorationEnabled) { return new BeanInjectionTarget<T>(type, bean, manager, injector, invoker); } throw new IllegalStateException( "Unsupported combination: [interceptorsEnabled=" + interceptorsEnabled + ", decorationEnabled=" + decorationEnabled + "]"); }