1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package javax.faces.internal; |
17 | |
|
18 | |
import java.util.HashMap; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import javax.faces.validator.Validator; |
22 | |
|
23 | |
import org.seasar.framework.util.ArrayUtil; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class ValidatorResource { |
30 | |
|
31 | 1 | private static Map validatorPairs = new HashMap(); |
32 | |
|
33 | |
private static ValidatorBuilder builder; |
34 | |
|
35 | 0 | protected ValidatorResource() { |
36 | 0 | } |
37 | |
|
38 | |
public static synchronized Validator getValidator(final String expression) { |
39 | 45 | if (builder == null) { |
40 | 0 | return null; |
41 | |
} |
42 | 45 | ValidatorPair[] pairs = (ValidatorPair[]) validatorPairs |
43 | |
.get(expression); |
44 | 45 | return builder.build(expression, pairs); |
45 | |
} |
46 | |
|
47 | |
public static synchronized void addValidator(final String expression, |
48 | |
final String validatorName) { |
49 | 4 | addValidator(expression, validatorName, new HashMap()); |
50 | 4 | } |
51 | |
|
52 | |
public static synchronized void addValidator(final String expression, |
53 | |
final String validatorName, final Map properties) { |
54 | 23 | ValidatorPair pair = new ValidatorPair(validatorName, properties); |
55 | 23 | ValidatorPair[] pairs = (ValidatorPair[]) validatorPairs |
56 | |
.get(expression); |
57 | 23 | if (pairs == null) { |
58 | 21 | pairs = new ValidatorPair[0]; |
59 | |
} |
60 | 23 | validatorPairs.put(expression, ArrayUtil.add(pairs, pair)); |
61 | 23 | } |
62 | |
|
63 | |
public static synchronized void removeValidator(String expression) { |
64 | 0 | validatorPairs.remove(expression); |
65 | 0 | if (builder != null) { |
66 | 0 | builder.clearValidator(expression); |
67 | |
} |
68 | 0 | } |
69 | |
|
70 | |
public static void removeAll() { |
71 | 1524 | validatorPairs.clear(); |
72 | 1524 | if (builder != null) { |
73 | 1514 | builder.clearAll(); |
74 | |
} |
75 | 1524 | } |
76 | |
|
77 | |
public static void setValidatorBuilder(ValidatorBuilder vb) { |
78 | 1792 | builder = vb; |
79 | 1792 | } |
80 | |
|
81 | |
public static class ValidatorPair { |
82 | |
|
83 | |
public String validatorName; |
84 | |
|
85 | |
public Map properties; |
86 | |
|
87 | 23 | public ValidatorPair(final String validatorName, final Map properties) { |
88 | 23 | this.validatorName = validatorName; |
89 | 23 | this.properties = properties; |
90 | 23 | } |
91 | |
} |
92 | |
|
93 | |
} |