Example usage for org.springframework.asm ClassReader accept

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

Introduction

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

Prototype

public void accept(final ClassVisitor classVisitor, final int parsingOptions) 

Source Link

Document

Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this ClassReader .

Usage

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

/**
 * @see org.openmrs.logic.rule.provider.RuleProvider#afterStartup()
 *//*from ww  w .j a v  a2  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:org.openmrs.module.amrsreports.rule.MohEvaluableRuleProvider.java

/**
 * @see org.openmrs.logic.rule.provider.RuleProvider#afterStartup()
 *//*ww w  .  j av a  2s. co  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:com.quirklabs.authorise.ProxyAwareLocalVariableTableParameterNameDiscoverer.java

/**
 * Visit the given method and discover its parameter names.
 *//*from  w  ww .  j a va 2  s  .c o m*/
private ParameterNameDiscoveringVisitor visitMethod(Method method) throws IOException {
    ClassReader classReader = getClassReader(method.getDeclaringClass());
    FindMethodParameterNamesClassVisitor classVisitor = new FindMethodParameterNamesClassVisitor(method);
    classReader.accept(classVisitor, 0);
    return classVisitor;
}

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

/**
 * Visit the given constructor and discover its parameter names.
 *//* ww  w .j  av a2 s .c  o m*/
private ParameterNameDiscoveringVisitor visitConstructor(Constructor ctor) throws IOException {
    ClassReader classReader = getClassReader(ctor.getDeclaringClass());
    FindConstructorParameterNamesClassVisitor classVisitor = new FindConstructorParameterNamesClassVisitor(
            ctor);
    classReader.accept(classVisitor, 0);
    return classVisitor;
}

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.
 *//*  w  w  w  . ja  va 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;
}

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;
    try {/*from w w w .  j a v a  2  s  . c  om*/
        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;
}