org.springframework.core.annotation.AnnotationAwareOrderComparator Java Examples

The following examples show how to use org.springframework.core.annotation.AnnotationAwareOrderComparator. 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: ExternalSearchProviderRegistryImpl.java    From inception with Apache License 2.0 6 votes vote down vote up
void init()
{
    List<ExternalSearchProviderFactory> exts = new ArrayList<>();

    if (providersProxy != null) {
        exts.addAll(providersProxy);
        AnnotationAwareOrderComparator.sort(exts);

        for (ExternalSearchProviderFactory fs : exts) {
            log.info("Found external search provider: {}",
                    ClassUtils.getAbbreviatedName(fs.getClass(), 20));
        }
    }

    providers = Collections.unmodifiableList(exts);
}
 
Example #2
Source File: DispatcherHandler.java    From spring-analysis-note with MIT License 6 votes vote down vote up
protected void initStrategies(ApplicationContext context) {
	Map<String, HandlerMapping> mappingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
			context, HandlerMapping.class, true, false);

	ArrayList<HandlerMapping> mappings = new ArrayList<>(mappingBeans.values());
	AnnotationAwareOrderComparator.sort(mappings);
	this.handlerMappings = Collections.unmodifiableList(mappings);

	Map<String, HandlerAdapter> adapterBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
			context, HandlerAdapter.class, true, false);

	this.handlerAdapters = new ArrayList<>(adapterBeans.values());
	AnnotationAwareOrderComparator.sort(this.handlerAdapters);

	Map<String, HandlerResultHandler> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
			context, HandlerResultHandler.class, true, false);

	this.resultHandlers = new ArrayList<>(beans.values());
	AnnotationAwareOrderComparator.sort(this.resultHandlers);
}
 
Example #3
Source File: RelationAdapter.java    From webanno with Apache License 2.0 6 votes vote down vote up
public RelationAdapter(LayerSupportRegistry aLayerSupportRegistry,
        FeatureSupportRegistry aFeatureSupportRegistry,
        ApplicationEventPublisher aEventPublisher, AnnotationLayer aLayer,
        String aTargetFeatureName, String aSourceFeatureName,
        Supplier<Collection<AnnotationFeature>> aFeatures,
        List<RelationLayerBehavior> aBehaviors)
{
    super(aLayerSupportRegistry, aFeatureSupportRegistry, aEventPublisher, aLayer, aFeatures);
    
    if (aBehaviors == null) {
        behaviors = emptyList();
    }
    else {
        List<RelationLayerBehavior> temp = new ArrayList<>(aBehaviors);
        AnnotationAwareOrderComparator.sort(temp);
        behaviors = temp;
    }
    
    sourceFeatureName = aSourceFeatureName;
    targetFeatureName = aTargetFeatureName;
}
 
Example #4
Source File: ContentNegotiatingViewResolver.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected void initServletContext(ServletContext servletContext) {
	Collection<ViewResolver> matchingBeans =
			BeanFactoryUtils.beansOfTypeIncludingAncestors(obtainApplicationContext(), ViewResolver.class).values();
	if (this.viewResolvers == null) {
		this.viewResolvers = new ArrayList<>(matchingBeans.size());
		for (ViewResolver viewResolver : matchingBeans) {
			if (this != viewResolver) {
				this.viewResolvers.add(viewResolver);
			}
		}
	}
	else {
		for (int i = 0; i < this.viewResolvers.size(); i++) {
			ViewResolver vr = this.viewResolvers.get(i);
			if (matchingBeans.contains(vr)) {
				continue;
			}
			String name = vr.getClass().getName() + i;
			obtainApplicationContext().getAutowireCapableBeanFactory().initializeBean(vr, name);
		}

	}
	AnnotationAwareOrderComparator.sort(this.viewResolvers);
	this.cnmFactoryBean.setServletContext(servletContext);
}
 
Example #5
Source File: FeatureIndexingSupportRegistryImpl.java    From inception with Apache License 2.0 6 votes vote down vote up
public void init()
{
    List<FeatureIndexingSupport> fsp = new ArrayList<>();

    if (indexingSupportsProxy != null) {
        fsp.addAll(indexingSupportsProxy);
        AnnotationAwareOrderComparator.sort(fsp);
    
        for (FeatureIndexingSupport fs : fsp) {
            log.info("Found indexing support: {}",
                    ClassUtils.getAbbreviatedName(fs.getClass(), 20));
        }
    }
    
    indexingSupports = Collections.unmodifiableList(fsp);
}
 
