uk.ac.rdg.resc.jstyx.server
Class StyxDirectory

java.lang.Object
  extended by uk.ac.rdg.resc.jstyx.server.StyxFile
      extended by uk.ac.rdg.resc.jstyx.server.StyxDirectory
Direct Known Subclasses:
DirectoryOnDisk, TimeDirectory

public class StyxDirectory
extends StyxFile

Class representing a directory on a Styx server. One would only rarely need to create subclasses of this; an example would be creating a StyxDirectory that represents a directory on the host filesystem (see DirectoryOnDisk).

Author:
Jon Blower $Revision: 601 $ $Date: 2006-03-20 17:51:50 +0000 (Mon, 20 Mar 2006) $ $Log$ Revision 1.13 2006/03/20 17:51:50 jonblower Adding authentication to base JStyx system Revision 1.12 2006/01/04 16:47:29 jonblower Reworked getName() and getFullPath() Revision 1.11 2005/09/08 07:08:59 jonblower Removed "String user" from list of parameters to StyxFile.write() Revision 1.10 2005/05/19 14:46:51 jonblower Changed behaviour of StyxDirectory.createChild(): no longer adds file to namespace in this method Revision 1.9 2005/05/11 10:34:31 jonblower Changed so that addChild() returns this StyxDirectory object to allow chaining Revision 1.8 2005/04/28 08:11:15 jonblower Modified permissions handling in documentation directory of SGS Revision 1.7 2005/03/24 09:48:31 jonblower Changed 'count' from long to int throughout for reading and writing Revision 1.6 2005/03/22 17:48:27 jonblower Removed debug code that tracked ByteBuffer allocation Revision 1.5 2005/03/21 17:57:11 jonblower Trying to fix ByteBuffer leak in SGS server Revision 1.4 2005/03/16 17:56:24 jonblower Replaced use of java.nio.ByteBuffer with MINA's ByteBuffer to minimise copying of buffers Revision 1.3 2005/03/11 14:02:16 jonblower Merged MINA-Test_20059309 into main line of development Revision 1.2.2.1 2005/03/10 11:53:54 jonblower Modified for MINA framework Revision 1.2 2005/03/01 13:47:43 jonblower Changed default user and group to 'user' and 'group' Revision 1.1.1.1 2005/02/16 18:58:32 jonblower Initial import

Field Summary
 
Fields inherited from class uk.ac.rdg.resc.jstyx.server.StyxFile
auth, directory, lastModifiedTime, name, parent
 
Constructor Summary
StyxDirectory(java.lang.String name)
          Creates a directory with default permissions (0777, rwxrwxrwx)
StyxDirectory(java.lang.String name, int permissions)
          Creates a directory with the given permissions
StyxDirectory(java.lang.String name, java.lang.String owner, java.lang.String group, int permissions)
          Creates a new instance of StyxDirectory
 
