Class JarLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- org.apache.derby.impl.services.reflect.JarLoader
-
final class JarLoader extends java.security.SecureClassLoader
-
-
Field Summary
Fields Modifier and Type Field Description private StorageFile
installedJar
Handle to the installed jar file.private boolean
isStream
True if the jar can only be accessed using a stream, because the jar is itself in a database jar.private java.util.jar.JarFile
jar
When the jar file can be manipulated as a java.util.JarFile this holds the reference to the open jar.private java.lang.String[]
name
Two part name for the jar file.private UpdateLoader
updateLoader
private HeaderPrintWriter
vs
-
Constructor Summary
Constructors Constructor Description JarLoader(UpdateLoader updateLoader, java.lang.String[] name, HeaderPrintWriter vs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) java.lang.Class
checkLoaded(java.lang.String className, boolean resolve)
(package private) java.lang.String
getJarName()
Return the SQL name for the installed jar.private java.io.InputStream
getRawStream(java.io.InputStream in, java.lang.String name)
Get a stream from a zip file that is itself a stream.private java.io.InputStream
getRawStream(java.lang.String name)
Get a stream for a resource directly from a JarFile.java.io.InputStream
getResourceAsStream(java.lang.String name)
private java.security.cert.Certificate[]
getSigners(java.lang.String className, java.util.jar.JarEntry je)
Validate the security certificates (signers) for the class data.(package private) java.io.InputStream
getStream(java.lang.String name)
Get an InputStream for the given resource.private java.lang.SecurityException
handleException(java.lang.Exception e, java.lang.String className)
Provide a SecurityManager with information about the class name and the jar file.(package private) void
initialize()
Initialize the class loader so it knows if it is loading from a ZipFile or an InputStreamprotected java.lang.Class
loadClass(java.lang.String className, boolean resolve)
Handle all requests to the top-level loader.private java.lang.Class
loadClassData(java.io.InputStream in, java.lang.String className, java.lang.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) java.lang.Class
loadClassData(java.lang.String className, java.lang.String jvmClassName, boolean resolve)
private java.lang.Class
loadClassData(java.util.jar.JarEntry e, java.io.InputStream in, java.lang.String className, boolean resolve)
Load and optionally resolve the class given its JarEntry and an InputStream to the class fiel format.private java.lang.Class
loadClassDataFromJar(java.lang.String className, java.lang.String jvmClassName, boolean resolve)
Load the class data when the installed jar is accessible as a java.util.jarFile.(package private) byte[]
readData(java.util.jar.JarEntry ze, java.io.InputStream in, java.lang.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
setInvalid()
Set this loader to be invaid so that it will not resolve any classes or resources.java.lang.String
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 Detail
-
name
private final java.lang.String[] name
Two part name for the jar file.
-
installedJar
private StorageFile installedJar
Handle to the installed jar file.
-
jar
private java.util.jar.JarFile 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 isStream
True 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
private UpdateLoader updateLoader
-
vs
private HeaderPrintWriter vs
-
-
Constructor Detail
-
JarLoader
JarLoader(UpdateLoader updateLoader, java.lang.String[] name, HeaderPrintWriter vs)
-
-
Method Detail
-
initialize
void initialize()
Initialize the class loader so it knows if it is loading from a ZipFile or an InputStream
-
loadClass
protected java.lang.Class loadClass(java.lang.String className, boolean resolve) throws java.lang.ClassNotFoundException
Handle all requests to the top-level loader.- Overrides:
loadClass
in classjava.lang.ClassLoader
- Throws:
java.lang.ClassNotFoundException
- Class can not be found
-
getResourceAsStream
public java.io.InputStream getResourceAsStream(java.lang.String name)
- Overrides:
getResourceAsStream
in classjava.lang.ClassLoader
-
getJarName
final java.lang.String getJarName()
Return the SQL name for the installed jar. Used for error and informational messages.
-
loadClassData
java.lang.Class loadClassData(java.lang.String className, java.lang.String jvmClassName, boolean resolve)
-
getStream
java.io.InputStream getStream(java.lang.String name)
Get an InputStream for the given resource.
-
loadClassDataFromJar
private java.lang.Class loadClassDataFromJar(java.lang.String className, java.lang.String jvmClassName, boolean resolve) throws java.io.IOException
Load the class data when the installed jar is accessible as a java.util.jarFile.- Throws:
java.io.IOException
-
loadClassData
private java.lang.Class loadClassData(java.io.InputStream in, java.lang.String className, java.lang.String jvmClassName, boolean resolve) throws java.io.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:
java.io.IOException
-
loadClassData
private java.lang.Class loadClassData(java.util.jar.JarEntry e, java.io.InputStream in, java.lang.String className, boolean resolve) throws java.io.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:
java.io.IOException
-
checkLoaded
java.lang.Class checkLoaded(java.lang.String className, boolean resolve)
-
setInvalid
void setInvalid()
Set this loader to be invaid so that it will not resolve any classes or resources.
-
getRawStream
private java.io.InputStream getRawStream(java.lang.String name)
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
private java.io.InputStream getRawStream(java.io.InputStream in, java.lang.String name)
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
byte[] readData(java.util.jar.JarEntry ze, java.io.InputStream in, java.lang.String className) throws java.io.IOException
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:
java.io.IOException
-
getSigners
private java.security.cert.Certificate[] getSigners(java.lang.String className, java.util.jar.JarEntry je) throws java.io.IOException
Validate the security certificates (signers) for the class data.- Throws:
java.io.IOException
-
handleException
private java.lang.SecurityException handleException(java.lang.Exception e, java.lang.String className)
Provide a SecurityManager with information about the class name and the jar file.
-
toString
public java.lang.String toString()
Return the jar name if toString() is called on this class loader.- Overrides:
toString
in classjava.lang.Object
-
-