/** * Finds a UI ancestor of this connector. <code>null</code> is returned if no UI ancestor is found * (typically because the connector is not attached to a proper hierarchy). * * @return the UI ancestor of this connector, or <code>null</code> if none is found. */ @Override public UI getUI() { ClientConnector connector = this; while (connector != null) { if (connector instanceof UI) { return (UI) connector; } connector = connector.getParent(); } return null; }
/** * 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(); }