Example usage for org.springframework.beans.factory BeanFactoryUtils beansOfTypeIncludingAncestors

List of usage examples for org.springframework.beans.factory BeanFactoryUtils beansOfTypeIncludingAncestors

Introduction

In this page you can find the example usage for org.springframework.beans.factory BeanFactoryUtils beansOfTypeIncludingAncestors.

Prototype

public static <T> Map<String, T> beansOfTypeIncludingAncestors(ListableBeanFactory lbf, Class<T> type)
        throws BeansException 

Source Link

Document

Return all beans of the given type or subtypes, also picking up beans defined in ancestor bean factories if the current bean factory is a HierarchicalBeanFactory.

Usage

From source file:org.springmodules.validation.bean.annotation.javascript.taglib.BeanAnnotationValidateTag.java

public void findConverter() throws BeansException {

    Map beansOfType = BeanFactoryUtils.beansOfTypeIncludingAncestors(
            getRequestContext().getWebApplicationContext(), CommandObjectToValangConverter.class);
    if (beansOfType.size() >= 1) {
        cotvc = (CommandObjectToValangConverter) beansOfType.values().iterator().next();
    } else {/*from w w w .j a v  a 2 s  . c o  m*/
        cotvc = new CommandObjectToValangConverter();
    }

}

From source file:de.hybris.platform.cissubscriptionatddtests.keywords.CisSubscriptionKeywordLibrary.java

private XStream getXstream() {
    if (xstream == null) {
        xstream = subscriptionXStreamAliasConverter.getXstream();

        final Map<String, AttributeAliasMapping> attributeAliases = BeanFactoryUtils
                .beansOfTypeIncludingAncestors(applicationContext, AttributeAliasMapping.class);

        for (final AttributeAliasMapping attributeAlias : attributeAliases.values()) {
            xstream.useAttributeFor(attributeAlias.getAliasedClass(), attributeAlias.getAttributeName());
        }/* www .j  a  v  a 2  s .c  om*/
    }

    return xstream;
}

From source file:au.edu.archer.dimsim.plugins.MultiUserPluginBase.java

@SuppressWarnings("unchecked")
private IEndPointSecurity getEndPointSecurity() {
    Map securityBeansMap = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, IEndPointSecurity.class);
    if ((securityBeansMap != null) && (securityBeansMap.size() > 0)) {
        for (Object beanName : securityBeansMap.keySet()) {
            //return first available Bean Object
            return (IEndPointSecurity) securityBeansMap.get(beanName);
        }/*from  w  ww  . ja  v a  2s .  c  om*/
    }
    return null;
}

From source file:se.inera.axel.shs.broker.routing.internal.DefaultShsRouter.java

@Override
synchronized public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ContextRefreshedEvent) {
        ListableBeanFactory beanFactory = (ListableBeanFactory) event.getSource();
        Map pluginMap = BeanFactoryUtils.beansOfTypeIncludingAncestors(beanFactory,
                ShsPluginRegistration.class);

        ArrayList<ShsPluginRegistration> pluginRegistrations = new ArrayList<ShsPluginRegistration>();

        pluginRegistrations.addAll(pluginMap.values());

        for (ShsPluginRegistration reg : pluginRegistrations) {
            log.info("Registered plugin '" + reg.getName() + "' from the application context");
        }/*from w  w w .  jav a2s .  com*/

        if (!pluginRegistrations.isEmpty()) {
            setPluginRegistrations(pluginRegistrations);
        }

    }
}

From source file:org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.java

@Bean
public PersistentEntities persistentEntities() {

    List<MappingContext<?, ?>> arrayList = new ArrayList<MappingContext<?, ?>>();

    for (MappingContext<?, ?> context : BeanFactoryUtils
            .beansOfTypeIncludingAncestors(applicationContext, MappingContext.class).values()) {
        arrayList.add(context);//  w  w w . j  av a2s  . c  om
    }

    return new PersistentEntities(arrayList);
}

From source file:net.stickycode.mockwire.spring30.MockwireFieldInjectionAnnotationBeanPostProcessor.java

