private void handleSubResourceLocator(SubResourceInstance subResourceInstance,
List<SubResourceInstance> subResources,
MessageContext context,
HandlersChain chain) throws Throwable {
ResourceRegistry registry = context.getAttribute(ResourceRegistry.class);
SearchResult result = context.getAttribute(SearchResult.class);
UriTemplateMatcher matcher = subResourceInstance.getMatcher();
// // dispatch to the sub-resource locator.
// result.setFound(true);
// result.setMethod(subResourceInstance);
// // save the matched template variables for UriInfo
// matcher.storeVariables(result.getData().getMatchedVariables(),
// false);
// // save the matched uri for UriInfo
// result.getData().addMatchedUri(matcher.getHead(false));
saveFoundMethod(result, matcher, subResourceInstance, context);
// continue the chain to invoke the locator
chain.doChain(context);
// the object returned from the locator is a sub-resource so we must
// continue the search in it
Object subResource = context.getResponseEntity();
if (subResource == null) {
result.setError(new WebApplicationException(Status.NOT_FOUND));
return;
}
ResourceRecord record = registry.getRecord(subResource, false);
ResourceInstance resourceInstance = new ResourceInstance(subResource, record, matcher);
// save the resource for UriInfo
result.getData().getMatchedResources().addFirst(resourceInstance);
// call recursively to search in the sub-resource