org.eclipse.osgi.baseadaptor.loader
Class ClasspathManager

java.lang.Object
  extended by org.eclipse.osgi.baseadaptor.loader.ClasspathManager

public class ClasspathManager
extends java.lang.Object

A helper class for BaseClassLoader implementations. This class will keep track of ClasspathEntry objects for the host bundle and any attached fragment bundles. This class takes care of seaching the ClasspathEntry objects for a base class loader implementation. Additional behavior may be added to a classpath manager by configuring ClassLoadingHook and ClassLoadingStatsHook.

Since:
3.2
See Also:
BaseClassLoader, ClassLoadingHook, ClassLoadingStatsHook

Constructor Summary
ClasspathManager(BaseData data, java.lang.String[] classpath, BaseClassLoader classloader)
          Constructs a classpath manager for the given host base data, classpath and base class loader
 
Method Summary
static boolean addClassPathEntry(java.util.ArrayList result, java.lang.String cp, ClasspathManager hostloader, BaseData sourcedata, java.security.ProtectionDomain sourcedomain)
          Adds a ClasspathEntry for the requested classpath to the result.
 void attachFragment(BundleData sourcedata, java.security.ProtectionDomain sourcedomain, java.lang.String[] sourceclasspath)
          Attaches the specified sourcedata, sourcedomain and sourceclasspath to this classpath manager
 void close()
          Closes all the classpath entry resources for this classpath manager.
static void findClassPathEntry(java.util.ArrayList result, java.lang.String cp, ClasspathManager hostloader, BaseData sourcedata, java.security.ProtectionDomain sourcedomain)
          Finds all the ClasspathEntry objects for the requested classpath.
 java.lang.String findLibrary(java.lang.String libname)
           
 java.lang.Class findLocalClass(java.lang.String classname)
          Finds a local class by searching the ClasspathEntry objects of the classpath manager.
 java.util.Enumeration findLocalEntries(java.lang.String path)
          Finds the local entries by searching the ClasspathEntry objects of the classpath manager.
 BundleEntry findLocalEntry(java.lang.String path)
          Finds a local entry by searching the ClasspathEntry objects of the classpath manager.
 java.net.URL findLocalResource(java.lang.String resource)
          Finds a local resource by searching the ClasspathEntry objects of the classpath manager.
 java.util.Enumeration findLocalResources(java.lang.String resource)
          Finds the local resources by searching the ClasspathEntry objects of the classpath manager.
 BaseClassLoader getBaseClassLoader()
          Returns the base class loader used by this classpath manager
 BaseData getBaseData()
          Returns the host base data for this classpath manager
 ClasspathEntry getClasspath(java.lang.String cp, BaseData sourcedata, java.security.ProtectionDomain sourcedomain)
          Creates a new ClasspathEntry object for the requested classpath if the source exists.
 ClasspathEntry getExternalClassPath(java.lang.String cp, BaseData sourcedata, java.security.ProtectionDomain sourcedomain)
          Uses the requested classpath as an absolute path to locate a source for a new ClasspathEntry.
 FragmentClasspath[] getFragmentClasspaths()
          Returns the fragment classpaths of this classpath manager
 ClasspathEntry[] getHostClasspathEntries()
          Returns the host classpath entries for this classpath manager
 void initialize()
          initializes this classpath manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClasspathManager

public ClasspathManager(BaseData data,
                        java.lang.String[] classpath,
                        BaseClassLoader classloader)
Constructs a classpath manager for the given host base data, classpath and base class loader

Parameters:
data - the host base data for this classpath manager
classpath - the host classpath for this classpath manager
classloader - the BaseClassLoader for this classpath manager
Method Detail

initialize

public void initialize()
initializes this classpath manager. This must be called after all existing fragments have been attached and before any resources/classes are loaded using this classpath manager.

After the classpath manager is initialized all configured class loading hooks ClassLoadingHook.initializedClassLoader(BaseClassLoader, BaseData) methods are called.


close

public void close()
Closes all the classpath entry resources for this classpath manager.


attachFragment

public void attachFragment(BundleData sourcedata,
                           java.security.ProtectionDomain sourcedomain,
                           java.lang.String[] sourceclasspath)
Attaches the specified sourcedata, sourcedomain and sourceclasspath to this classpath manager

Parameters:
sourcedata - the source fragment BundleData that should be attached.
sourcedomain - the source fragment domain that should be attached.
sourceclasspath - the source fragment classpath that should be attached.

findClassPathEntry

public static void findClassPathEntry(java.util.ArrayList result,
                                      java.lang.String cp,
                                      ClasspathManager hostloader,
                                      BaseData sourcedata,
                                      java.security.ProtectionDomain sourcedomain)
Finds all the ClasspathEntry objects for the requested classpath. This method will first call all the configured class loading hooks ClassLoadingHook.addClassPathEntry(ArrayList, String, ClasspathManager, BaseData, ProtectionDomain) methods. This allows class loading hooks to add additional ClasspathEntry objects to the result for the requested classpath. Then the local host classpath entries and attached fragment classpath entries are searched.

