Class Loader
- java.lang.Object
-
- org.apache.sling.launchpad.base.shared.Loader
-
public class Loader extends Object
TheLoader
class provides utility methods for the actual launchers to help launching the framework.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanupVM()
Tries to remove as many traces of class loaded by the framework from the Java VM as possible.protected void
info(String msg)
Meant to be overridden to display or log infoboolean
installLauncherJar(URL launcherJar)
Copies the contents of the launcher JAR as indicated by the URL to the sling home directory.Object
loadLauncher(String launcherClassName)
Creates an URLClassLoader from a _launcher JAR_ file in the given launchpadHome directory and loads and returns the launcher class identified by the launcherClassName.static void
spool(InputStream ins, File destFile)
Spools the contents of the input stream to the given file replacing the contents of the file with the contents of the input stream.
-
-
-
Constructor Detail
-
Loader
public Loader(File launchpadHome)
Creates a loader instance to load from the given launchpad home folder. Besides ensuring the existence of the launchpad home folder, the constructor also removes all but the most recent launcher JAR files from the Sling home folder (thus cleaning up from previous upgrades).- Parameters:
launchpadHome
- The launchpad home folder. This must not benull
or an empty string.- Throws:
IllegalArgumentException
- If thelaunchpadHome
argument isnull
or an empty string or if the launchpad home folder exists but is not a directory or if the Sling home folder cannot be created.
-
-
Method Detail
-
loadLauncher
public Object loadLauncher(String launcherClassName)
Creates an URLClassLoader from a _launcher JAR_ file in the given launchpadHome directory and loads and returns the launcher class identified by the launcherClassName.- Parameters:
launcherClassName
- The fully qualified name of a class implementing the Launcher interface. This class must have a public constructor taking no arguments.- Returns:
- the Launcher instance loaded from the newly created classloader
- Throws:
NullPointerException
- if launcherClassName is nullIllegalArgumentException
- if the launcherClassName cannot be instantiated. The cause of the failure is contained as the cause of the exception.
-
cleanupVM
public void cleanupVM()
Tries to remove as many traces of class loaded by the framework from the Java VM as possible. Most notably the following traces are removed:- JavaBeans property caches
- Close the Launcher Jar File (if opened by the platform)
This method must be called when the notifier is called.
-
installLauncherJar
public boolean installLauncherJar(URL launcherJar) throws IOException
Copies the contents of the launcher JAR as indicated by the URL to the sling home directory. If the existing file is is a more recent bundle version than the supplied launcher JAR file, it is is not replaced.- Parameters:
launcherJar
- The URL to the launcher JAR- Returns:
true
if the launcher JAR file has been installed or updated,false
otherwise.- Throws:
IOException
- If an error occurrs transferring the contents
-
spool
public static void spool(InputStream ins, File destFile) throws IOException
Spools the contents of the input stream to the given file replacing the contents of the file with the contents of the input stream. When this method returns, the input stream is guaranteed to be closed.- Parameters:
ins
- The input stream to spooldestFile
- The file to spool the input stream contents to- Throws:
IOException
- If an error occurrs reading or writing the input stream contents.
-
info
protected void info(String msg)
Meant to be overridden to display or log info- Parameters:
msg
- The message to display or log
-
-