Example usage for org.springframework.context.support GenericApplicationContext containsBean

List of usage examples for org.springframework.context.support GenericApplicationContext containsBean

Introduction

In this page you can find the example usage for org.springframework.context.support GenericApplicationContext containsBean.

Prototype

@Override
    public boolean containsBean(String name) 

Source Link

Usage

From source file:atunit.spring.SpringContainer.java

protected void fillInMissingFieldBeans(Class<?> testClass, GenericApplicationContext ctx) throws Exception {
    for (Field field : testClass.getDeclaredFields()) {
        Bean beanAnno = field.getAnnotation(Bean.class);
        if (beanAnno == null)
            continue;
        String name = beanAnno.value();
        if (!name.equals("") && !ctx.containsBean(name)) {
            ctx.registerBeanDefinition(name, defineAutowireBean(field.getType()));
        } else if (ctx.getBeansOfType(field.getType()).isEmpty()) {
            BeanDefinitionReaderUtils.registerWithGeneratedName(defineAutowireBean(field.getType()), ctx);
        }/*w w  w  .ja  v a2 s .  com*/
    }
}

From source file:org.pentaho.platform.plugin.services.pluginmgr.DefaultPluginManager.java

public Object getBean(String beanId, Class<?> requiredType) {
    if (beanId == null) {
        throw new IllegalArgumentException("beanId cannot be null"); //$NON-NLS-1$
    }//from www.j av a 2 s.c o m

    Object bean = null;
    for (GenericApplicationContext beanFactory : beanFactoryMap.values()) {
        if (beanFactory.containsBean(beanId)) {
            if (requiredType == null) {
                bean = beanFactory.getBean(beanId);
            } else {
                bean = beanFactory.getBean(beanId, requiredType);
            }
        }
    }
    if (bean == null) {
        throw new NoSuchBeanDefinitionException("Could not find bean with id " + beanId);
    }
    return bean;
}

From source file:org.pentaho.platform.plugin.services.pluginmgr.DefaultPluginManager.java

@Override
public Object getBean(String beanId) throws PluginBeanException {
    if (beanId == null) {
        throw new IllegalArgumentException("beanId cannot be null"); //$NON-NLS-1$
    }/*from  w  w w  . j  av  a 2 s  . com*/

    Object bean = null;
    for (GenericApplicationContext beanFactory : beanFactoryMap.values()) {
        if (beanFactory.containsBean(beanId)) {
            try {
                bean = beanFactory.getBean(beanId);
            } catch (Throwable ex) { // Catching throwable on purpose
                throw new PluginBeanException(ex);
            }
        }
    }
    if (bean == null) {
        throw new PluginBeanException(
                Messages.getInstance().getString("PluginManager.WARN_CLASS_NOT_REGISTERED", beanId)); //$NON-NLS-1$
    }
    return bean;
}

From source file:org.pentaho.platform.plugin.services.pluginmgr.DefaultPluginManager.java

@Override
public Class<?> loadClass(String beanId) throws PluginBeanException {
    if (beanId == null) {
        throw new IllegalArgumentException("beanId cannot be null"); //$NON-NLS-1$
    }//from  ww  w  . jav  a2  s.  c o m
    Class<?> type = null;
    for (GenericApplicationContext beanFactory : beanFactoryMap.values()) {
        if (beanFactory.containsBean(beanId)) {
            try {
                type = beanFactory.getType(beanId);
                break;
            } catch (Throwable ex) { // Catching throwable on purpose
                throw new PluginBeanException(ex);
            }
        }
    }

    if (type == null) {
        throw new PluginBeanException(
                Messages.getInstance().getString("PluginManager.WARN_CLASS_NOT_REGISTERED", beanId)); //$NON-NLS-1$
    }
    return type;
}

From source file:org.pentaho.platform.plugin.services.pluginmgr.DefaultPluginManager.java

@Override
public boolean isBeanRegistered(String beanId) {
    if (beanId == null) {
        throw new IllegalArgumentException("beanId cannot be null"); //$NON-NLS-1$
    }//www  . ja  v a 2s . c o m

    boolean registered = false;
    for (GenericApplicationContext beanFactory : beanFactoryMap.values()) {
        if (beanFactory.containsBean(beanId)) {
            registered = true;
        }
    }

    return registered;
}