org.springframework.stereotype.Indexed#org.springframework.core.type.filter.TypeFilter源码实例Demo

下面列出了org.springframework.stereotype.Indexed#org.springframework.core.type.filter.TypeFilter 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * 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;
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
@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);
	}
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
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;
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
@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);
	}
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
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;
}
 
@Override
public boolean match(MetadataReader metadataReader,
		MetadataReaderFactory metadataReaderFactory) throws IOException {

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

	return true;
}
 
源代码16 项目: BootNettyRpc   文件: NettyRpcRegistrar.java
@Override
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {

    for (TypeFilter filter : this.delegates) {
        if (!filter.match( metadataReader, metadataReaderFactory )) {
            return false;
        }
    }
    return true;
}
 
源代码17 项目: lams   文件: ComponentScanBeanDefinitionParser.java
@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);
	}
}
 
源代码18 项目: lams   文件: DefaultPersistenceUnitManager.java
/**
 * 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;
}
 
源代码19 项目: lams   文件: LocalSessionFactoryBuilder.java
/**
 * 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;
}
 
源代码20 项目: lams   文件: LocalSessionFactoryBuilder.java
/**
 * 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;
}
 
源代码21 项目: lams   文件: AnnotationSessionFactoryBean.java
/**
 * 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;
}
 
源代码22 项目: nh-micro   文件: GroovyScanner.java
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;
       }
     });
 
}
 
@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);
	}
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
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;
}
 
/**
 * 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;
}
 
源代码29 项目: nh-micro   文件: GroovyScanner.java
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;
       }
     });
 
}
 
源代码30 项目: spring-content   文件: CmisRegistrar.java
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
		throws IOException {

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

	return true;
}