Example #6
Source File: BootstrapImportSelector.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Override
public String[] selectImports(AnnotationMetadata annotationMetadata) {
	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
	// Use names and ensure unique to protect against duplicates
	List<String> names = new ArrayList<>(SpringFactoriesLoader
			.loadFactoryNames(BootstrapConfiguration.class, classLoader));
	names.addAll(Arrays.asList(StringUtils.commaDelimitedListToStringArray(
			this.environment.getProperty("spring.cloud.bootstrap.sources", ""))));

	List<OrderedAnnotatedElement> elements = new ArrayList<>();
	for (String name : names) {
		try {
			elements.add(
					new OrderedAnnotatedElement(this.metadataReaderFactory, name));
		}
		catch (IOException e) {
			continue;
		}
	}
	AnnotationAwareOrderComparator.sort(elements);

	String[] classNames = elements.stream().map(e -> e.name).toArray(String[]::new);

	return classNames;
}
 
Example #7
Source File: StatementColoringRegistryImpl.java    From inception with Apache License 2.0 6 votes vote down vote up
public void init()
{
    List<StatementColoringStrategy> fsp = new ArrayList<>();

    if (statementColoringStrategiesProxy != null) {
        fsp.addAll(statementColoringStrategiesProxy);
        AnnotationAwareOrderComparator.sort(fsp);

        for (StatementColoringStrategy fs : fsp) {
            log.info("Found value type support: {}",
                ClassUtils.getAbbreviatedName(fs.getClass(), 20));
        }
    }

    statementColoringStrategies = Collections.unmodifiableList(fsp);
}
 
