org.apache.commons.vfs2.impl
Class VFSClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by org.apache.commons.vfs2.impl.VFSClassLoader

public class VFSClassLoader
extends SecureClassLoader

A class loader that can load classes and resources from a search path VFS FileObjects refering both to folders and JAR files. Any FileObject of type FileType.FILE is asumed to be a JAR and is opened by creating a layered file system with the "jar" scheme. TODO - Test this with signed Jars and a SecurityManager.

Author:
Commons VFS team
See Also:
FileSystemManager.createFileSystem(java.lang.String, org.apache.commons.vfs2.FileObject)

Constructor Summary
VFSClassLoader(FileObject[] files, FileSystemManager manager)
          Constructors a new VFSClassLoader for the given files.
VFSClassLoader(FileObject[] files, FileSystemManager manager, ClassLoader parent)
          Constructors a new VFSClassLoader for the given FileObjects.
VFSClassLoader(FileObject file, FileSystemManager manager)
          Constructors a new VFSClassLoader for the given file.
VFSClassLoader(FileObject file, FileSystemManager manager, ClassLoader parent)
          Constructors a new VFSClassLoader for the given file.
 
Method Summary
protected  void copyPermissions(PermissionCollection src, PermissionCollection dest)
          Copies the permissions from src to dest.
protected  Class<?> findClass(String name)
          Finds and loads the class with the specified name from the search path.
protected  URL findResource(String name)
          Finds the resource with the specified name from the search path.
protected  Enumeration<URL> findResources(String name)
          Returns an Enumeration of all the resources in the search path with the specified name.
 FileObject[] getFileObjects()
          Provide access to the file objects this class loader represents.
protected  PermissionCollection getPermissions(CodeSource cs)
          Calls super.getPermissions both for the code source and also adds the permissions granted to the parent layers.
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VFSClassLoader

public VFSClassLoader(FileObject file,
                      FileSystemManager manager)
               throws FileSystemException
Constructors a new VFSClassLoader for the given file.

Parameters:
file - the file to load the classes and resources from.
manager - the FileManager to use when trying create a layered Jar file system.
Throws:
FileSystemException - if an error occurs.

VFSClassLoader

public VFSClassLoader(FileObject file,
                      FileSystemManager manager,
                      ClassLoader parent)
               throws FileSystemException
Constructors a new VFSClassLoader for the given file.

Parameters:
file - the file to load the classes and resources from.
manager - the FileManager to use when trying create a layered Jar file system.
parent - the parent class loader for delegation.
Throws:
FileSystemException - if an error occurs.

VFSClassLoader

public VFSClassLoader(FileObject[] files,
                      FileSystemManager manager)
               throws FileSystemException
Constructors a new VFSClassLoader for the given files. The files will be searched in the order specified.

Parameters:
files - the files to load the classes and resources from.
manager - the FileManager to use when trying create a layered Jar file system.
Throws:
FileSystemException - if an error occurs.

VFSClassLoader

public VFSClassLoader(FileObject[] files,
                      FileSystemManager manager,
                      ClassLoader parent)
               throws FileSystemException
Constructors a new VFSClassLoader for the given FileObjects. The FileObjects will be searched in the order specified.

Parameters:
files - the FileObjects to load the classes and resources from.
manager - the FileManager to use when trying create a layered Jar file system.
parent - the parent class loader for delegation.
Throws:
FileSystemException - if an error occurs.
Method Detail

getFileObjects

public FileObject[] getFileObjects()
Provide access to the file objects this class loader represents.

Returns:
An array of FileObjects.
Since:
2.0

findClass

protected Class<?> findClass(String name)
                      throws ClassNotFoundException
Finds and loads the class with the specified name from the search path.

Overrides:
findClass in class ClassLoader
Throws:
ClassNotFoundException - if the class is not found.

getPermissions

protected PermissionCollection getPermissions(CodeSource cs)
Calls super.getPermissions both for the code source and also adds the permissions granted to the parent layers.

Overrides:
getPermissions in class SecureClassLoader
Parameters:
cs - the CodeSource.
Returns:
The PermissionCollections.

copyPermissions

protected void copyPermissions(PermissionCollection src,
                               PermissionCollection dest)
Copies the permissions from src to dest.

Parameters:
src - The source PermissionCollection.
dest - The destination PermissionCollection.

findResource

protected URL findResource(String name)
Finds the resource with the specified name from the search path. This returns null if the resource is not found.

Overrides:
findResource in class ClassLoader
Parameters:
name - The resource name.
Returns:
The URL that matches the resource.

findResources

protected Enumeration<URL> findResources(String name)
Returns an Enumeration of all the resources in the search path with the specified name. TODO - Implement this.

Overrides:
findResources in class ClassLoader
Parameters:
name - The resources to find.
Returns:
An Enumeration of the resources associated with the name.


Copyright © 2002-2012 The Apache Software Foundation. All Rights Reserved.