/** * Validate PWA annotations of the potential route classes stream, search * for properly annotated PWA class and return it, or null if none existing. * * @param routeClasses * potential route classes * @return a PWA -annotated class, or null if none exist. */ @SuppressWarnings("unchecked") protected Class<?> validatePwaClass(Stream<Class<?>> routeClasses) { pwaClass = null; routeClasses.forEach(route -> { // check and validate route pwa annotation validatePwa(route); Route routeAnnotation = route.getAnnotation(Route.class); if (!UI.class.equals(routeAnnotation.layout())) { Class<? extends RouterLayout> topParentLayout = RouteUtil .getTopParentLayout(route, RouteUtil.resolve(route, routeAnnotation)); // check and validate top parent layout pwa annotation validatePwa(topParentLayout); } }); return pwaClass; }
.asSubclass(Annotation.class); validateRouteAnnotation(route, annotation); validateRouteAliasAnnotation(route, alias, annotation); validateRouteImplementation(route, PageConfigurator.class); validateRouteAliasImplementation(route, alias, PageConfigurator.class);
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(), RouteUtil .getTopParentLayout(route, RouteUtil .resolve(route, annotation)) .getName(), route.getName())); } List<Class<? extends RouterLayout>> parentLayouts = RouteUtil .getParentLayouts(route, RouteUtil.resolve(route, annotation)); Class<? extends RouterLayout> topParentLayout = RouteUtil .getTopParentLayout(route, RouteUtil.resolve(route, annotation)); validateParentImplementation(parentLayouts, topParentLayout, implementation); } }
private void validateRouteAliasAnnotation(Class<?> route, RouteAlias alias, Class<? extends Annotation> annotation) { if (!UI.class.equals(alias.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(), RouteUtil .getTopParentLayout(route, alias.value()).getName(), route.getName())); } List<Class<? extends RouterLayout>> parentLayouts = RouteUtil .getParentLayouts(route, alias.value()); Class<? extends RouterLayout> topParentLayout = RouteUtil .getTopParentLayout(route, alias.value()); validateParentAnnotation(parentLayouts, topParentLayout, annotation); } }
private void validateRouteAliasImplementation(Class<?> route, RouteAlias alias, Class<?> implementation) { if (!UI.class.equals(alias.layout())) { if (PageConfigurator.class.isAssignableFrom(route)) { throw new InvalidRouteLayoutConfigurationException( String.format( "%s needs to be the top parent layout '%s' not '%s'", implementation.getSimpleName(), RouteUtil .getTopParentLayout(route, alias.value()).getName(), route.getName())); } List<Class<? extends RouterLayout>> parentLayouts = RouteUtil .getParentLayouts(route, alias.value()); Class<? extends RouterLayout> topParentLayout = RouteUtil .getTopParentLayout(route, alias.value()); validateParentImplementation(parentLayouts, topParentLayout, implementation); } }
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(), RouteUtil .getTopParentLayout(route, RouteUtil .resolve(route, routeAnnotation)) .getName(), route.getName())); } List<Class<? extends RouterLayout>> parentLayouts = RouteUtil .getParentLayouts(route, RouteUtil.resolve(route, routeAnnotation)); Class<? extends RouterLayout> topParentLayout = RouteUtil .getTopParentLayout(route, RouteUtil.resolve(route, routeAnnotation)); validateParentAnnotation(parentLayouts, topParentLayout, annotation); } }