org.jboss.virtual.plugins.context
Class DelegatingHandler

java.lang.Object
  extended by org.jboss.virtual.plugins.context.AbstractVirtualFileHandler
      extended by org.jboss.virtual.plugins.context.DelegatingHandler
All Implemented Interfaces:
Serializable, VirtualFileHandler
Direct Known Subclasses:
AssembledFileHandler, ReplacementHandler

public class DelegatingHandler
extends AbstractVirtualFileHandler

A delegating VirtualFileHandler that allows for overriding the delegate parent and name. One usecase is a link which roots another VFSContext under a different parent and name.

Version:
$Revision:$
Author:
Scott.Stark@jboss.org, Ales.Justin@jboss.org
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jboss.virtual.plugins.context.AbstractVirtualFileHandler
cachedLastModified, log
 
Constructor Summary
DelegatingHandler(VFSContext context, VirtualFileHandler parent, String name)
          Create a DelegatingHandler without a delegate - which will have to be set afterwards
DelegatingHandler(VFSContext context, VirtualFileHandler parent, String name, VirtualFileHandler delegate)
          Create a DelegatingHandler
 
Method Summary
 void cleanup()
          Cleanup resources.
 void close()
          Close the resources
 boolean delete(int gracePeriod)
          Delete the file represented by this handler.
 boolean equals(Object o)
           
 boolean exists()
          Tests whether the underlying implementation file still exists.
 VirtualFileHandler getChild(String path)
          Get a child
 List<VirtualFileHandler> getChildren(boolean ignoreErrors)
          Get the children
 VirtualFileHandler getDelegate()
           
 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
 int hashCode()
           
protected  void internalReplaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
          Replace original child with unpacked replacement.
 boolean isArchive()
          Does this represent an archive.
 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.
 InputStream openStream()
          Access the file contents.
 boolean removeChild(String path)
          Remove a child
 void setDelegate(VirtualFileHandler handler)
           
protected  void setVfsUrl(URL vfsUrl)
          Set the vfs url.
 URI toURI()
          Get the VF URI (file://root/org/jboss/X.java)
 URL toURL()
          Get the VF URL (file://root/org/jboss/X.java)
 URL toVfsUrl()
          Get a VFS-based URL
 
Methods inherited from class org.jboss.virtual.plugins.context.AbstractVirtualFileHandler
checkClosed, checkParentExists, decrement, doClose, getChildPathName, getChildVfsUrl, getLocalPathName, getLocalVFSContext, getName, getParent, getPathName, getReferences, getVFSContext, getVfsUrl, getVirtualFile, hasBeenModified, increment, isTemporary, replaceChild, setPathName, simpleFindChild, structuredFindChild, toInternalVfsUrl, toString, toStringLocal
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DelegatingHandler

public DelegatingHandler(VFSContext context,
                         VirtualFileHandler parent,
                         String name)
Create a DelegatingHandler without a delegate - which will have to be set afterwards

Parameters:
context - - the context for the parent
parent - - the parent of the delegate in this VFS
name - - the name of the delegate in this VFS

DelegatingHandler

public DelegatingHandler(VFSContext context,
                         VirtualFileHandler parent,
                         String name,
                         VirtualFileHandler delegate)
Create a DelegatingHandler

Parameters:
context - - the context for the parent
parent - - the parent of the delegate in this VFS
name - - the name of the delegate in this VFS
delegate - - the handler delegate
Method Detail

setDelegate

public void setDelegate(VirtualFileHandler handler)

getDelegate

public VirtualFileHandler getDelegate()

setVfsUrl

protected void setVfsUrl(URL vfsUrl)
Set the vfs url.

Overrides:
setVfsUrl in class AbstractVirtualFileHandler
Parameters:
vfsUrl - the vfs url

getChild

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

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 path)
                    throws IOException
Description copied from interface: VirtualFileHandler
Remove a child

Parameters:
path - child name
Returns:
true if child was removed, 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

Parameters:
ignoreErrors - whether to ignore errors
Returns:
the children
Throws:
IOException - for an error accessing the file system

getLastModified

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

Returns:
the last modified time
Throws:
IOException - for any problem accessing the virtual file system

getSize

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

Returns:
the size
Throws:
IOException - for any problem accessing the virtual file system

isLeaf

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

Returns:
true if a simple file.
Throws:
IOException - for any problem accessing the virtual file system

isArchive

public boolean isArchive()
                  throws IOException
Description copied from interface: VirtualFileHandler
Does this represent an archive. e.g. zip, tar, ...

Specified by:
isArchive in interface VirtualFileHandler
Overrides:
isArchive in class AbstractVirtualFileHandler
Returns:
true if archive, false otherwise
Throws:
IOException - for any problem accessing the virtual file system

exists

public boolean exists()
               throws IOException
Description copied from interface: VirtualFileHandler
Tests whether the underlying implementation file still exists.

Returns:
true if the file exists, false otherwise.
Throws:
IOException - - thrown on failure to detect existence.

isHidden

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

Returns:
true if hidden.
Throws:
IOException - for any problem accessing the virtual file system

isNested

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

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

close

public void close()
Description copied from interface: VirtualFileHandler
Close the resources

Specified by:
close in interface VirtualFileHandler
Overrides:
close 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

openStream

public InputStream openStream()
                       throws IOException
Description copied from interface: VirtualFileHandler
Access the file contents.

Returns:
An InputStream for the file contents.
Throws:
IOException - for any problem accessing the virtual file system

toURI

public URI toURI()
          throws URISyntaxException
Description copied from interface: VirtualFileHandler
Get the VF URI (file://root/org/jboss/X.java)

Returns:
the full URI to the VF in the VFS.
Throws:
URISyntaxException - for an error parsing the URI

toURL

public URL toURL()
          throws URISyntaxException,
                 MalformedURLException
Description copied from interface: VirtualFileHandler
Get the VF URL (file://root/org/jboss/X.java)

Specified by:
toURL in interface VirtualFileHandler
Overrides:
toURL in class AbstractVirtualFileHandler
Returns:
the full URL to the VF in the VFS.
Throws:
URISyntaxException - for an error parsing the URI
MalformedURLException - for any error

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

toVfsUrl

public URL toVfsUrl()
             throws MalformedURLException,
                    URISyntaxException
Description copied from interface: VirtualFileHandler
Get a VFS-based URL

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

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

hashCode

public int hashCode()
Overrides:
hashCode in class AbstractVirtualFileHandler

equals

public boolean equals(Object o)
Overrides:
equals in class AbstractVirtualFileHandler


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