org.ow2.petals.system.classloader
Class PetalsClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by org.ow2.petals.system.classloader.PetalsClassLoader
Direct Known Subclasses:
ComponentClassLoader, SharedLibraryClassLoader

public class PetalsClassLoader
extends java.net.URLClassLoader

Petals class loader Do not implement loadClass(String) it causes a conflict with the SharedLibrariesClassLoader

Since:
Petals 1.0
Version:
$Rev: 27860 $ $Date: 2009-08-03 10:08:35 +0200 (lun., 03 août 2009) $
Author:
alouis, ddesjardins, Rafael Marins, Olivier Fabre

Constructor Summary
PetalsClassLoader(java.net.URL[] baseUrls, java.util.List<java.lang.String> classpathLocations)
          Create a class loader for petals
PetalsClassLoader(java.net.URL[] baseUrls, java.util.List<java.lang.String> classpathLocations, java.lang.ClassLoader parent)
          Create a class loader for petals
PetalsClassLoader(java.net.URL[] baseUrls, java.util.List<java.lang.String> classpathLocations, java.lang.ClassLoader parent, java.net.URLStreamHandlerFactory factory)
          Create a class loader for petals
 
Method Summary
protected  void addInRepository(java.lang.String location)
          Add specified location into the repository.
protected  void addLocalKnownPackage(java.lang.String packageName)
          Add a package name to the known package
 void close()
          Trick to close descriptor in Jars for Sun classloader.
 java.net.URL[] getBases()
           
 java.lang.String getClasspath()
           
protected  java.lang.String getPackageName(java.lang.String className)
          Return the package name of a class
 java.net.URL getResource(java.lang.String resourceName)
          Return a URL of the resource
 java.io.InputStream getResourceAsStream(java.lang.String resourceName)
          Get a stream from a resource in the classpath
 java.util.Enumeration<java.net.URL> getResources(java.lang.String resourceName)
          Return a enumeration of resources
protected  java.io.InputStream getStream(java.net.URL url)
          Return an input stream from a url
 boolean isParentFirst()
           
 boolean isUsingPackageIntelligence()
           
protected  boolean knowLocalPackage(java.lang.String packageName)
          Check if a package is in the known package list
protected  java.lang.Class<?> loadClass(java.lang.String className, boolean resolve)
          Load a class Use the parent classloader if parentFirst is set to true else use its own url classloader to load the class
 void setParentFirst(boolean use)
           
 void setUsingPackageIntelligence(boolean use)
           
 java.lang.String toString()
           
protected  boolean useParentFirst(java.lang.String resourceName, boolean usingForClass)
          Method to know if we choose to use the parent class loader first
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, findResource, findResources, getPermissions, getURLs, newInstance, newInstance
 
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, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PetalsClassLoader

public PetalsClassLoader(java.net.URL[] baseUrls,
                         java.util.List<java.lang.String> classpathLocations)
                  throws java.io.IOException
Create a class loader for petals

Parameters:
baseUrls - installation root path in petals
classpathLocations - jar defined in the classpath part of the jbi descriptor
Throws:
java.io.IOException

PetalsClassLoader

public PetalsClassLoader(java.net.URL[] baseUrls,
                         java.util.List<java.lang.String> classpathLocations,
                         java.lang.ClassLoader parent)
                  throws java.io.IOException
Create a class loader for petals

Parameters:
baseUrls - installation root path in petals
classpathLocations - jar defined in the classpath part of the jbi descriptor
parent -
Throws:
java.io.IOException

PetalsClassLoader

public PetalsClassLoader(java.net.URL[] baseUrls,
                         java.util.List<java.lang.String> classpathLocations,
                         java.lang.ClassLoader parent,
                         java.net.URLStreamHandlerFactory factory)
                  throws java.io.IOException
Create a class loader for petals

Parameters:
baseUrls - installation root path in petals
classpathLocations - jar defined in the classpath part of the jbi descriptor
parent - parent class loader
factory - url factory
Throws:
java.io.IOException
Method Detail

close

public void close()
Trick to close descriptor in Jars for Sun classloader.


getBases

public java.net.URL[] getBases()
Returns:
Returns the bases.

getClasspath

public java.lang.String getClasspath()
Returns:
Returns a String representation of the classpath used by this classloader

getResource

public java.net.URL getResource(java.lang.String resourceName)
Return a URL of the resource

Overrides:
getResource in class java.lang.ClassLoader
Parameters:
resourceName -
Returns:
url of the resource (null if the resource is not found)

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String resourceName)
Get a stream from a resource in the classpath

Overrides:
getResourceAsStream in class java.lang.ClassLoader
Parameters:
resourceName - name of the resource
Returns:
stream of the resource (null if the resource is not found)

getResources

public java.util.Enumeration<java.net.URL> getResources(java.lang.String resourceName)
                                                 throws java.io.IOException
Return a enumeration of resources

Overrides:
getResources in class java.lang.ClassLoader
Throws:
java.io.IOException
See Also:
ClassLoader.getResources(java.lang.String)

isParentFirst

public boolean isParentFirst()
Returns:
Returns the useParentFirst.

isUsingPackageIntelligence

public boolean isUsingPackageIntelligence()
Returns:
Returns the usePackageIntelligence.

setParentFirst

public void setParentFirst(boolean use)
Parameters:
use - The useParentFirst to set.

setUsingPackageIntelligence

public void setUsingPackageIntelligence(boolean use)
Parameters:
use - The usePackageIntelligence to set.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
Returns a String representation of the PetalsClassLoader

addInRepository

protected final void addInRepository(java.lang.String location)
                              throws java.io.IOException
Add specified location into the repository. If location is found in multiple URLs of the bases, new URLs will be added multiple times.

Parameters:
location - an entry name (for a jar) or a path name (for a directory)
Throws:
java.io.IOException - when constructed URL is malformed

addLocalKnownPackage

protected void addLocalKnownPackage(java.lang.String packageName)
Add a package name to the known package

Parameters:
packageName - package name

getPackageName

protected java.lang.String getPackageName(java.lang.String className)
Return the package name of a class

Parameters:
className - complete name of a class
Returns:
package name

getStream

protected java.io.InputStream getStream(java.net.URL url)
Return an input stream from a url

Parameters:
url -
Returns:

knowLocalPackage

protected boolean knowLocalPackage(java.lang.String packageName)
Check if a package is in the known package list

Parameters:
packageName - package name
Returns:
true if the package is already known

loadClass

protected java.lang.Class<?> loadClass(java.lang.String className,
                                       boolean resolve)
                                throws java.lang.ClassNotFoundException
Load a class Use the parent classloader if parentFirst is set to true else use its own url classloader to load the class

Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
className - name of the class to load
resolve - boolean to resolve or not the class
Throws:
java.lang.ClassNotFoundException

useParentFirst

protected boolean useParentFirst(java.lang.String resourceName,
                                 boolean usingForClass)
Method to know if we choose to use the parent class loader first

Parameters:
resourceName - resource name
usingForClass - resource as a class
Returns:
boolean


Copyright © 2005-2011 Petals Link (EBM Websourcing). All Rights Reserved.