org.mule.module.launcher.application
Class CompositeApplicationClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by org.mule.module.launcher.application.CompositeApplicationClassLoader
All Implemented Interfaces:
Closeable, ApplicationClassLoader, ArtifactClassLoader

public class CompositeApplicationClassLoader
extends ClassLoader
implements ApplicationClassLoader, Closeable

Defines a classloader that delegates classes and resources resolution to a list of classloaders.


Field Summary
protected static Log logger
           
 
Constructor Summary
CompositeApplicationClassLoader(String appName, List<ClassLoader> classLoaders)
           
 
Method Summary
 void close()
           
 void dispose()
          Gets rid of the class loader resources.
protected  String findLibrary(String libname)
           
protected  String findLibrary(String libname, ClassLoader classLoader)
           
 URL findResource(String name)
           
 String getAppName()
           
 String getArtifactName()
           
 ClassLoader getClassLoader()
          ClassLoader is an abstract class.
 URL getResource(String name)
           
 InputStream getResourceAsStream(String name)
           
 Enumeration<URL> getResources(String name)
           
protected  Class<?> loadClass(ClassLoader classLoader, String name, boolean resolve)
           
 Class<?> loadClass(String name)
           
protected  Class<?> loadClass(String name, boolean resolve)
           
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLoadedClass, findResources, findSystemClass, getPackage, getPackages, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final Log logger
Constructor Detail

CompositeApplicationClassLoader

public CompositeApplicationClassLoader(String appName,
                                       List<ClassLoader> classLoaders)
Method Detail

getAppName

public String getAppName()
Specified by:
getAppName in interface ApplicationClassLoader

loadClass

public Class<?> loadClass(String name)
                   throws ClassNotFoundException
Overrides:
loadClass in class ClassLoader
Throws:
ClassNotFoundException

loadClass

protected Class<?> loadClass(String name,
                             boolean resolve)
                      throws ClassNotFoundException
Overrides:
loadClass in class ClassLoader
Throws:
ClassNotFoundException

loadClass

protected Class<?> loadClass(ClassLoader classLoader,
                             String name,
                             boolean resolve)
                      throws ClassNotFoundException
Throws:
ClassNotFoundException

getResource

public URL getResource(String name)
Overrides:
getResource in class ClassLoader

getResourceAsStream

public InputStream getResourceAsStream(String name)
Overrides:
getResourceAsStream in class ClassLoader

findLibrary

protected String findLibrary(String libname)
Overrides:
findLibrary in class ClassLoader

findLibrary

protected String findLibrary(String libname,
                             ClassLoader classLoader)

getResources

public Enumeration<URL> getResources(String name)
                              throws IOException
Overrides:
getResources in class ClassLoader
Throws:
IOException

getArtifactName

public String getArtifactName()
Specified by:
getArtifactName in interface ArtifactClassLoader
Returns:
the artifact unique identifier

findResource

public URL findResource(String name)
Specified by:
findResource in interface ApplicationClassLoader
Specified by:
findResource in interface ArtifactClassLoader
Overrides:
findResource in class ClassLoader
Parameters:
name - name of the resource to find.
Returns:
the resource URL, null if it doesn't exists.

getClassLoader

public ClassLoader getClassLoader()
Description copied from interface: ArtifactClassLoader
ClassLoader is an abstract class. Not an interface. There are parts of the code that requires a ClassLoader and others that requires an ArtifactClassLoader. Ideally I would make ArtifactClassLoader implement ClassLoader interface but there's no such interface. So if I have a method that requires a ClassLoader instance and an ArtifactClassLoader I would have to down cast and assume that it can be down casted or send two parameters, one for the ClassLoader and one for the ArtifactClassLoader: public void doSomething(ArtifactClassLoader acl) { doSomething2(acl); //this requires an ArtifactClassLoader doSomething3((ClassLoader)acl); //this requires a ClassLoader } public void doSomething(ArtifactClassLoader acl, ClassLoader cl) { doSomething2(acl); //this requires an ArtifactClassLoader doSomething3(cl); //this requires a ClassLoader } To overcome that problem seems much better to have a method in ArtifactClassLoader that can actually return a ClassLoader instance: public void doSomething(ArtifactClassLoader acl) { doSomething2(acl); //this requires an ArtifactClassLoader doSomething3(acl.getDomainClassLoader()); //this requires a ClassLoader }

Specified by:
getClassLoader in interface ArtifactClassLoader
Returns:
class loader to use for this artifact.

dispose

public void dispose()
Description copied from interface: ArtifactClassLoader
Gets rid of the class loader resources.

Specified by:
dispose in interface ArtifactClassLoader

close

public void close()
Specified by:
close in interface Closeable


Copyright © 2003-2014 MuleSoft, Inc.. All Rights Reserved.