001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.beans; 018 019import org.springframework.core.AttributeAccessorSupport; 020 021/** 022 * Extension of {@link org.springframework.core.AttributeAccessorSupport}, 023 * holding attributes as {@link BeanMetadataAttribute} objects in order 024 * to keep track of the definition source. 025 * 026 * @author Juergen Hoeller 027 * @since 2.5 028 */ 029@SuppressWarnings("serial") 030public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport implements BeanMetadataElement { 031 032 private Object source; 033 034 035 /** 036 * Set the configuration source {@code Object} for this metadata element. 037 * <p>The exact type of the object will depend on the configuration mechanism used. 038 */ 039 public void setSource(Object source) { 040 this.source = source; 041 } 042 043 @Override 044 public Object getSource() { 045 return this.source; 046 } 047 048 049 /** 050 * Add the given BeanMetadataAttribute to this accessor's set of attributes. 051 * @param attribute the BeanMetadataAttribute object to register 052 */ 053 public void addMetadataAttribute(BeanMetadataAttribute attribute) { 054 super.setAttribute(attribute.getName(), attribute); 055 } 056 057 /** 058 * Look up the given BeanMetadataAttribute in this accessor's set of attributes. 059 * @param name the name of the attribute 060 * @return the corresponding BeanMetadataAttribute object, 061 * or {@code null} if no such attribute defined 062 */ 063 public BeanMetadataAttribute getMetadataAttribute(String name) { 064 return (BeanMetadataAttribute) super.getAttribute(name); 065 } 066 067 @Override 068 public void setAttribute(String name, Object value) { 069 super.setAttribute(name, new BeanMetadataAttribute(name, value)); 070 } 071 072 @Override 073 public Object getAttribute(String name) { 074 BeanMetadataAttribute attribute = (BeanMetadataAttribute) super.getAttribute(name); 075 return (attribute != null ? attribute.getValue() : null); 076 } 077 078 @Override 079 public Object removeAttribute(String name) { 080 BeanMetadataAttribute attribute = (BeanMetadataAttribute) super.removeAttribute(name); 081 return (attribute != null ? attribute.getValue() : null); 082 } 083 084}