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.
-
manager
- Our resource store manager.
-
SimpleResourceStore()
-
-
addResource(Resource)
- Add a new resource to the resource store.
-
enumerateResourceIdentifiers()
- Enumerate all the resources identifier in this repository.
-
getFileAt(int)
- Get our file, positionned at the given position.
-
getResourceBytes(ResourceIndex, byte[])
- Get the bytes that are the pickled version of the given resource.
-
hasResource(String)
- Does this store defines this resource.
-
initialize(ResourceStoreManager, File)
- Initialize this simple store with the given file.
-
internalSave(boolean)
- Internal save: save the repository back to disk.
-
loadIndex(Hashtable)
- Restore our whole index from our repository.
-
loadResource(String, Hashtable)
- Load a resource, or get one from the cache.
-
lockResource(ResourceLocker, String)
- Lock this resource in memory.
-
lookupResource(String)
- Lookup this resource.
-
main(String[])
-
-
markModified(String)
- Mark the given resource as being modified.
-
markUsed()
- Mark the store as having been used recently.
-
pickleResource(Resource, DataOutputStream)
- Pickle the given resource into the given output stream.
-
printIndex()
- Debug - print this resource store index.
-
removeResource(String)
- Remove a resource from this resource store.
-
renameResource(String, String)
- Rename a resource in the store.
-
save()
- Save all our modified resources back to our file.
-
saveResource(String)
- Save a given resource.
-
shutdown()
- Shutdown this store.
-
toString()
- Print a simple resource store.
-
unlockResource(ResourceLocker, String)
- Unlock this resource from memory.
-
warning(String)
- Emit the given string as a warning, to whoever it is appropriate.
manager
protected ResourceStoreManager manager
- Our resource store manager.
SimpleResourceStore
public SimpleResourceStore()
markUsed
protected final void markUsed()
- Mark the store as having been used recently.
warning
protected void warning(String msg)
- Emit the given string as a warning, to whoever it is appropriate.
- Parameters:
- msg - The warning message.
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.
loadIndex
protected synchronized void loadIndex(Hashtable target) throws IOException
- Restore our whole index from our repository.
printIndex
protected void printIndex()
- Debug - print this resource store index.
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.
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.
loadResource
public Resource loadResource(String identifier,
Hashtable defs) throws InvalidResourceException
- Load a resource, or get one from the cache.
- Parameters:
- identifier - The resource identifier.
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 ?
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.
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.
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.
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.
addResource
public synchronized void addResource(Resource resource)
- Add a new resource to the resource store.
- Parameters:
- resource - The resource to add.
removeResource
public synchronized void removeResource(String identifier)
- Remove a resource from this resource store.
- Parameters:
- identifier - The identifier of the resource to be removed.
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.
markModified
public synchronized void markModified(String identifier)
- Mark the given resource as being modified.
- Parameters:
- identifier - The identifier of the modified resource.
shutdown
public synchronized void shutdown()
- Shutdown this store.
save
public synchronized void save()
- Save all our modified resources back to our file.
enumerateResourceIdentifiers
public Enumeration enumerateResourceIdentifiers()
- Enumerate all the resources identifier in this repository.
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.
toString
public String toString()
- Print a simple resource store.
- Overrides:
- toString in class Object
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.
main
public static void main(String args[]) throws Exception
All Packages Class Hierarchy This Package Previous Next Index