214214 */
215215public interface Route {
216216
217+ interface Mapper <T > {
218+ Object map (T value ) throws Throwable ;
219+ }
220+
217221 /**
218222 * Common route properties, like static and global metadata via attributes, path exclusion,
219223 * produces and consumes types.
@@ -341,8 +345,9 @@ default T excludes(final String... excludes) {
341345 * @param excludes A path pattern.
342346 * @return This instance.
343347 */
344- public T excludes (final List <String > excludes );
348+ T excludes (final List <String > excludes );
345349
350+ T map (Mapper <?> mapper );
346351 }
347352
348353 class Group implements Props <Group > {
@@ -676,6 +681,14 @@ public Group excludes(final List<String> excludes) {
676681 return this ;
677682 }
678683
684+ @ Override
685+ public Group map (final Mapper <?> mapper ) {
686+ for (Definition definition : routes ) {
687+ definition .map (mapper );
688+ }
689+ return this ;
690+ }
691+
679692 private void newRoute (final String method , final String pattern ,
680693 final Route .Filter filter ) {
681694 newRoute (new Route .Definition (method , this .rootPattern + pattern , filter ));
@@ -706,65 +719,73 @@ private void newRoute(final Route.Definition route) {
706719 };
707720
708721 /**
709- * Collection of {@link Route.Definition } useful for registering/setting route options at once.
722+ * Collection of {@link Route.Props } useful for registering/setting route options at once.
710723 *
711724 * @author edgar
712725 * @since 0.5.0
713726 */
727+ @ SuppressWarnings ({"unchecked" , "rawtypes" })
714728 class Collection implements Props <Collection > {
715729
716730 /** List of definitions. */
717- private Route .Definition [] routes ;
731+ private Route .Props [] routes ;
718732
719733 /**
720734 * Creates a new collection of route definitions.
721735 *
722736 * @param definitions Collection of route definitions.
723737 */
724- public Collection (final Route .Definition ... definitions ) {
738+ public Collection (final Route .Props ... definitions ) {
725739 this .routes = requireNonNull (definitions , "Route definitions are required." );
726740 }
727741
728742 @ Override
729743 public Collection name (final String name ) {
730- for (Definition definition : routes ) {
744+ for (Props definition : routes ) {
731745 definition .name (name );
732746 }
733747 return this ;
734748 }
735749
736750 @ Override
737751 public Collection consumes (final List <MediaType > types ) {
738- for (Definition definition : routes ) {
752+ for (Props definition : routes ) {
739753 definition .consumes (types );
740754 }
741755 return this ;
742756 }
743757
744758 @ Override
745759 public Collection produces (final List <MediaType > types ) {
746- for (Definition definition : routes ) {
760+ for (Props definition : routes ) {
747761 definition .produces (types );
748762 }
749763 return this ;
750764 }
751765
752766 @ Override
753767 public Collection attr (final String name , final Object value ) {
754- for (Definition definition : routes ) {
768+ for (Props definition : routes ) {
755769 definition .attr (name , value );
756770 }
757771 return this ;
758772 }
759773
760774 @ Override
761775 public Collection excludes (final List <String > excludes ) {
762- for (Definition definition : routes ) {
776+ for (Props definition : routes ) {
763777 definition .excludes (excludes );
764778 }
765779 return this ;
766780 }
767781
782+ @ Override
783+ public Collection map (final Mapper <?> mapper ) {
784+ for (Props route : routes ) {
785+ route .map (mapper );
786+ }
787+ return this ;
788+ }
768789 }
769790
770791 /**
@@ -868,6 +889,8 @@ class Definition implements Props<Definition> {
868889
869890 private Map <String , Object > attributes = new HashMap <>();
870891
892+ private Mapper <?> mapper ;
893+
871894 /**
872895 * Creates a new route definition.
873896 *
@@ -1206,6 +1229,12 @@ public List<MediaType> produces() {
12061229 return ImmutableList .copyOf (this .produces );
12071230 }
12081231
1232+ @ Override
1233+ public Definition map (final Mapper <?> mapper ) {
1234+ this .mapper = requireNonNull (mapper , "Mapper is required." );
1235+ return this ;
1236+ }
1237+
12091238 @ Override
12101239 public String toString () {
12111240 StringBuilder buffer = new StringBuilder ();
@@ -1232,7 +1261,7 @@ private Route asRoute(final String method, final RouteMatcher matcher,
12321261 filter = ((AssetProxy ) filter ).delegate ();
12331262 }
12341263 return new RouteImpl (filter , method , matcher .path (), pattern , name , matcher .vars (), consumes ,
1235- produces , attributes );
1264+ produces , attributes , mapper );
12361265 }
12371266
12381267 }
0 commit comments