Example #8
Source File: SpringFactoriesLoader.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Load and instantiate the factory implementations of the given type from
 * {@value #FACTORIES_RESOURCE_LOCATION}, using the given class loader.
 * <p>The returned factories are sorted through {@link AnnotationAwareOrderComparator}.
 * <p>If a custom instantiation strategy is required, use {@link #loadFactoryNames}
 * to obtain all registered factory names.
 * @param factoryClass the interface or abstract class representing the factory
 * @param classLoader the ClassLoader to use for loading (can be {@code null} to use the default)
 * @throws IllegalArgumentException if any factory implementation class cannot
 * be loaded or if an error occurs while instantiating any factory
 * @see #loadFactoryNames
 */
public static <T> List<T> loadFactories(Class<T> factoryClass, @Nullable ClassLoader classLoader) {
	Assert.notNull(factoryClass, "'factoryClass' must not be null");
	ClassLoader classLoaderToUse = classLoader;
	if (classLoaderToUse == null) {
		classLoaderToUse = SpringFactoriesLoader.class.getClassLoader();
	}
	List<String> factoryNames = loadFactoryNames(factoryClass, classLoaderToUse);
	if (logger.isTraceEnabled()) {
		logger.trace("Loaded [" + factoryClass.getName() + "] names: " + factoryNames);
	}
	List<T> result = new ArrayList<>(factoryNames.size());
	for (String factoryName : factoryNames) {
		result.add(instantiateFactory(factoryName, factoryClass, classLoaderToUse));
	}
	AnnotationAwareOrderComparator.sort(result);
	return result;
}
 
Example #9
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 #10
Source File: VaultPropertySourceLocatorSupport.java    From spring-cloud-vault with Apache License 2.0 6 votes vote down vote up
/**
 * Create {@link PropertySource}s given {@link Environment} from the property
 * configuration.
 * @param environment must not be {@literal null}.
 * @return a {@link List} of ordered {@link PropertySource}s.
 */
protected List<PropertySource<?>> doCreatePropertySources(Environment environment) {

	Collection<SecretBackendMetadata> secretBackends = this.propertySourceLocatorConfiguration
			.getSecretBackends();
	List<SecretBackendMetadata> sorted = new ArrayList<>(secretBackends);
	List<PropertySource<?>> propertySources = new ArrayList<>();

	AnnotationAwareOrderComparator.sort(sorted);

	propertySources.addAll(doCreateKeyValuePropertySources(environment));

	for (SecretBackendMetadata backendAccessor : sorted) {

		PropertySource<?> vaultPropertySource = createVaultPropertySource(
				backendAccessor);
		propertySources.add(vaultPropertySource);
	}

	return propertySources;
}
 
Example #11
Source File: ContentNegotiatingViewResolver.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected void initServletContext(ServletContext servletContext) {
	Collection<ViewResolver> matchingBeans =
			BeanFactoryUtils.beansOfTypeIncludingAncestors(obtainApplicationContext(), ViewResolver.class).values();
	if (this.viewResolvers == null) {
		this.viewResolvers = new ArrayList<>(matchingBeans.size());
		for (ViewResolver viewResolver : matchingBeans) {
			if (this != viewResolver) {
				this.viewResolvers.add(viewResolver);
			}
		}
	}
	else {
		for (int i = 0; i < this.viewResolvers.size(); i++) {
			ViewResolver vr = this.viewResolvers.get(i);
			if (matchingBeans.contains(vr)) {
				continue;
			}
			String name = vr.getClass().getName() + i;
			obtainApplicationContext().getAutowireCapableBeanFactory().initializeBean(vr, name);
		}

	}
	AnnotationAwareOrderComparator.sort(this.viewResolvers);
	this.cnmFactoryBean.setServletContext(servletContext);
}
 
Example #12
Source File: TransactionSynchronizationManager.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Return an unmodifiable snapshot list of all registered synchronizations
 * for the current thread.
 * @return unmodifiable List of TransactionSynchronization instances
 * @throws IllegalStateException if synchronization is not active
 * @see TransactionSynchronization
 */
public static List<TransactionSynchronization> getSynchronizations() throws IllegalStateException {
	Set<TransactionSynchronization> synchs = synchronizations.get();
	if (synchs == null) {
		throw new IllegalStateException("Transaction synchronization is not active");
	}
	// Return unmodifiable snapshot, to avoid ConcurrentModificationExceptions
	// while iterating and invoking synchronization callbacks that in turn
	// might register further synchronizations.
	if (synchs.isEmpty()) {
		return Collections.emptyList();
	}
	else {
		// Sort lazily here, not in registerSynchronization.
		List<TransactionSynchronization> sortedSynchs = new ArrayList<>(synchs);
		AnnotationAwareOrderComparator.sort(sortedSynchs);
		return Collections.unmodifiableList(sortedSynchs);
	}
}
 
Example #13
Source File: ResourceServerTokenServicesConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean(JwtAccessTokenConverter.class)
public JwtAccessTokenConverter jwtTokenEnhancer() {
	JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
	String keyValue = this.resource.getJwt().getKeyValue();
	if (!StringUtils.hasText(keyValue)) {
		keyValue = getKeyFromServer();
	}
	if (StringUtils.hasText(keyValue) && !keyValue.startsWith("-----BEGIN")) {
		converter.setSigningKey(keyValue);
	}
	if (keyValue != null) {
		converter.setVerifierKey(keyValue);
	}
	if (!CollectionUtils.isEmpty(this.configurers)) {
		AnnotationAwareOrderComparator.sort(this.configurers);
		for (JwtAccessTokenConverterConfigurer configurer : this.configurers) {
			configurer.configure(converter);
		}
	}
	return converter;
}
 
Example #14
Source File: ContextLoader.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Customize the {@link ConfigurableWebApplicationContext} created by this
 * ContextLoader after config locations have been supplied to the context
 * but before the context is <em>refreshed</em>.
 * <p>The default implementation {@linkplain #determineContextInitializerClasses(ServletContext)
 * determines} what (if any) context initializer classes have been specified through
 * {@linkplain #CONTEXT_INITIALIZER_CLASSES_PARAM context init parameters} and
 * {@linkplain ApplicationContextInitializer#initialize invokes each} with the
 * given web application context.
 * <p>Any {@code ApplicationContextInitializers} implementing
 * {@link org.springframework.core.Ordered Ordered} or marked with @{@link
 * org.springframework.core.annotation.Order Order} will be sorted appropriately.
 * @param sc the current servlet context
 * @param wac the newly created application context
 * @see #CONTEXT_INITIALIZER_CLASSES_PARAM
 * @see ApplicationContextInitializer#initialize(ConfigurableApplicationContext)
 */
protected void customizeContext(ServletContext sc, ConfigurableWebApplicationContext wac) {
	List<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>> initializerClasses =
			determineContextInitializerClasses(sc);

	for (Class<ApplicationContextInitializer<ConfigurableApplicationContext>> initializerClass : initializerClasses) {
		Class<?> initializerContextClass =
				GenericTypeResolver.resolveTypeArgument(initializerClass, ApplicationContextInitializer.class);
		if (initializerContextClass != null) {
			Assert.isAssignable(initializerContextClass, wac.getClass(), String.format(
					"Could not add 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(),
					wac.getClass().getName()));
		}
		this.contextInitializers.add(BeanUtils.instantiateClass(initializerClass));
	}

	AnnotationAwareOrderComparator.sort(this.contextInitializers);
	for (ApplicationContextInitializer<ConfigurableApplicationContext> initializer : this.contextInitializers) {
		initializer.initialize(wac);
	}
}
 
Example #15
Source File: ContextLoader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Customize the {@link ConfigurableWebApplicationContext} created by this
 * ContextLoader after config locations have been supplied to the context
 * but before the context is <em>refreshed</em>.
 * <p>The default implementation {@linkplain #determineContextInitializerClasses(ServletContext)
 * determines} what (if any) context initializer classes have been specified through
 * {@linkplain #CONTEXT_INITIALIZER_CLASSES_PARAM context init parameters} and
 * {@linkplain ApplicationContextInitializer#initialize invokes each} with the
 * given web application context.
 * <p>Any {@code ApplicationContextInitializers} implementing
 * {@link org.springframework.core.Ordered Ordered} or marked with @{@link
 * org.springframework.core.annotation.Order Order} will be sorted appropriately.
 * @param sc the current servlet context
 * @param wac the newly created application context
 * @see #CONTEXT_INITIALIZER_CLASSES_PARAM
 * @see ApplicationContextInitializer#initialize(ConfigurableApplicationContext)
 */
protected void customizeContext(ServletContext sc, ConfigurableWebApplicationContext wac) {
	List<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>> initializerClasses =
			determineContextInitializerClasses(sc);

	for (Class<ApplicationContextInitializer<ConfigurableApplicationContext>> initializerClass : initializerClasses) {
		Class<?> initializerContextClass =
				GenericTypeResolver.resolveTypeArgument(initializerClass, ApplicationContextInitializer.class);
		if (initializerContextClass != null && !initializerContextClass.isInstance(wac)) {
			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(),
					wac.getClass().getName()));
		}
		this.contextInitializers.add(BeanUtils.instantiateClass(initializerClass));
	}

	AnnotationAwareOrderComparator.sort(this.contextInitializers);
	for (ApplicationContextInitializer<ConfigurableApplicationContext> initializer : this.contextInitializers) {
		initializer.initialize(wac);
	}
}
 
Example #16
Source File: AutowiredAnnotationBeanPostProcessorTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstructorResourceInjectionWithMultipleOrderedCandidates() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ConstructorsResourceInjectionBean.class));
	TestBean tb = new TestBean();
	bf.registerSingleton("testBean", tb);
	FixedOrder2NestedTestBean ntb1 = new FixedOrder2NestedTestBean();
	bf.registerSingleton("nestedTestBean1", ntb1);
	FixedOrder1NestedTestBean ntb2 = new FixedOrder1NestedTestBean();
	bf.registerSingleton("nestedTestBean2", ntb2);

	ConstructorsResourceInjectionBean bean = (ConstructorsResourceInjectionBean) bf.getBean("annotatedBean");
	assertNull(bean.getTestBean3());
	assertSame(tb, bean.getTestBean4());
	assertEquals(2, bean.getNestedTestBeans().length);
	assertSame(ntb2, bean.getNestedTestBeans()[0]);
	assertSame(ntb1, bean.getNestedTestBeans()[1]);
	bf.destroySingletons();
}
 
Example #17
Source File: BeanFactoryGenericsTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testGenericMatchingWithUnresolvedOrderedStream() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
	bf.setAutowireCandidateResolver(new GenericTypeAwareAutowireCandidateResolver());

	RootBeanDefinition bd1 = new RootBeanDefinition(NumberStoreFactory.class);
	bd1.setFactoryMethodName("newDoubleStore");
	bf.registerBeanDefinition("store1", bd1);
	RootBeanDefinition bd2 = new RootBeanDefinition(NumberStoreFactory.class);
	bd2.setFactoryMethodName("newFloatStore");
	bf.registerBeanDefinition("store2", bd2);

	ObjectProvider<NumberStore<?>> numberStoreProvider = bf.getBeanProvider(ResolvableType.forClass(NumberStore.class));
	List<NumberStore<?>> resolved = numberStoreProvider.orderedStream().collect(Collectors.toList());
	assertEquals(2, resolved.size());
	assertSame(bf.getBean("store2"), resolved.get(0));
	assertSame(bf.getBean("store1"), resolved.get(1));
}
 
