org.jboss.virtual.plugins.context.file
Class FileHandler

java.lang.Object
  extended by org.jboss.virtual.plugins.context.AbstractVirtualFileHandler
      extended by org.jboss.virtual.plugins.context.AbstractURLHandler
          extended by org.jboss.virtual.plugins.context.file.FileHandler
All Implemented Interfaces:
Serializable, StructuredVirtualFileHandler, VirtualFileHandler

public class FileHandler
extends AbstractURLHandler
implements StructuredVirtualFileHandler

FileHandler.

Version:
$Revision: 1.1 $
Author:
Adrian Brock, Scott.Stark@jboss.org, Marko Strukelj
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jboss.virtual.plugins.context.AbstractVirtualFileHandler
cachedLastModified, log
 
Constructor Summary
FileHandler(FileSystemContext context, VirtualFileHandler parent, File file, URI uri)
          Create a new FileHandler
FileHandler(FileSystemContext context, VirtualFileHandler parent, File file, URL url)
          Create a new FileHandler.
 
Method Summary
 void cleanup()
          Cleanup resources.
 VirtualFileHandler createChildHandler(String name)
          Create a virtual file context
 boolean delete(int gracePeriod)
          Delete the file represented by this handler.
 boolean exists()
          Basis existence on URLConnection.getLastModified() != 0.
 VirtualFileHandler getChild(String path)
          Get a child
 List<VirtualFileHandler> getChildren(boolean ignoreErrors)
          Get the children
protected  File getFile()
          Get the file for this file handler
 long getLastModified()
          When the file was last modified
 URL getRealURL()
          Get a file: or jar:file: URL representing a resource as precisely as possible.
 long getSize()
          Get the size
 FileSystemContext getVFSContext()
          Get this handler's most outer context (contexts can be mounted one within other).
protected  void initCacheLastModified()
           
protected  void internalReplaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
          Replace original child with unpacked replacement.
 boolean isHidden()
          Whether it is hidden
 boolean isLeaf()
          Whether it is a simple leaf of the VFS, i.e.
 boolean isNested()
          Are we nested in some archive.
 boolean removeChild(String name)
          Remove a child
protected  URL toInternalVfsUrl()
          Get internal representation of vfs url.
 
Methods inherited from class org.jboss.virtual.plugins.context.AbstractURLHandler
getURL, openConnection, openConnection, openStream, toURI, toURL
 
Methods inherited from class org.jboss.virtual.plugins.context.AbstractVirtualFileHandler
checkClosed, checkParentExists, close, decrement, doClose, equals, getChildPathName, getChildVfsUrl, getLocalPathName, getLocalVFSContext, getName, getParent, getPathName, getReferences, getVfsUrl, getVirtualFile, hasBeenModified, hashCode, increment, isArchive, isTemporary, replaceChild, setPathName, setVfsUrl, simpleFindChild, structuredFindChild, toString, toStringLocal, toVfsUrl
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileHandler

public FileHandler(FileSystemContext context,
                   VirtualFileHandler parent,
                   File file,
                   URL url)
            throws IOException
Create a new FileHandler.

Parameters:
context - the context
parent - the parent
file - the file
url - the url
Throws:
IOException - for an error accessing the file system
IllegalArgumentException - for a null context, url

FileHandler

public FileHandler(FileSystemContext context,
                   VirtualFileHandler parent,
                   File file,
                   URI uri)
            throws IOException
Create a new FileHandler

Parameters:
context - the context
parent - the parent
file - the file
uri - the uri
Throws:
IOException - for an error accessing the file system
IllegalArgumentException - for a null context, uri
Method Detail

initCacheLastModified

protected void initCacheLastModified()
Overrides:
initCacheLastModified in class AbstractURLHandler

toInternalVfsUrl

protected URL toInternalVfsUrl()
                        throws MalformedURLException,
                               URISyntaxException
Description copied from class: AbstractVirtualFileHandler
Get internal representation of vfs url.

Overrides:
toInternalVfsUrl in class AbstractVirtualFileHandler
Returns:
the vfs url
Throws:
MalformedURLException - for any error
URISyntaxException - for any error

getRealURL

public URL getRealURL()
               throws IOException,
                      URISyntaxException
