org.PingOO.DLAI.lib.util
Class DLAILoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--java.security.SecureClassLoader
              |
              +--java.net.URLClassLoader
                    |
                    +--org.PingOO.DLAI.lib.util.DLAILoader

public final class DLAILoader
extends java.net.URLClassLoader

Loader for the DLAI package.
While all was working perfectly under LINUX with code in PPM's own Request class (see save archive before 08/30/1999), some problems appears while testing the auto-update under Windows.
It seemed that the File.renameTo() and File.delete() methods did not worked under Windows for unknow reasons.
I once thought the problem occured while using DLAI.jar as part of the main CLASSPATH and decide to use an external loader and reflection process instead of letting Request do the update job by herself.

Problem was that, after modification and successfull tests under LINUX, the File.renameTo() and File.delete() still did not worked.
After various tries I came with the idea of doing basic byte-data transfert which seems to work under Windows and LINUX.

Futhermore using an external loader allows the user to still try to launch the appli event if DLAI.jar is damaged (note need to work on pseudo-fixing DLAI.jar with DLAI.tmp or DLAI.old).
We can event imagine trying to get a valid DLAI.jar from a web server on the local network.
The only downside is that at the launch time we do not have access to PWidget so we only have localized capabilities here, message will use standard JOptionPane with text in both english and french.
I also tryed to concentrate the code in only one class.

Note : after tests under Windows the code used to delete DLAI.tmp seems to work.
Jeff hypotesized this is a problem with the default SecurityManager which does not allow to deltes some files under Windows, I thisk he's right but I do not have enough remaining time to check this.

Since:
PingOO 2.0
Version:
2.0
Author:
Fabrice Bouyé (bouye@cur-archamps.fr)

Inner classes inherited from class java.lang.ClassLoader
java.lang.ClassLoader.NativeLibrary
 
Field Summary
static java.lang.String BACKUP_FILE
          The backup file.
private static int BUFFER_SIZE
          The default buffer size.
private static java.lang.String CLASS_TO_START
          The class to start.
static java.lang.String JAR_FILE
          The archive file.
private static DLAILoader loader
           
static java.lang.String UPDATED_FILE
          The tmp file created after an update.
private  java.net.URL url
          The url of the Jar file to load.
 
Fields inherited from class java.net.URLClassLoader
acc, ucp
 
Fields inherited from class java.security.SecureClassLoader
debug, pdcache
 
Fields inherited from class java.lang.ClassLoader
bootstrapClassPath, classes, defaultDomain, defaultPermissions, getClassLoaderPerm, initialized, loadedLibraryNames, nativeLibraries, nativeLibraryContext, packages, parent, scl, sclSet, sys_paths, systemNativeLibraries, usr_paths
 
Constructor Summary
private DLAILoader(java.net.URL url)
          Creates a new instance of the loader.
 
Method Summary
static DLAILoader getInstance()
          Return an instance of this loader.
 java.lang.String getMainClassName()
          Returns the name of the jar file main class, or null if no "Main-Class" manifest attributes was defined.
 void invokeClass(java.lang.String name, java.lang.String[] args)
          Invokes the application in this jar file given the name of the main class and an array of arguments.
static void main(java.lang.String[] args)
          Main method.
static void update(java.io.File destinationFile, java.io.File sourceFile)
          Put the content of one file into another.
 
Methods inherited from class java.net.URLClassLoader
addURL, defineClass, definePackage, findClass, findResource, findResources, getPermissions, getURLs, isSealed, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
, defineClass, getProtectionDomain
 
Methods inherited from class java.lang.ClassLoader
addClass, check, defineClass, defineClass, defineClass, defineClass0, definePackage, findBootstrapClass, findLibrary, findLoadedClass, findNative, findSystemClass, getBootstrapClassPath, getBootstrapResource, getBootstrapResources, getCallerClassLoader, getDefaultDomain, getGetClassLoaderPerm, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, initializePath, isAncestor, loadClass, loadClass, loadLibrary, loadLibrary0, resolveClass, resolveClass0, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

CLASS_TO_START

private static final java.lang.String CLASS_TO_START
The class to start.

UPDATED_FILE

public static final java.lang.String UPDATED_FILE
The tmp file created after an update.

JAR_FILE

public static final java.lang.String JAR_FILE
The archive file.

BACKUP_FILE

public static final java.lang.String BACKUP_FILE
The backup file.

url

private java.net.URL url
The url of the Jar file to load.

BUFFER_SIZE

private static final int BUFFER_SIZE
The default buffer size.

loader

private static DLAILoader loader
Constructor Detail

DLAILoader

private DLAILoader(java.net.URL url)
Creates a new instance of the loader.
Method Detail

getMainClassName

public java.lang.String getMainClassName()
                                  throws java.io.IOException
Returns the name of the jar file main class, or null if no "Main-Class" manifest attributes was defined.

invokeClass

public void invokeClass(java.lang.String name,
                        java.lang.String[] args)
                 throws java.lang.ClassNotFoundException,
                        java.lang.NoSuchMethodException,
                        java.lang.reflect.InvocationTargetException
Invokes the application in this jar file given the name of the main class and an array of arguments.
The class must define a static method "main" which takes an array of String arguments and is of return type "void".
Parameters:
name - the name of the main class
args - the arguments for the application
Throws:
java.lang.ClassNotFoundException - if the specified class could not be found
java.lang.NoSuchMethodException - if the specified class does not contain a "main" method
java.lang.reflect.InvocationTargetException - if the application raised an exception

update

public static void update(java.io.File destinationFile,
                          java.io.File sourceFile)
Put the content of one file into another.
In case of problems nothing happens.

I once tryed to use BufferedReader, BufferedWriter, FileReader or FileWriter to optimize access but characters where badly translated back to characters under Windows.
Again not enought time to fix that.

Parameters:
destinationFile - The destination file.
sourceFile - The source file.

main

public static void main(java.lang.String[] args)
Main method.
Parameters:
args - The arguments from the command line.
See Also:
PPM.main(java.lang.String[])

getInstance

public static final DLAILoader getInstance()
Return an instance of this loader. The instance is non-null only if the main method has allready been called.
Returns:
An instance of this class or null.