Search in sources :

Example 1 with InvalidRouteLayoutConfigurationException

use of com.vaadin.flow.server.InvalidRouteLayoutConfigurationException in project flow by vaadin.

the class AbstractRouteRegistryInitializer method checkForConflictingAnnotations.

private void checkForConflictingAnnotations(Class<?> route) {
    if (route.isAnnotationPresent(RouteAlias.class) && !route.isAnnotationPresent(Route.class)) {
        throw new InvalidRouteLayoutConfigurationException(String.format("'%s'" + " declares '@%s' but doesn't declare '@%s'. " + "The '%s' may not be used without '%s'", route.getCanonicalName(), RouteAlias.class.getSimpleName(), Route.class.getSimpleName(), RouteAlias.class.getSimpleName(), Route.class.getSimpleName()));
    }
    if (route.isAnnotationPresent(PageTitle.class) && HasDynamicTitle.class.isAssignableFrom(route)) {
        throw new DuplicateNavigationTitleException(String.format("'%s' has a PageTitle annotation, but also implements HasDynamicTitle.", route.getName()));
    }
    /* Validate annotation usage */
    Stream.of(AnnotationValidator.class.getAnnotation(HandlesTypes.class).value()).forEach(type -> {
        Class<? extends Annotation> annotation = type.asSubclass(Annotation.class);
        validateRouteAnnotation(route, annotation);
        for (RouteAlias alias : route.getAnnotationsByType(RouteAlias.class)) {
            validateRouteAliasAnnotation(route, alias, annotation);
        }
    });
    /* Validate PageConfigurator usage */
    validateRouteImplementation(route, PageConfigurator.class);
    for (RouteAlias alias : route.getAnnotationsByType(RouteAlias.class)) {
        validateRouteAliasImplementation(route, alias, PageConfigurator.class);
    }
}
Also used : InvalidRouteLayoutConfigurationException(com.vaadin.flow.server.InvalidRouteLayoutConfigurationException) PageTitle(com.vaadin.flow.router.PageTitle) RouteAlias(com.vaadin.flow.router.RouteAlias) HasDynamicTitle(com.vaadin.flow.router.HasDynamicTitle) HandlesTypes(javax.servlet.annotation.HandlesTypes)

Example 2 with InvalidRouteLayoutConfigurationException

use of com.vaadin.flow.server.InvalidRouteLayoutConfigurationException in project flow by vaadin.

the class AbstractRouteRegistryInitializer method validateRouteAnnotation.

/* Route validator methods for bootstrap annotations */
private void validateRouteAnnotation(Class<?> route, Class<? extends Annotation> annotation) {
    Route routeAnnotation = route.getAnnotation(Route.class);
    if (!UI.class.equals(routeAnnotation.layout())) {
        if (route.isAnnotationPresent(annotation)) {
            throw new InvalidRouteLayoutConfigurationException(String.format("%s annotation needs to be on the top parent layout '%s' not on '%s'", annotation.getSimpleName(), RouterUtil.getTopParentLayout(route, routeAnnotation.value()).getName(), route.getName()));
        }
        List<Class<? extends RouterLayout>> parentLayouts = RouterUtil.getParentLayouts(route, routeAnnotation.value());
        Class<? extends RouterLayout> topParentLayout = RouterUtil.getTopParentLayout(route, routeAnnotation.value());
        validateParentAnnotation(parentLayouts, topParentLayout, annotation);
    }
}
Also used : RouterLayout(com.vaadin.flow.router.RouterLayout) UI(com.vaadin.flow.component.UI) InvalidRouteLayoutConfigurationException(com.vaadin.flow.server.InvalidRouteLayoutConfigurationException) Route(com.vaadin.flow.router.Route)

Example 3 with InvalidRouteLayoutConfigurationException

use of com.vaadin.flow.server.InvalidRouteLayoutConfigurationException in project flow by vaadin.

the class AbstractRouteRegistryInitializer method validateRouteImplementation.

/* Route validator methods for bootstrap implementations */
private void validateRouteImplementation(Class<?> route, Class<?> implementation) {
    Route annotation = route.getAnnotation(Route.class);
    if (!UI.class.equals(annotation.layout())) {
        if (implementation.isAssignableFrom(route)) {
            throw new InvalidRouteLayoutConfigurationException(String.format("%s needs to be the top parent layout '%s' not '%s'", implementation.getSimpleName(), RouterUtil.getTopParentLayout(route, annotation.value()).getName(), route.getName()));
        }
        List<Class<? extends RouterLayout>> parentLayouts = RouterUtil.getParentLayouts(route, annotation.value());
        Class<? extends RouterLayout> topParentLayout = RouterUtil.getTopParentLayout(route, annotation.value());
        validateParentImplementation(parentLayouts, topParentLayout, implementation);
    }
}
Also used : RouterLayout(com.vaadin.flow.router.RouterLayout) UI(com.vaadin.flow.component.UI) InvalidRouteLayoutConfigurationException(com.vaadin.flow.server.InvalidRouteLayoutConfigurationException) Route(com.vaadin.flow.router.Route)

Aggregations

InvalidRouteLayoutConfigurationException (com.vaadin.flow.server.InvalidRouteLayoutConfigurationException)3 UI (com.vaadin.flow.component.UI)2 Route (com.vaadin.flow.router.Route)2 RouterLayout (com.vaadin.flow.router.RouterLayout)2 HasDynamicTitle (com.vaadin.flow.router.HasDynamicTitle)1 PageTitle (com.vaadin.flow.router.PageTitle)1 RouteAlias (com.vaadin.flow.router.RouteAlias)1 HandlesTypes (javax.servlet.annotation.HandlesTypes)1