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