KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > valid > ValidatorBindingFactory


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.BindingFactory;
23 import org.apache.tapestry.coerce.ValueConverter;
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 public class ValidatorBindingFactory implements BindingFactory
34 {
35     private BeanFactory _validatorBeanFactory;
36
37     private ValueConverter _valueConverter;
38
39     public void setValidatorBeanFactory(BeanFactory validatorBeanFactory)
40     {
41         _validatorBeanFactory = validatorBeanFactory;
42     }
43
44     public void setValueConverter(ValueConverter valueConverter)
45     {
46         _valueConverter = valueConverter;
47     }
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 JavaDoc bindingDescription, String JavaDoc path,
56             Location location)
57     {
58         try
59         {
60             IValidator validator = (IValidator) _validatorBeanFactory.get(path);
61
62             return new ValidatorBinding(bindingDescription, _valueConverter, location, validator);
63         }
64         catch (Exception JavaDoc ex)
65         {
66             throw new ApplicationRuntimeException(ex.getMessage(), location, ex);
67         }
68     }
69
70 }
Popular Tags