PropertyValue.java
Upload User: jiancairen
Upload Date: 2007-08-27
Package Size: 26458k
Code Size: 3k
Category:

Java Develop

Development Platform:

Java

  1. /*
  2.  * Copyright 2002-2004 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. package org.springframework.beans;
  17. import java.io.Serializable;
  18. /**
  19.  * Class to hold information and value for an individual property.
  20.  * Using an object here, rather than just storing all properties in a
  21.  * map keyed by property name, allows for more flexibility, and the
  22.  * ability to handle indexed properties etc in a special way if necessary.
  23.  *
  24.  * <p>Note that the value doesn't need to be the final required type:
  25.  * A BeanWrapper implementation should handle any necessary conversion, as
  26.  * this object doesn't know anything about the objects it will be applied to.
  27.  *
  28.  * @author Rod Johnson
  29.  * @since 13 May 2001
  30.  * @see PropertyValues
  31.  * @see BeanWrapper
  32.  */
  33. public class PropertyValue implements Serializable {
  34. /** Property name */
  35. private final String name;
  36. /** Value of the property */
  37. private final Object value;
  38. /**
  39.  * Create new PropertyValue.
  40.  * @param name name of the property
  41.  * @param value value of the property (possibly before type conversion)
  42.  */
  43. public PropertyValue(String name, Object value) {
  44. if (name == null) {
  45. throw new IllegalArgumentException("Property name cannot be null");
  46. }
  47. this.name = name;
  48. this.value = value;
  49. }
  50. /**
  51.  * Return the name of the property.
  52.  */
  53. public String getName() {
  54. return name;
  55. }
  56. /**
  57.  * Return the value of the property.
  58.  * <p>Note that type conversion will <i>not</i> have occurred here.
  59.  * It is the responsibility of the BeanWrapper implementation to
  60.  * perform type conversion.
  61.  */
  62. public Object getValue() {
  63. return value;
  64. }
  65. public String toString() {
  66. return "PropertyValue: name='" + this.name + "'; value=[" + this.value + "]";
  67. }
  68. public boolean equals(Object other) {
  69. if (this == other) {
  70. return true;
  71. }
  72. if (!(other instanceof PropertyValue)) {
  73. return false;
  74. }
  75. PropertyValue otherPv = (PropertyValue) other;
  76. return (this.name.equals(otherPv.name) &&
  77. ((this.value == null && otherPv.value == null) || this.value.equals(otherPv.value)));
  78. }
  79. public int hashCode() {
  80. return this.name.hashCode() * 29 + (this.value != null ? this.value.hashCode() : 0);
  81. }
  82. }