KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > validation > BeanPropertyBindingResult


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.validation;
18
19 import java.io.Serializable JavaDoc;
20
21 import org.springframework.beans.BeanWrapper;
22 import org.springframework.beans.BeanWrapperImpl;
23 import org.springframework.beans.ConfigurablePropertyAccessor;
24 import org.springframework.util.Assert;
25
26 /**
27  * Default implementation of the {@link Errors} and {@link BindingResult}
28  * interfaces, for the registration and evaluation of binding errors on
29  * JavaBean objects.
30  *
31  * <p>Performs standard JavaBean property access, also supporting nested
32  * properties. Normally, application code will work with the
33  * <code>Errors</code> interface or the <code>BindingResult</code> interface.
34  * A {@link DataBinder} returns its <code>BindingResult</code> via
35  * {@link org.springframework.validation.DataBinder#getBindingResult()}.
36  *
37  * @author Juergen Hoeller
38  * @since 2.0
39  * @see DataBinder#getBindingResult()
40  * @see DataBinder#initBeanPropertyAccess()
41  * @see DirectFieldBindingResult
42  */

43 public class BeanPropertyBindingResult extends AbstractPropertyBindingResult implements Serializable JavaDoc {
44
45     private final Object JavaDoc target;
46
47     private transient BeanWrapper beanWrapper;
48
49
50     /**
51      * Creates a new instance of the {@link BeanPropertyBindingResult} class.
52      * @param target the target bean to bind onto
53      * @param objectName the name of the target object
54      * @throws IllegalArgumentException if the supplied <code>target</code> is <code>null</code>
55      */

56     public BeanPropertyBindingResult(Object JavaDoc target, String JavaDoc objectName) {
57         super(objectName);
58         Assert.notNull(target, "Target bean must not be null");
59         this.target = target;
60     }
61
62     public final Object JavaDoc getTarget() {
63         return this.target;
64     }
65
66     /**
67      * Returns the {@link BeanWrapper} that this instance uses.
68      * Creates a new one if none existed before.
69      * @see #createBeanWrapper()
70      */

71     public final ConfigurablePropertyAccessor getPropertyAccessor() {
72         if (this.beanWrapper == null) {
73             this.beanWrapper = createBeanWrapper();
74             this.beanWrapper.setExtractOldValueForEditor(true);
75         }
76         return this.beanWrapper;
77     }
78
79     /**
80      * Create a new {@link BeanWrapper} for the underlying target object.
81      * @see #getTarget()
82      */

83     protected BeanWrapper createBeanWrapper() {
84         return new BeanWrapperImpl(getTarget());
85     }
86
87 }
88
Popular Tags