Java Code Examples for org.springframework.core.annotation.AnnotationAwareOrderComparator#sort()

The following examples show how to use org.springframework.core.annotation.AnnotationAwareOrderComparator#sort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChainAdapter.java    From webanno with Apache License 2.0 6 votes vote down vote up
public ChainAdapter(LayerSupportRegistry aLayerSupportRegistry,
        FeatureSupportRegistry aFeatureSupportRegistry,
        ApplicationEventPublisher aEventPublisher, AnnotationLayer aLayer,
        Supplier<Collection<AnnotationFeature>> aFeatures, List<SpanLayerBehavior> aBehaviors)
{
    super(aLayerSupportRegistry, aFeatureSupportRegistry, aEventPublisher, aLayer, aFeatures);

    if (aBehaviors == null) {
        behaviors = emptyList();
    }
    else {
        List<SpanLayerBehavior> temp = new ArrayList<>(aBehaviors);
        AnnotationAwareOrderComparator.sort(temp);
        behaviors = temp;
    }
}
 
Example 2
Source File: ExtensionPoint_ImplBase.java    From webanno with Apache License 2.0 6 votes vote down vote up
public void init()
{
    List<E> extensions = new ArrayList<>();

    if (extensionsListProxy != null) {
        extensions.addAll(extensionsListProxy);
        AnnotationAwareOrderComparator.sort(extensions);
    
        for (E fs : extensions) {
            log.info("Found {} extension: {}", getClass().getSimpleName(),
                    getAbbreviatedName(fs.getClass(), 20));
        }
    }
    
    extensionsList = Collections.unmodifiableList(extensions);
}
 
Example 3
Source File: SpanAdapter.java    From webanno with Apache License 2.0 6 votes vote down vote up
public SpanAdapter(LayerSupportRegistry aLayerSupportRegistry,
        FeatureSupportRegistry aFeatureSupportRegistry,
        ApplicationEventPublisher aEventPublisher, AnnotationLayer aLayer,
        Supplier<Collection<AnnotationFeature>> aFeatures, List<SpanLayerBehavior> aBehaviors)
{
    super(aLayerSupportRegistry, aFeatureSupportRegistry, aEventPublisher, aLayer, aFeatures);
    
    if (aBehaviors == null) {
        behaviors = emptyList();
    }
    else {
        List<SpanLayerBehavior> temp = new ArrayList<>(aBehaviors);
        AnnotationAwareOrderComparator.sort(temp);
        behaviors = temp;
    }
}
 
Example 4
Source File: RouteDefinitionRouteLocator.java    From spring-cloud-gateway with Apache License 2.0 6 votes vote down vote up
private List<GatewayFilter> getFilters(RouteDefinition routeDefinition) {
	List<GatewayFilter> filters = new ArrayList<>();

	// TODO: support option to apply defaults after route specific filters?
	if (!this.gatewayProperties.getDefaultFilters().isEmpty()) {
		filters.addAll(loadGatewayFilters(DEFAULT_FILTERS,
				new ArrayList<>(this.gatewayProperties.getDefaultFilters())));
	}

	if (!routeDefinition.getFilters().isEmpty()) {
		filters.addAll(loadGatewayFilters(routeDefinition.getId(),
				new ArrayList<>(routeDefinition.getFilters())));
	}

	AnnotationAwareOrderComparator.sort(filters);
	return filters;
}
 
Example 5
Source File: FooterItemRegistryImpl.java    From webanno with Apache License 2.0 6 votes vote down vote up
void init()
{
    List<FooterItem> exts = new ArrayList<>();

    if (extensionsProxy != null) {
        exts.addAll(extensionsProxy);
        AnnotationAwareOrderComparator.sort(exts);
    
        for (FooterItem fs : exts) {
            log.info("Found footer item: {}",
                    ClassUtils.getAbbreviatedName(fs.getClass(), 20));
        }
    }
    
    extensions = Collections.unmodifiableList(exts);
}
 
Example 6
Source File: AnnotationEditorRegistryImpl.java    From webanno with Apache License 2.0 6 votes vote down vote up
void init()
{
    List<AnnotationEditorFactory> exts = new ArrayList<>();

    if (extensionsProxy != null) {
        exts.addAll(extensionsProxy);
        AnnotationAwareOrderComparator.sort(exts);
    
        for (AnnotationEditorFactory fs : exts) {
            log.info("Found annotation editor: {}",
                    ClassUtils.getAbbreviatedName(fs.getClass(), 20));
        }
    }
    
    extensions = Collections.unmodifiableList(exts);
}
 
Example 7
Source File: SpringApplication.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private <T> Collection<T> getSpringFactoriesInstances(Class<T> type,
		Class<?>[] parameterTypes, Object... args) {
	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
	// Use names and ensure unique to protect against duplicates
	Set<String> names = new LinkedHashSet<>(
			SpringFactoriesLoader.loadFactoryNames(type, classLoader));
	List<T> instances = createSpringFactoriesInstances(type, parameterTypes,
			classLoader, args, names);
	AnnotationAwareOrderComparator.sort(instances);
	return instances;
}
 