Parameters:
result - a list of ClasspathEntry objects. This list is used to add new ClasspathEntry objects to.
cp - the requested classpath.
hostloader - the host classpath manager for the classpath
sourcedata - the source EquionoxData to search for the classpath
sourcedomain - the source domain to used by the new ClasspathEntry

addClassPathEntry

public static boolean addClassPathEntry(java.util.ArrayList result,
                                        java.lang.String cp,
                                        ClasspathManager hostloader,
                                        BaseData sourcedata,
                                        java.security.ProtectionDomain sourcedomain)
Adds a ClasspathEntry for the requested classpath to the result. The local host classpath entries are searched first and then attached fragments classpath entries are searched. The search stops once the first classpath entry is found.

Parameters:
result - a list of ClasspathEntry objects. This list is used to add new ClasspathEntry objects to.
cp - the requested classpath.
hostloader - the host classpath manager for the classpath
sourcedata - the source EquionoxData to search for the classpath
sourcedomain - the source domain to used by the new ClasspathEntry
Returns:
true if a ClasspathEntry was added to the result

getClasspath

public ClasspathEntry getClasspath(java.lang.String cp,
                                   BaseData sourcedata,
                                   java.security.ProtectionDomain sourcedomain)
Creates a new ClasspathEntry object for the requested classpath if the source exists.

Parameters:
cp - the requested classpath.
sourcedata - the source EquionoxData to search for the classpath
sourcedomain - the source domain to used by the new ClasspathEntry
Returns:
a new ClasspathEntry for the requested classpath or null if the source does not exist.

getExternalClassPath

public ClasspathEntry getExternalClassPath(java.lang.String cp,
                                           BaseData sourcedata,
                                           java.security.ProtectionDomain sourcedomain)
Uses the requested classpath as an absolute path to locate a source for a new ClasspathEntry.

Parameters:
cp - the requested classpath
sourcedata - the source EquionoxData to search for the classpath
sourcedomain - the source domain to used by the new ClasspathEntry
Returns:
a classpath entry which uses an absolut path as a source

findLocalResource

public java.net.URL findLocalResource(java.lang.String resource)
Finds a local resource by searching the ClasspathEntry objects of the classpath manager. This method will first call all the configured class loading stats hooks ClassLoadingStatsHook.preFindLocalResource(String, ClasspathManager) methods. Then it will search for the resource. Finally it will call all the configured class loading stats hooks ClassLoadingStatsHook.postFindLocalResource(String, URL, ClasspathManager) methods.

Parameters:
resource - the requested resource name.
Returns:
the requested resource URL or null if the resource does not exist

findLocalResources

public java.util.Enumeration findLocalResources(java.lang.String resource)
Finds the local resources by searching the ClasspathEntry objects of the classpath manager.

Parameters:
resource - the requested resource name.
Returns:
an enumeration of the the requested resources or null if the resources do not exist

findLocalEntry

public BundleEntry findLocalEntry(java.lang.String path)
Finds a local entry by searching the ClasspathEntry objects of the classpath manager.

Parameters:
path - the requested entry path.
Returns:
the requested entry or null if the entry does not exist

findLocalEntries

public java.util.Enumeration findLocalEntries(java.lang.String path)
Finds the local entries by searching the ClasspathEntry objects of the classpath manager.

Parameters:
path - the requested entry path.
Returns:
an enumeration of the the requested entries or null if the entries do not exist

findLocalClass

public java.lang.Class findLocalClass(java.lang.String classname)
                               throws java.lang.ClassNotFoundException
Finds a local class by searching the ClasspathEntry objects of the classpath manager. This method will first call all the configured class loading stats hooks ClassLoadingStatsHook.preFindLocalClass(String, ClasspathManager) methods. Then it will search for the class. If a class is found then all configured class loading hooks ClassLoadingHook.processClass(String, byte[], ClasspathEntry, BundleEntry, ClasspathManager) methods will be called. The class is then defined; if successfully then all configured class loading stats hooks ClassLoadingStatsHook.recordClassDefine(String, Class, byte[], ClasspathEntry, BundleEntry, ClasspathManager) methods are called. Finally all the configured class loading stats hooks ClassLoadingStatsHook.postFindLocalClass(String, Class, ClasspathManager) methods are called.

Parameters:
classname - the requested class name.
Returns:
the requested class
Throws:
java.lang.ClassNotFoundException - if the class does not exist

getBaseData

public BaseData getBaseData()
Returns the host base data for this classpath manager

Returns:
the host base data for this classpath manager

getFragmentClasspaths

public FragmentClasspath[] getFragmentClasspaths()
Returns the fragment classpaths of this classpath manager

Returns:
the fragment classpaths of this classpath manager

getHostClasspathEntries

public ClasspathEntry[] getHostClasspathEntries()
Returns the host classpath entries for this classpath manager

Returns:
the host classpath entries for this classpath manager

getBaseClassLoader

public BaseClassLoader getBaseClassLoader()
Returns the base class loader used by this classpath manager

Returns:
the base class loader used by this classpath manager

findLibrary

public java.lang.String findLibrary(java.lang.String libname)