KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.springframework.beans.ConfigurablePropertyAccessor;
20 import org.springframework.beans.DirectFieldAccessor;
21 import org.springframework.util.Assert;
22
23 /**
24  * Special implementation of the Errors and BindingResult interfaces,
25  * supporting registration and evaluation of binding errors on value objects.
26  * Performs direct field access instead of going through JavaBean getters.
27  *
28  * <p>This implementation just supports fields in the actual target object.
29  * It is not able to traverse nested fields.
30  *
31  * @author Juergen Hoeller
32  * @since 2.0
33  * @see DataBinder#getBindingResult()
34  * @see DataBinder#initDirectFieldAccess()
35  * @see BeanPropertyBindingResult
36  */

37 public class DirectFieldBindingResult extends AbstractPropertyBindingResult {
38
39     private final Object JavaDoc target;
40
41     private transient DirectFieldAccessor directFieldAccessor;
42
43
44     /**
45      * Create a new DirectFieldBindingResult instance.
46      * @param target the target object to bind onto
47      * @param objectName the name of the target object
48      */

49     public DirectFieldBindingResult(Object JavaDoc target, String JavaDoc objectName) {
50         super(objectName);
51         Assert.notNull(target, "Target bean must not be null");
52         this.target = target;
53     }
54
55
56     public final Object JavaDoc getTarget() {
57         return target;
58     }
59
60     /**
61      * Returns the DirectFieldAccessor that this instance uses.
62      * Creates a new one if none existed before.
63      * @see #createDirectFieldAccessor()
64      */

65     public final ConfigurablePropertyAccessor getPropertyAccessor() {
66         if (this.directFieldAccessor == null) {
67             this.directFieldAccessor = createDirectFieldAccessor();
68         }
69         return this.directFieldAccessor;
70     }
71
72     /**
73      * Create a new DirectFieldAccessor for the underlying target object.
74      * @see #getTarget()
75      */

76     protected DirectFieldAccessor createDirectFieldAccessor() {
77         return new DirectFieldAccessor(getTarget());
78     }
79
80 }
81
Popular Tags