org.ungoverned.moduleloader
Interface ResourceSource

All Known Implementing Classes:
JarResourceSource, SystemResourceSource

public interface ResourceSource

This interface represents a source for obtaining resources for a given module via the module's class loader. A resource source is used for retrieving both classes and resources; at this level, classes are treated in an identical manner as an ordinary resource. Resource sources are completely arbitrary and implementations may load resources from a JAR file, the network, a database, or anywhere.

All resource sources are initialized before first usage via a call to the ResourceSource.open() method and are also deinitialized via a call to ResourceSource.close(). Resource sources should be implemented such that they can be opened, closed, and then re-opened.

See Also:
Module, ModuleClassLoader

Method Summary
 void close()
           This method de-initializes the resource source.
 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.
 

Method Detail

open

void open()

This method initializes the resource source. It is called when the associated module is added to the ModuleManager. It is acceptable for implementations to ignore duplicate calls to this method if the resource source is already opened.


close

void close()

This method de-initializes the resource source. It is called when the associated module is removed from the ModuleManager or when the module is reset by the ModuleManager.


hasResource

boolean hasResource(java.lang.String name)
                    throws java.lang.IllegalStateException

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

Parameters:
name - the name of the resource whose existence is being checked.
true - if the resource source has the resource, false otherwise.
Throws:
java.lang.IllegalStateException - if the resource source has not been opened.

getBytes

byte[] getBytes(java.lang.String name)
                throws java.lang.IllegalStateException

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

Parameters:
name - the name of the resource to retrieve.
a - byte array of the resource's contents or null if the resource was not found.
Throws:
java.lang.IllegalStateException - if the resource source has not been opened.