Java Code Examples for org.springframework.core.type.filter.TypeFilter

The following examples show how to use org.springframework.core.type.filter.TypeFilter. These examples are extracted from open source projects. 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
/**
 * Determine if the index can be used by this instance.
 * @return {@code true} if the index is available and the configuration of this
 * instance is supported by it, {@code false} otherwise
 * @since 5.0
 */
private boolean indexSupportsIncludeFilters() {
	for (TypeFilter includeFilter : this.includeFilters) {
		if (!indexSupportsIncludeFilter(includeFilter)) {
			return false;
		}
	}
	return true;
}
 
Example 2
/**
 * Determine if the specified include {@link TypeFilter} is supported by the index.
 * @param filter the filter to check
 * @return whether the index supports this include filter
 * @since 5.0
 * @see #extractStereotype(TypeFilter)
 */
private boolean indexSupportsIncludeFilter(TypeFilter filter) {
	if (filter instanceof AnnotationTypeFilter) {
		Class<? extends Annotation> annotation = ((AnnotationTypeFilter) filter).getAnnotationType();
		return (AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, annotation) ||
				annotation.getName().startsWith("javax."));
	}
	if (filter instanceof AssignableTypeFilter) {
		Class<?> target = ((AssignableTypeFilter) filter).getTargetType();
		return AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, target);
	}
	return false;
}
 
Example 3
/**
 * Extract the stereotype to use for the specified compatible filter.
 * @param filter the filter to handle
 * @return the stereotype in the index matching this filter
 * @since 5.0
 * @see #indexSupportsIncludeFilter(TypeFilter)
 */
@Nullable
private String extractStereotype(TypeFilter filter) {
	if (filter instanceof AnnotationTypeFilter) {
		return ((AnnotationTypeFilter) filter).getAnnotationType().getName();
	}
	if (filter instanceof AssignableTypeFilter) {
		return ((AssignableTypeFilter) filter).getTargetType().getName();
	}
	return null;
}
 
Example 4
@SuppressWarnings("unchecked")
protected TypeFilter createTypeFilter(Element element, @Nullable ClassLoader classLoader,
		ParserContext parserContext) throws ClassNotFoundException {

	String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE);
	String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE);
	expression = parserContext.getReaderContext().getEnvironment().resolvePlaceholders(expression);
	if ("annotation".equals(filterType)) {
		return new AnnotationTypeFilter((Class<Annotation>) ClassUtils.forName(expression, classLoader));
	}
	else if ("assignable".equals(filterType)) {
		return new AssignableTypeFilter(ClassUtils.forName(expression, classLoader));
	}
	else if ("aspectj".equals(filterType)) {
		return new AspectJTypeFilter(expression, classLoader);
	}
	else if ("regex".equals(filterType)) {
		return new RegexPatternTypeFilter(Pattern.compile(expression));
	}
	else if ("custom".equals(filterType)) {
		Class<?> filterClass = ClassUtils.forName(expression, classLoader);
		if (!TypeFilter.class.isAssignableFrom(filterClass)) {
			throw new IllegalArgumentException(
					"Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression);
		}
		return (TypeFilter) BeanUtils.instantiateClass(filterClass);
	}
	else {
		throw new IllegalArgumentException("Unsupported filter type: " + filterType);
	}
}
 
Example 5
/**
 * Check whether any of the configured entity type filters matches
 * the current class descriptor contained in the metadata reader.
 */
private boolean matchesFilter(MetadataReader reader, MetadataReaderFactory readerFactory) throws IOException {
	for (TypeFilter filter : entityTypeFilters) {
		if (filter.match(reader, readerFactory)) {
			return true;
		}
	}
	return false;
}
 
Example 6
Source Project: spring-analysis-note   Source File: LocalSessionFactoryBuilder.java    License: MIT License 5 votes vote down vote up
/**
 * Check whether any of the configured entity type filters matches
 * the current class descriptor contained in the metadata reader.
 */
private boolean matchesEntityTypeFilter(MetadataReader reader, MetadataReaderFactory readerFactory) throws IOException {
	if (this.entityTypeFilters != null) {
		for (TypeFilter filter : this.entityTypeFilters) {
			if (filter.match(reader, readerFactory)) {
				return true;
			}
		}
	}
	return false;
}
 
