org.ungoverned.moduleloader
Class JarResourceSource

java.lang.Object
  extended by org.ungoverned.moduleloader.JarResourceSource
All Implemented Interfaces:
ResourceSource

public class JarResourceSource
extends java.lang.Object
implements ResourceSource

This class implements a ResourceSource for retrieving resources from a JAR file. The approach used by this implementation is to defer opening the JAR file until a request for a resource is made.

See Also:
ResourceSource

Constructor Summary
JarResourceSource(java.io.File file)
           Constructs an instance using the specified file as the source of the JAR file.
JarResourceSource(java.lang.String fileName)
           Constructs an instance using the specified file name as the source of the JAR file.
 
Method Summary
 void close()
           This method deinitializes the resource source by closing the associated JAR file if it is open.
protected  void finalize()
           Closes the JAR file if it has not already been closed.
 byte[] getBytes(java.lang.String name)
           This method returns a byte array of the specified resource's contents.
 boolean hasResource(java.lang.String name)
           This method returns a boolean indicating whether the resource source contains the specified resource.
 void open()
           This method initializes the resource source.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JarResourceSource

public JarResourceSource(java.lang.String fileName)

Constructs an instance using the specified file name as the source of the JAR file.

Parameters:
fileName - the name of the JAR file to be used as the source.

JarResourceSource

public JarResourceSource(java.io.File file)

Constructs an instance using the specified file as the source of the JAR file.

Parameters:
file - the JAR file to be used as the source.
Method Detail

finalize

protected void finalize()

Closes the JAR file if it has not already been closed.

Overrides:
finalize in class java.lang.Object

open

public void open()

This method initializes the resource source. Since opening the JAR file is deferred until a request for a resource is actually made, this method really only sets a flag indicating that the resource source has been initialized.

Specified by:
open in interface ResourceSource

close

public void close()

This method deinitializes the resource source by closing the associated JAR file if it is open.

Specified by:
close in interface ResourceSource

hasResource

public boolean hasResource(java.lang.String name)
                    throws java.lang.IllegalStateException
Description copied from interface: ResourceSource

This method returns a boolean indicating whether the resource source contains the specified resource.

Specified by:
hasResource in interface ResourceSource
Parameters:
name - the name of the resource whose existence is being checked.
Throws:
java.lang.IllegalStateException - if the resource source has not been opened.

getBytes

public byte[] getBytes(java.lang.String name)
                throws java.lang.IllegalStateException
Description copied from interface: ResourceSource

This method returns a byte array of the specified resource's contents.

Specified by:
getBytes in interface ResourceSource
Parameters:
name - the name of the resource to retrieve.
Throws:
java.lang.IllegalStateException - if the resource source has not been opened.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object