Example 8
Source File: SpringServletContainerInitializer.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Delegate the {@code ServletContext} to any {@link WebApplicationInitializer}
 * implementations present on the application classpath.
 * <p>Because this class declares @{@code HandlesTypes(WebApplicationInitializer.class)},
 * Servlet 3.0+ containers will automatically scan the classpath for implementations
 * of Spring's {@code WebApplicationInitializer} interface and provide the set of all
 * such types to the {@code webAppInitializerClasses} parameter of this method.
 * <p>If no {@code WebApplicationInitializer} implementations are found on the classpath,
 * this method is effectively a no-op. An INFO-level log message will be issued notifying
 * the user that the {@code ServletContainerInitializer} has indeed been invoked but that
 * no {@code WebApplicationInitializer} implementations were found.
 * <p>Assuming that one or more {@code WebApplicationInitializer} types are detected,
 * they will be instantiated (and <em>sorted</em> if the @{@link
 * org.springframework.core.annotation.Order @Order} annotation is present or
 * the {@link org.springframework.core.Ordered Ordered} interface has been
 * implemented). Then the {@link WebApplicationInitializer#onStartup(ServletContext)}
 * method will be invoked on each instance, delegating the {@code ServletContext} such
 * that each instance may register and configure servlets such as Spring's
 * {@code DispatcherServlet}, listeners such as Spring's {@code ContextLoaderListener},
 * or any other Servlet API componentry such as filters.
 * @param webAppInitializerClasses all implementations of
 * {@link WebApplicationInitializer} found on the application classpath
 * @param servletContext the servlet context to be initialized
 * @see WebApplicationInitializer#onStartup(ServletContext)
 * @see AnnotationAwareOrderComparator
 */
@Override
public void onStartup(@Nullable Set<Class<?>> webAppInitializerClasses, ServletContext servletContext)
		throws ServletException {

	List<WebApplicationInitializer> initializers = new LinkedList<>();

	if (webAppInitializerClasses != null) {
		for (Class<?> waiClass : webAppInitializerClasses) {
			// Be defensive: Some servlet containers provide us with invalid classes,
			// no matter what @HandlesTypes says...
			if (!waiClass.isInterface() && !Modifier.isAbstract(waiClass.getModifiers()) &&
					WebApplicationInitializer.class.isAssignableFrom(waiClass)) {
				try {
					initializers.add((WebApplicationInitializer)
							ReflectionUtils.accessibleConstructor(waiClass).newInstance());
				}
				catch (Throwable ex) {
					throw new ServletException("Failed to instantiate WebApplicationInitializer class", ex);
				}
			}
		}
	}

	if (initializers.isEmpty()) {
		servletContext.log("No Spring WebApplicationInitializer types detected on classpath");
		return;
	}

	servletContext.log(initializers.size() + " Spring WebApplicationInitializers detected on classpath");
	AnnotationAwareOrderComparator.sort(initializers);
	for (WebApplicationInitializer initializer : initializers) {
		initializer.onStartup(servletContext);
	}
}
 
Example 9
Source File: DataSourceServiceImpl.java    From multitenant with Apache License 2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	dataSourceMap.put(Constants.MASTER, dataSource);
	if (listeners != null) {
		AnnotationAwareOrderComparator.sort(listeners);
	}

	
}
 
Example 10
Source File: EmbeddedCassandraContextCustomizer.java    From embedded-cassandra with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static List<CassandraFactoryCustomizer<? super EmbeddedCassandraFactory>> getCustomizers(
		ConfigurableApplicationContext context) {
	List<CassandraFactoryCustomizer<? super EmbeddedCassandraFactory>> customizers = new ArrayList<>();
	String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context,
			ResolvableType.forType(new CassandraFactoryCustomizerTypeReference()));
	for (String name : names) {
		customizers.add((CassandraFactoryCustomizer<? super EmbeddedCassandraFactory>) context.getBean(name));
	}
	AnnotationAwareOrderComparator.sort(customizers);
	return customizers;
}
 
Example 11
Source File: HandlerMappingIntrospector.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static List<HandlerMapping> initHandlerMappings(ApplicationContext applicationContext) {
	Map<String, HandlerMapping> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
			applicationContext, HandlerMapping.class, true, false);
	if (!beans.isEmpty()) {
		List<HandlerMapping> mappings = new ArrayList<HandlerMapping>(beans.values());
		AnnotationAwareOrderComparator.sort(mappings);
		return Collections.unmodifiableList(mappings);
	}
	return Collections.unmodifiableList(initFallback(applicationContext));
}
 