Method Summary
 StyxDirectory addChild(StyxFile sf)
          Adds a file to this directory.
 void checkSetLength(ULong newLength)
          This method is overridden to return a more meaningful error message.
 boolean childExists(java.lang.String name)
           
 StyxFile createChild(java.lang.String name, int perm, boolean isDir, boolean isAppOnly, boolean isExclusive)
          Creates a new file to be added to this directory.
 StyxFile getChild(java.lang.String name)
          Gets the child with the given name or null if it does not exist
 StyxFile[] getChildren()
          Gets all the direct descendants of this directory
 java.lang.String getFullPath()
          Gets the full path relative to the root of this file system, or a single slash if this is the root directory.
 ULong getLength()
           
 java.lang.String getName()
           
 int getNumChildren()
          Gets the number of direct descendants of this directory
 StyxDirectory getParent()
          Returns the parent of this directory.
 boolean isRoot()
           
 void read(StyxFileClient client, long offset, int count, int tag)
          Returns the directory contents.
 void refresh()
          Refreshes this file (if it represents another entity, such as a file on disk, this method is used to make sure that the file metadata (length, access time etc) are up to date.
protected  void refresh(boolean updateChildren)
           
 void remove()
          Removes this directory from the server.
 void removeAllChildren()
          Recursively removes all children from this directory.
 void removeChild(StyxFile child)
          Removes the given file from this directory.
 void write(StyxFileClient client, long offset, int count, org.apache.mina.common.ByteBuffer data, boolean truncate, int tag)
          This always throws a StyxException as it is illegal to write to a directory
 
Methods inherited from class uk.ac.rdg.resc.jstyx.server.StyxFile
addChangeListener, addClient, checkSetLastModifiedTime, checkSetMode, checkSetName, clientConnected, clientDisconnected, contentsChanged, delete, fireContentsChanged, getClient, getDirEntry, getGroup, getNumClients, getOwner, getPermissions, getQid, getVersion, incrementVersion, isAppendOnly, isAuth, isDirectory, isExclusive, processAndReplyRead, processAndReplyRead, processAndReplyRead, removeChangeListener, removeClient, rename, replyRead, replyRead, replyRead, replyRead, replyRead, replyWrite, setLastAccessTime, setLastModified, setLength, setMode, setName, setPermissions, setReadOnly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StyxDirectory

public StyxDirectory(java.lang.String name,
                     java.lang.String owner,
                     java.lang.String group,
                     int permissions)
              throws StyxException
Creates a new instance of StyxDirectory

Throws:
StyxException

StyxDirectory

public StyxDirectory(java.lang.String name)
              throws StyxException
Creates a directory with default permissions (0777, rwxrwxrwx)

Throws:
StyxException

StyxDirectory

public StyxDirectory(java.lang.String name,
                     int permissions)
              throws StyxException
Creates a directory with the given permissions

Throws:
StyxException
Method Detail

checkSetLength

public void checkSetLength(ULong newLength)
                    throws StyxException
This method is overridden to return a more meaningful error message.

Overrides:
checkSetLength in class StyxFile
Throws:
StyxException

isRoot

public boolean isRoot()
Returns:
true if this is the root directory (i.e. if it has no parent)

getFullPath

public java.lang.String getFullPath()
Gets the full path relative to the root of this file system, or a single slash if this is the root directory. Since this is a directory, the full path will end in a slash

Overrides:
getFullPath in class StyxFile

getName

public java.lang.String getName()
Overrides:
getName in class StyxFile
Returns:
the name of this file

read

public final void read(StyxFileClient client,
                       long offset,
                       int count,
                       int tag)
                throws StyxException
Returns the directory contents. This method cannot be overridden.

Overrides:
read in class StyxFile
Parameters:
client - The client that is performing the read
offset - The point in the file at which to start reading
count - The maximum number of bytes to read
tag - The tag of the incoming Tread message (this is needed when calling readReply())
Throws:
StyxException

write

public void write(StyxFileClient client,
                  long offset,
                  int count,
                  org.apache.mina.common.ByteBuffer data,
                  boolean truncate,
                  int tag)
           throws StyxException
This always throws a StyxException as it is illegal to write to a directory

Overrides:
write in class StyxFile
Parameters:
client - The client that is performing the write operation
offset - The place in the file where the new data will be added
count - The number of bytes to write
data - The data to write. The position and limit of this ByteBuffer will be set correctly, but subclasses should note that the position might not be zero.
truncate - If this is true the file will be truncated at the end of the new data
tag - The tag of the incoming Twrite message (this is needed when calling writeReply())
Throws:
StyxException

getLength

public final ULong getLength()
Overrides:
getLength in class StyxFile
Returns:
the length of the file. This is always zero: subclasses cannot override this.

refresh

public void refresh()
Refreshes this file (if it represents another entity, such as a file on disk, this method is used to make sure that the file metadata (length, access time etc) are up to date.

Overrides:
refresh in class StyxFile

refresh

protected void refresh(boolean updateChildren)
Parameters:
updateChildren - If this is set true, this method will also refresh all the immediate children of this directory. This default method does nothing; subclasses must override this.

getChildren

public StyxFile[] getChildren()
Gets all the direct descendants of this directory

Returns:
the children as an array of StyxFiles or null if this StyxFile is not a directory

getNumChildren

public int getNumChildren()
Gets the number of direct descendants of this directory


addChild

public StyxDirectory addChild(StyxFile sf)
                       throws uk.ac.rdg.resc.jstyx.server.FileExistsException
Adds a file to this directory. If a file with the same name already exists, throws a FileExistsException

Returns:
this StyxDirectory object, so that calls can be chained: StyxDirectory root = new StyxDirectory().addChild(file1).addChile(file2)
Throws:
uk.ac.rdg.resc.jstyx.server.FileExistsException

childExists

public boolean childExists(java.lang.String name)
Returns:
true if a child with the given name exists in this directory

createChild

public StyxFile createChild(java.lang.String name,
                            int perm,
                            boolean isDir,
                            boolean isAppOnly,
                            boolean isExclusive)
                     throws StyxException
Creates a new file to be added to this directory. This default implementation throws an exception; subclasses should override this method to allow files to be created. This method should not add the new file to the directory. This will be done in StyxServerProtocolHandler.replyCreate().

Returns:
The newly-created file
Throws:
StyxException

removeChild

public void removeChild(StyxFile child)
Removes the given file from this directory.


remove

public void remove()
            throws StyxException
Removes this directory from the server. This directory must be empty (see this.removeAllChildren())

Overrides:
remove in class StyxFile
Throws:
StyxException - if this is the root directory, or if it is not empty

removeAllChildren

public void removeAllChildren()
Recursively removes all children from this directory.


getChild

public StyxFile getChild(java.lang.String name)
Gets the child with the given name or null if it does not exist


getParent

public final StyxDirectory getParent()
Returns the parent of this directory. The parent of the root directory is the root itself (according to the Inferno manual)

Overrides:
getParent in class StyxFile


Copyright © 2004-2006 Reading e-Science Centre. All Rights Reserved.