Class JarLoader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
org.apache.derby.impl.services.reflect.JarLoader
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StorageFile
Handle to the installed jar file.private boolean
True if the jar can only be accessed using a stream, because the jar is itself in a database jar.private JarFile
When the jar file can be manipulated as a java.util.JarFile this holds the reference to the open jar.private final String[]
Two part name for the jar file.private UpdateLoader
private HeaderPrintWriter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) Class
checkLoaded
(String className, boolean resolve) (package private) final String
Return the SQL name for the installed jar.private InputStream
getRawStream
(InputStream in, String name) Get a stream from a zip file that is itself a stream.private InputStream
getRawStream
(String name) Get a stream for a resource directly from a JarFile.getResourceAsStream
(String name) private Certificate[]
getSigners
(String className, JarEntry je) Validate the security certificates (signers) for the class data.(package private) InputStream
Get an InputStream for the given resource.private SecurityException
handleException
(Exception e, String className) Provide a SecurityManager with information about the class name and the jar file.(package private) void
Initialize the class loader so it knows if it is loading from a ZipFile or an InputStreamprotected Class
Handle all requests to the top-level loader.private Class
loadClassData
(InputStream in, String className, String jvmClassName, boolean resolve) Load the class data when the installed jar is accessible only as an input stream (the jar is itself in a database jar).(package private) Class
loadClassData
(String className, String jvmClassName, boolean resolve) private Class
loadClassData
(JarEntry e, InputStream in, String className, boolean resolve) Load and optionally resolve the class given its JarEntry and an InputStream to the class fiel format.private Class
loadClassDataFromJar
(String className, String jvmClassName, boolean resolve) Load the class data when the installed jar is accessible as a java.util.jarFile.(package private) byte[]
readData
(JarEntry ze, InputStream in, String className) Read the raw data for the class file format into a byte array that can be used for loading the class.(package private) void
Set this loader to be invaid so that it will not resolve any classes or resources.toString()
Return the jar name if toString() is called on this class loader.Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass, getPermissions
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Field Details
-
name
Two part name for the jar file. -
installedJar
Handle to the installed jar file. -
jar
When the jar file can be manipulated as a java.util.JarFile this holds the reference to the open jar. When the jar can only be manipulated as an InputStream (because the jar is itself in a database jar) then this will be null. -
isStream
private boolean isStreamTrue if the jar can only be accessed using a stream, because the jar is itself in a database jar. When fals the jar is accessed using the jar field. -
updateLoader
-
vs
-
-
Constructor Details
-
JarLoader
JarLoader(UpdateLoader updateLoader, String[] name, HeaderPrintWriter vs)
-
-
Method Details
-
initialize
void initialize()Initialize the class loader so it knows if it is loading from a ZipFile or an InputStream -
loadClass
Handle all requests to the top-level loader.- Overrides:
loadClass
in classClassLoader
- Throws:
ClassNotFoundException
- Class can not be found
-
getResourceAsStream
- Overrides:
getResourceAsStream
in classClassLoader
-
getJarName
Return the SQL name for the installed jar. Used for error and informational messages. -
loadClassData
-
getStream
Get an InputStream for the given resource. -
loadClassDataFromJar
private Class loadClassDataFromJar(String className, String jvmClassName, boolean resolve) throws IOException Load the class data when the installed jar is accessible as a java.util.jarFile.- Throws:
IOException
-
loadClassData
private Class loadClassData(InputStream in, String className, String jvmClassName, boolean resolve) throws IOException Load the class data when the installed jar is accessible only as an input stream (the jar is itself in a database jar).- Throws:
IOException
-
loadClassData
private Class loadClassData(JarEntry e, InputStream in, String className, boolean resolve) throws IOException Load and optionally resolve the class given its JarEntry and an InputStream to the class fiel format. This is common code for when the jar is accessed directly using JarFile or through InputStream.- Throws:
IOException
-
checkLoaded
-
setInvalid
void setInvalid()Set this loader to be invaid so that it will not resolve any classes or resources. -
getRawStream
Get a stream for a resource directly from a JarFile. In this case we can safely return the stream directly. It's a new stream set up by the zip code to read just the contents of this entry. -
getRawStream
Get a stream from a zip file that is itself a stream. We copy to the contents to a byte array and return a stream around that to the caller. Though a copy is involved it has the benefit of:- Isolating the application from the JarInputStream, thus denying any possibility of the application reading more of the jar that it should be allowed to. E.g. the contents class files are not exposed through getResource.
- Avoids any possibility of the application holding onto the open stream beyond shutdown of the database, thus leading to leaked file descriptors or inability to remove the jar.
-
readData
Read the raw data for the class file format into a byte array that can be used for loading the class. If this is a signed class and it has been compromised then a SecurityException will be thrown.- Throws:
IOException
-
getSigners
Validate the security certificates (signers) for the class data.- Throws:
IOException
-
handleException
Provide a SecurityManager with information about the class name and the jar file. -
toString
Return the jar name if toString() is called on this class loader.
-