Example 12
Source File: AbstractContextLoader.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void invokeApplicationContextInitializers(ConfigurableApplicationContext context,
		MergedContextConfiguration mergedConfig) {

	Set<Class<? extends ApplicationContextInitializer<?>>> initializerClasses =
			mergedConfig.getContextInitializerClasses();
	if (initializerClasses.isEmpty()) {
		// no ApplicationContextInitializers have been declared -> nothing to do
		return;
	}

	List<ApplicationContextInitializer<ConfigurableApplicationContext>> initializerInstances = new ArrayList<>();
	Class<?> contextClass = context.getClass();

	for (Class<? extends ApplicationContextInitializer<?>> initializerClass : initializerClasses) {
		Class<?> initializerContextClass =
				GenericTypeResolver.resolveTypeArgument(initializerClass, ApplicationContextInitializer.class);
		if (initializerContextClass != null && !initializerContextClass.isInstance(context)) {
			throw new ApplicationContextException(String.format(
					"Could not apply context initializer [%s] since its generic parameter [%s] " +
					"is not assignable from the type of application context used by this " +
					"context loader: [%s]", initializerClass.getName(), initializerContextClass.getName(),
					contextClass.getName()));
		}
		initializerInstances.add((ApplicationContextInitializer<ConfigurableApplicationContext>) BeanUtils.instantiateClass(initializerClass));
	}

	AnnotationAwareOrderComparator.sort(initializerInstances);
	for (ApplicationContextInitializer<ConfigurableApplicationContext> initializer : initializerInstances) {
		initializer.initialize(context);
	}
}
 
Example 13
Source File: UrlSecurityMetadataSource.java    From bdf3 with Apache License 2.0 5 votes vote down vote up
public Map<RequestMatcher, Collection<ConfigAttribute>> getRequestMap() {
	AnnotationAwareOrderComparator.sort(providers);
	requestMap = new ConcurrentHashMap<RequestMatcher, Collection<ConfigAttribute>>();
	for (FilterConfigAttributeProvider provider : providers) {
		Map<String, Collection<ConfigAttribute>> map = provider.provide();
		if (map != null && !map.isEmpty()) {
			for (Entry<String, Collection<ConfigAttribute>> entry : map.entrySet()) {
				requestMap.put(new AntPathRequestMatcher("/" + entry.getKey(), null), entry.getValue());
			}
		}
	}
	return requestMap;
}
 
Example 14
Source File: SpringApplication.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private void callRunners(ApplicationContext context, ApplicationArguments args) {
	List<Object> runners = new ArrayList<>();
	runners.addAll(context.getBeansOfType(ApplicationRunner.class).values());
	runners.addAll(context.getBeansOfType(CommandLineRunner.class).values());
	AnnotationAwareOrderComparator.sort(runners);
	for (Object runner : new LinkedHashSet<>(runners)) {
		if (runner instanceof ApplicationRunner) {
			callRunner((ApplicationRunner) runner, args);
		}
		if (runner instanceof CommandLineRunner) {
			callRunner((CommandLineRunner) runner, args);
		}
	}
}
 
Example 15
Source File: OrderedMultiFactorMethodRankingStrategy.java    From cas-mfa with Apache License 2.0 5 votes vote down vote up
@Override
public MultiFactorAuthenticationSupportingWebApplicationService
computeHighestRankingAuthenticationMethod(@NotNull final MultiFactorAuthenticationTransactionContext mfaTransaction) {
    final List<MultiFactorAuthenticationRequestContext> sortedRequests =
            new ArrayList<>(mfaTransaction.getMfaRequests());

    AnnotationAwareOrderComparator.sort(sortedRequests);
    return sortedRequests.get(0).getMfaService();
}
 
Example 16
Source File: ProxyFactoryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testInterfaceProxiesCanBeOrderedThroughAnnotations() {
	Object proxy1 = new ProxyFactory(new A()).getProxy();
	Object proxy2 = new ProxyFactory(new B()).getProxy();
	List<Object> list = new ArrayList<>(2);
	list.add(proxy1);
	list.add(proxy2);
	AnnotationAwareOrderComparator.sort(list);
	assertSame(proxy2, list.get(0));
	assertSame(proxy1, list.get(1));
}
 
Example 17
Source File: DubboGenericServiceExecutionContextFactory.java    From spring-cloud-alibaba with Apache License 2.0 4 votes vote down vote up
@PostConstruct
public void init() {
	AnnotationAwareOrderComparator.sort(resolvers);
}
 
Example 18
Source File: BootWebCommonAutoConfig.java    From onetwo with Apache License 2.0 4 votes vote down vote up
@PostConstruct
public void configureHttpMessageConverters() {
	for (RequestMappingHandlerAdapter handlerAdapter : this.handlerAdapters) {
		AnnotationAwareOrderComparator.sort(handlerAdapter.getMessageConverters());
	}
}
 
Example 19
Source File: GrantedAuthorityServiceImpl.java    From bdf3 with Apache License 2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	Assert.notEmpty(providers, "providers can not be empty");
	AnnotationAwareOrderComparator.sort(providers);
}
 
Example 20
Source File: GenericViewListener.java    From bdf3 with Apache License 2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	AnnotationAwareOrderComparator.sort(profileFilters);
	
}