1 package com.atlassian.rest.annotation;
2
3 import com.google.common.collect.ImmutableSet;
4
5 import java.lang.annotation.ElementType;
6 import java.lang.annotation.Retention;
7 import java.lang.annotation.RetentionPolicy;
8 import java.lang.annotation.Target;
9 import java.util.Set;
10
11
12
13
14 @Retention (RetentionPolicy.RUNTIME)
15 @Target ({ ElementType.FIELD, ElementType.METHOD })
16 public @interface RestProperty
17 {
18 public static enum Scope
19 {
20
21
22
23 REQUEST,
24
25
26
27 RESPONSE,
28
29
30
31 BOTH,
32
33
34
35 AUTO;
36
37 private final static Set<String> responseScopeByDefault = ImmutableSet.of("self", "expand");
38
39 public boolean contains(Scope scope)
40 {
41 return this == BOTH || this == AUTO || this == scope;
42 }
43
44 public boolean includes(Scope fieldScope, String fieldName)
45 {
46 fieldScope = resolveAuto(fieldScope, fieldName);
47 return fieldScope == BOTH || fieldScope == this || this == BOTH || this == AUTO;
48 }
49
50 private static Scope resolveAuto(Scope scope, String fieldName)
51 {
52 if (scope == AUTO)
53 {
54 return responseScopeByDefault.contains(fieldName) ? RESPONSE : BOTH;
55 }
56 else
57 {
58 return scope;
59 }
60 }
61 }
62
63
64
65
66
67
68
69
70
71
72 Scope scope() default Scope.AUTO;
73
74
75
76
77 String pattern() default ".+";
78 }