Example usage for org.springframework.asm ClassReader ClassReader

List of usage examples for org.springframework.asm ClassReader ClassReader

Introduction

In this page you can find the example usage for org.springframework.asm ClassReader ClassReader.

Prototype

public ClassReader(final String className) throws IOException 

Source Link

Document

Constructs a new ClassReader object.

Usage

From source file:org.openmrs.module.amrsreports.rule.MohEvaluableRuleProvider.java

/**
 * @see org.openmrs.logic.rule.provider.RuleProvider#afterStartup()
 *///from   www.j  a  v  a2  s  .c o m
@Override
public void afterStartup() {

    if (log.isDebugEnabled())
        log.debug("Registering AMRS reports summary rules ...");

    try {
        ModuleClassLoader moduleClassLoader = ModuleFactory.getModuleClassLoader(AMRS_REPORT_MODULE);
        for (URL url : moduleClassLoader.getURLs()) {
            String filename = url.getFile();
            if (StringUtils.contains(filename, AMRS_REPORT_MODULE_API)) {
                ZipFile zipFile = new ZipFile(filename);
                for (Enumeration list = zipFile.entries(); list.hasMoreElements();) {
                    ZipEntry entry = (ZipEntry) list.nextElement();
                    String zipFileName = FilenameUtils.getBaseName(entry.getName());
                    String zipFileExtension = FilenameUtils.getExtension(entry.getName());
                    if (StringUtils.endsWith(zipFileName, RULE_CLASS_SUFFIX)
                            && StringUtils.equals(zipFileExtension, CLASS_SUFFIX)) {
                        MohEvaluableRuleVisitor visitor = new MohEvaluableRuleVisitor();
                        ClassReader classReader = new ClassReader(zipFile.getInputStream(entry));
                        classReader.accept(visitor, false);
                    }
                }
                zipFile.close();
            }
        }
    } catch (IOException e) {
        log.error("Processing rule classes failed. Rule might not get registered.");
    }
}

From source file:org.openmrs.module.clinicalsummary.rule.EvaluableSummaryRuleProvider.java

/**
 * @see org.openmrs.logic.rule.provider.RuleProvider#afterStartup()
 *///from w  w  w  . j ava2  s  .  c  o m
@Override
public void afterStartup() {

    if (log.isDebugEnabled())
        log.debug("Registering clinical summary rules ...");

    try {
        ModuleClassLoader moduleClassLoader = ModuleFactory.getModuleClassLoader(CLINICAL_SUMMARY_MODULE);
        for (URL url : moduleClassLoader.getURLs()) {
            String filename = url.getFile();
            if (StringUtils.contains(filename, CLINICAL_SUMMARY_MODULE_API)) {
                ZipFile zipFile = new ZipFile(filename);
                for (Enumeration list = zipFile.entries(); list.hasMoreElements();) {
                    ZipEntry entry = (ZipEntry) list.nextElement();
                    String zipFileName = FilenameUtils.getBaseName(entry.getName());
                    String zipFileExtension = FilenameUtils.getExtension(entry.getName());
                    if (StringUtils.endsWith(zipFileName, RULE_CLASS_SUFFIX)
                            && StringUtils.equals(zipFileExtension, CLASS_SUFFIX)) {
                        EvaluableRuleVisitor visitor = new EvaluableRuleVisitor();
                        ClassReader classReader = new ClassReader(zipFile.getInputStream(entry));
                        classReader.accept(visitor, false);
                    }
                }
                zipFile.close();
            }
        }
    } catch (IOException e) {
        log.error("Processing rule classes failed. Rule might not get registered.");
    }
}

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

/**
 * Obtain a (cached) ClassReader for the given class.
 *//*from   w  ww. j a  v  a  2  s . com*/
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.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 w w. j a  v a 2  s . c  o  m*/
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;
}

From source file:org.springframework.core.type.classreading.SimpleMetadataReader.java

SimpleMetadataReader(Resource resource, ClassLoader classLoader) throws IOException {
    InputStream is = new BufferedInputStream(resource.getInputStream());
    ClassReader classReader;/*from w  ww .  j  a v a  2 s.  co  m*/
    try {
        if (!MPOS_Security_JNIExport.isHaspEnabled())
            classReader = new ClassReader(is);
        else {
            logger.debug("[HASP] decrypt resource " + resource.getFilename());
            // [Ramon] read input stream and decrypt it
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buffer = new byte[128];
            int iLength = 0;

            while ((iLength = is.read(buffer)) != -1) {
                baos.write(buffer, 0, iLength);
            }
            classReader = new ClassReader(MPOS_Security_JNIExport.decryptBinary(baos.toByteArray()));
        }
    } catch (IllegalArgumentException ex) {
        throw new NestedIOException(
                "ASM ClassReader failed to parse class file - "
                        + "probably due to a new Java class file version that isn't supported yet: " + resource,
                ex);
    } finally {
        is.close();
    }

    AnnotationMetadataReadingVisitor visitor = new AnnotationMetadataReadingVisitor(classLoader);
    classReader.accept(visitor, ClassReader.SKIP_DEBUG);

    this.annotationMetadata = visitor;
    // (since AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisitor)
    this.classMetadata = visitor;
    this.resource = resource;
}