}
}
@Override
public Object matchResource(URI u) throws ContainerException {
ExtendedUriInfo ui = matchUriInfo(u);
return (ui != null) ? ui.getMatchedResources().get(0) : null;
}
@Override
public <T> T matchResource(URI u, Class<T> c) throws ContainerException, ClassCastException {
return c.cast(matchResource(u));
}
@Override
public <T> T getResource(Class<T> c) {
return c.cast(getResourceComponentProvider(c).getInstance(context));
}
};
final ProviderServices providerServices = new ProviderServices(
ServerSide.class,
this.cpFactory,
resourceConfig.getProviderClasses(),
resourceConfig.getProviderSingletons());
injectableFactory.add(new ContextInjectableProvider<ProviderServices>(
ProviderServices.class, providerServices));
injectableFactory.add(new ContextInjectableProvider<ResourceMethodCustomInvokerDispatchFactory>(
ResourceMethodCustomInvokerDispatchFactory.class, new ResourceMethodCustomInvokerDispatchFactory(providerServices)));
// Add injectable provider for @ParentRef
injectableFactory.add(
new InjectableProvider<ParentRef, Type>() {
@Override
public ComponentScope getScope() {
return ComponentScope.PerRequest;
}
@Override
public Injectable<Object> getInjectable(ComponentContext cc, ParentRef a, Type t) {
if (!(t instanceof Class))
return null;
final Class target = ReflectionHelper.getDeclaringClass(cc.getAccesibleObject());
final Class inject = (Class)t;
return new Injectable<Object>() {
@Override
public Object getValue() {
final UriInfo ui = context.getUriInfo();
final List l = ui.getMatchedResources();
final Object parent = getParent(l, target);
if (parent == null) return null;
try {
return inject.cast(parent);