org.jboss.virtual.plugins.context.memory
Class MemoryContextFactory

java.lang.Object
  extended by org.jboss.virtual.plugins.context.memory.MemoryContextFactory
All Implemented Interfaces:
VFSContextFactory

public class MemoryContextFactory
extends java.lang.Object
implements VFSContextFactory

Singelton implementation of a MemoryContextFactory. The roots are indexed as the 'host' part of the URLs they are stored under

Version:
$Revision: 1.1 $
Author:
Kabir Khan

Method Summary
 VirtualFileHandler createDirectory(java.net.URL url)
          Creates a 'directory' within the context determined by the url host part
 VFSContext createRoot(java.net.URL url)
          Creates a new root MemoryContext, or returns an already exixting one of one already exists for the name
 boolean delete(java.net.URL url)
          Deletes a 'file' or a 'directory'
 boolean deleteRoot(java.net.URL url)
          Deletes a root MemoryContext
 MemoryContext find(java.lang.String host)
          Gets hold of a root MemoryContext
static MemoryContextFactory getInstance()
          Gets the singleton instance
 java.lang.String[] getProtocols()
          Get the URL protocols/URI schemes this factory supports
 VFSContext getVFS(java.net.URI rootURI)
          Obtain a vfs context for the given root uri.
 VFSContext getVFS(java.net.URL rootURL)
          Obtain a vfs context for the given root url.
 VirtualFileHandler putFile(java.net.URL url, byte[] contents)
          Creates a 'file' within the context determined by the url host part
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static MemoryContextFactory getInstance()
Gets the singleton instance

Returns:
The singleton instance

getProtocols

public java.lang.String[] getProtocols()
Description copied from interface: VFSContextFactory
Get the URL protocols/URI schemes this factory supports

Specified by:
getProtocols in interface VFSContextFactory
Returns:
list of supported protocols.

getVFS

public VFSContext getVFS(java.net.URL rootURL)
                  throws java.io.IOException
Description copied from interface: VFSContextFactory
Obtain a vfs context for the given root url.

Specified by:
getVFS in interface VFSContextFactory
Parameters:
rootURL - - the URL for the root of the virtual context
Returns:
the vfs context
Throws:
java.io.IOException - - thrown if the root cannot be opened/accessed

getVFS

public VFSContext getVFS(java.net.URI rootURI)
                  throws java.io.IOException
Description copied from interface: VFSContextFactory
Obtain a vfs context for the given root uri.

Specified by:
getVFS in interface VFSContextFactory
Parameters:
rootURI - - the URI for the root of the virtual context
Returns:
the vfs context
Throws:
java.io.IOException - - thrown if the root cannot be opened/accessed

find

public MemoryContext find(java.lang.String host)
Gets hold of a root MemoryContext

Parameters:
host - The name of the root
Returns:
the found root MemoryContext, or null if none exists for the name

createRoot

public VFSContext createRoot(java.net.URL url)
Creates a new root MemoryContext, or returns an already exixting one of one already exists for the name

Parameters:
url - The url of the root, we use the 'host' part of the name for indexing the context
Returns:
The found or created context
Throws:
java.lang.IllegalArgumentException - If the url parameter contains a path

createDirectory

public VirtualFileHandler createDirectory(java.net.URL url)
Creates a 'directory' within the context determined by the url host part

Parameters:
url - The url of the directory we want tot create
Returns:
The created directory
Throws:
java.lang.IllegalArgumentException - if there is no root matching the host part of the url

putFile

public VirtualFileHandler putFile(java.net.URL url,
                                  byte[] contents)
Creates a 'file' within the context determined by the url host part

Parameters:
url - The url of the directory we want tot create
contents - The contents of the file
Returns:
The created file
Throws:
java.lang.IllegalArgumentException - if there is no root matching the host part of the url

deleteRoot

public boolean deleteRoot(java.net.URL url)
Deletes a root MemoryContext

Parameters:
url - of the root context we want to delete
Returns:
true if we deleted a root MemoryContext, false otherwise
Throws:
java.lang.IllegalArgumentException - If the url parameter contains a path

delete

public boolean delete(java.net.URL url)
Deletes a 'file' or a 'directory'

Parameters:
url - of the 'file' or 'directory' we want to delete
Returns:
true if we deleted a 'file' or 'directory', false otherwise