/** * Introspect given type to determine if it represents a JAX-RS component. * * @param clazz type to be introspected. * @return true if the type represents a JAX-RS component type. */ /* package */ boolean isJaxRsComponentType(final Class<?> clazz) { return jaxRsComponentCache.apply(clazz); }
@Override public Boolean apply(final Class<?> clazz) { return Application.class.isAssignableFrom(clazz) || Providers.isJaxRsProvider(clazz) || jaxRsResourceCache.apply(clazz); } });
@AroundInvoke public Object validateMethodInvocation(InvocationContext ctx) throws Exception { final boolean isJaxRsMethod = extension.jaxRsResourceCache.apply(ctx.getMethod().getDeclaringClass()); return isJaxRsMethod ? ctx.proceed() : interceptor.validateMethodInvocation(ctx); }
@AroundConstruct public void validateConstructorInvocation(InvocationContext ctx) throws Exception { final boolean isJaxRsConstructor = extension.jaxRsResourceCache.apply(ctx.getConstructor().getDeclaringClass()); if (!isJaxRsConstructor) { interceptor.validateConstructorInvocation(ctx); } } }
@Override public Object apply(ContainerRequest request) { Class<?> rawType = parameter.getRawType(); Object fromHk2 = injectionManager.getInstance(rawType); if (fromHk2 != null) { // the bean parameter type is already bound in HK2, let's just take it from there return fromHk2; } ForeignDescriptor foreignDescriptor = descriptorCache.apply(rawType); return injectionManager.getInstance(foreignDescriptor); } }
@Override public Object apply(ContainerRequest request) { Class<?> rawType = parameter.getRawType(); Object fromHk2 = injectionManager.getInstance(rawType); if (fromHk2 != null) { // the bean parameter type is already bound in HK2, let's just take it from there return fromHk2; } ForeignDescriptor foreignDescriptor = descriptorCache.apply(rawType); return injectionManager.getInstance(foreignDescriptor); } }
/** * Provide a value for given injection point. If the injection point does not refer * to a CDI bean constructor parameter, or the value could not be found, the method will return null. * * @param injectionPoint actual injection point. * @param beanManager current application bean manager. * @return concrete JAX-RS parameter value for given injection point. */ @javax.enterprise.inject.Produces @JaxRsParamQualifier public String getParameterValue(final InjectionPoint injectionPoint, final BeanManager beanManager) { final Parameter parameter = parameterCache.apply(injectionPoint); if (parameter != null) { InjectionManager injectionManager = beanManager.getExtension(CdiComponentProvider.class).getEffectiveInjectionManager(); Set<ValueParamProvider> providers = Providers.getProviders(injectionManager, ValueParamProvider.class); ContainerRequest containerRequest = injectionManager.getInstance(ContainerRequest.class); for (ValueParamProvider vfp : providers) { Function<ContainerRequest, ?> paramValueSupplier = vfp.getValueProvider(parameter); if (paramValueSupplier != null) { return (String) paramValueSupplier.apply(containerRequest); } } } return null; } }
@Override public Object resolve(Injectee injectee) { Injectee newInjectee = injectee; if (injectee.isFactory()) { newInjectee = getFactoryInjectee(injectee, ReflectionHelper.getTypeArgument(injectee.getRequiredType(), 0)); } Bean<?> bean = descriptorCache.apply(newInjectee.getRequiredType()); if (bean != null) { CreationalContext ctx = beanManager.get().createCreationalContext(bean); Object result = bean.create(ctx); if (injectee.isFactory()) { return (Supplier<Object>) () -> result; } else { return result; } } return null; }
@Override public Object resolve(Injectee injectee, ServiceHandle<?> root) { Type requiredType = injectee.getRequiredType(); boolean isHk2Factory = ReflectionHelper.isSubClassOf(requiredType, Factory.class); Injectee newInjectee; if (isHk2Factory) { newInjectee = getFactoryInjectee(injectee, ReflectionHelper.getTypeArgument(requiredType, 0)); } else { newInjectee = foreignRequestScopedInjecteeCache.apply(new CacheKey(injectee)); } ActiveDescriptor<?> ad = descriptorCache.apply(new CacheKey(newInjectee)); if (ad != null) { final ServiceHandle handle = serviceLocator.getServiceHandle(ad, newInjectee); if (isHk2Factory) { return asFactory(handle); } else { return handle.getService(); } } return null; }
@Override public Object resolve(Injectee injectee, ServiceHandle<?> root) { Type requiredType = injectee.getRequiredType(); boolean isHk2Factory = ReflectionHelper.isSubClassOf(requiredType, Factory.class); Injectee newInjectee; if (isHk2Factory) { newInjectee = getFactoryInjectee(injectee, ReflectionHelper.getTypeArgument(requiredType, 0)); } else { newInjectee = foreignRequestScopedInjecteeCache.apply(new CacheKey(injectee)); } ActiveDescriptor<?> ad = descriptorCache.apply(new CacheKey(newInjectee)); if (ad != null) { final ServiceHandle handle = serviceLocator.getServiceHandle(ad, newInjectee); if (isHk2Factory) { return asFactory(handle); } else { return handle.getService(); } } return null; }
final boolean isJaxRsResource = jaxRsResourceCache.apply(clazz);
/** * Creates a new object {@link Injectee} corresponding to the injecting point. The injectee contains basic information * about the injection point types and {@link ForeignDescriptor} of the underlying DI provider to make delegated injection * resolver as simple as possible. * * @param parameter jersey-like parameter corresponding to one resource-method's parameter. * @return injectee instance as a source of the information about the injecting point. */ private Injectee getInjectee(Parameter parameter) { InjecteeImpl injectee = new InjecteeImpl(); injectee.setRequiredType(parameter.getType()); injectee.setInjecteeClass(parameter.getRawType()); ForeignDescriptor proxyDescriptor = descriptorCache.apply(parameter); if (proxyDescriptor != null) { injectee.setInjecteeDescriptor(proxyDescriptor); } return injectee; }
/** * Creates a new object {@link Injectee} corresponding to the injecting point. The injectee contains basic information * about the injection point types and {@link ForeignDescriptor} of the underlying DI provider to make delegated injection * resolver as simple as possible. * * @param parameter jersey-like parameter corresponding to one resource-method's parameter. * @return injectee instance as a source of the information about the injecting point. */ private Injectee getInjectee(Parameter parameter) { InjecteeImpl injectee = new InjecteeImpl(); injectee.setRequiredType(parameter.getType()); injectee.setInjecteeClass(parameter.getRawType()); ForeignDescriptor proxyDescriptor = descriptorCache.apply(parameter); if (proxyDescriptor != null) { injectee.setInjecteeDescriptor(proxyDescriptor); } return injectee; }
@Override public Object apply(ContainerRequest request) { Class<?> rawType = parameter.getRawType(); Object fromHk2 = injectionManager.getInstance(rawType); if (fromHk2 != null) { // the bean parameter type is already bound in HK2, let's just take it from there return fromHk2; } ForeignDescriptor foreignDescriptor = descriptorCache.apply(rawType); return injectionManager.getInstance(foreignDescriptor); } }
/** * Creates a new object {@link Injectee} corresponding to the injecting point. The injectee contains basic information * about the injection point types and {@link ForeignDescriptor} of the underlying DI provider to make delegated injection * resolver as simple as possible. * * @param parameter jersey-like parameter corresponding to one resource-method's parameter. * @return injectee instance as a source of the information about the injecting point. */ private Injectee getInjectee(Parameter parameter) { InjecteeImpl injectee = new InjecteeImpl(); injectee.setRequiredType(parameter.getType()); injectee.setInjecteeClass(parameter.getRawType()); ForeignDescriptor proxyDescriptor = descriptorCache.apply(parameter); if (proxyDescriptor != null) { injectee.setInjecteeDescriptor(proxyDescriptor); } return injectee; }
/** * Introspect given type to determine if it represents a JAX-RS component. * * @param clazz type to be introspected. * @return true if the type represents a JAX-RS component type. */ /* package */ boolean isJaxRsComponentType(final Class<?> clazz) { return jaxRsComponentCache.apply(clazz); }
@Override public Boolean apply(final Class<?> clazz) { return Application.class.isAssignableFrom(clazz) || Providers.isJaxRsProvider(clazz) || jaxRsResourceCache.apply(clazz); } });
@Override public Object apply(ContainerRequest request) { Class<?> rawType = parameter.getRawType(); Object fromHk2 = injectionManager.getInstance(rawType); if (fromHk2 != null) { // the bean parameter type is already bound in HK2, let's just take it from there return fromHk2; } ForeignDescriptor foreignDescriptor = descriptorCache.apply(rawType); return injectionManager.getInstance(foreignDescriptor); } }
/** * Provide a value for given injection point. If the injection point does not refer * to a CDI bean constructor parameter, or the value could not be found, the method will return null. * * @param injectionPoint actual injection point. * @param beanManager current application bean manager. * @return concrete JAX-RS parameter value for given injection point. */ @javax.enterprise.inject.Produces @JaxRsParamQualifier public String getParameterValue(final InjectionPoint injectionPoint, final BeanManager beanManager) { final Parameter parameter = parameterCache.apply(injectionPoint); if (parameter != null) { InjectionManager injectionManager = beanManager.getExtension(CdiComponentProvider.class).getEffectiveInjectionManager(); Set<ValueParamProvider> providers = Providers.getProviders(injectionManager, ValueParamProvider.class); ContainerRequest containerRequest = injectionManager.getInstance(ContainerRequest.class); for (ValueParamProvider vfp : providers) { Function<ContainerRequest, ?> paramValueSupplier = vfp.getValueProvider(parameter); if (paramValueSupplier != null) { return (String) paramValueSupplier.apply(containerRequest); } } } return null; } }
@Override public Object resolve(Injectee injectee, ServiceHandle<?> root) { Type requiredType = injectee.getRequiredType(); boolean isHk2Factory = ReflectionHelper.isSubClassOf(requiredType, Factory.class); Injectee newInjectee; if (isHk2Factory) { newInjectee = getFactoryInjectee(injectee, ReflectionHelper.getTypeArgument(requiredType, 0)); } else { newInjectee = foreignRequestScopedInjecteeCache.apply(new CacheKey(injectee)); } ActiveDescriptor<?> ad = descriptorCache.apply(new CacheKey(newInjectee)); if (ad != null) { final ServiceHandle handle = serviceLocator.getServiceHandle(ad, newInjectee); if (isHk2Factory) { return asFactory(handle); } else { return handle.getService(); } } return null; }