/**
  * Gets a global URI for a resource if it's registered with this handler.
  *
  * @param connector the connector for which the uri should be generated.
  * @param resource the resource for which the uri should be generated.
  * @return an URI string, or <code>null</code> if the resource is not registered.
  */
 public String getUri(ClientConnector connector, ConnectorResource resource) {
   // app://APP/global/[ui]/[type]/[id]
   String uri = legacyResourceKeys.get(resource);
   if (uri != null && !uri.isEmpty()) {
     return ApplicationConstants.APP_PROTOCOL_PREFIX
         + ApplicationConstants.APP_PATH
         + '/'
         + RESOURCE_REQUEST_PATH
         + connector.getUI().getUIId()
         + '/'
         + uri;
   } else {
     return null;
   }
 }
예제 #2
0
  /**
   * Method for finding the error handler for the given connector. Uses connector hierarchy to find
   * a connector with an error handler. Falls back to the VaadinSession error handler if no
   * connector has specified an error handler.
   *
   * <p>Returns a {@link DefaultErrorHandler} if no error handler was found
   *
   * @param connector The target connector
   * @return An ErrorHandler for the connector
   */
  public static ErrorHandler findErrorHandler(ClientConnector connector) {
    if (connector != null) {
      ErrorHandler errorHandler = connector.getErrorHandler();
      if (errorHandler != null) {
        return errorHandler;
      }

      ClientConnector parent = connector.getParent();
      if (parent != null) {
        return findErrorHandler(parent);
      }

      /*
       * Reached UI and found no error handler. Try session which
       * typically has one.
       */
      UI ui = connector.getUI();
      if (ui != null) {
        errorHandler = findErrorHandler(ui.getSession());
        if (errorHandler != null) {
          return errorHandler;
        }
      }
    }

    /*
     * No connector known or the connector is not attached to a session. Try
     * the current session
     */
    if (VaadinSession.getCurrent() != null) {
      ErrorHandler errorHandler = VaadinSession.getCurrent().getErrorHandler();
      if (errorHandler != null) {
        return errorHandler;
      }
    }

    /*
     * We should never really get here as at least the session should have
     * an error handler. If for some reason it does not we use the default
     * error handler.
     */
    return new DefaultErrorHandler();
  }