1 package org.apache.velocity.tools;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25
26
27
28
29
30
31
32
33 public final class Scope
34 {
35 public static final String REQUEST = "request";
36 public static final String SESSION = "session";
37 public static final String APPLICATION = "application";
38
39 private static final List<String> VALUES;
40 static
41 {
42 List<String> defaults = new ArrayList<String>(3);
43 defaults.add(REQUEST);
44 defaults.add(SESSION);
45 defaults.add(APPLICATION);
46 VALUES = Collections.synchronizedList(defaults);
47 }
48
49
50
51 private static final Scope INSTANCE = new Scope();
52
53 public static final Scope getInstance()
54 {
55 return INSTANCE;
56 }
57
58 public static final void add(String newScope)
59 {
60
61 newScope = newScope.toLowerCase();
62
63 if (VALUES.contains(newScope))
64 {
65 throw new IllegalArgumentException("Scope '"+newScope+"' has already been registered.");
66 }
67 VALUES.add(newScope);
68 }
69
70 public static final boolean exists(String scope)
71 {
72
73 scope = scope.toLowerCase();
74 return VALUES.contains(scope);
75 }
76
77 public static final List<String> values()
78 {
79 return Collections.unmodifiableList(VALUES);
80 }
81
82 private Scope()
83 {
84
85 }
86
87 }