Example usage for org.springframework.beans.factory.config ConfigurableListableBeanFactory getAliases

List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory getAliases

Introduction

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

Prototype

String[] getAliases(String name);

Source Link

Document

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

Usage

From source file:me.springframework.di.spring.SpringConfigurationLoader.java

/**
 * Returns a {@link Map} of {@link MutableInstance MutableInstances},
 * indexed by name./*from ww  w.j ava2s .c o  m*/
 * 
 * @param registry
 *            The {@link BeanDefinitionRegistry} holding the bean
 *            definitions.
 * @return A {@link Map} of {@link MutableInstance MutableInstances}
 *         representing the root beans defined by the
 *         {@link ListableBeanFactory}.
 */
protected static MutableContext loadBeans(ConfigurableListableBeanFactory factory) {
    MutableContext context = new MutableContext();
    for (String name : factory.getBeanDefinitionNames()) {
        for (String alias : factory.getAliases(name)) {
            context.addAlias(alias, name);
        }
    }

    for (String name : factory.getBeanDefinitionNames()) {
        BeanDefinition definition = factory.getBeanDefinition(name);
        if (!definition.isAbstract()) {
            BeanDefinition merged = factory.getMergedBeanDefinition(name);
            MutableInstance instance = new MutableInstance(name);
            load(instance, merged, context);
            context.addInstance(name, instance);
        }
    }
    return context;
}

From source file:gov.nih.nci.cabig.ctms.tools.spring.BeanNameControllerUrlResolver.java

/**
 * Uses this first alias for this bean that starts with '/'.   This is based on the behavior
 * of {@link org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping}.
 *///from  w w  w  .j a  v a 2 s  .  c om
private String resolveUrl(String controllerName, ConfigurableListableBeanFactory beanFactory) {
    String[] aliases = beanFactory.getAliases(controllerName);
    for (String alias : aliases) {
        if (alias.startsWith("/"))
            return alias;
    }
    return null;
}

From source file:org.echocat.jomon.spring.BeanPostConfigurer.java

@Nonnull
protected List<AbstractBeanDefinition> getAllBeanDefinitionsBy(@Nonnull String targetBeanDefinitionName,
        @Nonnull ConfigurableListableBeanFactory beanFactory) {
    final List<AbstractBeanDefinition> result = new ArrayList<>();
    for (final String beanDefinitionName : beanFactory.getBeanDefinitionNames()) {
        if (targetBeanDefinitionName.equals(beanDefinitionName)
                || beanDefinitionName.startsWith(targetBeanDefinitionName + "#")) {
            result.add((AbstractBeanDefinition) beanFactory.getBeanDefinition(beanDefinitionName));
        } else {/* w  w w . j a v a 2 s  .  co m*/
            for (final String alias : beanFactory.getAliases(beanDefinitionName)) {
                if (targetBeanDefinitionName.equals(alias)) {
                    result.add((AbstractBeanDefinition) beanFactory.getBeanDefinition(beanDefinitionName));
                }
            }
        }
    }
    return result;
}

From source file:uk.org.ponder.rsac.support.BeanDefUtil.java

static RSACBeanInfo convertBeanDef(BeanDefinition origdef, String beanname,
        ConfigurableListableBeanFactory factory, MethodAnalyser abdAnalyser, BeanDefConverter converter) {
    RSACBeanInfo rbi = new RSACBeanInfo();
    AbstractBeanDefinition def = getMergedBeanDefinition(factory, beanname, origdef);
    MutablePropertyValues pvs = def.getPropertyValues();
    PropertyValue[] values = pvs.getPropertyValues();
    for (int j = 0; j < values.length; ++j) {
        PropertyValue thispv = values[j];
        Object beannames = BeanDefUtil.propertyValueToBeanName(thispv.getValue(), converter);
        boolean skip = false;
        // skip recording the dependency if it was unresolvable (some
        // unrecognised
        // type) or was a single-valued type referring to a static dependency.
        // NB - we now record ALL dependencies - bean-copying strategy
        // discontinued.
        if (beannames == null
        // || beannames instanceof String
        // && !blankcontext.containsBean((String) beannames)
        ) {//from   ww  w  .ja  va2 s .  c om
            skip = true;
        }
        if (!skip) {
            rbi.recordDependency(thispv.getName(), beannames);
        }
    }
    // NB - illegal cast here is unavoidable.
    // Bit of a problem here with Spring flow - apparently the bean class
    // will NOT be set for a "factory-method" bean UNTIL it has been
    // instantiated
    // via the logic in AbstractAutowireCapableBeanFactory l.376:
    // protected BeanWrapper instantiateUsingFactoryMethod(
    AbstractBeanDefinition abd = def;
    rbi.factorybean = abd.getFactoryBeanName();
    rbi.factorymethod = abd.getFactoryMethodName();
    rbi.initmethod = abd.getInitMethodName();
    rbi.destroymethod = abd.getDestroyMethodName();
    rbi.islazyinit = abd.isLazyInit();
    rbi.dependson = abd.getDependsOn();
    rbi.issingleton = abd.isSingleton();
    rbi.isabstract = abd.isAbstract();
    rbi.aliases = factory.containsBeanDefinition(beanname) ? factory.getAliases(beanname)
            : StringArrayParser.EMPTY_STRINGL;
    if (abd.hasConstructorArgumentValues()) {
        ConstructorArgumentValues cav = abd.getConstructorArgumentValues();
        boolean hasgeneric = !cav.getGenericArgumentValues().isEmpty();
        boolean hasindexed = !cav.getIndexedArgumentValues().isEmpty();
        if (hasgeneric && hasindexed) {
            throw new UnsupportedOperationException("RSAC Bean " + beanname
                    + " has both indexed and generic constructor arguments, which is not supported");
        }
        if (hasgeneric) {
            List cvalues = cav.getGenericArgumentValues();
            rbi.constructorargvals = new ConstructorArgumentValues.ValueHolder[cvalues.size()];
            for (int i = 0; i < cvalues.size(); ++i) {
                rbi.constructorargvals[i] = (ConstructorArgumentValues.ValueHolder) cvalues.get(i);
            }
        } else if (hasindexed) {
            Map cvalues = cav.getIndexedArgumentValues();
            rbi.constructorargvals = new ConstructorArgumentValues.ValueHolder[cvalues.size()];
            for (int i = 0; i < cvalues.size(); ++i) {
                rbi.constructorargvals[i] = (ConstructorArgumentValues.ValueHolder) cvalues.get(new Integer(i));
            }
        }
    }
    if (rbi.factorymethod == null) {
        // Core Spring change at 2.0M5 - ALL bean classes are now irrevocably
        // lazy!!
        // Package org.springframework.beans
        // introduced lazy loading (and lazy validation) of bean classes in
        // standard bean factories and bean definition readers
        AccessMethod bcnaccess = abdAnalyser.getAccessMethod("beanClassName");
        if (bcnaccess != null) {
            String bcn = (String) bcnaccess.getChildObject(abd);
            if (bcn != null) {
                rbi.beanclass = ClassGetter.forName(bcn);
                if (rbi.beanclass == null) {
                    throw new IllegalArgumentException("Class name " + bcn + " for bean definition with name "
                            + beanname + " cannot be resolved");
                }
            }
        } else {
            // all right then BE like that! We'll work out the class later.
            // NB - beandef.getBeanClass() was eliminated around 1.2, we must
            // use the downcast even earlier now.
            rbi.beanclass = abd.getBeanClass();
        }
    }
    return rbi;
}