Java Reference
In-Depth Information
L ISTING 6.3 Continued
* Chapter 6 - The Custom Classloader
*
* @author Mauro Marinilli
* @version 1.0
*/
public class BankClientLoader extends ClassLoader {
private ApplicationHelper helper;
/**
* Constructor
*/
public BankClientLoader(ApplicationHelper h) {
helper = h;
}
/**
* Gets a resource from the currently available resources
* the order is the following: <br>
* - cached files <br>
* - super.classloader's resources <br>
* - server resources <br>
*/
public URL getResource(String name) {
URL resource = null;
try {
if (helper.isCached(name))
return helper.getCachedFile(name).toURL();
resource = super.getResource(name);
// check the obtained resource
try {
System.out.println(“BCL- resource=”+resource.getContent());
resource.getContent();
} catch (Exception e) {
// the url is empty or null
System.out.println(“BankClientLoader- getResource( “+name+” ) EMPTY:
“+e);
resource = helper.getRemoteFile(name, false).toURL();
}
} catch (IOException e) {
System.out.println(“BankClientLoader- getResource( “+name+” ): “+e);
}
return resource;
}
Search WWH ::




Custom Search