|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ValidatorBindingFactory.java | - | 80% | 100% | 85.7% |
|
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 | ||
24 | /** | |
25 | * Uses the tapestry.valid.ValidatorBeanFactory service to obtain configuration IValidator | |
26 | * instances. | |
27 | * | |
28 | * @author Howard M. Lewis Ship | |
29 | * @since 4.0 | |
30 | * @see org.apache.tapestry.valid.ValidatorBinding | |
31 | */ | |
32 | public class ValidatorBindingFactory extends AbstractBindingFactory | |
33 | { | |
34 | private BeanFactory _validatorBeanFactory; | |
35 | ||
36 | 2 | public void setValidatorBeanFactory(BeanFactory validatorBeanFactory) |
37 | { | |
38 | 2 | _validatorBeanFactory = validatorBeanFactory; |
39 | } | |
40 | ||
41 | /** | |
42 | * Creates and returns a {@link ValidatorBinding}. Interprets the path as a bean initializer, | |
43 | * used to locate a particular type of validator and a particular configuration of its | |
44 | * properties. | |
45 | */ | |
46 | ||
47 | 2 | public IBinding createBinding(IComponent root, String bindingDescription, String expression, |
48 | Location location) | |
49 | { | |
50 | 2 | try |
51 | { | |
52 | 2 | IValidator validator = (IValidator) _validatorBeanFactory.get(expression); |
53 | ||
54 | 2 | return new ValidatorBinding(bindingDescription, getValueConverter(), location, |
55 | validator); | |
56 | } | |
57 | catch (Exception ex) | |
58 | { | |
59 | 0 | throw new ApplicationRuntimeException(ex.getMessage(), location, ex); |
60 | } | |
61 | } | |
62 | } |
|