Example #18
Source File: LayerSupportRegistryImpl.java    From webanno with Apache License 2.0 6 votes vote down vote up
public void init()
{
    List<LayerSupport> lsp = new ArrayList<>();

    if (layerSupportsProxy != null) {
        lsp.addAll(layerSupportsProxy);
        AnnotationAwareOrderComparator.sort(lsp);
    
        for (LayerSupport<?, ?> fs : lsp) {
            log.info("Found layer support: {}",
                    ClassUtils.getAbbreviatedName(fs.getClass(), 20));
            fs.setLayerSupportRegistry(this);
        }
    }
    
    layerSupports = Collections.unmodifiableList(lsp);
}
 
Example #19
Source File: PhysicalIndexRegistryImpl.java    From inception with Apache License 2.0 6 votes vote down vote up
void init()
{
    List<PhysicalIndexFactory> exts = new ArrayList<>();

    if (extensionsProxy != null) {
        exts.addAll(extensionsProxy);
        AnnotationAwareOrderComparator.sort(exts);
    
        for (PhysicalIndexFactory fs : exts) {
            log.info("Found index extension: {}",
                    ClassUtils.getAbbreviatedName(fs.getClass(), 20));
        }
    }
    
    extensions = Collections.unmodifiableList(exts);
}
 
