FileDocCategorySizeDatePackage
ModuleScanner.javaAPI DocGlassfish v2 API7037Fri May 04 22:31:34 BST 2007com.sun.enterprise.deployment.annotation.impl

ModuleScanner

public abstract class ModuleScanner extends com.sun.enterprise.deployment.annotation.impl.JavaEEScanner implements com.sun.enterprise.deployment.annotation.Scanner
This is an abstract class of the Scanner interface for J2EE module.
author
Shing Wai Chan

Fields Summary
protected File
archiveFile
protected ClassLoader
classLoader
protected com.sun.enterprise.deployment.annotation.introspection.ClassFile
classFile
private boolean
processAllClasses
private Set
entries
Constructors Summary
Methods Summary
private voidaddEntry(java.util.jar.JarEntry je)

        String className = je.getName().replace('/", '.");
        className = className.substring(0, className.length()-6);
        entries.add(className);                                
    
private voidaddEntry(java.io.File top, java.io.File f)

        String fileName = f.getPath();
        fileName = fileName.substring(top.getPath().length()+1);
        String className = fileName.replace(File.separatorChar, '.");
        className = className.substring(0, className.length()-6);
        entries.add(className);        
    
protected voidaddScanClassName(java.lang.String className)
This add extra className to be scanned.

param
className


                  
        
        if (className!=null && className.length()!=0)
            entries.add(className);
    
protected voidaddScanDirectory(java.io.File directory)
This will include all class in directory to be scanned. param directory

        initScanDirectory(directory, directory);
    
protected voidaddScanJar(java.io.File jarFile)
This add all classes in given jarFile to be scanned.

param
jarFile

        JarFile jf = new JarFile(jarFile);
        

        Enumeration<JarEntry> entriesEnum = jf.entries();
        while(entriesEnum.hasMoreElements()) {
            JarEntry je = entriesEnum.nextElement();
            if (je.getName().endsWith(".class")) {
                if (processAllClasses) {
                    addEntry(je);
                } else {
                    // check if it contains top level annotations...
                    ReadableByteChannel channel = Channels.newChannel(jf.getInputStream(je));
                    if (channel!=null) {
                        if (classFile.containsAnnotation(channel, je.getSize())) {
                            addEntry(je);                     
                        }
                    }
                }
            }
        }
    
public java.lang.ClassLoadergetClassLoader()

        return classLoader;
    
public java.util.SetgetElements()

        Set<Class> elements = new HashSet<Class>();
        if (getClassLoader() == null) {
            AnnotationUtils.getLogger().severe("Class loader null");
            return elements;
        }        

        for (String className : entries) {
            if (AnnotationUtils.getLogger().isLoggable(Level.FINE)) {
                AnnotationUtils.getLogger().fine("Getting " + className);
            }
            try {                
                elements.add(classLoader.loadClass(className));
            } catch(ClassNotFoundException cnfe) {
                AnnotationUtils.getLogger().log(Level.WARNING, "Cannot load " + className + " reason : " + cnfe.getMessage(), cnfe);
            }
        }
        return elements;
    
private voidinitScanDirectory(java.io.File top, java.io.File directory)

   
        File[] files = directory.listFiles();
        for (File file : files) {
            if (file.isFile()) {
                String fileName = file.getPath();
                if (fileName.endsWith(".class")) {
                    if (processAllClasses) {
                        addEntry(top, file);
                    } else {
                        FileInputStream fis = null;
                        try {
                            fis = new FileInputStream(file);
                            if (classFile.containsAnnotation(fis.getChannel(), file.length())) {
                                addEntry(top, file);
                            }
                        } finally {
                            if (fis != null) {
                                fis.close();
                            }
                        }
                    }
                }
            } else {
                initScanDirectory(top, file);
            }
        }