org.w3c.tools.jdbm
Class jdbmResourceStore

java.lang.Object
  |
  +--org.w3c.tools.jdbm.jdbmResourceStore

public class jdbmResourceStore
extends java.lang.Object
implements ResourceStore


Field Summary
static int LOADED_LIMIT
           
static int LOADED_THRESOLD
           
 
Constructor Summary
jdbmResourceStore()
           
 
Method Summary
 boolean acceptUnload()
           
 void addResource(Resource resource)
          Add this resource to this resource store.
protected  void dbmError(java.lang.Exception ex, java.lang.String msg)
          A jdbm error has occured, this is potentially serious.
 java.util.Enumeration enumerateResourceIdentifiers()
          Enumerate all the resources saved in this store.
 java.lang.String getIdentifier()
          Get the identifier for that store.
 int getLoadedCount()
           
protected  byte[] getResourceBytes(java.lang.String identifier)
          Get the bytes that are the pickled version of the given resource.
 int getVersion()
           
 boolean hasResource(java.lang.String identifier)
          Check for the existence of a resource in this store.
 void initialize(ResourceStoreManager manager, java.lang.Object token, java.io.File repository)
          This resource store is being built, initialize it with the given arg.
 void listLRU(java.io.PrintStream out, java.lang.String msg)
           
 Resource loadResource(java.lang.String identifier)
           
 Resource loadResource(java.lang.String identifier, java.util.Hashtable defs)
          Restore the resource whose name is given.
 Resource lookupResource(java.lang.String identifier)
          Get this resource, but only if already loaded.
static void main(java.lang.String[] args)
          Dump all resources.
 void markModified(Resource resource)
          Mark this resource as modified.
 void removeResource(java.lang.String identifier)
          Remove this resource from the repository.
 void renameResource(java.lang.String oldid, java.lang.String newid)
           
protected  void reorganize()
           
 void runStoreSweeper()
           
 void save()
          Save this store.
protected  void saveResource(org.w3c.tools.jdbm.jdbmResource entry)
           
 void saveResource(Resource resource)
          Stabilize the resource having the given identifier.
 void setPersist(Resource resource)
           
 void shutdown()
          Shutdown this store.
protected  void startReorganize()
           
 void unloadResource()
          Unload one selected resource from the store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOADED_LIMIT

public static final int LOADED_LIMIT

LOADED_THRESOLD

public static final int LOADED_THRESOLD
Constructor Detail

jdbmResourceStore

public jdbmResourceStore()
Method Detail

reorganize

protected void reorganize()

startReorganize

protected final void startReorganize()

getIdentifier

public java.lang.String getIdentifier()
Get the identifier for that store. We use the repository as an identifier, which is safe here.
Specified by:
getIdentifier in interface ResourceStore
Returns:
The absolute path of the repository.

getVersion

public int getVersion()
Specified by:
getVersion in interface ResourceStore

setPersist

public void setPersist(Resource resource)

listLRU

public void listLRU(java.io.PrintStream out,
                    java.lang.String msg)

runStoreSweeper

public void runStoreSweeper()

getLoadedCount

public final int getLoadedCount()

unloadResource

public void unloadResource()
Unload one selected resource from the store.

dbmError

protected void dbmError(java.lang.Exception ex,
                        java.lang.String msg)
A jdbm error has occured, this is potentially serious.
Parameters:
ex - The dbm exception.
msg - An informative description of the error.

getResourceBytes

protected byte[] getResourceBytes(java.lang.String identifier)
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.

saveResource

protected void saveResource(org.w3c.tools.jdbm.jdbmResource entry)

loadResource

public Resource loadResource(java.lang.String identifier,
                             java.util.Hashtable defs)
                      throws InvalidResourceException
Restore the resource whose name is given.
Specified by:
loadResource in interface ResourceStore
Parameters:
identifier - The identifier of the resource to restore.
defs - Default attribute values. If the resource needs to be restored from its pickled version, this Hashtable provides a set of default values for some of the attributes.
Returns:
A Resource instance, or null.

loadResource

public Resource loadResource(java.lang.String identifier)
                      throws InvalidResourceException

renameResource

public void renameResource(java.lang.String oldid,
                           java.lang.String newid)
Specified by:
renameResource in interface ResourceStore

lookupResource

public Resource lookupResource(java.lang.String identifier)
Get this resource, but only if already loaded. The resource store may (recommended) maintain a cache of the resource it loads from its store. If the resource having this identifier has already been loaded, return it, otherwise, return null.
Specified by:
lookupResource in interface ResourceStore
Parameters:
identifier - The resource identifier.
Returns:
A Resource instance, or null.

saveResource

public void saveResource(Resource resource)
Stabilize the resource having the given identifier.
Specified by:
saveResource in interface ResourceStore
Parameters:
identifier - The resource identifier.
Throws:
UnknownResourceException - If the resource is unknown.

addResource

public void addResource(Resource resource)
Add this resource to this resource store.
Specified by:
addResource in interface ResourceStore
Parameters:
resource - The resource to be added.

removeResource

public void removeResource(java.lang.String identifier)
Remove this resource from the repository.
Specified by:
removeResource in interface ResourceStore
Parameters:
identifier - The identifier of the resource to be removed.

markModified

public void markModified(Resource resource)
Mark this resource as modified.
Specified by:
markModified in interface ResourceStore
Parameters:
identifier - The identifier of the modified resource.

acceptUnload

public boolean acceptUnload()
Specified by:
acceptUnload in interface ResourceStore

shutdown

public void shutdown()
Shutdown this store.
Specified by:
shutdown in interface ResourceStore

save

public void save()
Save this store.
Specified by:
save in interface ResourceStore

enumerateResourceIdentifiers

public java.util.Enumeration enumerateResourceIdentifiers()
Enumerate all the resources saved in this store.
Specified by:
enumerateResourceIdentifiers in interface ResourceStore
Returns:
An enumeration of Strings, giving the identifier for all the resources that this store knows about.

hasResource

public boolean hasResource(java.lang.String identifier)
Check for the existence of a resource in this store.
Specified by:
hasResource in interface ResourceStore
Parameters:
identifier - The identifier of the resource to check.
Returns:
A boolean true if the resource exists in this store, false otherwise.

initialize

public void initialize(ResourceStoreManager manager,
                       java.lang.Object token,
                       java.io.File repository)
This resource store is being built, initialize it with the given arg.
Specified by:
initialize in interface ResourceStore
Parameters:
repository - A file, giving the location of the associated repository.

main

public static void main(java.lang.String[] args)
Dump all resources.