> From: Berin Loritsch [mailto:[EMAIL PROTECTED] 
>
> > Idea:
> > How about this. We include in the MANIFEST.mf a list of all 
> classes in 
> > the JAR. That's it. Just one big list. That is the only packaging 
> > requirement.
> > 
> > Then we solve everything else at runtime.
> > 
> > Then we can load classes and index them and so on as 
> needed, but the 
> > packaging requirements are fixed and dead simple.
> 
> 
> Excellent.  Now the official JAR packaging takes advantage of 
> an "index" service to help a classloader know what is in the JAR.  
> I think the JAR utility can automatically create this "index" file--so

> all we have to do is specify that Avalon JARs need to use the indexing

> feature.
> 
> Bam.  Simple solution, minimal coding.

Sadly, the indexing feature only include the package names in a JAR.

What you have to do is this:

 1. Get the classloader.
 2. Get the URLs it uses (if it is a URL class loader, otherwise you're
out of luck).
 3. Open a JarURLConnection.
 4. Call JarURLConnection.getJarFile() to get a JarFile
 5. Call JarFile.entries() to get a list of everythign in the Jar file.
 6. Iterate over the entries, and for each .class file, load the
corresponding class.
 7. Check the attributes of the class and index it as needed.

So the API would be:

  public Collection getClasses (URLClassLoader cl);

  public Collection getClassesWithAttributeType (Collection allClasses,
Class attributeType);

*No* packaging requirements.

I can include that in the Proof-of-concept.

It doesn't work very well for classes loaded over http from a directory,
or
from a database, but as long as the classes are in JARs, we're fine.

Maybe one should provide a pluggable way of scanning for classes:

public interface ClassLoaderScanner {
    // What type of classloader can you scan?
    public Class getClassLoaderType ();

    // OK, scan this one, then.
    public Collection scan (ClassLoader cl);
}

public class URLClassLoaderScanner implements ClassLoaderScanner {
    public Class getClassLoaderType () {
        return URLClassLoader.class;
    }

    public Collection scan (ClassLoader cl) {
        ...
    }
}


public class ClassLoaderUtils {
    public static void addClassLoaderScanner (ClassLoaderScanner cls);

    public static Collection getClasses (ClassLoader cl);
}

/LS


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to