Class w3c.jigsaw.resources.SimpleResourceStore
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class w3c.jigsaw.resources.SimpleResourceStore

java.lang.Object
   |
   +----w3c.jigsaw.resources.SimpleResourceStore

public class SimpleResourceStore
extends Object
implements ResourceStore
A very naive resource store. This resource store keeps all the resources in a file. It loads all resources (on a per-demand basis), and never unloads them.

Variable Index

 o manager
Our resource store manager.

Constructor Index

 o SimpleResourceStore()

Method Index

 o addResource(Resource)
Add a new resource to the resource store.
 o enumerateResourceIdentifiers()
Enumerate all the resources identifier in this repository.
 o getFileAt(int)
Get our file, positionned at the given position.
 o getResourceBytes(ResourceIndex, byte[])
Get the bytes that are the pickled version of the given resource.
 o hasResource(String)
Does this store defines this resource.
 o initialize(ResourceStoreManager, File)
Initialize this simple store with the given file.
 o internalSave(boolean)
Internal save: save the repository back to disk.
 o loadIndex(Hashtable)
Restore our whole index from our repository.
 o loadResource(String, Hashtable)
Load a resource, or get one from the cache.
 o lockResource(ResourceLocker, String)
Lock this resource in memory.
 o lookupResource(String)
Lookup this resource.
 o main(String[])
 o markModified(String)
Mark the given resource as being modified.
 o markUsed()
Mark the store as having been used recently.
 o pickleResource(Resource, DataOutputStream)
Pickle the given resource into the given output stream.
 o printIndex()
Debug - print this resource store index.
 o removeResource(String)
Remove a resource from this resource store.
 o renameResource(String, String)
Rename a resource in the store.
 o save()
Save all our modified resources back to our file.
 o saveResource(String)
Save a given resource.
 o shutdown()
Shutdown this store.
 o toString()
Print a simple resource store.
 o unlockResource(ResourceLocker, String)
Unlock this resource from memory.
 o warning(String)
Emit the given string as a warning, to whoever it is appropriate.

Variables

 o manager
  protected ResourceStoreManager manager
Our resource store manager.

Constructors

 o SimpleResourceStore
  public SimpleResourceStore()

Methods

 o markUsed
  protected final void markUsed()
Mark the store as having been used recently.
 o warning
  protected void warning(String msg)
Emit the given string as a warning, to whoever it is appropriate.
Parameters:
msg - The warning message.
 o getFileAt
  protected RandomAccessFile getFileAt(int pos) throws IOException
Get our file, positionned at the given position. We won't keep our repository file always open (too much of these resource stroe would burn our available file descriptors).
Parameters:
at - The position at wich you want the stream.
 o loadIndex
  protected synchronized void loadIndex(Hashtable target) throws IOException
Restore our whole index from our repository.
 o printIndex
  protected void printIndex()
Debug - print this resource store index.
 o getResourceBytes
  protected synchronized byte[] getResourceBytes(ResourceIndex index,
                                                 byte into[]) throws IOException
Get the bytes that are the pickled version of the given resource. This opens the file for each resource, it could of course be optimized for the cases were all the resources are to be loaded at once.
Parameters:
identifier - The resource identifier.
Returns:
The length, in the instance buffer, of the bytes that makes this resource.
 o pickleResource
  protected int pickleResource(Resource resource,
                               DataOutputStream out) throws IOException
Pickle the given resource into the given output stream.
Parameters:
resource - The resource to pickle.
out - The data output stream to pickle to.
Returns:
The size of the pickled version of the resource.
 o loadResource
  public Resource loadResource(String identifier,
                               Hashtable defs) throws InvalidResourceException
Load a resource, or get one from the cache.
Parameters:
identifier - The resource identifier.
 o internalSave
  protected synchronized void internalSave(boolean unload) throws IOException
Internal save: save the repository back to disk.
Parameters:
unload - Should we unload any existing resources ?
 o lookupResource
  public Resource lookupResource(String identifier)
Lookup this resource.
Parameters:
identifier - The resource identifier.
Returns:
A Resource instance, or null if either the resource doesn't exist, or it isn't loaded yet.
 o saveResource
  public void saveResource(String identifier) throws UnknownResourceException
Save a given resource. If the resource has been modified, we save all our resources.
Parameters:
identifier - The resource identifier.
 o lockResource
  public synchronized boolean lockResource(ResourceLocker locker,
                                           String identifier)
Lock this resource in memory.
Parameters:
locker - The object willing to acuiqre the lock.
identifier - The resource to lock.
Returns:
A boolean true if the locking succeeds.
 o unlockResource
  public synchronized void unlockResource(ResourceLocker locker,
                                          String identifier)
Unlock this resource from memory.
Parameters:
lcoker - The object willing to relinquish the lock.
identifier - The resource to unlock.
 o addResource
  public synchronized void addResource(Resource resource)
Add a new resource to the resource store.
Parameters:
resource - The resource to add.
 o removeResource
  public synchronized void removeResource(String identifier)
Remove a resource from this resource store.
Parameters:
identifier - The identifier of the resource to be removed.
 o renameResource
  public synchronized void renameResource(String oldid,
                                          String newid)
Rename a resource in the store.
Parameters:
oldid - The old resource identifier.
newid - The new resource identifier.
 o markModified
  public synchronized void markModified(String identifier)
Mark the given resource as being modified.
Parameters:
identifier - The identifier of the modified resource.
 o shutdown
  public synchronized void shutdown()
Shutdown this store.
 o save
  public synchronized void save()
Save all our modified resources back to our file.
 o enumerateResourceIdentifiers
  public Enumeration enumerateResourceIdentifiers()
Enumerate all the resources identifier in this repository.
 o hasResource
  public boolean hasResource(String identifier)
Does this store defines this resource.
Parameters:
identifier - The resource we are looking for.
Returns:
A boolean true if found.
 o toString
  public String toString()
Print a simple resource store.
Overrides:
toString in class Object
 o initialize
  public void initialize(ResourceStoreManager manager,
                         File repository)
Initialize this simple store with the given file.
Parameters:
manager - The resource store manager that loaded use.
file - The repository file.
 o main
  public static void main(String args[]) throws Exception

All Packages  Class Hierarchy  This Package  Previous  Next  Index