Example usage for org.springframework.util ClassUtils convertResourcePathToClassName

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

Introduction

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

Prototype

public static String convertResourcePathToClassName(String resourcePath) 

Source Link

Document

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

Usage

From source file:com.reactive.hzdfs.dll.JarClassLoader.java

private static TreeSet<String> scanForPackages(String path) throws IOException {
    try (JarFile file = new JarFile(path)) {
        TreeSet<String> packages = new TreeSet<>(new Comparator<String>() {

            @Override//from  ww  w  .jav  a  2 s .  c om
            public int compare(String o1, String o2) {
                if (o2.length() > o1.length() && o2.contains(o1))
                    return -1;
                else if (o2.length() < o1.length() && o1.contains(o2))
                    return 1;
                else
                    return o1.compareTo(o2);
            }
        });
        for (Enumeration<JarEntry> entries = file.entries(); entries.hasMoreElements();) {
            JarEntry entry = entries.nextElement();
            String name = entry.getName();

            if (name.endsWith(".class")) {
                String fqcn = ClassUtils.convertResourcePathToClassName(name);
                fqcn = StringUtils.delete(fqcn, ".class");
                packages.add(ClassUtils.getPackageName(fqcn));
            }
        }

        return packages;
    }
}

From source file:com.agileapes.couteau.maven.resource.ClassPathScanningClassProvider.java

private Class resolveClass(Resource resource, String basePackage) throws IOException, ClassNotFoundException {
    final String clazzCleanPath = StringUtils.cleanPath(resource.getURL().getPath());
    final String clazzPathWithoutExtension = StringUtils.stripFilenameExtension(clazzCleanPath);
    final String resourcePackageLikeStr = ClassUtils.convertResourcePathToClassName(clazzPathWithoutExtension);
    final String className = resourcePackageLikeStr.substring(resourcePackageLikeStr.lastIndexOf(basePackage));
    return ClassUtils.forName(className, classLoader);
}

From source file:org.openlegacy.support.DefaultRegistryLoader.java

private static Class<?> getClassFromResource(String packagePath, Resource resource)
        throws IOException, ClassNotFoundException {
    String resourcePath = resource.getURI().toString();
    String resourceRelativePath = resourcePath.substring(resourcePath.indexOf(packagePath),
            resourcePath.indexOf(".class"));
    String className = ClassUtils.convertResourcePathToClassName(resourceRelativePath);

    Class<?> beanClass = Class.forName(className);
    return beanClass;
}