Example 7
Source Project: spring-analysis-note   Source File: ClassPathJaxb2TypeScanner.java    License: MIT License 5 votes vote down vote up
protected boolean isJaxb2Class(MetadataReader reader, MetadataReaderFactory factory) throws IOException {
	for (TypeFilter filter : JAXB2_TYPE_FILTERS) {
		if (filter.match(reader, factory) && !reader.getClassMetadata().isInterface() ) {
			return true;
		}
	}
	return false;
}
 
Example 8
/**
 * Determine if the index can be used by this instance.
 * @return {@code true} if the index is available and the configuration of this
 * instance is supported by it, {@code false} otherwise
 * @since 5.0
 */
private boolean indexSupportsIncludeFilters() {
	for (TypeFilter includeFilter : this.includeFilters) {
		if (!indexSupportsIncludeFilter(includeFilter)) {
			return false;
		}
	}
	return true;
}
 
Example 9
/**
 * Determine if the specified include {@link TypeFilter} is supported by the index.
 * @param filter the filter to check
 * @return whether the index supports this include filter
 * @since 5.0
 * @see #extractStereotype(TypeFilter)
 */
private boolean indexSupportsIncludeFilter(TypeFilter filter) {
	if (filter instanceof AnnotationTypeFilter) {
		Class<? extends Annotation> annotation = ((AnnotationTypeFilter) filter).getAnnotationType();
		return (AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, annotation) ||
				annotation.getName().startsWith("javax."));
	}
	if (filter instanceof AssignableTypeFilter) {
		Class<?> target = ((AssignableTypeFilter) filter).getTargetType();
		return AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, target);
	}
	return false;
}
 
Example 10
/**
 * Extract the stereotype to use for the specified compatible filter.
 * @param filter the filter to handle
 * @return the stereotype in the index matching this filter
 * @since 5.0
 * @see #indexSupportsIncludeFilter(TypeFilter)
 */
@Nullable
private String extractStereotype(TypeFilter filter) {
	if (filter instanceof AnnotationTypeFilter) {
		return ((AnnotationTypeFilter) filter).getAnnotationType().getName();
	}
	if (filter instanceof AssignableTypeFilter) {
		return ((AssignableTypeFilter) filter).getTargetType().getName();
	}
	return null;
}
 
Example 11
@SuppressWarnings("unchecked")
protected TypeFilter createTypeFilter(Element element, @Nullable ClassLoader classLoader,
		ParserContext parserContext) throws ClassNotFoundException {

	String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE);
	String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE);
	expression = parserContext.getReaderContext().getEnvironment().resolvePlaceholders(expression);
	if ("annotation".equals(filterType)) {
		return new AnnotationTypeFilter((Class<Annotation>) ClassUtils.forName(expression, classLoader));
	}
	else if ("assignable".equals(filterType)) {
		return new AssignableTypeFilter(ClassUtils.forName(expression, classLoader));
	}
	else if ("aspectj".equals(filterType)) {
		return new AspectJTypeFilter(expression, classLoader);
	}
	else if ("regex".equals(filterType)) {
		return new RegexPatternTypeFilter(Pattern.compile(expression));
	}
	else if ("custom".equals(filterType)) {
		Class<?> filterClass = ClassUtils.forName(expression, classLoader);
		if (!TypeFilter.class.isAssignableFrom(filterClass)) {
			throw new IllegalArgumentException(
					"Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression);
		}
		return (TypeFilter) BeanUtils.instantiateClass(filterClass);
	}
	else {
		throw new IllegalArgumentException("Unsupported filter type: " + filterType);
	}
}
 
Example 12
/**
 * Check whether any of the configured entity type filters matches
 * the current class descriptor contained in the metadata reader.
 */
private boolean matchesFilter(MetadataReader reader, MetadataReaderFactory readerFactory) throws IOException {
	for (TypeFilter filter : entityTypeFilters) {
		if (filter.match(reader, readerFactory)) {
			return true;
		}
	}
	return false;
}
 
Example 13
Source Project: java-technology-stack   Source File: LocalSessionFactoryBuilder.java    License: MIT License 5 votes vote down vote up
/**
 * Check whether any of the configured entity type filters matches
 * the current class descriptor contained in the metadata reader.
 */
private boolean matchesEntityTypeFilter(MetadataReader reader, MetadataReaderFactory readerFactory) throws IOException {
	if (this.entityTypeFilters != null) {
		for (TypeFilter filter : this.entityTypeFilters) {
			if (filter.match(reader, readerFactory)) {
				return true;
			}
		}
	}
	return false;
}
 
