com.holonplatform.vaadin.navigator.internal

## Class ViewNavigationUtils

- java.lang.Object
- - com.holonplatform.vaadin.navigator.internal.ViewNavigationUtils

- All Implemented Interfaces:
    Serializable

      public final class ViewNavigationUtils
      extends Object
      implements Serializable

  Utility class for `View` configuration and navigation management.
  Since:
    5.0.0
  See Also:
    Serialized Form

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static ViewConfiguration` | `buildViewConfiguration(Class<? extends com.vaadin.navigator.View> viewClass)` Build a `ViewConfiguration` using given view class
    `static void` | `checkValidViewClass(Class<? extends com.vaadin.navigator.View> viewClass)` Check if given view class is valid
    `static void` | `checkValidViewName(String viewName)` Check if given view name is valid
    `static Map<String,Object>` | `deserializeParameters(ViewConfiguration configuration, String parameters, String encoding)` Deserialize given parameters String into a map of View parameters consistent with `ViewConfiguration` parameters declarations.
    `static Object` | `deserializeParameterValue(String value, Class<?> requiredType)` Deserialize given String parameter value
    `static <E extends com.vaadin.navigator.ViewChangeListener.ViewChangeEvent & ViewNavigator.ViewNavigatorChangeEvent> void` | `fireViewOnLeave(com.vaadin.navigator.View view, ViewConfiguration configuration, E event)` Fire `OnLeave` view methods
    `static <E extends com.vaadin.navigator.ViewChangeListener.ViewChangeEvent & ViewNavigator.ViewNavigatorChangeEvent> void` | `fireViewOnShow(com.vaadin.navigator.View view, ViewConfiguration configuration, E event, boolean refresh)` Fire `OnShow` view methods
    `static String` | `generateParametersString(Map<String,Object> paramsMap, String encoding)` Generate parameters URI string from name-value map
    `static Collection<ViewContextField>` | `getContextInjectionFields(Class<?> cls)` Get `ViewContext` annotated fields of class and its superclasses
    `static ViewNavigator` | `getCurrentUIViewNavigator()` Try to obtain ViewNavigator from current thread-bound `UI`
    `static List<Method>` | `getViewOnLeaveMethods(Class<?> viewClass)` Get valid `OnLeave` methods in given `viewClass`
    `static List<Method>` | `getViewOnShowMethods(Class<?> viewClass)` Get valid `OnShow` methods in given `viewClass`
    `static Collection<ViewConfiguration.ViewParameterDefinition>` | `getViewParameterDefinitions(Class<?> viewClass)` Search for any `ViewParameter` annotated field in given `viewClass` and returns a set of `ViewConfiguration.ViewParameterDefinition` corresponding to detected parameter fields.
    `static String` | `getViewParameters(String viewName, String nameAndParameters)` Extract parameters string from view request
    `static List<Method>` | `getViewWindowConfigurationMethods(Class<?> viewClass)` Get valid `ViewWindowConfiguration` methods in given `viewClass`
    `static com.vaadin.navigator.View` | `injectContext(ViewConfiguration.ViewConfigurationProvider viewConfigurationProvider, com.vaadin.navigator.View view)` Inject `Context` field, if any, in a given View instance
    `static Map<String,String>` | `parseParametersString(String parametersString, String encoding)` Convert given parameters String into a name-value parameters Map
    `static void` | `setViewParameters(com.vaadin.navigator.View view, ViewConfiguration configuration, Map<String,String> parameters)` Set parameters values in View instance using any matching parameter definition
    `static void` | `setViewParameters(com.vaadin.navigator.View view, ViewConfiguration configuration, String parametersString, String encoding)` Set parameters values in View instance using any matching parameter definition

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getCurrentUIViewNavigator

          public static ViewNavigator getCurrentUIViewNavigator()

      Try to obtain ViewNavigator from current thread-bound `UI`
      Returns:
        If current `UI` is available and has a ViewNavigator setted, this one is retuned. Null otherwise.

    - #### checkValidViewName

          public static void checkValidViewName(String viewName)
                                         throws ViewConfiguration.ViewConfigurationException

      Check if given view name is valid
      Parameters:
        `viewName` - View name to check
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Invalid view name

    - #### checkValidViewClass

          public static void checkValidViewClass(Class<? extends com.vaadin.navigator.View> viewClass)
                                          throws ViewConfiguration.ViewConfigurationException

      Check if given view class is valid
      Parameters:
        `viewClass` - View class to check
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Invalid view class

    - #### fireViewOnShow

          public static <E extends com.vaadin.navigator.ViewChangeListener.ViewChangeEvent & ViewNavigator.ViewNavigatorChangeEvent> void fireViewOnShow(com.vaadin.navigator.View view,
                                                                                                                                                         ViewConfiguration configuration,
                                                                                                                                                         E event,
                                                                                                                                                         boolean refresh)
                                                                                                                                                  throws ViewConfiguration.ViewConfigurationException

      Fire `OnShow` view methods
      Type Parameters:
        `E` - Actual event type
      Parameters:
        `view` - View instance (not null)
        `configuration` - View configuration (not null)
        `event` - View change event
        `refresh` - `true` if is a page refresh
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Error invoking view methods

    - #### fireViewOnLeave

          public static <E extends com.vaadin.navigator.ViewChangeListener.ViewChangeEvent & ViewNavigator.ViewNavigatorChangeEvent> void fireViewOnLeave(com.vaadin.navigator.View view,
                                                                                                                                                          ViewConfiguration configuration,
                                                                                                                                                          E event)
                                                                                                                                                   throws ViewConfiguration.ViewConfigurationException

      Fire `OnLeave` view methods
      Type Parameters:
        `E` - Actual event type
      Parameters:
        `view` - View instance (not null)
        `configuration` - View configuration (not null)
        `event` - View change event
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Error invoking view methods

    - #### getViewParameters

          public static String getViewParameters(String viewName,
                                                 String nameAndParameters)

      Extract parameters string from view request
      Parameters:
        `viewName` - View name
        `nameAndParameters` - Full request string
      Returns:
        Parameters string

    - #### generateParametersString

          public static String generateParametersString(Map<String,Object> paramsMap,
                                                        String encoding)
                                                 throws ViewConfiguration.ViewConfigurationException

      Generate parameters URI string from name-value map
      Parameters:
        `paramsMap` - name-value map
        `encoding` - URI encoding (charset)
      Returns:
        Parameters string
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Error in URI building

    - #### parseParametersString

          public static Map<String,String> parseParametersString(String parametersString,
                                                                 String encoding)
                                                          throws UnsupportedEncodingException

      Convert given parameters String into a name-value parameters Map
      Parameters:
        `parametersString` - Parameters String
        `encoding` - Parameters String encoding (charset), or `null` for default
      Returns:
        Converted parameters Map
      Throws:
        `UnsupportedEncodingException` - Given encoding is not supported

    - #### setViewParameters

          public static void setViewParameters(com.vaadin.navigator.View view,
                                               ViewConfiguration configuration,
                                               String parametersString,
                                               String encoding)
                                        throws ViewConfiguration.ViewConfigurationException

      Set parameters values in View instance using any matching parameter definition
      Parameters:
        `view` - View instance (not null)
        `configuration` - View configuration (not null)
        `parametersString` - Parameters String
        `encoding` - Parameters String encoding (charset), or `null` for default
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Error setting parameter values

    - #### setViewParameters

          public static void setViewParameters(com.vaadin.navigator.View view,
                                               ViewConfiguration configuration,
                                               Map<String,String> parameters)
                                        throws ViewConfiguration.ViewConfigurationException

      Set parameters values in View instance using any matching parameter definition
      Parameters:
        `view` - View instance (not null)
        `configuration` - View configuration (not null)
        `parameters` - Parameters name-value map
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Error setting parameter values

    - #### deserializeParameters

          public static Map<String,Object> deserializeParameters(ViewConfiguration configuration,
                                                                 String parameters,
                                                                 String encoding)
                                                          throws ViewConfiguration.ViewConfigurationException

      Deserialize given parameters String into a map of View parameters consistent with `ViewConfiguration` parameters declarations.
      Parameters:
        `configuration` - ViewConfiguration (required)
        `parameters` - Parameters string
        `encoding` - Optional encoding
      Returns:
        Deserialized View parameters
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Error processing parameters

    - #### buildViewConfiguration

          public static ViewConfiguration buildViewConfiguration(Class<? extends com.vaadin.navigator.View> viewClass)
                                                          throws ViewConfiguration.ViewConfigurationException

      Build a `ViewConfiguration` using given view class
      Parameters:
        `viewClass` - View class (not null)
      Returns:
        ViewConfiguration
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Error building view configuration

    - #### getViewOnShowMethods

          public static List<Method> getViewOnShowMethods(Class<?> viewClass)
                                                   throws ViewConfiguration.ViewConfigurationException

      Get valid `OnShow` methods in given `viewClass`
      Parameters:
        `viewClass` - View class
      Returns:
        List of methods ordered according to class hierarchy
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Error parsing methods or invalid method signature

    - #### getViewOnLeaveMethods

          public static List<Method> getViewOnLeaveMethods(Class<?> viewClass)
                                                    throws ViewConfiguration.ViewConfigurationException

      Get valid `OnLeave` methods in given `viewClass`
      Parameters:
        `viewClass` - View class
      Returns:
        List of methods ordered according to class hierarchy
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Error parsing methods or invalid method signature

    - #### getViewWindowConfigurationMethods

          public static List<Method> getViewWindowConfigurationMethods(Class<?> viewClass)
                                                                throws ViewConfiguration.ViewConfigurationException

      Get valid `ViewWindowConfiguration` methods in given `viewClass`
      Parameters:
        `viewClass` - View class
      Returns:
        List of methods ordered according to class hierarchy
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Error parsing methods or invalid method signature

    - #### getContextInjectionFields

          public static Collection<ViewContextField> getContextInjectionFields(Class<?> cls)
                                                                        throws ViewConfiguration.ViewConfigurationException

      Get `ViewContext` annotated fields of class and its superclasses
      Parameters:
        `cls` - Class to inspect
      Returns:
        ViewContext annotated fields
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Invalid Context injection type

    - #### getViewParameterDefinitions

          public static Collection<ViewConfiguration.ViewParameterDefinition> getViewParameterDefinitions(Class<?> viewClass)
                                                                                                   throws ViewConfiguration.ViewConfigurationException

      Search for any `ViewParameter` annotated field in given `viewClass` and returns a set of `ViewConfiguration.ViewParameterDefinition` corresponding to detected parameter fields.
      Parameters:
        `viewClass` - View class
      Returns:
        ViewParameterDefinitions
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Error parsing view parameters

    - #### deserializeParameterValue

          public static Object deserializeParameterValue(String value,
                                                         Class<?> requiredType)
                                                  throws ViewConfiguration.ViewConfigurationException

      Deserialize given String parameter value
      Parameters:
        `value` - Parameter value
        `requiredType` - Required value type
      Returns:
        The deserialized value
      Throws:
        `ViewConfiguration.ViewConfigurationException`

    - #### injectContext

          public static com.vaadin.navigator.View injectContext(ViewConfiguration.ViewConfigurationProvider viewConfigurationProvider,
                                                                com.vaadin.navigator.View view)
                                                         throws ViewConfiguration.ViewConfigurationException

      Inject `Context` field, if any, in a given View instance
      Parameters:
        `viewConfigurationProvider` - ViewConfigurationProvider
        `view` - View instance
      Returns:
        View
      Throws:
        `ViewConfiguration.ViewConfigurationException` - Error in context data injection

Copyright © 2019 The Holon Platform. All rights reserved.