org.planx.xmlstore.koala.io
Class NodeFileSystemImpl<R extends Locatable>

java.lang.Object
  extended by org.planx.xmlstore.koala.io.NodeFileSystemImpl<R>
All Implemented Interfaces:
FileSystem, Loader<R,SystemNode>, NodeFileSystem<R>
Direct Known Subclasses:
CacheNodeFileSystem, MemoryNodeFileSystem

public class NodeFileSystemImpl<R extends Locatable>
extends Object
implements NodeFileSystem<R>

A NodeFileSystem that decorates an existing FileSystem and associates an IOPolicy.

Author:
Thomas Ambus

Constructor Summary
NodeFileSystemImpl(FileSystem fs, IOPolicy<R> policy)
          The NodeFileSystem will use a NodeConverter for converting nodes to and from byte representation.
 
Method Summary
 Bound all()
          Returns a locator encapsulating all data currently in this file system.
 Bound allocate()
          (Optional) Returns a locator to a free write position that can hold an unspecified amount of bytes.
 Bound allocate(long size)
          Returns a locator to a free write position that can hold size number of bytes.
 void clear()
          Frees all data in this FileSystem.
 void clearModified()
          Marks this file system as unmodified.
 void close()
          Closes this file system and releases all resources.
 void free(Bound l)
          Frees the space occupied by the specified Bound.
 PositionalData getData(Locator l)
          Returns a PositionalData for reading and writing to the FileSystem at the specified location.
 Bound getMeta()
          Returns a locator to a special block of meta data.
 IOPolicy<R> getPolicy()
          Returns the IOPolicy associated with this NodeFileSystem.
 SourceId id()
          Returns a SourceId identifying this FileSystem in its present state.
 boolean isContained(Locator l)
          Returns true if the specified Locator originates from this FileSystem and is valid.
 boolean isModified()
          Returns true if this file system has been modified since it was created or since the last call to FileSystem.clearModified().
 boolean isReadOnly()
          Returns true if this file system is read-only.
 SystemNode load(Locator loc, RelativeDualReference<Locator,R> ref)
          Loads a node from the file system.
 SystemNode load(R ref)
          Loads a node from the file system.
 Locator save(SystemNode node)
          Saves at end of the file system by appending (i.e. allocating using allocate()).
 void setMeta(Bound b)
          Sets the meta data pointer of this file system.
 void setReadOnly(boolean isReadOnly)
          Sets the read-only status of this file system.
 long size()
          Returns the size of this file system.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NodeFileSystemImpl

public NodeFileSystemImpl(FileSystem fs,
                          IOPolicy<R> policy)
The NodeFileSystem will use a NodeConverter for converting nodes to and from byte representation.

Method Detail

getPolicy

public IOPolicy<R> getPolicy()
Description copied from interface: NodeFileSystem
Returns the IOPolicy associated with this NodeFileSystem.

Specified by:
getPolicy in interface NodeFileSystem<R extends Locatable>

load

public SystemNode load(R ref)
                throws IOException
Description copied from interface: NodeFileSystem
Loads a node from the file system.

Specified by:
load in interface Loader<R extends Locatable,SystemNode>
Specified by:
load in interface NodeFileSystem<R extends Locatable>
Throws:
IOException

load

public SystemNode load(Locator loc,
                       RelativeDualReference<Locator,R> ref)
                throws IOException
Description copied from interface: NodeFileSystem
Loads a node from the file system.

Specified by:
load in interface NodeFileSystem<R extends Locatable>
Throws:
IOException

save

public Locator save(SystemNode node)
             throws IOException
Saves at end of the file system by appending (i.e. allocating using allocate()).

Specified by:
save in interface NodeFileSystem<R extends Locatable>
Throws:
IOException

id

public SourceId id()
            throws IOException
Description copied from interface: FileSystem
Returns a SourceId identifying this FileSystem in its present state. The SourceId can change at any point and is not necessarily equal to the SourceIds returned by allocation method even though these may still be valid. Thus, this SourceId should be regarded as a unique canonical id that identifies only the present state of this FileSystem.

