001/* 002 * Copyright 2002-2018 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.factory.config; 018 019import org.springframework.beans.factory.NamedBean; 020import org.springframework.util.Assert; 021 022/** 023 * A simple holder for a given bean name plus bean instance. 024 * 025 * @author Juergen Hoeller 026 * @since 4.3.3 027 * @param <T> the bean type 028 * @see AutowireCapableBeanFactory#resolveNamedBean(Class) 029 */ 030public class NamedBeanHolder<T> implements NamedBean { 031 032 private final String beanName; 033 034 private final T beanInstance; 035 036 037 /** 038 * Create a new holder for the given bean name plus instance. 039 * @param beanName the name of the bean 040 * @param beanInstance the corresponding bean instance 041 */ 042 public NamedBeanHolder(String beanName, T beanInstance) { 043 Assert.notNull(beanName, "Bean name must not be null"); 044 this.beanName = beanName; 045 this.beanInstance = beanInstance; 046 } 047 048 049 /** 050 * Return the name of the bean. 051 */ 052 @Override 053 public String getBeanName() { 054 return this.beanName; 055 } 056 057 /** 058 * Return the corresponding bean instance. 059 */ 060 public T getBeanInstance() { 061 return this.beanInstance; 062 } 063 064}