Example 14
Source Project: java-technology-stack   Source File: ClassPathJaxb2TypeScanner.java    License: MIT License 5 votes vote down vote up
protected boolean isJaxb2Class(MetadataReader reader, MetadataReaderFactory factory) throws IOException {
	for (TypeFilter filter : JAXB2_TYPE_FILTERS) {
		if (filter.match(reader, factory) && !reader.getClassMetadata().isInterface() ) {
			return true;
		}
	}
	return false;
}
 
Example 15
@Override
public boolean match(MetadataReader metadataReader,
		MetadataReaderFactory metadataReaderFactory) throws IOException {

	for (TypeFilter filter : this.delegates) {
		if (!filter.match(metadataReader, metadataReaderFactory)) {
			return false;
		}
	}

	return true;
}
 
Example 16
Source Project: BootNettyRpc   Source File: NettyRpcRegistrar.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {

    for (TypeFilter filter : this.delegates) {
        if (!filter.match( metadataReader, metadataReaderFactory )) {
            return false;
        }
    }
    return true;
}
 
Example 17
@SuppressWarnings("unchecked")
protected TypeFilter createTypeFilter(Element element, ClassLoader classLoader, ParserContext parserContext) {
	String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE);
	String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE);
	expression = parserContext.getReaderContext().getEnvironment().resolvePlaceholders(expression);
	try {
		if ("annotation".equals(filterType)) {
			return new AnnotationTypeFilter((Class<Annotation>) classLoader.loadClass(expression));
		}
		else if ("assignable".equals(filterType)) {
			return new AssignableTypeFilter(classLoader.loadClass(expression));
		}
		else if ("aspectj".equals(filterType)) {
			return new AspectJTypeFilter(expression, classLoader);
		}
		else if ("regex".equals(filterType)) {
			return new RegexPatternTypeFilter(Pattern.compile(expression));
		}
		else if ("custom".equals(filterType)) {
			Class<?> filterClass = classLoader.loadClass(expression);
			if (!TypeFilter.class.isAssignableFrom(filterClass)) {
				throw new IllegalArgumentException(
						"Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression);
			}
			return (TypeFilter) BeanUtils.instantiateClass(filterClass);
		}
		else {
			throw new IllegalArgumentException("Unsupported filter type: " + filterType);
		}
	}
	catch (ClassNotFoundException ex) {
		throw new FatalBeanException("Type filter class not found: " + expression, ex);
	}
}
 
Example 18
/**
 * Check whether any of the configured entity type filters matches
 * the current class descriptor contained in the metadata reader.
 */
private boolean matchesFilter(MetadataReader reader, MetadataReaderFactory readerFactory) throws IOException {
	for (TypeFilter filter : entityTypeFilters) {
		if (filter.match(reader, readerFactory)) {
			return true;
		}
	}
	return false;
}
 
Example 19
/**
 * Check whether any of the configured entity type filters matches
 * the current class descriptor contained in the metadata reader.
 */
private boolean matchesEntityTypeFilter(MetadataReader reader, MetadataReaderFactory readerFactory) throws IOException {
	if (this.entityTypeFilters != null) {
		for (TypeFilter filter : this.entityTypeFilters) {
			if (filter.match(reader, readerFactory)) {
				return true;
			}
		}
	}
	return false;
}
 
Example 20
/**
 * Check whether any of the configured entity type filters matches
 * the current class descriptor contained in the metadata reader.
 */
private boolean matchesEntityTypeFilter(MetadataReader reader, MetadataReaderFactory readerFactory) throws IOException {
	if (this.entityTypeFilters != null) {
		for (TypeFilter filter : this.entityTypeFilters) {
			if (filter.match(reader, readerFactory)) {
				return true;
			}
		}
	}
	return false;
}
 
Example 21
/**
 * Check whether any of the configured entity type filters matches
 * the current class descriptor contained in the metadata reader.
 */
private boolean matchesEntityTypeFilter(MetadataReader reader, MetadataReaderFactory readerFactory) throws IOException {
	if (this.entityTypeFilters != null) {
		for (TypeFilter filter : this.entityTypeFilters) {
			if (filter.match(reader, readerFactory)) {
				return true;
			}
		}
	}
	return false;
}
 
Example 22
Source Project: nh-micro   Source File: GroovyScanner.java    License: Apache License 2.0 5 votes vote down vote up
public void registerDefaultFilters() {
 this.addIncludeFilter(new TypeFilter() {
       @Override
       public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
       	//add 201806 ninghao
         boolean flag=metadataReader.getAnnotationMetadata().hasAnnotation("com.nh.micro.service.InjectGroovy");
         return flag;
       }
     });
 
}
 
