Package com.foreach.across.core.context

Examples of com.foreach.across.core.context.ModuleBeanOrderComparator


  private ModuleBeanOrderComparator comparator;

  @Before
  public void reset() {
    beans = new ArrayList<>();
    comparator = new ModuleBeanOrderComparator();

    comparator.register( orderedOne, 0 );
    comparator.register( orderedTwo, 0 );
    comparator.register( orderedThree, 0 );
    comparator.register( orderedMinusOneAndOrderThree, 0 );
View Full Code Here


  @Override
  @SuppressWarnings("unchecked")
  public <T> List<T> getBeansOfType( ResolvableType resolvableType, boolean includeModuleInternals ) {
    Set<T> beans = new LinkedHashSet<>();
    ModuleBeanOrderComparator comparator = new ModuleBeanOrderComparator();

    DependencyDescriptor dd = new ResolvableTypeDescriptor( resolvableType );
    ResolvableTypeAutowireCandidateResolver resolver = new ResolvableTypeAutowireCandidateResolver();
    AcrossListableBeanFactory beanFactory = beanFactory( contextInfo.getApplicationContext() );

    resolver.setBeanFactory( beanFactory );
    for ( String beanName : BeanFactoryUtils.beansOfTypeIncludingAncestors( beanFactory,
                                                                            resolvableType.getRawClass() )
                                            .keySet() ) {

      if ( beanFactory.isAutowireCandidate( beanName, dd, resolver ) ) {
        Object bean = beanFactory.getBean( beanName );
        comparator.register( bean, Ordered.HIGHEST_PRECEDENCE );
        beans.add( (T) bean );
      }
    }

    if ( includeModuleInternals ) {
      for ( AcrossModuleInfo module : contextInfo.getModules() ) {
        beanFactory = beanFactory( module.getApplicationContext() );

        if ( beanFactory != null ) {
          resolver.setBeanFactory( beanFactory );

          for ( String beanName : beanFactory.getBeansOfType( resolvableType.getRawClass() ).keySet() ) {
            if ( beanFactory.isAutowireCandidate( beanName, dd, resolver ) ) {
              Object bean = beanFactory.getBean( beanName );
              comparator.register( bean, module.getIndex() );
              beans.add( (T) bean );
            }
          }
        }
      }
    }

    List<T> beanList = new ArrayList<>( beans );
    comparator.sort( beanList );

    return beanList;
  }
View Full Code Here

TOP

Related Classes of com.foreach.across.core.context.ModuleBeanOrderComparator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.