/**
  * Check whether any of the configured entity type filters matches the current class descriptor
  * contained in the metadata reader.
  */
 protected boolean matchesFilter(MetadataReader reader, MetadataReaderFactory readerFactory)
     throws IOException {
   for (TypeFilter filter : ENTITY_TYPE_FILTERS) {
     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 matchesFilter(MetadataReader reader, MetadataReaderFactory readerFactory)
     throws IOException {
   for (TypeFilter filter : entityTypeFilters) {
     if (filter.match(reader, readerFactory)) {
       return true;
     }
   }
   return false;
 }
コード例 #3
0
ファイル: ClassScaner.java プロジェクト: gitter-badger/wx_api
 protected boolean matches(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;
 }
 /**
  * Determine whether the given class does not match any exclude filter and does match at least one
  * include filter.
  *
  * @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)) {
       AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
       if (!metadata.isAnnotated(Profile.class.getName())) {
         return true;
       }
       AnnotationAttributes profile = MetadataUtils.attributesFor(metadata, Profile.class);
       return this.environment.acceptsProfiles(profile.getStringArray("value"));
     }
   }
   return false;
 }
コード例 #5
0
 /**
  * Perform Spring-based scanning for entity classes, registering them as annotated classes with
  * this {@code Configuration}.
  *
  * @param packagesToScan one or more Java package names
  * @throws HibernateException if scanning fails for any reason
  */
 public LocalSessionFactoryBuilder scanPackages(String... packagesToScan)
     throws HibernateException {
   Set<String> entityClassNames = new TreeSet<String>();
   Set<String> converterClassNames = new TreeSet<String>();
   Set<String> packageNames = new TreeSet<String>();
   try {
     for (String pkg : packagesToScan) {
       String pattern =
           ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
               + ClassUtils.convertClassNameToResourcePath(pkg)
               + RESOURCE_PATTERN;
       Resource[] resources = this.resourcePatternResolver.getResources(pattern);
       MetadataReaderFactory readerFactory =
           new CachingMetadataReaderFactory(this.resourcePatternResolver);
       for (Resource resource : resources) {
         if (resource.isReadable()) {
           MetadataReader reader = readerFactory.getMetadataReader(resource);
           String className = reader.getClassMetadata().getClassName();
           if (matchesEntityTypeFilter(reader, readerFactory)) {
             entityClassNames.add(className);
           } else if (converterTypeFilter != null
               && converterTypeFilter.match(reader, readerFactory)) {
             converterClassNames.add(className);
           } else if (className.endsWith(PACKAGE_INFO_SUFFIX)) {
             packageNames.add(
                 className.substring(0, className.length() - PACKAGE_INFO_SUFFIX.length()));
           }
         }
       }
     }
   } catch (IOException ex) {
     throw new MappingException("Failed to scan classpath for unlisted classes", ex);
   }
   try {
     ClassLoader cl = this.resourcePatternResolver.getClassLoader();
     for (String className : entityClassNames) {
       addAnnotatedClass(cl.loadClass(className));
     }
     for (String className : converterClassNames) {
       ConverterRegistrationDelegate.registerConverter(this, cl.loadClass(className));
     }
     for (String packageName : packageNames) {
       addPackage(packageName);
     }
   } catch (ClassNotFoundException ex) {
     throw new MappingException("Failed to load annotated classes from classpath", ex);
   }
   return this;
 }