com.vaadin.flow.server.startup.
Class RouteRegistry
- java.lang.Object
-
- com.vaadin.flow.server.startup.RouteRegistry
-
All Implemented Interfaces:
public class RouteRegistry extends Object implements Serializable
Registry for holding navigation target components found on servlet initialization.
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static class
RouteRegistry.ErrorTargetEntry
A pair of a navigation target for handling exceptions and the exception type handled by the navigation target.
-
Constructor Summary
Constructors Modifier Constructor and Description protected
RouteRegistry()
Creates a new uninitialized route registry.
-
Method Summary
All Methods Modifier and Type Method and Description boolean
errorNavigationTargetsInitialized()
Returns whether this registry has been initialized with error navigation targets.
Optional<RouteRegistry.ErrorTargetEntry>
getErrorNavigationTarget(Exception exception)
Get a registered navigation target for given exception.
static RouteRegistry
getInstance(ServletContext servletContext)
Gets the route registry for the given servlet context.
Optional<Class<? extends Component>>
getNavigationTarget(String pathString)
Gets the optional navigation target class for a given Location.
Optional<Class<? extends Component>>
getNavigationTarget(String pathString, List<String> segments)
Gets the optional navigation target class for a given Location matching with path segments.
List<RouteData>
getRegisteredRoutes()
Get the
RouteData
for all registered navigation targets.Optional<String>
getTargetUrl(Class<? extends Component> navigationTarget)
Get the url string for given navigation target.
Optional<ThemeDefinition>
getThemeFor(Class<?> navigationTarget, String path)
Gets the
ThemeDefinition
associated with the given navigation target, if any.boolean
hasNavigationTargets()
Checks whether any navigation targets have been registered.
boolean
hasRoutes()
Check if there are any registered routes.
boolean
hasRouteTo(String pathString)
Checks if the registry contains a route to the given path.
boolean
navigationTargetsInitialized()
Returns whether this registry has been initialized with navigation targets.
void
setErrorNavigationTargets(Set<Class<? extends Component>> errorNavigationTargets)
Set error handler navigation targets.
void
setNavigationTargets(Set<Class<? extends Component>> navigationTargets)
Registers a set of components as navigation targets.
-
-
-
Constructor Detail
-
RouteRegistry
protected RouteRegistry()
Creates a new uninitialized route registry.
-
-
Method Detail
-
getInstance
public static RouteRegistry getInstance(ServletContext servletContext)
Gets the route registry for the given servlet context. If the servlet context has no route registry, a new instance is created and assigned to the context.
Parameters:
servletContext
- the servlet context for which to get a route registry, notnull
Returns:
a registry instance for the given servlet context, not
null
-
setNavigationTargets
public void setNavigationTargets(Set<Class<? extends Component>> navigationTargets) throws InvalidRouteConfigurationException
Registers a set of components as navigation targets.
Note: Navigation targets can only be set once, i.e. when
navigationTargetsInitialized()
isfalse
.Parameters:
navigationTargets
- set of navigation target componentsThrows:
InvalidRouteConfigurationException
- if routing has been configured incorrectly
-
setErrorNavigationTargets
public void setErrorNavigationTargets(Set<Class<? extends Component>> errorNavigationTargets)
Set error handler navigation targets.
Parameters:
errorNavigationTargets
- error handler navigation targets
-
getRegisteredRoutes
public List<RouteData> getRegisteredRoutes()
Get the
RouteData
for all registered navigation targets.Returns:
list of routes available for this registry
-
errorNavigationTargetsInitialized
public boolean errorNavigationTargetsInitialized()
Returns whether this registry has been initialized with error navigation targets.
Returns:
whether this registry has been initialized with error navigation targets
-
getErrorNavigationTarget
public Optional<RouteRegistry.ErrorTargetEntry> getErrorNavigationTarget(Exception exception)
Get a registered navigation target for given exception. First we will search for a matching cause for in the exception chain and if no match found search by extended type.
Parameters:
exception
- exception to search error view forReturns:
optional error target entry corresponding to the given exception
-
getNavigationTarget
public Optional<Class<? extends Component>> getNavigationTarget(String pathString)
Gets the optional navigation target class for a given Location. Returns an empty optional if no navigation target corresponds to the given Location.
Parameters:
pathString
- the path to get the navigation target for, notnull
Returns:
optional of the navigation target corresponding to the given location
See Also:
-
getNavigationTarget
public Optional<Class<? extends Component>> getNavigationTarget(String pathString, List<String> segments)
Gets the optional navigation target class for a given Location matching with path segments.
Parameters:
pathString
- path to get navigation target for, notnull
segments
- segments given for pathReturns:
optional navigation target corresponding to the given location with given segments if any applicable targets found.
See Also:
-
hasRouteTo
public boolean hasRouteTo(String pathString)
Checks if the registry contains a route to the given path.
Parameters:
pathString
- path to get navigation target for, notnull
Returns:
true if the registry contains a route to the given path, false otherwise.
-
getTargetUrl
public Optional<String> getTargetUrl(Class<? extends Component> navigationTarget)
Get the url string for given navigation target.
Parameters:
navigationTarget
- navigation target to get registered route for, notnull
Returns:
optional navigation target url string
-
navigationTargetsInitialized
public boolean navigationTargetsInitialized()
Returns whether this registry has been initialized with navigation targets.
Returns:
whether this registry has been initialized
-
hasNavigationTargets
public boolean hasNavigationTargets()
Checks whether any navigation targets have been registered.
Returns:
true
if at least one navigation target is registered; otherwisefalse
-
hasRoutes
public boolean hasRoutes()
Check if there are any registered routes.
Returns:
true if we have registered routes
-
getThemeFor
public Optional<ThemeDefinition> getThemeFor(Class<?> navigationTarget, String path)
Gets the
ThemeDefinition
associated with the given navigation target, if any. The theme is defined by using theTheme
annotation on the navigation target class.If no
Theme
andNoTheme
annotation are used, by default thecom.vaadin.flow.theme.lumo.Lumo
class is used (if present on the classpath).Parameters:
navigationTarget
- the navigation target classpath
- the resolved route path so we can determine what the rendered target is forReturns:
the associated ThemeDefinition, or empty if none is defined and the Lumo class is not in the classpath, or if the NoTheme annotation is being used.
-
-