Example #20
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testAutowireBeanByTypeWithIdenticalPriorityCandidates() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
	RootBeanDefinition bd = new RootBeanDefinition(HighPriorityTestBean.class);
	RootBeanDefinition bd2 = new RootBeanDefinition(HighPriorityTestBean.class);
	lbf.registerBeanDefinition("test", bd);
	lbf.registerBeanDefinition("spouse", bd2);

	try {
		lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
		fail("Should have thrown UnsatisfiedDependencyException");
	}
	catch (UnsatisfiedDependencyException ex) {
		// expected
		assertNotNull("Exception should have cause", ex.getCause());
		assertEquals("Wrong cause type", NoUniqueBeanDefinitionException.class, ex.getCause().getClass());
		assertTrue(ex.getMessage().contains("5"));  // conflicting priority
	}
}
 
Example #21
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testMapInjectionWithPriority() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
	RootBeanDefinition bd1 = new RootBeanDefinition(HighPriorityTestBean.class);
	RootBeanDefinition bd2 = new RootBeanDefinition(LowPriorityTestBean.class);
	RootBeanDefinition bd3 = new RootBeanDefinition(NullTestBeanFactoryBean.class);
	RootBeanDefinition bd4 = new RootBeanDefinition(TestBeanRecipient.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR, false);
	lbf.registerBeanDefinition("bd1", bd1);
	lbf.registerBeanDefinition("bd2", bd2);
	lbf.registerBeanDefinition("bd3", bd3);
	lbf.registerBeanDefinition("bd4", bd4);
	lbf.preInstantiateSingletons();
	TestBean bean = lbf.getBean(TestBeanRecipient.class).testBean;
	assertThat(bean.getBeanName(), equalTo("bd1"));
}
 
Example #22
Source File: RaptorServiceAutoConfiguration.java    From raptor with Apache License 2.0 5 votes vote down vote up
@Override
public void addInterceptors(InterceptorRegistry registry) {
    //先增加RaptorContextInitHandlerInterceptor,其他拦截器之前先初始化RaptorContext
    registry.addInterceptor(new RaptorContextInitHandlerInterceptor());

    List<RaptorServiceInterceptor> handlerInterceptorList = handlerInterceptors.getIfAvailable();
    if (CollectionUtils.isEmpty(handlerInterceptorList)) {
        return;
    }
    handlerInterceptorList.sort(new AnnotationAwareOrderComparator());
    for (RaptorServiceInterceptor raptorServiceInterceptor : handlerInterceptorList) {
        registry.addInterceptor(new RaptorHandlerInterceptorAdapter(raptorServiceInterceptor));
    }
}
 
Example #23
Source File: TelemetryServiceImpl.java    From webanno with Apache License 2.0 5 votes vote down vote up
public void init()
{
    List<TelemetrySupport> tsp = new ArrayList<>();

    if (telemetrySupportsProxy != null) {
        tsp.addAll(telemetrySupportsProxy);
        AnnotationAwareOrderComparator.sort(tsp);
    
        for (TelemetrySupport ts : tsp) {
            log.info("Found telemetry support: {}", ts.getId());
        }
    }
    
    telemetrySupports = Collections.unmodifiableList(tsp);
}
 
