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

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

Introduction

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

Prototype

boolean isSingleton(String name) throws NoSuchBeanDefinitionException;

Source Link

Document

Is this bean a shared singleton?

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  w  w.  ja  v  a2s .  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());
    }
}

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

@Override
public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
    for (BeanFactory f : factories) {
        try {/*from  w w  w.  ja  va 2s  .c o  m*/
            boolean b = f.isSingleton(name);
            if (b) {
                return b;
            }
        } catch (BeansException e) {
            LOG.info("bean exception", e);
        }
    }
    return false;
}