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.core.AttributeAccessorSupport;
20:
21: /**
22: * Extension of {@link org.springframework.core.AttributeAccessorSupport},
23: * holding attributes as {@link BeanMetadataAttribute} objects in order
24: * to keep track of the definition source.
25: *
26: * @author Juergen Hoeller
27: * @since 2.5
28: */
29: public class BeanMetadataAttributeAccessor extends
30: AttributeAccessorSupport implements BeanMetadataElement {
31:
32: private Object source;
33:
34: /**
35: * Set the configuration source <code>Object</code> for this metadata element.
36: * <p>The exact type of the object will depend on the configuration mechanism used.
37: */
38: public void setSource(Object source) {
39: this .source = source;
40: }
41:
42: public Object getSource() {
43: return this .source;
44: }
45:
46: /**
47: * Add the given BeanMetadataAttribute to this accessor's set of attributes.
48: * @param attribute the BeanMetadataAttribute object to register
49: */
50: public void addMetadataAttribute(BeanMetadataAttribute attribute) {
51: super .setAttribute(attribute.getName(), attribute);
52: }
53:
54: /**
55: * Look up the given BeanMetadataAttribute in this accessor's set of attributes.
56: * @param name the name of the attribute
57: * @return the corresponding BeanMetadataAttribute object,
58: * or <code>null</code> if no such attribute defined
59: */
60: public BeanMetadataAttribute getMetadataAttribute(String name) {
61: return (BeanMetadataAttribute) super .getAttribute(name);
62: }
63:
64: public void setAttribute(String name, Object value) {
65: super
66: .setAttribute(name, new BeanMetadataAttribute(name,
67: value));
68: }
69:
70: public Object getAttribute(String name) {
71: BeanMetadataAttribute attribute = (BeanMetadataAttribute) super
72: .getAttribute(name);
73: return (attribute != null ? attribute.getValue() : null);
74: }
75:
76: public Object removeAttribute(String name) {
77: BeanMetadataAttribute attribute = (BeanMetadataAttribute) super
78: .removeAttribute(name);
79: return (attribute != null ? attribute.getValue() : null);
80: }
81:
82: }
|