FileDocCategorySizeDatePackage
JarScanner.javaAPI DocGlassfish v2 API4337Fri May 04 22:30:22 BST 2007com.sun.enterprise.deployment.annotation.impl

JarScanner

public class JarScanner extends JavaEEScanner implements com.sun.enterprise.deployment.annotation.Scanner
Implements the scanner interface on a jar file.
author
Jerome Dochez

Fields Summary
File
jarFile
Set
entries
ClassLoader
classLoader
Constructors Summary
public JarScanner(File jarFile)
Creates a new instance of JarScanner

    
           
         
        this.jarFile = jarFile;
        init();
    
Methods Summary
public java.lang.ClassLoadergetClassLoader()

        if (classLoader==null) {
            URL[] urls = new URL[1];
            try {
                urls[0] = jarFile.getAbsoluteFile().toURL();
                classLoader = new URLClassLoader(urls);
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
        return classLoader;
    
public java.util.SetgetElements()

        
        
        Set<Class> elements = new HashSet<Class>();
        if (getClassLoader()==null) {
            AnnotationUtils.getLogger().severe("Class loader null");
            return elements;
        }        
        for (JarEntry je : entries) {
            String fileName = je.getName();
            // convert to a class name...
            String className = fileName.replace(File.separatorChar, '.");
            className = className.substring(0, className.length()-6);
            try {                
                elements.add(classLoader.loadClass(className));
                
            } catch(ClassNotFoundException cnfe) {
                cnfe.printStackTrace();
            }
        }
        return elements;
    
private voidinit()

        JarFile jf = new JarFile(jarFile);
        
        Enumeration<JarEntry> entriesEnum = jf.entries();
        while(entriesEnum.hasMoreElements()) {
            JarEntry je = entriesEnum.nextElement();
            if (je.getName().endsWith(".class")) {
                entries.add(je);
            }
        }