org.quartz.simpl
public class: CascadingClassLoadHelper [javadoc |
source]
java.lang.Object
org.quartz.simpl.CascadingClassLoadHelper
All Implemented Interfaces:
ClassLoadHelper
A
ClassLoadHelper uses all of the
ClassLoadHelper
types that are found in this package in its attempts to load a class, when
one scheme is found to work, it is promoted to the scheme that will be used
first the next time a class is loaded (in order to improve perfomance).
This approach is used because of the wide variance in class loader behavior
between the various environments in which Quartz runs (e.g. disparate
application servers, stand-alone, mobile devices, etc.). Because of this
disparity, Quartz ran into difficulty with a one class-load style fits-all
design. Thus, this class loader finds the approach that works, then
'remembers' it.
| Method from org.quartz.simpl.CascadingClassLoadHelper Detail: |
public URL getResource(String name) {
if (bestCandidate != null) {
try {
return bestCandidate.getResource(name);
} catch (Exception e) {
bestCandidate = null;
}
}
URL result = null;
ClassLoadHelper loadHelper = null;
Iterator iter = loadHelpers.iterator();
while (iter.hasNext()) {
loadHelper = (ClassLoadHelper) iter.next();
result = loadHelper.getResource(name);
if (result != null) {
break;
}
}
bestCandidate = loadHelper;
return result;
}
Finds a resource with a given name. This method returns null if no
resource with this name is found. |
public InputStream getResourceAsStream(String name) {
if (bestCandidate != null) {
try {
return bestCandidate.getResourceAsStream(name);
} catch (Exception e) {
bestCandidate = null;
}
}
InputStream result = null;
ClassLoadHelper loadHelper = null;
Iterator iter = loadHelpers.iterator();
while (iter.hasNext()) {
loadHelper = (ClassLoadHelper) iter.next();
result = loadHelper.getResourceAsStream(name);
if (result != null) {
break;
}
}
bestCandidate = loadHelper;
return result;
}
Finds a resource with a given name. This method returns null if no
resource with this name is found. |
public void initialize() {
loadHelpers = new LinkedList();
loadHelpers.add(new LoadingLoaderClassLoadHelper());
loadHelpers.add(new SimpleClassLoadHelper());
loadHelpers.add(new ThreadContextClassLoadHelper());
loadHelpers.add(new InitThreadContextClassLoadHelper());
Iterator iter = loadHelpers.iterator();
while (iter.hasNext()) {
ClassLoadHelper loadHelper = (ClassLoadHelper) iter.next();
loadHelper.initialize();
}
}
Called to give the ClassLoadHelper a chance to initialize itself,
including the oportunity to "steal" the class loader off of the calling
thread, which is the thread that is initializing Quartz. |
public Class loadClass(String name) throws ClassNotFoundException {
if (bestCandidate != null) {
try {
return bestCandidate.loadClass(name);
} catch (Exception e) {
bestCandidate = null;
}
}
ClassNotFoundException cnfe = null;
Class clazz = null;
ClassLoadHelper loadHelper = null;
Iterator iter = loadHelpers.iterator();
while (iter.hasNext()) {
loadHelper = (ClassLoadHelper) iter.next();
try {
clazz = loadHelper.loadClass(name);
break;
} catch (ClassNotFoundException e) {
cnfe = e;
}
}
if (clazz == null) {
throw cnfe;
}
bestCandidate = loadHelper;
return clazz;
}
Return the class with the given name. |