KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.Serializable JavaDoc;
20
21 import org.springframework.core.AttributeAccessorSupport;
22 import org.springframework.util.Assert;
23 import org.springframework.util.ObjectUtils;
24
25 /**
26  * Class to hold information and value for an individual property.
27  * Using an object here, rather than just storing all properties in a
28  * map keyed by property name, allows for more flexibility, and the
29  * ability to handle indexed properties etc in a special way if necessary.
30  *
31  * <p>Note that the value doesn't need to be the final required type:
32  * A BeanWrapper implementation should handle any necessary conversion, as
33  * this object doesn't know anything about the objects it will be applied to.
34  *
35  * @author Rod Johnson
36  * @author Rob Harrop
37  * @author Juergen Hoeller
38  * @since 13 May 2001
39  * @see PropertyValues
40  * @see BeanWrapper
41  */

42 public class PropertyValue extends AttributeAccessorSupport implements BeanMetadataElement, Serializable JavaDoc {
43
44     private final String JavaDoc name;
45
46     private final Object JavaDoc value;
47
48     private Object JavaDoc source;
49
50
51     /**
52      * Create a new PropertyValue instance.
53      * @param name name of the property
54      * @param value value of the property (possibly before type conversion)
55      */

56     public PropertyValue(String JavaDoc name, Object JavaDoc value) {
57         if (name == null) {
58             throw new IllegalArgumentException JavaDoc("Property name cannot be null");
59         }
60         this.name = name;
61         this.value = value;
62     }
63
64     /**
65      * Copy constructor.
66      * @param original the PropertyValue to copy
67      */

68     public PropertyValue(PropertyValue original) {
69         Assert.notNull(original, "Original must not be null");
70         this.name = original.getName();
71         this.value = original.getValue();
72         this.source = original.getSource();
73         copyAttributesFrom(original);
74     }
75
76
77     /**
78      * Return the name of the property.
79      */

80     public String JavaDoc getName() {
81         return name;
82     }
83
84     /**
85      * Return the value of the property.
86      * <p>Note that type conversion will <i>not</i> have occurred here.
87      * It is the responsibility of the BeanWrapper implementation to
88      * perform type conversion.
89      */

90     public Object JavaDoc getValue() {
91         return value;
92     }
93
94     /**
95      * Set the configuration source <code>Object</code> for this metadata element.
96      * <p>The exact type of the object will depend on the configuration mechanism used.
97      */

98     public void setSource(Object JavaDoc source) {
99         this.source = source;
100     }
101
102     public Object JavaDoc getSource() {
103         return source;
104     }
105
106
107     public boolean equals(Object JavaDoc other) {
108         if (this == other) {
109             return true;
110         }
111         if (!(other instanceof PropertyValue)) {
112             return false;
113         }
114         PropertyValue otherPv = (PropertyValue) other;
115         return (this.name.equals(otherPv.name) &&
116                 ObjectUtils.nullSafeEquals(this.value, otherPv.value) &&
117                 ObjectUtils.nullSafeEquals(this.source, otherPv.source));
118     }
119
120     public int hashCode() {
121         return this.name.hashCode() * 29 + (this.value == null ? 0 : this.value.hashCode());
122     }
123
124     public String JavaDoc toString() {
125         return "PropertyValue: name='" + this.name + "', value=[" + this.value + "]";
126     }
127
128 }
129
Popular Tags