Top Fields Constructors Methods
org.apache.derby.impl.services.reflect

pack-priv final Class JarLoader

extends SecureClassLoader
Class Inheritance
Imports
org.apache.derby.shared.common.stream.HeaderPrintWriter, org.apache.derby.shared.common.error.StandardException, java.io.ByteArrayOutputStream, .File, .FileNotFoundException, .InputStream, .IOException, java.security.CodeSource, .GeneralSecurityException, .SecureClassLoader, java.security.cert.Certificate, .X509Certificate, java.util.jar.JarEntry, .JarFile, .JarInputStream, org.apache.derby.iapi.services.io.AccessibleByteArrayOutputStream, .InputStreamUtil, .LimitInputStream, org.apache.derby.iapi.util.IdUtil, org.apache.derby.shared.common.reference.MessageId, org.apache.derby.shared.common.i18n.MessageService, org.apache.derby.io.StorageFile

Field Summary

Modifier and TypeField and 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 JarFile
jar

When the jar file can be manipulated as a java.util.JarFile this holds the reference to the open jar.

private final String[]
name

Hides java.lang.ClassLoader.name.

Two part name for the jar file.
private UpdateLoader
private HeaderPrintWriter

Constructor Summary

AccessConstructor and Description
pack-priv
JarLoader(UpdateLoader updateLoader, String[] name, HeaderPrintWriter vs)

Method Summary

Modifier and TypeMethod and Description
pack-priv Class<T>
checkLoaded(String className, boolean resolve)

pack-priv final String
getJarName()

Return the SQL name for the installed jar.

private InputStream
getRawStream(String name)

Get a stream for a resource directly from a JarFile.

private InputStream
getRawStream(InputStream in, String name)

Get a stream from a zip file that is itself a stream.

public InputStream
getResourceAsStream(String
The resource name
name
)

Overrides java.lang.ClassLoader.getResourceAsStream.

Returns an input stream for reading the specified resource.

private Certificate[]
getSigners(String className, JarEntry je)

Validate the security certificates (signers) for the class data.

pack-priv InputStream
getStream(String name)

Get an InputStream for the given resource.

private SecurityException
handleException(Exception e, String className)

Provide a SecurityException with information about the class name and the jar file.

pack-priv void
initialize()

Initialize the class loader so it knows if it is loading from a ZipFile or an InputStream

private boolean
isDerbyDriver(String className)

Return true if the class is a Derby driver class which must be accessible to java.sql.DriverManager.

protected Class<T>
loadClass(String
The binary name of the class
className
,
boolean
If true then resolve the class
resolve
)

Overrides java.lang.ClassLoader.loadClass.

Handle all requests to the top-level loader.

pack-priv Class<T>
loadClassData(String className, String jvmClassName, boolean resolve)

private Class<T>
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).

private Class<T>
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<T>
loadClassDataFromJar(String className, String jvmClassName, boolean resolve)

Load the class data when the installed jar is accessible as a java.util.jarFile.

pack-priv 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.

pack-priv void
setInvalid()

Set this loader to be invaid so that it will not resolve any classes or resources.

public String
toString()

Overrides java.lang.Object.toString.

Return the jar name if toString() is called on this class loader.

Inherited from java.security.SecureClassLoader:
defineClassdefineClassgetPermissions

Field Detail

installedJarback to summary
private StorageFile installedJar

Handle to the installed jar file.

isStreamback to summary
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.

jarback to summary
private 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.

nameback to summary
private final String[] name

Hides java.lang.ClassLoader.name.

Two part name for the jar file.

updateLoaderback to summary
private UpdateLoader updateLoader
vsback to summary
private HeaderPrintWriter vs

Constructor Detail

JarLoaderback to summary
pack-priv JarLoader(UpdateLoader updateLoader, String[] name, HeaderPrintWriter vs)

Method Detail

checkLoadedback to summary
pack-priv Class<T> checkLoaded(String className, boolean resolve)
getJarNameback to summary
pack-priv final String getJarName()

Return the SQL name for the installed jar. Used for error and informational messages.

getRawStreamback to summary
private InputStream getRawStream(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.

getRawStreamback to summary
private InputStream getRawStream(InputStream in, 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.
getResourceAsStreamback to summary
public InputStream getResourceAsStream(String name)

Overrides java.lang.ClassLoader.getResourceAsStream.

Doc from java.lang.ClassLoader.getResourceAsStream.

Returns an input stream for reading the specified resource.

The search order is described in the documentation for getResource(String).

Resources in named modules are subject to the encapsulation rules specified by Module.getResourceAsStream. Additionally, and except for the special case where the resource has a name ending with ".class", this method will only find resources in packages of named modules when the package is opened unconditionally.

Parameters
name:String

The resource name

Returns:InputStream

An input stream for reading the resource; null if the resource could not be found, the resource is in a package that is not opened unconditionally, or access to the resource is denied by the security manager.

getSignersback to summary
private Certificate[] getSigners(String className, JarEntry je) throws IOException

Validate the security certificates (signers) for the class data.

getStreamback to summary
pack-priv InputStream getStream(String name)

Get an InputStream for the given resource.

handleExceptionback to summary
private SecurityException handleException(Exception e, String className)

Provide a SecurityException with information about the class name and the jar file.

initializeback to summary
pack-priv void initialize()

Initialize the class loader so it knows if it is loading from a ZipFile or an InputStream

isDerbyDriverback to summary
private boolean isDerbyDriver(String className)

Return true if the class is a Derby driver class which must be accessible to java.sql.DriverManager.

loadClassback to summary
protected Class<T> loadClass(String className, boolean resolve) throws ClassNotFoundException

Overrides java.lang.ClassLoader.loadClass.

Handle all requests to the top-level loader.

Parameters
className:String

Doc from java.lang.ClassLoader.loadClass.

The binary name of the class

resolve:boolean

Doc from java.lang.ClassLoader.loadClass.

If true then resolve the class

Returns:Class<T>

Doc from java.lang.ClassLoader.loadClass.

The resulting Class object

Exceptions
ClassNotFoundException:
Class can not be found
loadClassDataback to summary
pack-priv Class<T> loadClassData(String className, String jvmClassName, boolean resolve)
loadClassDataback to summary
private Class<T> 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).

loadClassDataback to summary
private Class<T> 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.

loadClassDataFromJarback to summary
private Class<T> loadClassDataFromJar(String className, String jvmClassName, boolean resolve) throws IOException

Load the class data when the installed jar is accessible as a java.util.jarFile.

readDataback to summary
pack-priv byte[] readData(JarEntry ze, InputStream in, String className) throws 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 an IOException will be thrown.

setInvalidback to summary
pack-priv void setInvalid()

Set this loader to be invaid so that it will not resolve any classes or resources.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return the jar name if toString() is called on this class loader.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object