/**
 * Obtain all beans of the given type as autowire candidates.
 * @param type the type of the bean/* ww w .  ja v a 2s.  c  om*/
 * @return the target beans, or an empty Collection if no bean of this type is found
 * @throws BeansException if bean retrieval failed
 */
protected <T> Map<String, T> findAutowireCandidates(Class<T> type) throws BeansException {
    if (this.beanFactory == null) {
        throw new IllegalStateException("No BeanFactory configured - "
                + "override the getBeanOfType method or specify the 'beanFactory' property");
    }
    return BeanFactoryUtils.beansOfTypeIncludingAncestors(this.beanFactory, type);
}

From source file:org.beadle.framework.view.ReturnTypeViewResolver.java

@Override
protected void initServletContext(ServletContext servletContext) {
    Collection<ViewResolver> matchingBeans = BeanFactoryUtils
            .beansOfTypeIncludingAncestors(getApplicationContext(), ViewResolver.class).values();
    if (this.viewResolvers == null) {
        this.viewResolvers = new ArrayList<ViewResolver>(matchingBeans.size());
        for (ViewResolver viewResolver : matchingBeans) {
            if (this != viewResolver) {
                this.viewResolvers.add(viewResolver);
            }/*from  ww w .ja v a  2s. c  o m*/
        }
    } else {
        for (int i = 0; i < viewResolvers.size(); i++) {
            if (matchingBeans.contains(viewResolvers.get(i))) {
                continue;
            }
            String name = viewResolvers.get(i).getClass().getName() + i;
            getApplicationContext().getAutowireCapableBeanFactory().initializeBean(viewResolvers.get(i), name);
        }

    }
    if (this.viewResolvers.isEmpty()) {
        logger.warn("Did not find any ViewResolvers to delegate to; please configure them using the "
                + "'viewResolvers' property on the ContentNegotiatingViewResolver");
    }
    OrderComparator.sort(this.viewResolvers);
    this.cnManagerFactoryBean.setServletContext(servletContext);
}

From source file:org.codehaus.enunciate.modules.rest.RESTResourceExporter.java

@Override
protected void initApplicationContext() throws BeansException {
    super.initApplicationContext();

    if (resource == null) {
        throw new ApplicationContextException("A REST resource must be provided.");
    }/* www. j a  va 2 s.c o  m*/

    if (contentTypeSupport == null) {
        throw new ApplicationContextException("No content type support was supplied.");
    }

    if (this.multipartRequestHandler == null) {
        this.multipartRequestHandler = new DefaultMultipartRequestHandler();
        Map beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(getApplicationContext(),
                AutowiredAnnotationBeanPostProcessor.class);
        if (!beans.isEmpty()) {
            AutowiredAnnotationBeanPostProcessor processor = (AutowiredAnnotationBeanPostProcessor) beans
                    .values().iterator().next();
            processor.processInjection(this.multipartRequestHandler);
        }
    }
}

From source file:org.jahia.bin.filters.ContentManagerAccessCheckFilter.java

protected Map<String, String> getMapping() {
    if (mapping == null) {
        mapping = new HashMap<String, String>();
        for (JahiaTemplatesPackage aPackage : ServicesRegistry.getInstance().getJahiaTemplateManagerService()
                .getAvailableTemplatePackages()) {
            if (aPackage.getContext() != null) {
                for (Map.Entry<String, ManagerConfiguration> cfg : BeanFactoryUtils
                        .beansOfTypeIncludingAncestors(aPackage.getContext(), ManagerConfiguration.class)
                        .entrySet()) {//from   w w w.j a v a2 s .co m
                    mapping.put(cfg.getKey(), cfg.getValue().getRequiredPermission());
                }
            }
        }
    }

    return mapping;
}

From source file:org.openehealth.ipf.commons.core.extend.config.ExtensionConfigurer.java

@SuppressWarnings("unchecked")
@Override/*w w w .j a  v  a  2 s . c  om*/
public Collection<Extension> lookup(ListableBeanFactory source) {
    List list = new ArrayList(BeanFactoryUtils.beansOfTypeIncludingAncestors(source, Extension.class).values());
    return list;
}