Specified by:
id in interface FileSystem
Throws:
IOException

allocate

public Bound allocate()
               throws IOException
Description copied from interface: FileSystem
(Optional) Returns a locator to a free write position that can hold an unspecified amount of bytes. Implementations are allowed to throw an UnsupportedOperationException if this is not supported.

Specified by:
allocate in interface FileSystem
Throws:
IOException - if an I/O error occurred.

allocate

public Bound allocate(long size)
               throws IOException
Description copied from interface: FileSystem
Returns a locator to a free write position that can hold size number of bytes.

Specified by:
allocate in interface FileSystem
Throws:
IOException - if an I/O error occurred or the specified amount of bytes could not be allocated.

all

public Bound all()
          throws IOException
Description copied from interface: FileSystem
Returns a locator encapsulating all data currently in this file system.

Specified by:
all in interface FileSystem
Throws:
IOException - if an I/O error occurred.

free

public void free(Bound l)
          throws IOException
Description copied from interface: FileSystem
Frees the space occupied by the specified Bound.

Specified by:
free in interface FileSystem
Throws:
IOException - if an I/O error occurred.
InvalidSourceIdException - if the file system identifier of the locator is invalid.
OutOfBoundsException - if the locator is out of bounds.

getMeta

public Bound getMeta()
              throws IOException
Description copied from interface: FileSystem
Returns a locator to a special block of meta data. Only one meta data block is allowed per file system. If no meta data block has been set, or meta data is not supported, null is returned.

Specified by:
getMeta in interface FileSystem
Throws:
IOException

setMeta

public void setMeta(Bound b)
             throws IOException
Description copied from interface: FileSystem
Sets the meta data pointer of this file system. If meta data is not supported the operation is ignored.

Specified by:
setMeta in interface FileSystem
Throws:
IOException

clear

public void clear()
           throws IOException
Description copied from interface: FileSystem
Frees all data in this FileSystem.

Specified by:
clear in interface FileSystem
Throws:
IOException

getData

public PositionalData getData(Locator l)
                       throws IOException
Description copied from interface: FileSystem
Returns a PositionalData for reading and writing to the FileSystem at the specified location.

Specified by:
getData in interface FileSystem
Throws:
IOException - if an I/O error occurred.
InvalidSourceIdException - if the file system identifier of the locator is invalid.
OutOfBoundsException - if the locator is out of bounds.

size

public long size()
          throws IOException
Description copied from interface: FileSystem
Returns the size of this file system.

Specified by:
size in interface FileSystem
Throws:
IOException - if an I/O error occurred.

isModified

public boolean isModified()
                   throws IOException
Description copied from interface: FileSystem
Returns true if this file system has been modified since it was created or since the last call to FileSystem.clearModified().

Specified by:
isModified in interface FileSystem
Throws:
IOException

clearModified

public void clearModified()
                   throws IOException
Description copied from interface: FileSystem
Marks this file system as unmodified.

Specified by:
clearModified in interface FileSystem
Throws:
IOException

isReadOnly

public boolean isReadOnly()
                   throws IOException
Description copied from interface: FileSystem
Returns true if this file system is read-only.

Specified by:
isReadOnly in interface FileSystem
Throws:
IOException

setReadOnly

public void setReadOnly(boolean isReadOnly)
                 throws IOException
Description copied from interface: FileSystem
Sets the read-only status of this file system.

Specified by:
setReadOnly in interface FileSystem
Throws:
IOException

close

public void close()
           throws IOException
Description copied from interface: FileSystem
Closes this file system and releases all resources.

Specified by:
close in interface FileSystem
Throws:
IOException - if an I/O error occurred.

isContained

public boolean isContained(Locator l)
                    throws IOException
Description copied from interface: FileSystem
Returns true if the specified Locator originates from this FileSystem and is valid.

Specified by:
isContained in interface FileSystem
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2004-2005 Plan-X. All Rights Reserved.