KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > AbstractPropertyAccessor


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.beans;
18
19 import java.util.LinkedList JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22
23 /**
24  * Abstract implementation of the ConfigurablePropertyAccessor interface.
25  * Provides base implementations of all convenience methods, with the
26  * implementation of actual property access left to subclasses
27  *
28  * @author Juergen Hoeller
29  * @since 2.0
30  * @see #getPropertyValue
31  * @see #setPropertyValue
32  */

33 public abstract class AbstractPropertyAccessor extends PropertyEditorRegistrySupport
34         implements ConfigurablePropertyAccessor {
35
36     private boolean extractOldValueForEditor = false;
37
38
39     public void setExtractOldValueForEditor(boolean extractOldValueForEditor) {
40         this.extractOldValueForEditor = extractOldValueForEditor;
41     }
42
43     public boolean isExtractOldValueForEditor() {
44         return extractOldValueForEditor;
45     }
46
47
48     public void setPropertyValue(PropertyValue pv) throws BeansException {
49         setPropertyValue(pv.getName(), pv.getValue());
50     }
51
52     public void setPropertyValues(Map JavaDoc map) throws BeansException {
53         setPropertyValues(new MutablePropertyValues(map));
54     }
55
56     public void setPropertyValues(PropertyValues pvs) throws BeansException {
57         setPropertyValues(pvs, false, false);
58     }
59
60     public void setPropertyValues(PropertyValues pvs, boolean ignoreUnknown) throws BeansException {
61         setPropertyValues(pvs, ignoreUnknown, false);
62     }
63
64     public void setPropertyValues(PropertyValues pvs, boolean ignoreUnknown, boolean ignoreInvalid)
65             throws BeansException {
66
67         List JavaDoc propertyAccessExceptions = new LinkedList JavaDoc();
68         PropertyValue[] pvArray = pvs.getPropertyValues();
69         for (int i = 0; i < pvArray.length; i++) {
70             try {
71                 // This method may throw any BeansException, which won't be caught
72
// here, if there is a critical failure such as no matching field.
73
// We can attempt to deal only with less serious exceptions.
74
setPropertyValue(pvArray[i]);
75             }
76             catch (NotWritablePropertyException ex) {
77                 if (!ignoreUnknown) {
78                     throw ex;
79                 }
80                 // Otherwise, just ignore it and continue...
81
}
82             catch (NullValueInNestedPathException ex) {
83                 if (!ignoreInvalid) {
84                     throw ex;
85                 }
86                 // Otherwise, just ignore it and continue...
87
}
88             catch (PropertyAccessException ex) {
89                 propertyAccessExceptions.add(ex);
90             }
91         }
92
93         // If we encountered individual exceptions, throw the composite exception.
94
if (!propertyAccessExceptions.isEmpty()) {
95             PropertyAccessException[] paeArray = (PropertyAccessException[])
96                     propertyAccessExceptions.toArray(new PropertyAccessException[propertyAccessExceptions.size()]);
97             throw new PropertyBatchUpdateException(paeArray);
98         }
99     }
100
101
102     public Class JavaDoc getPropertyType(String JavaDoc propertyPath) {
103         return null;
104     }
105
106     /**
107      * Actually get the value of a property.
108      * @param propertyName name of the property to get the value of
109      * @return the value of the property
110      * @throws InvalidPropertyException if there is no such property or
111      * if the property isn't readable
112      * @throws PropertyAccessException if the property was valid but the
113      * accessor method failed
114      */

115     public abstract Object JavaDoc getPropertyValue(String JavaDoc propertyName) throws BeansException;
116
117     /**
118      * Actually set a property value.
119      * @param propertyName name of the property to set value of
120      * @param value the new value
121      * @throws InvalidPropertyException if there is no such property or
122      * if the property isn't writable
123      * @throws PropertyAccessException if the property was valid but the
124      * accessor method failed or a type mismatch occured
125      */

126     public abstract void setPropertyValue(String JavaDoc propertyName, Object JavaDoc value) throws BeansException;
127
128 }
129
Popular Tags