Example usage for org.springframework.util ClassUtils convertClassNameToResourcePath

List of usage examples for org.springframework.util ClassUtils convertClassNameToResourcePath

Introduction

In this page you can find the example usage for org.springframework.util ClassUtils convertClassNameToResourcePath.

Prototype

public static String convertClassNameToResourcePath(String className) 

Source Link

Document

Convert a "."-based fully qualified class name to a "/"-based resource path.

Usage

From source file:viewfx.view.DefaultPathConvention.java

@Override
public String apply(Class<? extends View> viewClass) {
    return ClassUtils.convertClassNameToResourcePath(viewClass.getName()).concat(".fxml");
}

From source file:com.baomidou.mybatisplus.toolkit.PackageHelper.java

/**
 * <p>/*from  ww w . jav a 2  s. c o  m*/
 * ???
 * </p>
 * <p>
 * <property name="typeAliasesPackage" value="com.baomidou.*.entity"/>
 * </p>
 * 
 * @param typeAliasesPackage
 *            ??
 * @return
 */
public static String[] convertTypeAliasesPackage(String typeAliasesPackage) {
    ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
    MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
    String pkg = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
            + ClassUtils.convertClassNameToResourcePath(typeAliasesPackage) + "/*.class";

    /*
     * ??Resource
     * ClassLoader.getResource("META-INF")?????????
     */
    try {
        Set<String> set = new HashSet<String>();
        Resource[] resources = resolver.getResources(pkg);
        if (resources != null && resources.length > 0) {
            MetadataReader metadataReader = null;
            for (Resource resource : resources) {
                if (resource.isReadable()) {
                    metadataReader = metadataReaderFactory.getMetadataReader(resource);
                    set.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage()
                            .getName());
                }
            }
        }
        if (!set.isEmpty()) {
            return set.toArray(new String[] {});
        } else {
            throw new MybatisPlusException("not find typeAliasesPackage:" + pkg);
        }
    } catch (Exception e) {
        throw new MybatisPlusException("not find typeAliasesPackage:" + pkg, e);
    }
}

From source file:com.baomidou.framework.spring.SpringScanPackage.java

/**
 * <p>/*from   w  w  w  .  j a  va  2 s . co  m*/
 * ???,?
 * </p>
 *
 * @param scanPackages
 *            ??package
 * @return
 */
public static Set<String> findPackageClass(String scanPackages) {
    Set<String> clazzSet = new HashSet<String>();
    ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
    MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
    String pkg = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
            + ClassUtils.convertClassNameToResourcePath(scanPackages) + "/**/*.class";
    /*
     * ??Resource
     * ClassLoader.getResource("META-INF")?????????
     */
    try {
        Resource[] resources = resolver.getResources(pkg);
        if (resources != null && resources.length > 0) {
            for (Resource resource : resources) {
                if (resource.isReadable()) {
                    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
                    if (metadataReader != null) {
                        clazzSet.add(metadataReader.getClassMetadata().getClassName());
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return clazzSet;
}

From source file:com.qrmedia.commons.test.annotation.processing.AbstractAnnotationProcessorTest.java

private static String toResourcePath(Class<?> clazz) {
    return ClassUtils.convertClassNameToResourcePath(clazz.getName()) + SOURCE_FILE_SUFFIX;
}

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

/**
 * ??BeanClass??/*  w  w w .j  a v  a2  s .  co m*/
 * @return
 * @throws IOException
 * @throws ClassNotFoundException
 */
public Set<Class<?>> getClassSet() throws IOException, ClassNotFoundException {
    this.classSet.clear();
    if (!this.packagesList.isEmpty()) {
        for (String pkg : this.packagesList) {
            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)) {
                        this.classSet.add(Class.forName(className));
                    }
                }
            }
        }
    }
    //
    //      if (logger.isInfoEnabled()){
    //         for (Class<?> clazz : this.classSet) {
    //            //logger.info(String.format("Found class:%s", clazz.getName()));
    //         }
    //      }
    return this.classSet;
}

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

@SafeVarargs
public final Set<Class<?>> scan(String[] confPkgs, Class<? extends Annotation>... annotationTags) {
    Set<Class<?>> resClazzSet = new HashSet<>();
    List<AnnotationTypeFilter> typeFilters = new LinkedList<>();
    if (ArrayUtils.isNotEmpty(annotationTags)) {
        for (Class<? extends Annotation> annotation : annotationTags) {
            typeFilters.add(new AnnotationTypeFilter(annotation, false));
        }/*from  www .j  av  a2  s . c  o  m*/
    }
    if (ArrayUtils.isNotEmpty(confPkgs)) {
        for (String pkg : confPkgs) {
            String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
                    + String.format(RESOURCE_PATTERN, ClassUtils.convertClassNameToResourcePath(pkg));
            try {
                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 (ifMatchesEntityType(reader, readerFactory, typeFilters)) {
                            Class<?> curClass = Thread.currentThread().getContextClassLoader()
                                    .loadClass(className);
                            context.register(curClass);
                            resClazzSet.add(curClass);
                        }
                    }
                }
            } catch (Exception e) {
                logger.error("?????[{}][{}]", pattern,
                        StringUtils.join(typeFilters, ","));
            }
        }
    }
    if (!context.isActive()) {
        context.refresh();
    }
    return resClazzSet;
}

From source file:com.fantasy.Application.java

private static String resolveBasePackage(String basePackage) {
    return ClassUtils.convertClassNameToResourcePath(SystemPropertyUtils.resolvePlaceholders(basePackage));
}

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

/**
 * Generate the SQL file. This is based on the code in {@link LocalSessionFactoryBuilder#scanPackages(String...)}
 *
 * @param dialect/*from   w  w w  .  j a v  a  2 s. c o m*/
 *            the dialect (e.g: org.hibernate.dialect.MySQL5InnoDBDialect )
 * @param outputSqlFile
 *            where to put the generated SQL file
 * @param useUnderscore
 *            true: to have tables names like "employe_manager" ; false: to have tables names like "employeManager"
 * @param packagesToScan
 *            the packages where your entities are
 */
@SuppressWarnings("deprecation")
public static void generateSqlSchema(Class<? extends Dialect> dialect, String outputSqlFile,
        boolean useUnderscore, String... packagesToScan) {

    // Configuration
    Configuration configuration = new Configuration();
    if (useUnderscore) {
        configuration.setNamingStrategy(new ImprovedNamingStrategy());
    }

    Properties properties = new Properties();
    properties.setProperty(AvailableSettings.DIALECT, dialect.getName());

    // Scan packages
    Set<String> classNames = 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 = resourcePatternResolver.getResources(pattern);
            MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
            for (Resource resource : resources) {
                if (resource.isReadable()) {
                    MetadataReader reader = readerFactory.getMetadataReader(resource);
                    String className = reader.getClassMetadata().getClassName();
                    if (matchesEntityTypeFilter(reader, readerFactory)) {
                        classNames.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 {
        for (String className : classNames) {
            configuration.addAnnotatedClass(resourcePatternResolver.getClassLoader().loadClass(className));
        }
        for (String packageName : packageNames) {
            configuration.addPackage(packageName);
        }
    } catch (ClassNotFoundException ex) {
        throw new MappingException("Failed to load annotated classes from classpath", ex);
    }

    // Exportation
    SchemaExport schemaExport = new SchemaExport(configuration, properties);
    schemaExport.setOutputFile(outputSqlFile);
    schemaExport.setDelimiter(";");
    schemaExport.setFormat(true);
    schemaExport.execute(true, false, false, true);
}