Example usage for org.springframework.beans.factory BeanFactory getAliases

List of usage examples for org.springframework.beans.factory BeanFactory getAliases

Introduction

In this page you can find the example usage for org.springframework.beans.factory BeanFactory getAliases.

Prototype

String[] getAliases(String name);

Source Link

Document

Return the aliases for the given bean name, if any.

Usage

From source file:org.kuali.rice.test.CompositeBeanFactory.java

@Override
public String[] getAliases(String name) {
    for (BeanFactory f : factories) {
        try {//www .  jav a 2  s .com
            String[] s = f.getAliases(name);
            if (s != null) {
                return s;
            }
        } catch (BeansException e) {
            LOG.info("bean exception", e);
        }
    }
    return null;
}

From source file:org.springframework.beans.factory.support.AbstractBeanFactory.java

public String[] getAliases(String name) throws NoSuchBeanDefinitionException {
    String beanName = transformedBeanName(name);
    // Check if bean actually exists in this bean factory.
    if (containsSingleton(beanName) || containsBeanDefinition(beanName)) {
        // If found, gather aliases.
        List aliases = new ArrayList();
        synchronized (this.aliasMap) {
            for (Iterator it = this.aliasMap.entrySet().iterator(); it.hasNext();) {
                Map.Entry entry = (Map.Entry) it.next();
                if (entry.getValue().equals(beanName)) {
                    aliases.add(entry.getKey());
                }//from   w  w w.j  av a2s .  c o  m
            }
        }
        return StringUtils.toStringArray(aliases);
    } else {
        // Not found -> check parent.
        BeanFactory parentBeanFactory = getParentBeanFactory();
        if (parentBeanFactory != null) {
            return parentBeanFactory.getAliases(name);
        }
        throw new NoSuchBeanDefinitionException(beanName, toString());
    }
}

From source file:org.springframework.data.gemfire.support.GemfireBeanFactoryLocator.java

/**
 * Resolves all names (including aliases) from the given Spring {@link BeanFactory}
 * assigned to the {@link #getAssociatedBeanName()}.
 *
 * @param beanFactory {@link BeanFactory} used to resolve the names assigned to the Spring bean
 * identified by the {@link #getAssociatedBeanName()}.
 * @return a {@link Set} of all the names assigned to the Spring bean identified by
 * the {@link #getAssociatedBeanName()} using the provided Spring {@link BeanFactory}.
 * @see org.springframework.beans.factory.BeanFactory
 * @see #getAssociatedBeanName()/*w ww  . j  a  v  a  2s. c  om*/
 */
Set<String> resolveAndInitializeBeanNamesWithAliases(BeanFactory beanFactory) {

    String associatedBeanName = getAssociatedBeanName();

    if (beanFactory != null && StringUtils.hasText(associatedBeanName)) {

        String[] beanAliases = beanFactory.getAliases(associatedBeanName);

        this.associatedBeanNameWithAliases = new TreeSet<>();
        this.associatedBeanNameWithAliases.add(associatedBeanName);

        Collections.addAll(this.associatedBeanNameWithAliases, beanAliases);
    }

    return this.associatedBeanNameWithAliases;
}