Example usage for org.springframework.core OrderComparator sort

List of usage examples for org.springframework.core OrderComparator sort

Introduction

In this page you can find the example usage for org.springframework.core OrderComparator sort.

Prototype

public static void sort(Object[] array) 

Source Link

Document

Sort the given array with a default OrderComparator.

Usage

From source file:com.asual.summer.core.util.BeanUtils.java

public static <T> T getBeanOfType(ConfigurableListableBeanFactory beanFactory, Class<T> clazz) {
    Map<String, T> beans = beanFactory.getBeansOfType(clazz);
    ArrayList<T> values = new ArrayList<T>(beans.values());
    if (values.size() != 0) {
        OrderComparator.sort(values);
        return values.get(0);
    }//from   www  .  j  av a 2 s .  c  om
    return null;
}

From source file:org.focusns.common.web.page.config.PositionConfig.java

public List<WidgetConfig> getOrderedWidgetConfigList() {
    List<WidgetConfig> widgetConfigList = new ArrayList<WidgetConfig>();
    for (WidgetConfig widgetConfig : widgetConfigMap.values()) {
        widgetConfigList.add(widgetConfig);
    }/*from w  ww  .  ja  v a 2  s .co m*/
    OrderComparator.sort(widgetConfigList);
    //
    return widgetConfigList;
}

From source file:com.asual.summer.core.resource.CompositeResource.java

public List<CompositeResource> getChildren() {
    if (children == null) {
        LinkedHashSet<CompositeResource> set = new LinkedHashSet<CompositeResource>();
        Map<String, CompositeResource> beans = BeanUtils.getBeansOfType(CompositeResource.class);
        for (CompositeResource resource : beans.values()) {
            if (this.equals(resource.getParent())) {
                set.add(resource);//from  ww  w. java 2  s  . co  m
            }
        }
        children = new ArrayList<CompositeResource>(set);
        OrderComparator.sort(children);
    }
    return children;
}

From source file:com.griddynamics.banshun.web.ScanChildrenHandlerMapping.java

public void createHandlerMappingsAndRegisterHandlers(ApplicationContext child) {
    Map<String, HandlerMapping> matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(child,
            HandlerMapping.class, true, false);

    List<HandlerMapping> handlerMappings = new ArrayList<HandlerMapping>(matchingBeans.values());
    OrderComparator.sort(handlerMappings);
    handlerMappings.remove(this);
    if (handlerMappings.isEmpty()) {
        handlerMappings = createDefaultHandlerMappings(child);
        if (logger.isDebugEnabled()) {
            logger.debug("No HandlerMappings found in context '" + child.getDisplayName() + "': using default");
        }/*from   ww w.  j  a v a  2 s .com*/
    }
    registerHandlers(handlerMappings);
}

From source file:im.tym.wraop.impl.AspectJWrapperFactorySpi.java

private boolean addAdvisorsFromAspectInstanceFactory(MetadataAwareAspectInstanceFactory instanceFactory) {
    boolean hadAspects = aspectJAdvisors.addAll(this.aspectFactory.getAdvisors(instanceFactory));
    if (hadAspects) {
        AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(aspectJAdvisors);
        OrderComparator.sort(aspectJAdvisors);
    }/*from w  w  w  .  j  av  a  2 s  .  com*/
    return hadAspects;
}

From source file:org.tangram.components.spring.TangramViewHandler.java

/**
 * Initialize the ViewResolvers used by this class.
 * <p>/*from w  w  w .  j a  v a2 s  .  co  m*/
 * If no ViewResolver beans are defined in the BeanFactory for this namespace, we default to
 * InternalResourceViewResolver.
 */
private void initViewResolvers(ApplicationContext context) {
    this.modelAwareViewResolvers = null;

    if (this.detectAllModelAwareViewResolvers) {
        // Find all ViewResolvers in the ApplicationContext, including ancestor contexts.
        Map<String, ModelAwareViewResolver> matchingBeans = BeanFactoryUtils
                .beansOfTypeIncludingAncestors(context, ModelAwareViewResolver.class, true, false);
        if (!matchingBeans.isEmpty()) {
            this.modelAwareViewResolvers = new ArrayList<>(matchingBeans.values());
            // We keep ViewResolvers in sorted order.
            OrderComparator.sort(this.modelAwareViewResolvers);
        } // if
    } else {
        try {
            ModelAwareViewResolver vr = context.getBean(DispatcherServlet.VIEW_RESOLVER_BEAN_NAME,
                    ModelAwareViewResolver.class);
            this.modelAwareViewResolvers = Collections.singletonList(vr);
        } catch (NoSuchBeanDefinitionException e) {
            // Ignore, we'll add a default ViewResolver later.
            LOG.warn("initViewResolvers()", e);
        } // try/catch
    } // if
}

