Java Reference
In-Depth Information
L ISTING 6.2 Continued
cache(cacheName, resBytes);
return getCachedFile(cacheName);
}
// file not found
throw new FileNotFoundException(“File “ + serverFilename +
“ not found neither in cache nor in the server.”);
}
/**
* launch the app via main() method
*/
private boolean mainMethodLaunch(Class mainClass){
boolean launched = true;
try {
Class[] types = { Class.forName(“[Ljava.lang.String;”) };
Method mainMethod = mainClass.getDeclaredMethod(“main”, types);
Object[] p = new Object[0];
mainMethod.invoke(null, p);
System.out.println(“ApplicationHelper- appl. launched invoking:
“+mainMethod);
} catch (Exception ex) {
// ok, no main() method
launched = false;
}
return launched;
}
/**
* launch the app via constructor(s)
*/
private boolean creationLaunch(Class mainClass){
boolean launched = true;
// first, try default constructor
try {
Object ob = mainClass.newInstance();
System.out.println(“ApplicationHelper- appl. launched creating:
“+mainClass+”( )”);
}
catch (Exception ex) {
// it doesn't support the default constructor
// just use the first of its constructors
try {
Constructor cons = mainClass.getConstructors()[0];
int paramNumber = cons.getParameterTypes().length;
Search WWH ::




Custom Search