if (subResourceInstance == null) {
throw new NotFoundException();
}
Resource subResource;
if (subResourceInstance.getClass().isAssignableFrom(Resource.class)) {
subResource = (Resource) subResourceInstance;
} else {
if (subResourceInstance.getClass().isAssignableFrom(Class.class)) {
final Class<?> clazz = (Class<?>) subResourceInstance;
subResourceInstance = Injections.getOrCreate(locator, clazz);
} else {
routingContext.pushMatchedResource(subResourceInstance);
resourceContext.bindResourceIfSingleton(subResourceInstance);
}
Resource.Builder builder = Resource.builder(subResourceInstance.getClass());
if (builder == null) {
// resource is empty - do not throw 404, wait if ModelProcessors add any method
builder = Resource.builder().name(subResourceInstance.getClass().getName());
}
subResource = builder.build();
}
ResourceModel resourceModel = new ResourceModel.Builder(true).addResource(subResource).build();
resourceModel = processSubResource(resourceModel);
if (!disableValidation) {
validate(resourceModel, ignoreValidationErrors);
}
subResource = resourceModel.getResources().get(0);
routingContext.pushLocatorSubResource(subResource);
processingContext.triggerEvent(RequestEvent.Type.SUBRESOURCE_LOCATED);
for (Class<?> handlerClass : subResource.getHandlerClasses()) {
resourceContext.bindResource(handlerClass);
}
// TODO: implement generated sub-resource methodAcceptorPair caching
Router subResourceAcceptor = runtimeModelBuilder.buildModel(resourceModel.getRuntimeResourceModel(), true);