Search in sources :

Example 1 with EnhancerClassChecker

use of org.datanucleus.enhancer.EnhancerClassChecker in project datanucleus-core by datanucleus.

the class ClassEnhancerImpl method checkClassIsEnhanced.

/**
 * Convenience method to return if a class is enhanced.
 * @param logErrors Whether to log any errors (missing methods etc) as errors (otherwise info/debug)
 * @return Whether the class is enhanced
 */
protected boolean checkClassIsEnhanced(boolean logErrors) {
    try {
        // Create an adapter using a writer
        EnhancerClassChecker checker = new EnhancerClassChecker(this, logErrors);
        InputStream classReaderInputStream = null;
        try {
            // Create a reader for the class and visit it using the checker
            ClassReader cr = null;
            if (inputBytes != null) {
                cr = new ClassReader(inputBytes);
            } else {
                classReaderInputStream = clr.getResource(inputResourceName, null).openStream();
                cr = new ClassReader(classReaderInputStream);
            }
            // [ASM Note : In 2.2 this should be "cr.accept(checker, false);"]
            cr.accept(checker, 0);
        } finally {
            if (classReaderInputStream != null) {
                classReaderInputStream.close();
            }
        }
        return checker.isEnhanced();
    } catch (Exception e) {
        DataNucleusEnhancer.LOGGER.error("Error thrown enhancing with ASMClassEnhancer", e);
    }
    return false;
}
Also used : EnhancerClassChecker(org.datanucleus.enhancer.EnhancerClassChecker) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ClassReader(org.datanucleus.enhancer.asm.ClassReader) InvalidMetaDataException(org.datanucleus.metadata.InvalidMetaDataException) IOException(java.io.IOException)

Aggregations

FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 EnhancerClassChecker (org.datanucleus.enhancer.EnhancerClassChecker)1 ClassReader (org.datanucleus.enhancer.asm.ClassReader)1 InvalidMetaDataException (org.datanucleus.metadata.InvalidMetaDataException)1