ResourceComponentProviderFactoryClass rf = annotationClass.getAnnotation(
ResourceComponentProviderFactoryClass.class);
if (rf != null && providerFactoryClass == null)
providerFactoryClass = rf.value();
else if (rf != null && providerFactoryClass != null)
throw new ContainerException(c.toString()+
" has multiple ResourceComponentProviderClass annotations");
}
if (providerFactoryClass == null) {
Object v = config.getProperties().
get(ResourceConfig.PROPERTY_DEFAULT_RESOURCE_COMPONENT_PROVIDER_FACTORY_CLASS);
if (v == null) {
// Use default provider if none specified
providerFactoryClass = PerRequestFactory.class;
} else if (v instanceof Class) {
Class<?> _c = (Class<?>)v;
if (ResourceComponentProviderFactory.class.isAssignableFrom(_c)) {
providerFactoryClass = _c.asSubclass(ResourceComponentProviderFactory.class);
} else {
throw new IllegalArgumentException("Property value for "
+ ResourceConfig.PROPERTY_DEFAULT_RESOURCE_COMPONENT_PROVIDER_FACTORY_CLASS
+ " of type " + v.getClass() + " not of a subclass of " + ResourceComponentProviderFactory.class);
}
} else {
throw new IllegalArgumentException("Property value for "
+ ResourceConfig.PROPERTY_DEFAULT_RESOURCE_COMPONENT_PROVIDER_FACTORY_CLASS
+ " of type " + v.getClass() + " not of a subclass of " + ResourceComponentProviderFactory.class);
}
}
try {
ComponentConstructor<ResourceComponentProviderFactory> cc =
new ComponentConstructor(ipc, providerFactoryClass);
ResourceComponentProviderFactory rcpf = cc.getInstance();
ComponentInjector<ResourceComponentProviderFactory> ci =
new ComponentInjector(ipc, providerFactoryClass);
ci.inject(rcpf);
return rcpf;
} catch (IllegalArgumentException ex) {
throw new ContainerException("Unable to create resource component provider", ex);
} catch (InvocationTargetException ex) {
throw new ContainerException("Unable to create resource component provider", ex);
} catch (IllegalAccessException ex) {
throw new ContainerException("Unable to create resource component provider", ex);
} catch (InstantiationException ex) {
throw new ContainerException("Unable to create resource component provider", ex);
}
}