From source file:com.alexshabanov.springrestapi.restapitest.DefaultRestTestSupport.java

private boolean handleException(Exception e, HttpServletRequest request, HttpServletResponse response,
        Object handler) {//from w w  w. ja v  a  2  s . co  m
    final Map<String, HandlerExceptionResolver> resolverMap = BeanFactoryUtils
            .beansOfTypeIncludingAncestors(context, HandlerExceptionResolver.class, true, false);

    final List<HandlerExceptionResolver> resolvers = new ArrayList<HandlerExceptionResolver>(
            resolverMap.values());
    OrderComparator.sort(resolvers);

    for (HandlerExceptionResolver exceptionResolver : resolvers) {
        final Object o = exceptionResolver.resolveException(request, response, handler, e);
        if (o != null) {
            // we don't care about model-and-view in the result (this is not needed for testing)
            return true;
        }
    }

    return false;
}

From source file:com.yy.kunka.core.workflow.processor.BaseProcessor.java

/**
 * Called after the properties have been set, Ensures the list of activities
 * is not empty and each activity is supported by this Workflow Processor.
 *
 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
 *///  www.j  a  v  a  2 s.  c om
@Override
public void afterPropertiesSet() throws Exception {

    if (!(beanFactory instanceof ListableBeanFactory)) {
        throw new BeanInitializationException("The workflow processor [" + beanName + "] "
                + "is not managed by a ListableBeanFactory, please re-deploy using some derivative of ListableBeanFactory such as"
                + "ClassPathXmlApplicationContext ");
    }

    if (CollectionUtils.isEmpty(activities) && !isAllowEmptyActivities()) {
        throw new UnsatisfiedDependencyException(getBeanDesc(), beanName, "activities",
                "No activities were wired for this workflow");
    }

    //sort the activities based on their configured order
    OrderComparator.sort(activities);
}

From source file:com.asual.summer.core.util.ResourceUtils.java

@SuppressWarnings("unchecked")
private static <T> List<T> getResources(Class<T> clazz) {

    String[] names = BeanUtils.getBeanNames(clazz);

    if (names != null) {
        List<T> resources = new ArrayList<T>();
        for (String name : names) {
            T bean = (T) BeanUtils.getBean(name);
            if (!resources.contains(bean)) {
                resources.add(bean);//w w w .  j  ava 2  s.  c om
            }
        }
        OrderComparator.sort(resources);
        return resources;
    }

    return null;
}

From source file:com.mystudy.source.spring.mvc.DispatcherServlet.java

/**
 * Initialize the HandlerMappings used by this class.
 * <p>If no HandlerMapping beans are defined in the BeanFactory for this namespace,
 * we default to BeanNameUrlHandlerMapping.
 */// w  w w . ja  v a 2  s .  c o m
private void initHandlerMappings(ApplicationContext context) {
    this.handlerMappings = null;

    if (this.detectAllHandlerMappings) {
        // Find all HandlerMappings in the ApplicationContext, including ancestor contexts.
        Map<String, HandlerMapping> matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(context,
                HandlerMapping.class, true, false);
        if (!matchingBeans.isEmpty()) {
            this.handlerMappings = new ArrayList<HandlerMapping>(matchingBeans.values());
            // We keep HandlerMappings in sorted order.
            OrderComparator.sort(this.handlerMappings);
        }
    } else {
        try {
            HandlerMapping hm = context.getBean(HANDLER_MAPPING_BEAN_NAME, HandlerMapping.class);
            this.handlerMappings = Collections.singletonList(hm);
        } catch (NoSuchBeanDefinitionException ex) {
            // Ignore, we'll add a default HandlerMapping later.
        }
    }

    // Ensure we have at least one HandlerMapping, by registering
    // a default HandlerMapping if no other mappings are found.
    if (this.handlerMappings == null) {
        this.handlerMappings = getDefaultStrategies(context, HandlerMapping.class);
        if (logger.isDebugEnabled()) {
            logger.debug("No HandlerMappings found in servlet '" + getServletName() + "': using default");
        }
    }
}