|
11 | 11 | import javax.annotation.Nullable; |
12 | 12 | import java.io.Serializable; |
13 | 13 | import java.lang.reflect.Type; |
14 | | -import java.util.ArrayList; |
15 | | -import java.util.Arrays; |
16 | 14 | import java.util.Collection; |
17 | 15 | import java.util.Collections; |
| 16 | +import java.util.Set; |
18 | 17 | import java.util.HashSet; |
19 | | -import java.util.List; |
20 | 18 | import java.util.Map; |
21 | | -import java.util.Set; |
| 19 | +import java.util.HashMap; |
| 20 | +import java.util.List; |
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.Arrays; |
| 23 | + |
22 | 24 |
|
23 | 25 | /** |
24 | 26 | * Route contains information about the HTTP method, path pattern, which content types consumes and |
@@ -334,6 +336,8 @@ public interface Handler extends Serializable { |
334 | 336 |
|
335 | 337 | private List<MediaType> consumes = EMPTY_LIST; |
336 | 338 |
|
| 339 | + private Map<String, Object> attributes = EMPTY_MAP; |
| 340 | + |
337 | 341 | private Set<String> supportedMethod; |
338 | 342 |
|
339 | 343 | /** |
@@ -618,6 +622,58 @@ public Route(@Nonnull String method, @Nonnull String pattern, @Nonnull Handler h |
618 | 622 | return this; |
619 | 623 | } |
620 | 624 |
|
| 625 | + /** |
| 626 | + * Attributes set to this route. |
| 627 | + * |
| 628 | + * @return Map of attributes set to the route. |
| 629 | + */ |
| 630 | + public @Nonnull Map<String, Object> getAttributes() { |
| 631 | + return attributes; |
| 632 | + } |
| 633 | + |
| 634 | + /** |
| 635 | + * Retrieve value of this specific Attribute set to this route. |
| 636 | + * |
| 637 | + * @param name of the attribute to retrieve. |
| 638 | + * @return value of the specific attribute. |
| 639 | + */ |
| 640 | + public Object attribute(String name) { |
| 641 | + return attributes.get(name); |
| 642 | + } |
| 643 | + |
| 644 | + /** |
| 645 | + * Add one or more attributes applied to this route. |
| 646 | + * |
| 647 | + * @param attributes . |
| 648 | + * @return This route. |
| 649 | + */ |
| 650 | + public @Nonnull Route setAttributes(@Nonnull Map<String, Object> attributes) { |
| 651 | + if (attributes.size() > 0) { |
| 652 | + if (this.attributes == EMPTY_MAP) { |
| 653 | + this.attributes = new HashMap<>(); |
| 654 | + } |
| 655 | + this.attributes.putAll(attributes); |
| 656 | + } |
| 657 | + return this; |
| 658 | + } |
| 659 | + |
| 660 | + /** |
| 661 | + * Add one or more attributes applied to this route. |
| 662 | + * |
| 663 | + * @param name attribute name |
| 664 | + * @param value attribute value |
| 665 | + * @return This route. |
| 666 | + */ |
| 667 | + public @Nonnull Route attribute(@Nonnull String name, @Nonnull Object value) { |
| 668 | + if (this.attributes == EMPTY_MAP) { |
| 669 | + this.attributes = new HashMap<>(); |
| 670 | + } |
| 671 | + |
| 672 | + this.attributes.put(name, value); |
| 673 | + |
| 674 | + return this; |
| 675 | + } |
| 676 | + |
621 | 677 | /** |
622 | 678 | * MessageDecoder for given media type. |
623 | 679 | * |
|
0 commit comments