Description copied from interface: VirtualFileHandler
Get a file: or jar:file: URL representing a resource as precisely as possible. file: urls can represent files in the file system (i.e.: file:/classes/MyClass.class) jar:file: urls can represent entries within zip archives in the filesystem (i.e.: jar:file:/lib/classes.jar!/MyClass.class) There is no standard URL handler to represent entries within archives that are themselves entries within archives. (i.e.: this doesn't work: jar:file:/lib/app.ear!/classes.jar!/MyClass.class In this case the most precise supported resource locator is: jar:file:/lib/app.ear!/classes.jar )

Specified by:
getRealURL in interface VirtualFileHandler
Overrides:
getRealURL in class AbstractVirtualFileHandler
Returns:
the url
Throws:
MalformedURLException - for any error constructing the URL
URISyntaxException - for an error parsing the URI
IOException

getVFSContext

public FileSystemContext getVFSContext()
Description copied from class: AbstractVirtualFileHandler
Get this handler's most outer context (contexts can be mounted one within other).

Specified by:
getVFSContext in interface VirtualFileHandler
Overrides:
getVFSContext in class AbstractVirtualFileHandler
Returns:
context

getFile

protected File getFile()
Get the file for this file handler

Returns:
the file

getLastModified

public long getLastModified()
Description copied from interface: VirtualFileHandler
When the file was last modified

Specified by:
getLastModified in interface VirtualFileHandler
Overrides:
getLastModified in class AbstractURLHandler
Returns:
the last modified time

exists

public boolean exists()
               throws IOException
Description copied from class: AbstractURLHandler
Basis existence on URLConnection.getLastModified() != 0. This may not be true for all url connections.

Specified by:
exists in interface VirtualFileHandler
Overrides:
exists in class AbstractURLHandler
Returns:
true if the file exists, false otherwise.
Throws:
IOException - - thrown on failure to detect existence.
See Also:
URLConnection.getLastModified(), org.jboss.test.virtual.test.URLExistsUnitTestCase

getSize

public long getSize()
Description copied from interface: VirtualFileHandler
Get the size

Specified by:
getSize in interface VirtualFileHandler
Overrides:
getSize in class AbstractURLHandler
Returns:
the size

isLeaf

public boolean isLeaf()
Description copied from interface: VirtualFileHandler
Whether it is a simple leaf of the VFS, i.e. whether it can contain other files

Specified by:
isLeaf in interface VirtualFileHandler
Returns:
true if a simple file.

isHidden

public boolean isHidden()
Description copied from interface: VirtualFileHandler
Whether it is hidden

Specified by:
isHidden in interface VirtualFileHandler
Overrides:
isHidden in class AbstractURLHandler
Returns:
true if hidden.

isNested

public boolean isNested()
                 throws IOException
Description copied from interface: VirtualFileHandler
Are we nested in some archive.

Specified by:
isNested in interface VirtualFileHandler
Returns:
true if this is archive entry
Throws:
IOException - for any error

cleanup

public void cleanup()
Description copied from interface: VirtualFileHandler
Cleanup resources.

Specified by:
cleanup in interface VirtualFileHandler
Overrides:
cleanup in class AbstractVirtualFileHandler

delete

public boolean delete(int gracePeriod)
               throws IOException
Description copied from class: AbstractVirtualFileHandler
Delete the file represented by this handler. File deletion is comprised of two parts:
  1. physical file deletion - performed by this method or its override
  2. removal of any child references from the parent - performed by VirtualFileHandler.removeChild(String) of the parent
This method doesn't do any physical file removal because it has no concept of underlying physical file. An implementation that does physical file removal should override this method and call super.delete() at the end.

Specified by:
delete in interface VirtualFileHandler
Overrides:
delete in class AbstractVirtualFileHandler
Parameters:
gracePeriod - max time to wait for any locks
Returns:
true if file was deleted, false otherwise
Throws:
IOException - if an error occurs

getChildren

public List<VirtualFileHandler> getChildren(boolean ignoreErrors)
                                     throws IOException
Description copied from interface: VirtualFileHandler
Get the children

Specified by:
getChildren in interface VirtualFileHandler
Parameters:
ignoreErrors - whether to ignore errors
Returns:
the children
Throws:
IOException - for an error accessing the file system

createChildHandler

public VirtualFileHandler createChildHandler(String name)
                                      throws IOException
Description copied from interface: StructuredVirtualFileHandler
Create a virtual file context

Specified by:
createChildHandler in interface StructuredVirtualFileHandler
Parameters:
name - the name
Returns:
the handler
Throws:
IOException - for any error accessing the virtual file system

getChild

public VirtualFileHandler getChild(String path)
                            throws IOException
Description copied from interface: VirtualFileHandler
Get a child

Specified by:
getChild in interface VirtualFileHandler
Parameters:
path - the path
Returns:
the child or null if not found
Throws:
IOException - for an error accessing the file system

removeChild

public boolean removeChild(String name)
                    throws IOException
Description copied from interface: VirtualFileHandler
Remove a child

Specified by:
removeChild in interface VirtualFileHandler
Parameters:
name - child name
Returns:
true if child was removed, false otherwise
Throws:
IOException - if an error occurs

internalReplaceChild

protected void internalReplaceChild(VirtualFileHandler original,
                                    VirtualFileHandler replacement)
Description copied from class: AbstractVirtualFileHandler
Replace original child with unpacked replacement.

Overrides:
internalReplaceChild in class AbstractVirtualFileHandler
Parameters:
original - the original
replacement - the replacement


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