Example usage for org.springframework.util ClassUtils getClassFileName

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

Introduction

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

Prototype

public static String getClassFileName(Class<?> clazz) 

Source Link

Document

Determine the name of the class file, relative to the containing package: e.g.

Usage

From source file:com.quirklabs.authorise.ProxyAwareLocalVariableTableParameterNameDiscoverer.java

/**
 * Obtain a (cached) ClassReader for the given class.
 *///from   w w w.jav a 2 s .c  om
private ClassReader getClassReader(Class clazz) throws IOException {
    synchronized (this.classReaderCache) {
        ClassReader classReader = (ClassReader) this.classReaderCache.get(clazz.getDeclaringClass());
        if (classReader == null) {
            InputStream is = clazz.getResourceAsStream(ClassUtils.getClassFileName(clazz));
            if (is == null) {
                throw new FileNotFoundException("Class file for class [" + clazz.getName() + "] not found");
            }
            try {
                classReader = new ClassReader(is);
                this.classReaderCache.put(clazz.getDeclaringClass(), classReader);
            } finally {
                is.close();
            }
        }
        return classReader;
    }
}

From source file:org.eclipse.gemini.blueprint.test.AbstractOnTheFlyBundleCreatorTests.java

/**
 * Determine imports for the given bundle. Based on the user settings, this
 * method will consider only the the test hierarchy until the testing
 * framework is found or all classes available inside the test bundle. <p/>
 * Note that split packages are not supported.
 * //  www  . j av a2s  .  com
 * @return
 */
private String[] determineImports() {

    boolean useTestClassOnly = false;

    // no jar entry present, bail out.
    if (jarEntries == null || jarEntries.isEmpty()) {
        logger.debug("No test jar content detected, generating bundle imports from the test class");
        useTestClassOnly = true;
    }

    else if (createManifestOnlyFromTestClass()) {
        logger.info("Using the test class for generating bundle imports");
        useTestClassOnly = true;
    } else
        logger.info("Using all classes in the jar for the generation of bundle imports");

    // className, class resource
    Map entries;

    if (useTestClassOnly) {

        entries = new LinkedHashMap(4);

        // get current class (test class that bootstraps the OSGi infrastructure)
        Class<?> clazz = getClass();
        String clazzPackage = null;
        String endPackage = AbstractOnTheFlyBundleCreatorTests.class.getPackage().getName();

        do {

            // consider inner classes as well
            List classes = new ArrayList(4);
            classes.add(clazz);
            CollectionUtils.mergeArrayIntoCollection(clazz.getDeclaredClasses(), classes);

            for (Iterator iterator = classes.iterator(); iterator.hasNext();) {
                Class<?> classToInspect = (Class) iterator.next();

                Package pkg = classToInspect.getPackage();
                if (pkg != null) {
                    clazzPackage = pkg.getName();
                    String classFile = ClassUtils.getClassFileName(classToInspect);
                    entries.put(classToInspect.getName().replace('.', '/').concat(ClassUtils.CLASS_FILE_SUFFIX),
                            new InputStreamResource(classToInspect.getResourceAsStream(classFile)));
                }
                // handle default package
                else {
                    logger.warn("Could not find package for class " + classToInspect + "; ignoring...");
                }
            }

            clazz = clazz.getSuperclass();

        } while (!endPackage.equals(clazzPackage));
    } else
        entries = jarEntries;

    return determineImportsFor(entries);

}

From source file:org.springframework.core.LocalVariableTableParameterNameDiscoverer.java

/**
 * Inspects the target class. Exceptions will be logged and a maker map returned
 * to indicate the lack of debug information.
 *//*from w  ww  . java 2 s. com*/
private Map<Member, String[]> inspectClass(Class<?> clazz) {
    InputStream is = clazz.getResourceAsStream(ClassUtils.getClassFileName(clazz));
    if (is == null) {
        // We couldn't load the class file, which is not fatal as it
        // simply means this method of discovering parameter names won't work.
        if (logger.isDebugEnabled()) {
            logger.debug("Cannot find '.class' file for class [" + clazz
                    + "] - unable to determine constructor/method parameter names");
        }
        return NO_DEBUG_INFO_MAP;
    }
    try {
        ClassReader classReader = new ClassReader(is);
        Map<Member, String[]> map = new ConcurrentHashMap<>(32);
        classReader.accept(new ParameterNameDiscoveringVisitor(clazz, map), 0);
        return map;
    } catch (IOException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Exception thrown while reading '.class' file for class [" + clazz
                    + "] - unable to determine constructor/method parameter names", ex);
        }
    } catch (IllegalArgumentException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("ASM ClassReader failed to parse class file [" + clazz
                    + "], probably due to a new Java class file version that isn't supported yet "
                    + "- unable to determine constructor/method parameter names", ex);
        }
    } finally {
        try {
            is.close();
        } catch (IOException ex) {
            // ignore
        }
    }
    return NO_DEBUG_INFO_MAP;
}