Example #24
Source File: SpanRenderer.java    From webanno with Apache License 2.0 5 votes vote down vote up
public SpanRenderer(SpanAdapter aTypeAdapter, LayerSupportRegistry aLayerSupportRegistry,
        FeatureSupportRegistry aFeatureSupportRegistry, List<SpanLayerBehavior> aBehaviors)
{
    super(aTypeAdapter, aLayerSupportRegistry, aFeatureSupportRegistry);
    
    if (aBehaviors == null) {
        behaviors = emptyList();
    }
    else {
        List<SpanLayerBehavior> temp = new ArrayList<>(aBehaviors);
        AnnotationAwareOrderComparator.sort(temp);
        behaviors = temp;
    }
}
 
Example #25
Source File: ContentNegotiatingViewResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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);
			}
		}
	}
	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");
	}
	AnnotationAwareOrderComparator.sort(this.viewResolvers);
	this.cnmFactoryBean.setServletContext(servletContext);
}
 
Example #26
Source File: AspectJProxyFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add all {@link Advisor Advisors} from the supplied {@link MetadataAwareAspectInstanceFactory}
 * to the current chain. Exposes any special purpose {@link Advisor Advisors} if needed.
 * @see AspectJProxyUtils#makeAdvisorChainAspectJCapableIfNecessary(List)
 */
private void addAdvisorsFromAspectInstanceFactory(MetadataAwareAspectInstanceFactory instanceFactory) {
	List<Advisor> advisors = this.aspectFactory.getAdvisors(instanceFactory);
	advisors = AopUtils.findAdvisorsThatCanApply(advisors, getTargetClass());
	AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(advisors);
	AnnotationAwareOrderComparator.sort(advisors);
	addAdvisors(advisors);
}
 
Example #27
Source File: ChainRenderer.java    From webanno with Apache License 2.0 5 votes vote down vote up
public ChainRenderer(ChainAdapter aTypeAdapter, LayerSupportRegistry aLayerSupportRegistry,
        FeatureSupportRegistry aFeatureSupportRegistry, List<SpanLayerBehavior> aBehaviors)
{
    super(aTypeAdapter, aLayerSupportRegistry, aFeatureSupportRegistry);
    
    if (aBehaviors == null) {
        behaviors = emptyList();
    }
    else {
        List<SpanLayerBehavior> temp = new ArrayList<>(aBehaviors);
        AnnotationAwareOrderComparator.sort(temp);
        behaviors = temp;
    }
}
 
Example #28
Source File: ErrorResponseComposer.java    From staccato with Apache License 2.0 5 votes vote down vote up
public ErrorResponseComposer(List<AbstractExceptionHandler<T>> handlers) {
    this.handlers = handlers.stream().collect(
            Collectors.toMap(AbstractExceptionHandler::getExceptionName,
                    Function.identity(), (handler1, handler2) -> AnnotationAwareOrderComparator
                            .INSTANCE.compare(handler1, handler2) < 0 ?
                            handler1 : handler2));
}
 
Example #29
Source File: InterceptingHttpAccessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Set the request interceptors that this accessor should use.
 * <p>The interceptors will get sorted according to their order
 * once the {@link ClientHttpRequestFactory} will be built.
 * @see #getRequestFactory()
 * @see AnnotationAwareOrderComparator
 */
public void setInterceptors(List<ClientHttpRequestInterceptor> interceptors) {
	// Take getInterceptors() List as-is when passed in here
	if (this.interceptors != interceptors) {
		this.interceptors.clear();
		this.interceptors.addAll(interceptors);
		AnnotationAwareOrderComparator.sort(this.interceptors);
	}
}
 
Example #30
Source File: RelationRenderer.java    From webanno with Apache License 2.0 5 votes vote down vote up
public RelationRenderer(RelationAdapter aTypeAdapter,
        LayerSupportRegistry aLayerSupportRegistry,
        FeatureSupportRegistry aFeatureSupportRegistry, List<RelationLayerBehavior> aBehaviors)
{
    super(aTypeAdapter, aLayerSupportRegistry, aFeatureSupportRegistry);

    if (aBehaviors == null) {
        behaviors = emptyList();
    }
    else {
        List<RelationLayerBehavior> temp = new ArrayList<>(aBehaviors);
        AnnotationAwareOrderComparator.sort(temp);
        behaviors = temp;
    }
}