Class AbstractRouteRegistry
- All Implemented Interfaces:
RouteRegistry,Serializable
- Direct Known Subclasses:
ApplicationRouteRegistry,SessionRouteRegistry
For internal use only. May be renamed or removed in a future release.
- Since:
- 1.3
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceConfiguration interface to use for updating the configuration entity. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddErrorTarget(Class<? extends Component> target, Map<Class<? extends Exception>, Class<? extends Component>> exceptionTargetsMap) Add the given error target to the exceptionTargetMap.addRoutesChangeListener(RoutesChangedListener listener) Adds the given route change listener to the registry.voidclean()Clear all registered routes from the registry.protected voidThread-safe update of the RouteConfiguration.protected voidfireEvent(RoutesChangedEvent routeChangedEvent) Fire routes changed event to all registered listeners.Get the current valid configuration.Class<? extends RouterLayout>Get the layout component for the current path.Search for a route target using given navigationurlargument.Gets the optional navigation target class for a given path.getNavigationTarget(String url, List<String> segments) Gets the optional navigation target class for a given Location matching with path segments.getRegisteredAccessibleMenuRoutes(VaadinRequest vaadinRequest, Collection<BeforeEnterListener> accessControls) Get theRouteDatafor all accessible registered navigation targets with a menu information.Get theRouteDatafor all registered navigation targets.getRouteTarget(Class<? extends Component> target, RouteParameters parameters) Gets theRouteTargetinstance matching the given target component and route parameters.getTargetUrl(Class<? extends Component> navigationTarget) Get the url string for given navigation target.getTargetUrl(Class<? extends Component> navigationTarget, RouteParameters parameters) Get the url string for given navigation target.getTemplate(Class<? extends Component> navigationTarget) Get the main template for given navigation target.booleanCheck if a layout component has been registered for the current path.protected booleanhasLock()booleanhasMandatoryParameter(Class<? extends Component> navigationTarget) Check if the given navigationTarget requires parameters.voidremoveRoute(Class<? extends Component> navigationTarget) Remove the given navigation target route registration.voidremoveRoute(String path) Remove the registration for given path.voidremoveRoute(String path, Class<? extends Component> navigationTarget) Remove navigationTarget for the path.protected Optional<ErrorTargetEntry>searchByCause(Exception exception) Get the exception handler for given exception or recurse by exception cause until possible exception with handler found.protected Optional<ErrorTargetEntry>searchBySuperType(Throwable exception) Search given exception super classes to get exception handler for if any exist.voidsetLayout(Class<? extends RouterLayout> layout) Set a layout component for use as automatic layout.voidsetRoute(String path, Class<? extends Component> navigationTarget, List<Class<? extends RouterLayout>> parentChain) Register a navigation target with specified path and given parent layout chain.voidBlock updates to the registry configuration from other threads until update command has completed.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.server.RouteRegistry
getContext
-
Constructor Details
-
AbstractRouteRegistry
public AbstractRouteRegistry()
-
-
Method Details
-
configure
Thread-safe update of the RouteConfiguration.- Parameters:
command- command that will mutate the configuration copy.
-
update
Description copied from interface:RouteRegistryBlock updates to the registry configuration from other threads until update command has completed. This makes the command changes atomic for the registry as no one else can change the registry state during the command.Any other thread trying to configure current registry will be blocked until the update has released all the locks.
- Specified by:
updatein interfaceRouteRegistry- Parameters:
command- command to execute for the update
-
fireEvent
Fire routes changed event to all registered listeners.- Parameters:
routeChangedEvent- event containing changes
-
addRoutesChangeListener
Description copied from interface:RouteRegistryAdds the given route change listener to the registry.- Specified by:
addRoutesChangeListenerin interfaceRouteRegistry- Parameters:
listener- listener to be informed on route changes- Returns:
- registration to remove the listener
-
hasLock
protected boolean hasLock() -
getConfiguration
Get the current valid configuration.Note! there may exist a possibility that someone updates this while it's being read, but the given configuration is valid at the given point in time.
- Returns:
- current state of the registry as a value object
-
getRegisteredRoutes
Description copied from interface:RouteRegistryGet theRouteDatafor all registered navigation targets.- Specified by:
getRegisteredRoutesin interfaceRouteRegistry- Returns:
- list of routes available for this registry
-
getRegisteredAccessibleMenuRoutes
public List<RouteData> getRegisteredAccessibleMenuRoutes(VaadinRequest vaadinRequest, Collection<BeforeEnterListener> accessControls) Description copied from interface:RouteRegistryGet theRouteDatafor all accessible registered navigation targets with a menu information. Access checking depends on the activeVaadinServiceandVaadinRequestand the given collection of access controls.- Specified by:
getRegisteredAccessibleMenuRoutesin interfaceRouteRegistry- Parameters:
vaadinRequest- the request to check access foraccessControls- the access controls to use for checking access- Returns:
- list of accessible menu routes available for this registry
-
getTargetUrl
Description copied from interface:RouteRegistryGet the url string for given navigation target.- Specified by:
getTargetUrlin interfaceRouteRegistry- Parameters:
navigationTarget- navigation target to get registered route for, notnull- Returns:
Optionalnavigation target url string orOptional.empty()if navigation target was not found
-
getTargetUrl
public Optional<String> getTargetUrl(Class<? extends Component> navigationTarget, RouteParameters parameters) Description copied from interface:RouteRegistryGet the url string for given navigation target.- Specified by:
getTargetUrlin interfaceRouteRegistry- Parameters:
navigationTarget- navigation target to get registered route for, notnullparameters- parameters for the target url.- Returns:
Optionalnavigation target url string orOptional.empty()if navigation target was not found
-
getTemplate
Description copied from interface:RouteRegistryGet the main template for given navigation target.In case of annotated target the main template is composed of the
Routeannotation value prefixed by allRoutePrefixvalues of the parentRouterLayouts chain.- Specified by:
getTemplatein interfaceRouteRegistry- Parameters:
navigationTarget- navigation target to get route definition for, notnull- Returns:
Optionalnavigation target template string orOptional.empty()if navigation target was not found
-
setRoute
public void setRoute(String path, Class<? extends Component> navigationTarget, List<Class<? extends RouterLayout>> parentChain) Description copied from interface:RouteRegistryRegister a navigation target with specified path and given parent layout chain. AnyParentLayout,RouteorRouteAliaswill be ignored in route handling.- Specified by:
setRoutein interfaceRouteRegistry- Parameters:
path- path to register navigation target tonavigationTarget- navigation target to register into session scopeparentChain- chain of parent layouts that should be used with this target
-
removeRoute
Description copied from interface:RouteRegistryRemove the given navigation target route registration.Note! this will remove target route and if possible any
RouteAliasroute that can be found for the class.- Specified by:
removeRoutein interfaceRouteRegistry- Parameters:
navigationTarget- navigation target class to remove
-
removeRoute
Description copied from interface:RouteRegistryRemove the registration for given path.In case navigationTarget is a
HasUrlParameter, path argument needs to include the parameter placeholder which is added automatically. Otherwise, usingRouteRegistry.removeRoute(String, Class)is preferred in such a case.- Specified by:
removeRoutein interfaceRouteRegistry- Parameters:
path- path for which to remove the navigation target.
-
removeRoute
Description copied from interface:RouteRegistryRemove navigationTarget for the path.This method will check if indeed navigationTarget is registered with path.
In case navigationTarget is a
HasUrlParameter, the path needs to be specified exactly as it is in theRouteannotation or as it was registered usingRouteRegistry.setRoute(String, Class, List), without the parameter placeholder which is automatically added.- Specified by:
removeRoutein interfaceRouteRegistry- Parameters:
path- path to remove from registrynavigationTarget- path navigation target to remove
-
clean
public void clean()Description copied from interface:RouteRegistryClear all registered routes from the registry.- Specified by:
cleanin interfaceRouteRegistry
-
hasMandatoryParameter
Description copied from interface:RouteRegistryCheck if the given navigationTarget requires parameters.- Specified by:
hasMandatoryParameterin interfaceRouteRegistry- Parameters:
navigationTarget- navigation target to check- Returns:
trueif parameters are required
-
getRouteTarget
Description copied from interface:RouteRegistryGets theRouteTargetinstance matching the given target component and route parameters.- Specified by:
getRouteTargetin interfaceRouteRegistry- Parameters:
target- a component class which is a navigation target.parameters- parameter values that may be used with given target.- Returns:
- the
RouteTargetinstance matching the given target component and route parameters.
-
addErrorTarget
protected void addErrorTarget(Class<? extends Component> target, Map<Class<? extends Exception>, Class<? extends Component>> exceptionTargetsMap) Add the given error target to the exceptionTargetMap. This will handle existing overlapping exception types by assigning the correct error target according to inheritance or throw if existing and new are not related.- Parameters:
target- error handler targetexceptionTargetsMap- map of existing error handlers- Throws:
InvalidRouteConfigurationException- if trying to add a non related exception handler for which a handler already exists
-
searchByCause
Get the exception handler for given exception or recurse by exception cause until possible exception with handler found.- Parameters:
exception- exception to get handler for- Returns:
- Optional containing found handler or empty if none found
-
searchBySuperType
Search given exception super classes to get exception handler for if any exist.- Parameters:
exception- exception to get handler for- Returns:
- Optional containing found handler or empty if none found
-
setLayout
Description copied from interface:RouteRegistrySet a layout component for use as automatic layout.- Specified by:
setLayoutin interfaceRouteRegistry- Parameters:
layout-RouterLayoutclass
-
getLayout
Description copied from interface:RouteRegistryGet the layout component for the current path.- Specified by:
getLayoutin interfaceRouteRegistry- Parameters:
path- current path- Returns:
RouterLayoutcomponent or null
-
hasLayout
Description copied from interface:RouteRegistryCheck if a layout component has been registered for the current path.- Specified by:
hasLayoutin interfaceRouteRegistry- Parameters:
path- current path- Returns:
trueif layout exists
-