Example usage for org.springframework.beans.factory.support AbstractBeanFactory getAliases

List of usage examples for org.springframework.beans.factory.support AbstractBeanFactory getAliases

Introduction

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

Prototype

@Override
    public String[] getAliases(String name) 

Source Link

Usage

From source file:net.mojodna.sprout.Sprout.java

public final void setBeanFactory(final BeanFactory factory) throws BeansException {
    if (!factory.isSingleton(beanName)) {
        log.warn(getClass().getName() + " must be defined with singleton=\"true\" in order to self-register.");
        return;//w  ww. j  a  v  a 2 s  . c o  m
    }

    final String pkgName = getClass().getPackage().getName();
    final String path = pkgName.substring(pkgName.indexOf(PACKAGE_DELIMITER) + PACKAGE_DELIMITER.length())
            .replace('.', '/') + "/";

    if (factory instanceof AbstractBeanFactory) {
        final AbstractBeanFactory dlbf = (AbstractBeanFactory) factory;

        final Collection<Method> methods = SproutUtils.getDeclaredMethods(getClass(), Sprout.class);

        // register beans for each url
        log.debug("Registering paths...");
        for (final Iterator<Method> i = methods.iterator(); i.hasNext();) {
            final Method method = i.next();
            String name = method.getName();
            if (Modifier.isPublic(method.getModifiers())
                    && method.getReturnType().equals(ActionForward.class)) {
                if (name.equals("publick"))
                    name = "public";
                final String url = path + name.replaceAll("([A-Z])", "_$1").toLowerCase();
                log.debug(url);
                if (!ArrayUtils.contains(dlbf.getAliases(beanName), url))
                    dlbf.registerAlias(beanName, url);
            }
        }
    } else {
        log.warn("Unable to self-register; factory bean was of an unsupported type.");
        throw new BeanNotOfRequiredTypeException(beanName, AbstractBeanFactory.class, factory.getClass());
    }
}