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.internal.ValidatorResource.ValidatorPair; |
22 | |
import javax.faces.validator.Validator; |
23 | |
|
24 | |
import org.seasar.framework.beans.util.BeanUtil; |
25 | |
import org.seasar.framework.container.S2Container; |
26 | |
import org.seasar.framework.container.factory.SingletonS2ContainerFactory; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public class NormalValidatorBuilderImpl implements ValidatorBuilder { |
33 | |
|
34 | |
private S2Container container; |
35 | |
|
36 | 1783 | private Map validators = new HashMap(); |
37 | |
|
38 | 443 | public NormalValidatorBuilderImpl() { |
39 | 443 | container = SingletonS2ContainerFactory.getContainer(); |
40 | 443 | } |
41 | |
|
42 | 1340 | public NormalValidatorBuilderImpl(S2Container container) { |
43 | 1340 | this.container = container; |
44 | 1340 | } |
45 | |
|
46 | |
public Validator build(String expression, ValidatorPair[] pairs) { |
47 | 36 | if (pairs == null || pairs.length == 0) { |
48 | 16 | return null; |
49 | |
} |
50 | 20 | if (validators.containsKey(expression)) { |
51 | 3 | return (Validator) validators.get(expression); |
52 | |
} |
53 | 17 | if (pairs.length == 1) { |
54 | 17 | Validator validator = getSingleValidator(pairs[0]); |
55 | 17 | validators.put(expression, validator); |
56 | 17 | return validator; |
57 | |
} |
58 | 0 | final ValidatorChain chain = new ValidatorChain(); |
59 | 0 | for (int i = 0; i < pairs.length; i++) { |
60 | 0 | chain.add(getSingleValidator(pairs[i])); |
61 | |
} |
62 | 0 | validators.put(expression, chain); |
63 | 0 | return chain; |
64 | |
} |
65 | |
|
66 | |
protected Validator getSingleValidator(ValidatorPair pair) { |
67 | 17 | final Validator validator = (Validator) container |
68 | |
.getComponent(pair.validatorName); |
69 | 17 | BeanUtil.copyProperties(pair.properties, validator); |
70 | 17 | return validator; |
71 | |
} |
72 | |
|
73 | |
public void setContainer(S2Container container) { |
74 | 443 | this.container = container; |
75 | 443 | } |
76 | |
|
77 | |
public void clearAll() { |
78 | 1514 | validators.clear(); |
79 | 1514 | } |
80 | |
|
81 | |
public void clearValidator(String expression) { |
82 | 0 | validators.remove(expression); |
83 | 0 | } |
84 | |
|
85 | |
} |