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

DirectoryScanner

public class DirectoryScanner extends JavaEEScanner implements com.sun.enterprise.deployment.annotation.Scanner
Implementation of the Scanner interface for a directory
author
Jerome Dochez

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

    
           
         
        this(directory, null);
    
public DirectoryScanner(File directory, ClassLoader classLoader)

        AnnotationUtils.getLogger().finer("dir is " + directory);
        AnnotationUtils.getLogger().finer("classLoader is " + classLoader);
        this.directory = directory;
        this.classLoader = classLoader;
        init(directory);
    
Methods Summary
public java.lang.ClassLoadergetClassLoader()

        if (classLoader==null) {
            URL[] urls = new URL[1];
            try {
                urls[0] = directory.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 (String fileName : entries) {
            // convert to a class name...
            String className = fileName.replace(File.separatorChar, '.");
            className = className.substring(0, className.length()-6);
            System.out.println("Getting " + className);
            try {                
                elements.add(classLoader.loadClass(className));
                
            } catch(Throwable cnfe) {
                AnnotationUtils.getLogger().severe("cannot load " + className + " reason : " + cnfe.getMessage());
            }
        }
        return elements;
    
protected java.util.SetgetEntries()

        return entries;
    
private voidinit(java.io.File directory)

        init(directory, directory);
    
private voidinit(java.io.File top, java.io.File directory)

        
        File[] dirFiles = directory.listFiles(new FileFilter() {
                public boolean accept(File pathname) {
                    return pathname.getAbsolutePath().endsWith(".class");
                }
        });
        for (File file : dirFiles) {
            entries.add(file.getPath().substring(top.getPath().length()+1));
        }
        
        File[] subDirs = directory.listFiles(new FileFilter() {
                public boolean accept(File pathname) {
                    return pathname.isDirectory();
                }
        });
        for (File subDir : subDirs) {
            init(top, subDir);
        }