Example 23
@SuppressWarnings("unchecked")
protected TypeFilter createTypeFilter(Element element, ClassLoader classLoader, ParserContext parserContext) {
	String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE);
	String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE);
	expression = parserContext.getReaderContext().getEnvironment().resolvePlaceholders(expression);
	try {
		if ("annotation".equals(filterType)) {
			return new AnnotationTypeFilter((Class<Annotation>) classLoader.loadClass(expression));
		}
		else if ("assignable".equals(filterType)) {
			return new AssignableTypeFilter(classLoader.loadClass(expression));
		}
		else if ("aspectj".equals(filterType)) {
			return new AspectJTypeFilter(expression, classLoader);
		}
		else if ("regex".equals(filterType)) {
			return new RegexPatternTypeFilter(Pattern.compile(expression));
		}
		else if ("custom".equals(filterType)) {
			Class<?> filterClass = classLoader.loadClass(expression);
			if (!TypeFilter.class.isAssignableFrom(filterClass)) {
				throw new IllegalArgumentException(
						"Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression);
			}
			return (TypeFilter) BeanUtils.instantiateClass(filterClass);
		}
		else {
			throw new IllegalArgumentException("Unsupported filter type: " + filterType);
		}
	}
	catch (ClassNotFoundException ex) {
		throw new FatalBeanException("Type filter class not found: " + expression, ex);
	}
}
 
Example 24
/**
 * Check whether any of the configured entity type filters matches
 * the current class descriptor contained in the metadata reader.
 */
private boolean matchesFilter(MetadataReader reader, MetadataReaderFactory readerFactory) throws IOException {
	for (TypeFilter filter : entityTypeFilters) {
		if (filter.match(reader, readerFactory)) {
			return true;
		}
	}
	return false;
}
 
Example 25
/**
 * Check whether any of the configured entity type filters matches
 * the current class descriptor contained in the metadata reader.
 */
private boolean matchesEntityTypeFilter(MetadataReader reader, MetadataReaderFactory readerFactory) throws IOException {
	if (this.entityTypeFilters != null) {
		for (TypeFilter filter : this.entityTypeFilters) {
			if (filter.match(reader, readerFactory)) {
				return true;
			}
		}
	}
	return false;
}
 
Example 26
/**
 * Check whether any of the configured entity type filters matches
 * the current class descriptor contained in the metadata reader.
 */
private boolean matchesEntityTypeFilter(MetadataReader reader, MetadataReaderFactory readerFactory) throws IOException {
	if (this.entityTypeFilters != null) {
		for (TypeFilter filter : this.entityTypeFilters) {
			if (filter.match(reader, readerFactory)) {
				return true;
			}
		}
	}
	return false;
}
 
Example 27
protected boolean isJaxb2Class(MetadataReader reader, MetadataReaderFactory factory) throws IOException {
	for (TypeFilter filter : JAXB2_TYPE_FILTERS) {
		if (filter.match(reader, factory) && !reader.getClassMetadata().isInterface() ) {
			return true;
		}
	}
	return false;
}
 
Example 28
/**
 * Check whether any of the configured entity type filters matches
 * the current class descriptor contained in the metadata reader.
 */
private boolean matchesEntityTypeFilter(MetadataReader reader, MetadataReaderFactory readerFactory) throws IOException {
	if (this.entityTypeFilters != null) {
		for (TypeFilter filter : this.entityTypeFilters) {
			if (filter.match(reader, readerFactory)) {
				return true;
			}
		}
	}
	return false;
}
 
Example 29
Source Project: nh-micro   Source File: GroovyScanner.java    License: Apache License 2.0 5 votes vote down vote up
public void registerDefaultFilters() {
 this.addIncludeFilter(new TypeFilter() {
       @Override
       public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
       	//add 201806 ninghao
         boolean flag=metadataReader.getAnnotationMetadata().hasAnnotation("com.nh.micro.service.InjectGroovy");
         return flag;
       }
     });
 
}
 
Example 30
Source Project: spring-content   Source File: CmisRegistrar.java    License: Apache License 2.0 5 votes vote down vote up
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
		throws IOException {

	for (TypeFilter filter : delegates) {
		if (!filter.match(metadataReader, metadataReaderFactory)) {
			return false;
		}
	}

	return true;
}