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 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
 VirtualFile createDirectory(URL url)
          Creates a 'directory' within the context determined by the url host part
 VFSContext createRoot(URL url)
          Creates a new root MemoryContext, or returns an already exixting one of one already exists for the name
 boolean delete(URL url)
          Deletes a 'file' or a 'directory'
 boolean deleteRoot(URL url)
          Deletes a root MemoryContext
 VFS find(String host)
          Gets hold of a root MemoryContext
static MemoryContextFactory getInstance()
          Gets the singleton instance
 String[] getProtocols()
          Get the URL protocols/URI schemes this factory supports
 VFSContext getVFS(URI rootURI)
          Obtain a vfs context for the given root uri.
 VFSContext getVFS(URL rootURL)
          Obtain a vfs context for the given root url.
protected static boolean isValidRootURL(URL url)
          Is url valid root url.
 VirtualFile putFile(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 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(URL rootURL)
                  throws 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:
IOException - - thrown if the root cannot be opened/accessed

getVFS

public VFSContext getVFS(URI rootURI)
                  throws 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:
IOException - - thrown if the root cannot be opened/accessed

find

public VFS find(String host)
Gets hold of a root MemoryContext

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

isValidRootURL

protected static boolean isValidRootURL(URL url)
Is url valid root url.

Parameters:
url - the url to check
Returns:
true if url is root url

createRoot

public VFSContext createRoot(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:
IllegalArgumentException - If the url parameter contains a path

createDirectory

public VirtualFile createDirectory(URL url)
Creates a 'directory' within the context determined by the url host part

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

putFile

public VirtualFile putFile(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 to create
contents - The contents of the file
Returns:
The created file
Throws:
IllegalArgumentException - if there is no root matching the host part of the url

deleteRoot

public boolean deleteRoot(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:
IllegalArgumentException - If the url parameter contains a path

delete

public boolean delete(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


Copyright © 2009 JBoss, A division of Red Hat, Inc. All Rights Reserved.