public class LoadObject
extends java.lang.Object
URLClassLoader
is used to try to
load in a Java object from an external jar file. these get added to the list of
loaders when you call loadObject
to create an object instance, or when you call
addLoader
to add a new loader. One tip might be to add a set of the new jar files together.Constructor and Description |
---|
LoadObject()
Creates a new instance of LoadObject
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
addJarPrefix(java.lang.String theJarFile)
Calculate what the correct prefix for the jar file paths is
based on the uri of the server and add to the server uri.
|
static java.util.ArrayList<java.lang.String> |
addJarPrefix(java.lang.String serverUri,
java.util.ArrayList<java.lang.String> jarUris)
Calculate what the correct prefix for the jar file paths is
based on the uri of the server and add to the jar file paths.
|
static java.lang.String |
addJarPrefix(java.lang.String serverUri,
java.lang.String theJarFile)
Calculate what the correct jar file path is based on the uri of the server and file path.
|
static void |
addLoader(java.util.ArrayList<java.lang.String> uris)
Add the list of jar uris to the current loader.
|
protected static java.util.ArrayList<java.lang.Integer> |
convertToParent(java.util.ArrayList<?> params)
Return indexes of parameters that should now be changed to the parent object.
|
static java.util.ArrayList<java.lang.String> |
getAllClasses(java.lang.String jarUri,
boolean rtnOnError)
Retrieve and return the names of all classes stored in the jar identified
by the uri.
|
static boolean |
getAllowNewLoaders()
Get the value indicating if url classloaders can be used.
|
static java.lang.Class |
getClass(java.lang.String theClassName)
Retrieve a class instance of the class specified.
|
protected static boolean |
isLegalClassFile(java.lang.String jarClassName)
Return true if the class name is a legal one for separate loading and creation.
|
static boolean |
isLegalJarFile(java.lang.String jarFilePath)
Return true if the file path is a legal jar file type.
|
protected static boolean |
isUrlLoader(java.lang.ClassLoader loader)
Return true if the classloader is a URL class loader.
|
static void |
loadAllClasses()
Traverse through all currently stored class loaders and try to create an
instance of each class.
|
protected static java.util.jar.JarFile |
loadJarFile(java.lang.String jarUri)
Load and return the jar file from the specified uri.
|
static java.lang.Object |
loadObject(java.util.ArrayList<java.lang.String> theJarUris,
java.lang.String theClassName,
java.util.ArrayList<?> params)
Create a new instance of the specified object and return.
|
static java.lang.Object |
objStream(byte[] objBytes)
Use the jar loaders to read on a (base64) byte stream.
|
static java.lang.String |
removeJarPrefix(java.lang.String theJarFile)
Remove additional jar file formatting that is used to define a jar file for
a class loader.
|
static boolean |
setAllowNewLoaders(boolean thisAllowNew,
java.lang.String thisKey)
Set/change the value indicating if url classloaders can be used.
|
static boolean |
setLoaderKey(java.lang.String thisKey)
Set the secret loader key.
|
protected static java.net.URL |
uriToUrl(java.lang.String theUri)
Convert the uri spec into a URL.
|
protected static java.io.File |
urlToFile(java.net.URL theUrl)
Convert the URL into a file object if it is valid.
|
public static boolean isLegalJarFile(java.lang.String jarFilePath)
jarFilePath
- the jar file path.protected static boolean isLegalClassFile(java.lang.String jarClassName)
jarClassName
- the name of the class in the jar file.public static java.lang.Object loadObject(java.util.ArrayList<java.lang.String> theJarUris, java.lang.String theClassName, java.util.ArrayList<?> params) throws java.lang.Exception
theJarUris
- uris from which the remote object can be loaded, only if needed.theClassName
- the name of the class.params
- initialisation parameters.java.lang.Exception
- any error.public static void addLoader(java.util.ArrayList<java.lang.String> uris) throws java.lang.Exception
uris
- the list of jar uris.java.lang.Exception
- any error.protected static java.util.jar.JarFile loadJarFile(java.lang.String jarUri) throws java.lang.Exception
jarUri
- the uri specification for the jar file.java.lang.Exception
- any error.public static void loadAllClasses() throws java.lang.Exception
java.lang.Exception
- any error.public static java.util.ArrayList<java.lang.String> getAllClasses(java.lang.String jarUri, boolean rtnOnError)
jarUri
- the uri for the jar file.rtnOnError
- if true, exit with the first load error, returning null. If
false, try to load every class and ignore any errors.public static java.lang.Class getClass(java.lang.String theClassName)
theClassName
- the binary or fully qualified name of the class.public static java.lang.Object objStream(byte[] objBytes)
objBytes
- the byte stream.public static java.lang.String addJarPrefix(java.lang.String theJarFile) throws java.lang.Exception
theJarFile
- the file path for the jar file.java.lang.Exception
- any error.public static java.lang.String addJarPrefix(java.lang.String serverUri, java.lang.String theJarFile) throws java.lang.Exception
serverUri
- the uri of the server to send the jar spec to.theJarFile
- the file path for the jar file.java.lang.Exception
- any error.public static java.util.ArrayList<java.lang.String> addJarPrefix(java.lang.String serverUri, java.util.ArrayList<java.lang.String> jarUris) throws java.lang.Exception
serverUri
- the uri of the server to send the jar spec to.jarUris
- the jar file specifications.java.lang.Exception
- any error.public static java.lang.String removeJarPrefix(java.lang.String theJarFile)
theJarFile
- the file path for the jar file.protected static java.net.URL uriToUrl(java.lang.String theUri)
theUri
- the uri description in String format.protected static java.io.File urlToFile(java.net.URL theUrl)
theUrl
- the URL.protected static java.util.ArrayList<java.lang.Integer> convertToParent(java.util.ArrayList<?> params)
params
- the current parameters.protected static boolean isUrlLoader(java.lang.ClassLoader loader)
loader
- the loader to check.public static boolean setLoaderKey(java.lang.String thisKey)
thisKey
- the key value.public static boolean setAllowNewLoaders(boolean thisAllowNew, java.lang.String thisKey)
thisAllowNew
- true if allow adding new url classloaders, false if not allow,
when only the setup loaders can be used.thisKey
- the loader key to protect any changes.public static boolean getAllowNewLoaders()