1 16 17 package org.springframework.beans; 18 19 import java.io.Serializable ; 20 21 import org.springframework.core.AttributeAccessorSupport; 22 import org.springframework.util.Assert; 23 import org.springframework.util.ObjectUtils; 24 25 42 public class PropertyValue extends AttributeAccessorSupport implements BeanMetadataElement, Serializable { 43 44 private final String name; 45 46 private final Object value; 47 48 private Object source; 49 50 51 56 public PropertyValue(String name, Object value) { 57 if (name == null) { 58 throw new IllegalArgumentException ("Property name cannot be null"); 59 } 60 this.name = name; 61 this.value = value; 62 } 63 64 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 80 public String getName() { 81 return name; 82 } 83 84 90 public Object getValue() { 91 return value; 92 } 93 94 98 public void setSource(Object source) { 99 this.source = source; 100 } 101 102 public Object getSource() { 103 return source; 104 } 105 106 107 public boolean equals(Object 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 toString() { 125 return "PropertyValue: name='" + this.name + "', value=[" + this.value + "]"; 126 } 127 128 } 129 | Popular Tags |