com.vaadin.flow.router.internal.

Class AbstractRouteRegistry

java.lang.Object
com.vaadin.flow.router.internal.AbstractRouteRegistry

All Implemented Interfaces:

RouteRegistry, Serializable

Direct Known Subclasses:

ApplicationRouteRegistry, SessionRouteRegistry

public abstract class AbstractRouteRegistry extends Object implements RouteRegistry

AbstractRouteRegistry with locking support and configuration.

For internal use only. May be renamed or removed in a future release.

Since:

1.3

See Also:

  • Constructor Details

    • AbstractRouteRegistry

      public AbstractRouteRegistry()
  • Method Details

    • configure

      protected void configure(AbstractRouteRegistry.Configuration command)

      Thread-safe update of the RouteConfiguration.

      Parameters:

      command - command that will mutate the configuration copy.

    • update

      public void update(Command command)

      Description copied from interface: RouteRegistry

      Block 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:

      update in interface RouteRegistry

      Parameters:

      command - command to execute for the update

    • fireEvent

      protected void fireEvent(RoutesChangedEvent routeChangedEvent)

      Fire routes changed event to all registered listeners.

      Parameters:

      routeChangedEvent - event containing changes

    • addRoutesChangeListener

      public Registration addRoutesChangeListener(RoutesChangedListener listener)

      Description copied from interface: RouteRegistry

      Adds the given route change listener to the registry.

      Specified by:

      addRoutesChangeListener in interface RouteRegistry

      Parameters:

      listener - listener to be informed on route changes

      Returns:

      registration to remove the listener

    • hasLock

      protected boolean hasLock()
    • getConfiguration

      public ConfiguredRoutes 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

      public List<RouteData> getRegisteredRoutes()

      Description copied from interface: RouteRegistry

      Get the RouteData for all registered navigation targets.

      Specified by:

      getRegisteredRoutes in interface RouteRegistry

      Returns:

      list of routes available for this registry

    • getRegisteredAccessibleMenuRoutes

      public List<RouteData> getRegisteredAccessibleMenuRoutes(VaadinRequest vaadinRequest, Collection<BeforeEnterListener> accessControls)

      Description copied from interface: RouteRegistry

      Get the RouteData for all accessible registered navigation targets with a menu information. Access checking depends on the active VaadinService and VaadinRequest and the given collection of access controls.

      Specified by:

      getRegisteredAccessibleMenuRoutes in interface RouteRegistry

      Parameters:

      vaadinRequest - the request to check access for

      accessControls - the access controls to use for checking access

      Returns:

      list of accessible menu routes available for this registry

    • getTargetUrl

      public Optional<String> getTargetUrl(Class<? extends Component> navigationTarget)

      Description copied from interface: RouteRegistry

      Get the url string for given navigation target.

      Specified by:

      getTargetUrl in interface RouteRegistry

      Parameters:

      navigationTarget - navigation target to get registered route for, not null

      Returns:

      Optional navigation target url string or Optional.empty() if navigation target was not found

    • getTargetUrl

      public Optional<String> getTargetUrl(Class<? extends Component> navigationTarget, RouteParameters parameters)

      Description copied from interface: RouteRegistry

      Get the url string for given navigation target.

      Specified by:

      getTargetUrl in interface RouteRegistry

      Parameters:

      navigationTarget - navigation target to get registered route for, not null

      parameters - parameters for the target url.

      Returns:

      Optional navigation target url string or Optional.empty() if navigation target was not found

    • getTemplate

      public Optional<String> getTemplate(Class<? extends Component> navigationTarget)

      Description copied from interface: RouteRegistry

      Get the main template for given navigation target.

      In case of annotated target the main template is composed of the Route annotation value prefixed by all RoutePrefix values of the parent RouterLayouts chain.

      Specified by:

      getTemplate in interface RouteRegistry

      Parameters:

      navigationTarget - navigation target to get route definition for, not null

      Returns:

      Optional navigation target template string or Optional.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: RouteRegistry

      Register a navigation target with specified path and given parent layout chain. Any ParentLayout, Route or RouteAlias will be ignored in route handling.

      Specified by:

      setRoute in interface RouteRegistry

      Parameters:

      path - path to register navigation target to

      navigationTarget - navigation target to register into session scope

      parentChain - chain of parent layouts that should be used with this target

    • removeRoute

      public void removeRoute(Class<? extends Component> navigationTarget)

      Description copied from interface: RouteRegistry

      Remove the given navigation target route registration.

      Note! this will remove target route and if possible any RouteAlias route that can be found for the class.

      Specified by:

      removeRoute in interface RouteRegistry

      Parameters:

      navigationTarget - navigation target class to remove

    • removeRoute

      public void removeRoute(String path)

      Description copied from interface: RouteRegistry

      Remove the registration for given path.

      In case navigationTarget is a HasUrlParameter, path argument needs to include the parameter placeholder which is added automatically. Otherwise, using RouteRegistry.removeRoute(String, Class) is preferred in such a case.

      Specified by:

      removeRoute in interface RouteRegistry

      Parameters:

      path - path for which to remove the navigation target.

    • removeRoute

      public void removeRoute(String path, Class<? extends Component> navigationTarget)

      Description copied from interface: RouteRegistry

      Remove 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 the Route annotation or as it was registered using RouteRegistry.setRoute(String, Class, List), without the parameter placeholder which is automatically added.

      Specified by:

      removeRoute in interface RouteRegistry

      Parameters:

      path - path to remove from registry

      navigationTarget - path navigation target to remove

    • clean

      public void clean()

      Description copied from interface: RouteRegistry

      Clear all registered routes from the registry.

      Specified by:

      clean in interface RouteRegistry

    • hasMandatoryParameter

      public boolean hasMandatoryParameter(Class<? extends Component> navigationTarget)

      Description copied from interface: RouteRegistry

      Check if the given navigationTarget requires parameters.

      Specified by:

      hasMandatoryParameter in interface RouteRegistry

      Parameters:

      navigationTarget - navigation target to check

      Returns:

      true if parameters are required

    • getNavigationRouteTarget

      public NavigationRouteTarget getNavigationRouteTarget(String url)

      Description copied from interface: RouteRegistry

      Search for a route target using given navigation url argument.

      Specified by:

      getNavigationRouteTarget in interface RouteRegistry

      Parameters:

      url - the navigation url used to search a route target.

      Returns:

      a NavigationRouteTarget instance containing the RouteTarget and RouteParameters extracted from the url argument according with the route configuration.

    • getRouteTarget

      public RouteTarget getRouteTarget(Class<? extends Component> target, RouteParameters parameters)

      Description copied from interface: RouteRegistry

      Gets the RouteTarget instance matching the given target component and route parameters.

      Specified by:

      getRouteTarget in interface RouteRegistry

      Parameters:

      target - a component class which is a navigation target.

      parameters - parameter values that may be used with given target.

      Returns:

      the RouteTarget instance matching the given target component and route parameters.

    • getNavigationTarget

      public Optional<Class<? extends Component>> getNavigationTarget(String url)

      Description copied from interface: RouteRegistry

      Gets the optional navigation target class for a given path. Returns an empty optional if no navigation target corresponds to the given url.

      Specified by:

      getNavigationTarget in interface RouteRegistry

      Parameters:

      url - the path to get the navigation target for, not null

      Returns:

      optional of the navigation target corresponding to the given path

    • getNavigationTarget

      public Optional<Class<? extends Component>> getNavigationTarget(String url, List<String> segments)

      Description copied from interface: RouteRegistry

      Gets the optional navigation target class for a given Location matching with path segments.

      Specified by:

      getNavigationTarget in interface RouteRegistry

      Parameters:

      url - path to get navigation target for, not null

      segments - segments given for path

      Returns:

      optional navigation target corresponding to the given location with given segments if any applicable targets found.

      See Also:

    • 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 target

      exceptionTargetsMap - map of existing error handlers

      Throws:

      InvalidRouteConfigurationException - if trying to add a non related exception handler for which a handler already exists

    • searchByCause

      protected Optional<ErrorTargetEntry> searchByCause(Exception exception)

      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

      protected Optional<ErrorTargetEntry> searchBySuperType(Throwable exception)

      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

      public void setLayout(Class<? extends RouterLayout> layout)

      Description copied from interface: RouteRegistry

      Set a layout component for use as automatic layout.

      Specified by:

      setLayout in interface RouteRegistry

      Parameters:

      layout - RouterLayout class

    • getLayout

      public Class<? extends RouterLayout> getLayout(String path)

      Description copied from interface: RouteRegistry

      Get the layout component for the current path.

      Specified by:

      getLayout in interface RouteRegistry

      Parameters:

      path - current path

      Returns:

      RouterLayout component or null

    • hasLayout

      public boolean hasLayout(String path)

      Description copied from interface: RouteRegistry

      Check if a layout component has been registered for the current path.

      Specified by:

      hasLayout in interface RouteRegistry

      Parameters:

      path - current path

      Returns:

      true if layout exists