Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ValidatorBindingFactory |
|
| 2.0;2 |
1 | // Copyright 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.tapestry.valid; | |
16 | ||
17 | import org.apache.hivemind.ApplicationRuntimeException; | |
18 | import org.apache.hivemind.Location; | |
19 | import org.apache.hivemind.lib.BeanFactory; | |
20 | import org.apache.tapestry.IBinding; | |
21 | import org.apache.tapestry.IComponent; | |
22 | import org.apache.tapestry.binding.AbstractBindingFactory; | |
23 | import org.apache.tapestry.engine.IScriptSource; | |
24 | ||
25 | /** | |
26 | * Uses the tapestry.valid.ValidatorBeanFactory service to obtain configuration IValidator | |
27 | * instances. | |
28 | * | |
29 | * @author Howard M. Lewis Ship | |
30 | * @since 4.0 | |
31 | * @see org.apache.tapestry.valid.ValidatorBinding | |
32 | */ | |
33 | 0 | public class ValidatorBindingFactory extends AbstractBindingFactory |
34 | { | |
35 | private BeanFactory _validatorBeanFactory; | |
36 | ||
37 | private IScriptSource _scriptSource; | |
38 | ||
39 | public void setValidatorBeanFactory(BeanFactory validatorBeanFactory) | |
40 | { | |
41 | 0 | _validatorBeanFactory = validatorBeanFactory; |
42 | 0 | } |
43 | ||
44 | public void setScriptSource(IScriptSource scriptSource) | |
45 | { | |
46 | 0 | _scriptSource = scriptSource; |
47 | 0 | } |
48 | ||
49 | /** | |
50 | * Creates and returns a {@link ValidatorBinding}. Interprets the path as a bean initializer, | |
51 | * used to locate a particular type of validator and a particular configuration of its | |
52 | * properties. | |
53 | */ | |
54 | ||
55 | public IBinding createBinding(IComponent root, String bindingDescription, String expression, | |
56 | Location location) | |
57 | { | |
58 | try | |
59 | { | |
60 | 0 | IValidator validator = (IValidator) _validatorBeanFactory.get(expression); |
61 | 0 | validator.setScriptSource(_scriptSource); |
62 | ||
63 | 0 | return new ValidatorBinding(bindingDescription, getValueConverter(), location, |
64 | validator); | |
65 | } | |
66 | 0 | catch (Exception ex) |
67 | { | |
68 | 0 | throw new ApplicationRuntimeException(ex.getMessage(), location, ex); |
69 | } | |
70 | } | |
71 | } |