001/*
002 * Copyright 2002-2016 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 * @see AutowireCapableBeanFactory#resolveNamedBean(Class)
028 */
029public class NamedBeanHolder<T> implements NamedBean {
030
031        private final String beanName;
032
033        private final T beanInstance;
034
035
036        /**
037         * Create a new holder for the given bean name plus instance.
038         * @param beanName the name of the bean
039         * @param beanInstance the corresponding bean instance
040         */
041        public NamedBeanHolder(String beanName, T beanInstance) {
042                Assert.notNull(beanName, "Bean name must not be null");
043                this.beanName = beanName;
044                this.beanInstance = beanInstance;
045        }
046
047
048        /**
049         * Return the name of the bean (never {@code null}).
050         */
051        @Override
052        public String getBeanName() {
053                return this.beanName;
054        }
055
056        /**
057         * Return the corresponding bean instance (can be {@code null}).
058         */
059        public T getBeanInstance() {
060                return this.beanInstance;
061        }
062
063}