001/* 002 * Copyright 2002-2017 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.parsing; 018 019import org.springframework.beans.BeanMetadataElement; 020import org.springframework.lang.Nullable; 021import org.springframework.util.Assert; 022 023/** 024 * Representation of an alias that has been registered during the parsing process. 025 * 026 * @author Juergen Hoeller 027 * @since 2.0 028 * @see ReaderEventListener#aliasRegistered(AliasDefinition) 029 */ 030public class AliasDefinition implements BeanMetadataElement { 031 032 private final String beanName; 033 034 private final String alias; 035 036 @Nullable 037 private final Object source; 038 039 040 /** 041 * Create a new AliasDefinition. 042 * @param beanName the canonical name of the bean 043 * @param alias the alias registered for the bean 044 */ 045 public AliasDefinition(String beanName, String alias) { 046 this(beanName, alias, null); 047 } 048 049 /** 050 * Create a new AliasDefinition. 051 * @param beanName the canonical name of the bean 052 * @param alias the alias registered for the bean 053 * @param source the source object (may be {@code null}) 054 */ 055 public AliasDefinition(String beanName, String alias, @Nullable Object source) { 056 Assert.notNull(beanName, "Bean name must not be null"); 057 Assert.notNull(alias, "Alias must not be null"); 058 this.beanName = beanName; 059 this.alias = alias; 060 this.source = source; 061 } 062 063 064 /** 065 * Return the canonical name of the bean. 066 */ 067 public final String getBeanName() { 068 return this.beanName; 069 } 070 071 /** 072 * Return the alias registered for the bean. 073 */ 074 public final String getAlias() { 075 return this.alias; 076 } 077 078 @Override 079 @Nullable 080 public final Object getSource() { 081 return this.source; 082 } 083 084}