PushMatchedRuntimeResourceRouter resourcePushingRouter = new PushMatchedRuntimeResourceRouter(resource);
// resource methods
if (!resource.getResourceMethods().isEmpty()) {
final List<MethodAcceptorPair> methodAcceptors = createAcceptors(resource, subResourceMode);
final PathPattern resourceClosedPattern =
(subResourceMode) ? PathPattern.END_OF_PATH_PATTERN : PathPattern.asClosed(resource.getPathPattern());
lastRoutedBuilder = routeMethodAcceptor(
lastRoutedBuilder,
resourceClosedPattern,
uriPushingRouter,
resourcePushingRouter,
new MethodSelectingRouter(workers, methodAcceptors),
subResourceMode);
}
RouteToPathBuilder<PathPattern> srRoutedBuilder = null;
if (!resource.getChildRuntimeResources().isEmpty()) {
for (RuntimeResource child : resource.getChildRuntimeResources()) {
final PathPattern childOpenPattern = child.getPathPattern();
final PathPattern childClosedPattern = PathPattern.asClosed(childOpenPattern);
PushMatchedRuntimeResourceRouter childResourcePushingRouter =
new PushMatchedRuntimeResourceRouter(child);
// sub resource methods
if (!child.getResourceMethods().isEmpty()) {
final List<MethodAcceptorPair> childMethodAcceptors = createAcceptors(child, subResourceMode);
srRoutedBuilder = routedBuilder(srRoutedBuilder)
.route(childClosedPattern)
.to(uriPushingRouter)
.to(childResourcePushingRouter)
.to(new MethodSelectingRouter(workers, childMethodAcceptors));
}
// sub resource locator
if (child.getResourceLocator() != null) {
PushMatchedTemplateRouter locTemplateRouter = getTemplateRouterForChildLocator(subResourceMode, child);
srRoutedBuilder = routedBuilder(srRoutedBuilder)
.route(childOpenPattern)
.to(uriPushingRouter)
.to(locTemplateRouter)
.to(childResourcePushingRouter)
.to(new PushMatchedMethodRouter(child.getResourceLocator()))
.to(createMethodAcceptor(child.getResourceLocator()));
}
}
}
// resource locator with empty path
if (resource.getResourceLocator() != null) {
final PushMatchedTemplateRouter resourceTemplateRouter = getTemplateRouter(subResourceMode,
getLocatorResource(resource).getPathPattern().getTemplate(),
PathPattern.OPEN_ROOT_PATH_PATTERN.getTemplate());
srRoutedBuilder = routedBuilder(srRoutedBuilder)
.route(PathPattern.OPEN_ROOT_PATH_PATTERN)
.to(uriPushingRouter)
.to(resourceTemplateRouter)
.to(new PushMatchedMethodRouter(resource.getResourceLocator()))
.to(createMethodAcceptor(resource.getResourceLocator()));
}
if (srRoutedBuilder != null) {
final PathPattern resourceOpenPattern =
(subResourceMode) ? PathPattern.OPEN_ROOT_PATH_PATTERN : resource.getPathPattern();
lastRoutedBuilder = routeMethodAcceptor(
lastRoutedBuilder, resourceOpenPattern, uriPushingRouter, resourcePushingRouter,
srRoutedBuilder.build(), subResourceMode);