001/*
002 * Copyright 2002-2014 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.context.annotation;
018
019import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
020import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
021import org.springframework.beans.factory.support.GenericBeanDefinition;
022import org.springframework.core.type.AnnotationMetadata;
023import org.springframework.core.type.MethodMetadata;
024import org.springframework.core.type.classreading.MetadataReader;
025import org.springframework.util.Assert;
026
027/**
028 * Extension of the {@link org.springframework.beans.factory.support.GenericBeanDefinition}
029 * class, based on an ASM ClassReader, with support for annotation metadata exposed
030 * through the {@link AnnotatedBeanDefinition} interface.
031 *
032 * <p>This class does <i>not</i> load the bean {@code Class} early.
033 * It rather retrieves all relevant metadata from the ".class" file itself,
034 * parsed with the ASM ClassReader. It is functionally equivalent to
035 * {@link AnnotatedGenericBeanDefinition#AnnotatedGenericBeanDefinition(AnnotationMetadata)}
036 * but distinguishes by type beans that have been <em>scanned</em> vs those that have
037 * been otherwise registered or detected by other means.
038 *
039 * @author Juergen Hoeller
040 * @author Chris Beams
041 * @since 2.5
042 * @see #getMetadata()
043 * @see #getBeanClassName()
044 * @see org.springframework.core.type.classreading.MetadataReaderFactory
045 * @see AnnotatedGenericBeanDefinition
046 */
047@SuppressWarnings("serial")
048public class ScannedGenericBeanDefinition extends GenericBeanDefinition implements AnnotatedBeanDefinition {
049
050        private final AnnotationMetadata metadata;
051
052
053        /**
054         * Create a new ScannedGenericBeanDefinition for the class that the
055         * given MetadataReader describes.
056         * @param metadataReader the MetadataReader for the scanned target class
057         */
058        public ScannedGenericBeanDefinition(MetadataReader metadataReader) {
059                Assert.notNull(metadataReader, "MetadataReader must not be null");
060                this.metadata = metadataReader.getAnnotationMetadata();
061                setBeanClassName(this.metadata.getClassName());
062        }
063
064
065        @Override
066        public final AnnotationMetadata getMetadata() {
067                return this.metadata;
068        }
069
070        @Override
071        public MethodMetadata getFactoryMethodMetadata() {
072                return null;
073        }
074
075}