01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 org.springframework.util.Assert;
20: import org.springframework.util.ObjectUtils;
21:
22: /**
23: * Holder for a key-value style attribute that is part of a bean definition.
24: * Keeps track of the definition source in addition to the key-value pair.
25: *
26: * @author Juergen Hoeller
27: * @since 2.5
28: */
29: public class BeanMetadataAttribute implements BeanMetadataElement {
30:
31: private final String name;
32:
33: private final Object value;
34:
35: private Object source;
36:
37: /**
38: * Create a new AttributeValue instance.
39: * @param name the name of the attribute (never <code>null</code>)
40: * @param value the value of the attribute (possibly before type conversion)
41: */
42: public BeanMetadataAttribute(String name, Object value) {
43: Assert.notNull(name, "Name must not be null");
44: this .name = name;
45: this .value = value;
46: }
47:
48: /**
49: * Return the name of the attribute.
50: */
51: public String getName() {
52: return this .name;
53: }
54:
55: /**
56: * Return the value of the attribute.
57: */
58: public Object getValue() {
59: return this .value;
60: }
61:
62: /**
63: * Set the configuration source <code>Object</code> for this metadata element.
64: * <p>The exact type of the object will depend on the configuration mechanism used.
65: */
66: public void setSource(Object source) {
67: this .source = source;
68: }
69:
70: public Object getSource() {
71: return this .source;
72: }
73:
74: public boolean equals(Object other) {
75: if (this == other) {
76: return true;
77: }
78: if (!(other instanceof BeanMetadataAttribute)) {
79: return false;
80: }
81: BeanMetadataAttribute otherMa = (BeanMetadataAttribute) other;
82: return (this .name.equals(otherMa.name)
83: && ObjectUtils
84: .nullSafeEquals(this .value, otherMa.value) && ObjectUtils
85: .nullSafeEquals(this .source, otherMa.source));
86: }
87:
88: public int hashCode() {
89: return this .name.hashCode() * 29
90: + ObjectUtils.nullSafeHashCode(this .value);
91: }
92:
93: public String toString() {
94: return "metadata attribute '" + this .name + "'";
95: }
96:
97: }
|