bibliothek.gui.dock.support.util
Class ApplicationResourceManager

java.lang.Object
  extended by bibliothek.gui.dock.support.util.ApplicationResourceManager

public class ApplicationResourceManager
extends Object

Manages a set of ApplicationResources, can load and store the resources at any time.
The ApplicationResources are organized in a Map. Each resource is associated with a unique key. This key is used to determine, which stream of bytes belongs to which resource. If data is loaded, the byte-streams for missing resources will be stored in a buffer that is read as soon as a missing resource is registered. Additional resources are ignored.
Note that there is no order how the resources are stored in the file.

Author:
Benjamin Sigg

Constructor Summary
ApplicationResourceManager()
           
 
Method Summary
 void put(String name, ApplicationResource resource)
          Stores a resource that might be read or written at any time.
 void readArray(byte[] array)
          Reads the contents of this manager from an array of bytes.
 void readFile(File file)
          Reads the contents of this manager from file.
 void readPreferences()
          Reads the content of this manager from the Preferences that represent the package of ApplicationResourceManager.
 void readStream(DataInputStream in)
          Lets all ApplicationResources read from in.
 void readXML(XElement element)
          Reads the contents of this manager from a xml element.
 void remove(String name)
          Removes a resources that was earlier added to this manager.
 byte[] writeArray()
          Writes the contents of this manager into an array of bytes.
 void writeFile(File file)
          Writes the contents of this manager into file.
 void writePreferences()
          Writes the contents of this manager into the Preferences which represent the package of ApplicationResourceManager.
 void writeStream(DataOutputStream out)
          Writes all currently known ApplicationResources into out.
 void writeXML(XElement element)
          Writes the content of this manager in xml format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ApplicationResourceManager

public ApplicationResourceManager()
Method Detail

put

public void put(String name,
                ApplicationResource resource)
         throws IOException
Stores a resource that might be read or written at any time. If a stream was already read by this manager, and if there was an entry in that stream that equals name, then resource will immediately be asked to read the stream.

Parameters:
name - the unique identifier of the resource
resource - the new resource
Throws:
NullPointerException - if name of resource is null
IOException - if the buffered stream can't be read. The resource will be stored in this manager even if an exception occurs

remove

public void remove(String name)
Removes a resources that was earlier added to this manager.

Parameters:
name - the name of the resource to remove

writeStream

public void writeStream(DataOutputStream out)
                 throws IOException
Writes all currently known ApplicationResources into out.

Parameters:
out - the stream to write into
Throws:
IOException - if the operation can't be completed

readStream

public void readStream(DataInputStream in)
                throws IOException
Lets all ApplicationResources read from in.

Parameters:
in - the stream to read from
Throws:
IOException - if the operation can't be completed

writeXML

public void writeXML(XElement element)
Writes the content of this manager in xml format.

Parameters:
element - the element to write into, the attributes of this element will not be changed.

readXML

public void readXML(XElement element)
Reads the contents of this manager from a xml element.

Parameters:
element - the element to read

writeFile

public void writeFile(File file)
               throws IOException
Writes the contents of this manager into file.

Parameters:
file - the file to write into
Throws:
IOException - if the operation can't be completed

readFile

public void readFile(File file)
              throws IOException
Reads the contents of this manager from file.

Parameters:
file - the file to read
Throws:
IOException - if the operation can't be completed

writeArray

public byte[] writeArray()
                  throws IOException
Writes the contents of this manager into an array of bytes.

Returns:
the contents as stream of bytes
Throws:
IOException - if the operation can't be completed

readArray

public void readArray(byte[] array)
               throws IOException
Reads the contents of this manager from an array of bytes.

Parameters:
array - the content as stream of bytes
Throws:
IOException - if the operation can't be completed

writePreferences

public void writePreferences()
                      throws IOException
Writes the contents of this manager into the Preferences which represent the package of ApplicationResourceManager.

Throws:
IOException - if the operation can't be completed

readPreferences

public void readPreferences()
                     throws IOException
Reads the content of this manager from the Preferences that represent the package of ApplicationResourceManager.

Throws:
IOException - if the operation can't be completed