}
config = new ComponentsClientConfig(config, components);
}
final InjectableProviderFactory injectableFactory = new InjectableProviderFactory();
getProperties().putAll(config.getProperties());
if (provider != null) {
if (provider instanceof IoCComponentProcessorFactoryInitializer) {
IoCComponentProcessorFactoryInitializer i = (IoCComponentProcessorFactoryInitializer)provider;
i.init(new ComponentProcessorFactoryImpl(injectableFactory));
}
}
// Set up the component provider factory
this.componentProviderFactory = (provider == null)
? new ProviderFactory(injectableFactory)
: new IoCProviderFactory(injectableFactory, provider);
ProviderServices providerServices = new ProviderServices(
ClientSide.class,
this.componentProviderFactory,
config.getClasses(),
config.getSingletons());
// Get the set of WebResourceProxy
vpps = providerServices.getServices(ViewProxyProvider.class);
// Allow injection of features and properties
injectableFactory.add(new ContextInjectableProvider<FeaturesAndProperties>(
FeaturesAndProperties.class, config));
// Allow injection of client config
injectableFactory.add(new ContextInjectableProvider<ClientConfig>(
ClientConfig.class, config));
// Allow injection of client
injectableFactory.add(new ContextInjectableProvider<Client>(
Client.class, this));
injectableFactory.configure(providerServices);
// Obtain all context resolvers
final ContextResolverFactory crf = new ContextResolverFactory();
// Obtain all message body readers/writers
final MessageBodyFactory bodyContext = new MessageBodyFactory(providerServices,
config.getFeature(FeaturesAndProperties.FEATURE_PRE_1_4_PROVIDER_PRECEDENCE));
workers = bodyContext;
// Allow injection of message body context
injectableFactory.add(new ContextInjectableProvider<MessageBodyWorkers>(
MessageBodyWorkers.class, bodyContext));
// Injection of Providers
this.providers = new Providers() {
@Override
public <T> MessageBodyReader<T> getMessageBodyReader(Class<T> c, Type t,
Annotation[] as, MediaType m) {
return bodyContext.getMessageBodyReader(c, t, as, m);
}
@Override
public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> c, Type t,
Annotation[] as, MediaType m) {
return bodyContext.getMessageBodyWriter(c, t, as, m);
}
@Override
public <T extends Throwable> ExceptionMapper<T> getExceptionMapper(Class<T> c) {
throw new IllegalArgumentException("This method is not supported on the client side");
}
@Override
public <T> ContextResolver<T> getContextResolver(Class<T> ct, MediaType m) {
return crf.resolve(ct, m);
}
};
injectableFactory.add(
new ContextInjectableProvider<Providers>(
Providers.class, this.providers));
injectableFactory.add(new InjectableProvider<Context, Type>() {
@Override
public ComponentScope getScope() {
return ComponentScope.Singleton;
}
@Override
public Injectable<Injectable> getInjectable(ComponentContext ic, Context a, Type c) {
if (c instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType)c;
if (pt.getRawType() == Injectable.class) {
if (pt.getActualTypeArguments().length == 1) {
final Injectable<?> i = injectableFactory.getInjectable(
a.annotationType(),
ic,
a,
pt.getActualTypeArguments()[0],
ComponentScope.PERREQUEST_UNDEFINED_SINGLETON);