Class AbstractRouter<A,B,C extends Route<A>,D extends RouteManager<A,B,C,D,E>,E extends Router<A,B,C,D,E>,F extends RouteExtractor<A,C>>
- Type Parameters:
A
- the resource typeB
- the input typeC
- the route typeD
- the route manager typeE
- the router typeF
- the route extractor type
- All Implemented Interfaces:
Router<A,
B, C, D, E>
Base Router
implementation.
It is based on a routing chain
, implementors must also provide consistent implementations for: AbstractRoute
, AbstractRouteManager
and
AbstractRouteExtractor
.
Assuming resource resolution is based on criteria A
, B
and C
extracted from a SampleInput
, implementors would provides RoutingLink
implementations:
ARoutingLink
, BRoutingLink
and CRoutingLink
, each of them being responsible for resolving the next routing link from their respective criteria. A sample router could then be
implemented as follows:
public class SampleRouter extends AbstractRouter<SampleResource, SampleInput, SampleRoute, SampleRouteManager, SampleRouter, SampleRouteExtractor> {
public TestRouter() {
super(RoutingLink
.link(ARoutingLink::new)
.link(BRoutingLink::new)
.link(ign -> new CRoutingLink())
);
}
@Override
protected SampleRoute createRoute(String resource, boolean disabled) {
return new SampleRoute(this, resource, disabled);
}
@Override
protected SampleRouteExtractor createRouteExtractor() {
return new SampleRouteExtractor(this);
}
@Override
protected SampleRouteManager createRouteManager() {
return new SampleRouteManager(this);
}
}
- Since:
- 1.12
- Author:
- Jeremy Kuhn
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractRouter
(RoutingLink.ChainBuilder<A, B, C, F> chainBuilder) Creates a router.protected
AbstractRouter
(RoutingLink<A, B, C, F> firstLink) Creates a router. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract C
createRoute
(A resource, boolean disabled) Creates a route.protected abstract F
Creates a route extractor.protected abstract D
Creates a route manager.protected void
disableRoute
(C route) Disables the specified route in the router.protected void
enableRoute
(C route) Enables the specified route in the router.Returns the routes defined in the router.protected void
removeRoute
(C route) Removes the specified route from the router.Resolves the resource best matching the specified input.resolveAll
(B input) Resolves all resources matching the specified input ordered from the best matching to the least matching.route()
Returns a new route manager to define a route in the router.Defines a route in the router using a configurer.protected void
Sets the specified route in the router.
-
Constructor Details
-
AbstractRouter
Creates a router.
- Parameters:
chainBuilder
- the routing chain builder
-
AbstractRouter
Creates a router.
- Parameters:
firstLink
- the first link in the routing chain
-
-
Method Details
-
createRoute
Creates a route.
- Parameters:
resource
- the resource targeted by the routedisabled
- true to create a disabled route, false otherwise- Returns:
- a route
-
createRouteManager
Creates a route manager.
- Returns:
- a route manager
-
createRouteExtractor
Creates a route extractor.
- Returns:
- a route extractor
-
setRoute
Sets the specified route in the router.
- Parameters:
route
- the route to set
-
removeRoute
Removes the specified route from the router.
- Parameters:
route
- the route to remove
-
disableRoute
Disables the specified route in the router.
- Parameters:
route
- the route to disable
-
enableRoute
Enables the specified route in the router.
- Parameters:
route
- the route to enable
-
route
Description copied from interface:Router
Returns a new route manager to define a route in the router.
-
route
Description copied from interface:Router
Defines a route in the router using a configurer.
-
getRoutes
Description copied from interface:Router
Returns the routes defined in the router.
-
resolve
Description copied from interface:Router
Resolves the resource best matching the specified input.
-
resolveAll
Description copied from interface:Router
Resolves all resources matching the specified input ordered from the best matching to the least matching.
-