All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class w3c.tools.store.SimpleResourceStore

java.lang.Object
   |
   +----w3c.tools.store.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 acceptUnload()
Can the resource store manager unload that store from memory.
 o addHolder(ResourceStoreHolder)
Add a holder to that store.
 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 getIdentifier()
Get the identifier for that store.
 o getResourceBytes(ResourceIndex, byte[])
Get the bytes that are the pickled version of the given resource.
 o getVersion()
Get the store format version number.
 o hasResource(String)
Does this store defines this resource.
 o initialize(ResourceStoreManager, Object, 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, Resource)
Lock this resource in memory.
 o lookupResource(String)
Lookup this resource.
 o main(String[])
 o markModified(Resource)
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 removeHolder(ResourceStoreHolder)
Remove a store holder.
 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(Resource)
Save a given resource.
 o shutdown()
Shutdown this store.
 o toString()
Print a simple resource store.
 o unlockResource(ResourceLocker, Resource)
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 addHolder
 public synchronized void addHolder(ResourceStoreHolder holder)
Add a holder to that store.

Parameters:
holder - The holder to add.
 o removeHolder
 public synchronized void removeHolder(ResourceStoreHolder holder)
Remove a store holder.

Parameters:
holder - The holder to remove.
 o getIdentifier
 public String getIdentifier()
Get the identifier for that store. We use the repository as an identifier, which is safe here.

Returns:
The absolute path of the repository.
 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 getVersion
 public int getVersion()
Get the store format version number.

Returns:
An ineteger version number, guaranteed to change whenever the format used by the store changes.
 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.
Returns:
A Resource instance, or null if the resource doesn't exist in that store.
Throws: InvalidResourceException
If the resource couldn't be restored from its pickled format.
 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(Resource resource)
Save a given resource. If the resource has been modified, we save all our resources.

Parameters:
resource - The resource to be save right now.
 o lockResource
 public synchronized boolean lockResource(ResourceLocker locker,
                                          Resource resource)
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,
                                         Resource resource)
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(Resource resource)
Mark the given resource as being modified.

Parameters:
identifier - The identifier of the modified resource.
 o acceptUnload
 public synchronized boolean acceptUnload()
Can the resource store manager unload that store from memory. We check all the loaded resource, to see if they are willing to be unloaded; we do unload straight all the resources that accept (to reduce memory usage), and return false only if one of our resource refuse to be unloaded.

 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,
                        Object token,
                        File repository)
Initialize this simple store with the given file.

Parameters:
manager - The resource store manager that loaded use.
token - Our identification token from the above resource store manager (this is an opaque object).
file - The repository file.
 o main
 public static void main(String args[]) throws Exception

All Packages  Class Hierarchy  This Package  Previous  Next  Index