Example usage for org.springframework.core.type.filter TypeFilter match

List of usage examples for org.springframework.core.type.filter TypeFilter match

Introduction

In this page you can find the example usage for org.springframework.core.type.filter TypeFilter match.

Prototype

boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException;

Source Link

Document

Determine whether this filter matches for the class described by the given metadata.

Usage

From source file:com.foilen.smalltools.tools.Hibernate4Tools.java

/**
 * Check whether any of the configured entity type filters matches the current class descriptor contained in the metadata reader.
 *///from w  ww  .j av  a 2  s . c o m
private static boolean matchesEntityTypeFilter(MetadataReader reader, MetadataReaderFactory readerFactory)
        throws IOException {
    for (TypeFilter filter : entityTypeFilters) {
        if (filter.match(reader, readerFactory)) {
            return true;
        }
    }
    return false;
}

From source file:org.codehaus.grepo.core.config.CompositeTypeFilter.java

/**
 * {@inheritDoc}/*w  w  w . j a v  a 2  s. com*/
 */
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
        throws IOException {
    boolean matches = true;
    for (TypeFilter tf : typeFilters) {
        if (!tf.match(metadataReader, metadataReaderFactory)) {
            matches = false;
            break;
        }
    }
    return matches;
}

From source file:org.lightadmin.core.config.bootstrap.scanning.TypeFilterClassScanner.java

private boolean hasApplicableType(MetadataReader metadataReader) throws IOException {
    for (TypeFilter typeFilter : typeFilters) {
        if (typeFilter.match(metadataReader, this.metadataReaderFactory)) {
            return true;
        }/*from w  w w.ja va 2 s. c o  m*/
    }
    return false;
}

From source file:com.zht.common.generator.util.LoadPackageClasses.java

/**
 * ???Bean?/*  ww w . java  2  s  .c o  m*/
 * @param reader
 * @param readerFactory
 * @return
 * @throws IOException
 */
private boolean matchesEntityTypeFilter(MetadataReader reader, MetadataReaderFactory readerFactory)
        throws IOException {
    if (!this.typeFilters.isEmpty()) {
        for (TypeFilter filter : this.typeFilters) {
            if (filter.match(reader, readerFactory)) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.opentides.persistence.hibernate.PersistenceScanner.java

/**
 * /*from   w  w  w .j a va2  s .  c om*/
 * 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 {
    if (this.entityTypeFilters != null) {
        for (TypeFilter filter : this.entityTypeFilters) {
            if (filter.match(reader, readerFactory)) {
                return true;
            }
        }
    }
    return false;
}

From source file:cn.wanghaomiao.seimi.core.SeimiScanner.java

/**
 * ?????/*from   www.  ja va2s  .c o m*/
 * @param reader
 * @param readerFactory
 * @return ture/false
 */
private boolean ifMatchesEntityType(MetadataReader reader, MetadataReaderFactory readerFactory,
        List<AnnotationTypeFilter> typeFilters) {
    if (!CollectionUtils.isEmpty(typeFilters)) {
        for (TypeFilter filter : typeFilters) {
            try {
                if (filter.match(reader, readerFactory)) {
                    return true;
                }
            } catch (IOException e) {
                logger.error("? {}", e.getMessage());
            }
        }
    }
    return false;
}

From source file:org.spring.guice.module.GuiceModuleMetadata.java

private boolean matches(Class<?> type) {
    if (infrastructureTypes.contains(type)) {
        return false;
    }//from w  ww. j  a va 2  s .  c o  m

    if (!visible(type)) {
        return false;
    }

    if (includeFilters != null) {
        try {
            MetadataReader reader = metadataReaderFactory.getMetadataReader(type.getName());
            for (TypeFilter filter : includeFilters) {
                if (!filter.match(reader, metadataReaderFactory)) {
                    return false;
                }
            }
        } catch (IOException e) {
            throw new IllegalStateException("Cannot read metadata for class " + type, e);
        }
    }
    if (excludeFilters != null) {
        try {
            MetadataReader reader = metadataReaderFactory.getMetadataReader(type.getName());
            for (TypeFilter filter : excludeFilters) {
                if (filter.match(reader, metadataReaderFactory)) {
                    return false;
                }
            }
        } catch (IOException e) {
            throw new IllegalStateException("Cannot read metadata for class " + type, e);
        }
    }
    return true;
}

From source file:com.gzj.tulip.jade.context.spring.JadeComponentProvider.java

/**
 * Determine whether the given class does not match any exclude filter
 * and does match at least one include filter.
 * //w  w  w. j  a v  a  2s . c om
 * @param metadataReader the ASM ClassReader for the class
 * @return whether the class qualifies as a candidate component
 */
protected boolean isCandidateComponent(MetadataReader metadataReader) throws IOException {
    for (TypeFilter tf : this.excludeFilters) {
        if (tf.match(metadataReader, this.metadataReaderFactory)) {
            return false;
        }
    }
    for (TypeFilter tf : this.includeFilters) {
        if (tf.match(metadataReader, this.metadataReaderFactory)) {
            return true;
        }
    }
    return false;
}

From source file:au.com.permeance.liferay.spring.BeanLocatorDefinitionCopier.java

/**
 * Wraps a call to/* www .  j  a v  a 2s  . co m*/
 * {@link TypeFilter#match(MetadataReader, org.springframework.core.type.classreading.MetadataReaderFactory)}
 * so that any {@link IOException} is logged rather than propagating up the call stack. Returns the result of the
 * match if successful, {@code false} otherwise.
 *
 * @param filter         the filter to match against.
 * @param metadataReader the metadata reader to match with.
 *
 * @return true if
 *         {@link TypeFilter#match(MetadataReader, org.springframework.core.type.classreading.MetadataReaderFactory)}
 *         returns it, {@code false} otherwise.
 */
protected final boolean safeMatch(final TypeFilter filter, final MetadataReader metadataReader) {
    try {
        return filter.match(metadataReader, null);
    } catch (final IOException e) {
        LOG.warn(format("Error checking for filter %s match against reader %s", filter, metadataReader));
    }
    return false;
}

From source file:org.openmrs.module.webservices.rest.web.OpenmrsClassScanner.java

/**
 * Searches for classes extending or implementing the given type.
 * /*from   w  ww  .  jav a2  s  .com*/
 * @param <T>
 * @param type
 * @param concrete true if only concrete classes should be returned
 * @return the list of found classes
 * @throws IOException
 */

public <T> List<Class<? extends T>> getClasses(Class<? extends T> type, boolean concrete) throws IOException {

    List<Class<? extends T>> types = new ArrayList<Class<? extends T>>();

    String pattern = "classpath*:org/openmrs/**/*.class";

    Resource[] resources = resourceResolver.getResources(pattern);

    TypeFilter typeFilter = new AssignableTypeFilter(type);

    for (Resource resource : resources) {

        try {

            MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);

            if (typeFilter.match(metadataReader, metadataReaderFactory)) {

                if (concrete == metadataReader.getClassMetadata().isConcrete()) {

                    String classname = metadataReader.getClassMetadata().getClassName();

                    try {

                        @SuppressWarnings("unchecked")
                        Class<? extends T> metadata = (Class<? extends T>) OpenmrsClassLoader.getInstance()
                                .loadClass(

                                        classname);

                        types.add(metadata);

                    }

                    catch (ClassNotFoundException e) {

                        throw new IOException("Class cannot be loaded: " + classname, e);

                    }

                }

            }

        }

        catch (IOException e) {

            log.debug("Resource cannot be loaded: " + resource);

        }

    }

    return types;

}