org.jboss.virtual.plugins.context
Class AbstractVirtualFileHandler

java.lang.Object
  extended by org.jboss.virtual.plugins.context.AbstractVirtualFileHandler
All Implemented Interfaces:
Serializable, VirtualFileHandler
Direct Known Subclasses:
AbstractURIHandler, AbstractURLHandler, AssembledDirectoryHandler, ByteArrayHandler, DelegatingHandler, ZipEntryHandler

public abstract class AbstractVirtualFileHandler
extends Object
implements VirtualFileHandler

AbstractVirtualFileHandler.

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

Field Summary
protected  long cachedLastModified
          The cached last modified
protected static org.jboss.logging.Logger log
          The log
 
Constructor Summary
protected AbstractVirtualFileHandler(VFSContext context, VirtualFileHandler parent, String name)
          Create a new handler
 
Method Summary
protected  void checkClosed()
          Check whether we are closed
protected  void checkParentExists()
          Check if parent exists.
 void cleanup()
          Cleanup resources.
 void close()
          Close the resources
protected  int decrement()
          Decrement the reference count
 boolean delete(int gracePeriod)
          Delete the file represented by this handler.
protected  void doClose()
          The real close
 boolean equals(Object obj)
           
protected  String getChildPathName(String childPath, boolean isDirectory)
          Get child path name.
protected  URL getChildVfsUrl(String childPath, boolean isDirectory)
          Get child url.
 String getLocalPathName()
          Get a pathName relative to local context
 VFSContext getLocalVFSContext()
          Get this handler's local context
 String getName()
          Get the simple VF name (X.java)
 VirtualFileHandler getParent()
          Get this handler's parent.
 String getPathName()
          Get a pathName relative to most outer context (contexts can be mounted one within other)
 URL getRealURL()
          Get a file: or jar:file: URL representing a resource as precisely as possible.
protected  int getReferences()
          Get the references count.
 VFSContext getVFSContext()
          Get this handler's most outer context (contexts can be mounted one within other).
protected  URL getVfsUrl()
          Get VFS url.
 VirtualFile getVirtualFile()
          Get the virtual file wrapper
 boolean hasBeenModified()
          Returns true if the file has been modified since this method was last called Last modified time is initialized at handler instantiation.
 int hashCode()
           
protected  int increment()
          Increment the reference count
protected  void internalReplaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
          Replace original child with unpacked replacement.
 boolean isArchive()
          Does this represent an archive.
protected  boolean isTemporary()
          Is the handler temporary.
 void replaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
          Replace child.
 void setPathName(String path)
          todo This is a hack until we can fix http://jira.jboss.com/jira/browse/JBMICROCONT-164
protected  void setVfsUrl(URL vfsUrl)
          Set the vfs URL.
 VirtualFileHandler simpleFindChild(String path)
          Simple implementation of findChild
 VirtualFileHandler structuredFindChild(String path)
          Structured implementation of get child
protected  URL toInternalVfsUrl()
          Get internal representation of vfs url.
 String toString()
           
 String toStringLocal()
           
 URL toURL()
          Get the VF URL (file://root/org/jboss/X.java)
 URL toVfsUrl()
          Get a VFS-based URL
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jboss.virtual.spi.VirtualFileHandler
exists, getChild, getChildren, getLastModified, getSize, isHidden, isLeaf, isNested, openStream, removeChild, toURI
 

Field Detail

log

protected static final org.jboss.logging.Logger log
The log


cachedLastModified

protected transient long cachedLastModified
The cached last modified

Constructor Detail

AbstractVirtualFileHandler

protected AbstractVirtualFileHandler(VFSContext context,
                                     VirtualFileHandler parent,
                                     String name)
Create a new handler

Parameters:
context - the context
parent - the parent
name - the name
Throws:
IllegalArgumentException - if the context or name is null;
Method Detail

checkParentExists

protected void checkParentExists()
Check if parent exists.


getChildVfsUrl

protected URL getChildVfsUrl(String childPath,
                             boolean isDirectory)
                      throws IOException,
                             URISyntaxException
Get child url.

Parameters:
childPath - the child path
isDirectory - is directory
Returns:
full child URL
Throws:
IOException - for any io error
URISyntaxException - for any uri error

getChildPathName

protected String getChildPathName(String childPath,
                                  boolean isDirectory)
                           throws IOException
Get child path name.

Parameters:
childPath - the child path
isDirectory - is directory
Returns:
full child URL
Throws:
IOException - for any io error

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
Returns:
true if archive, false otherwise
Throws:
IOException - for any problem accessing the virtual file system

hasBeenModified

public boolean hasBeenModified()
                        throws IOException
Description copied from interface: VirtualFileHandler
Returns true if the file has been modified since this method was last called Last modified time is initialized at handler instantiation.

Specified by:
hasBeenModified in interface VirtualFileHandler
Returns:
true if modified, false otherwise
Throws:
IOException - for any error

getName

public String getName()
Description copied from interface: VirtualFileHandler
Get the simple VF name (X.java)

Specified by:
getName in interface VirtualFileHandler
Returns:
the simple file name

getPathName

public String getPathName()
Get a pathName relative to most outer context (contexts can be mounted one within other)

Specified by:
getPathName in interface VirtualFileHandler
Returns:
pathName

setPathName

public void setPathName(String path)
todo This is a hack until we can fix http://jira.jboss.com/jira/browse/JBMICROCONT-164

Parameters:
path - the path name

getLocalPathName

public String getLocalPathName()
Get a pathName relative to local context

Specified by:
getLocalPathName in interface VirtualFileHandler
Returns:
pathName

toURL

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

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

toVfsUrl

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

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

toInternalVfsUrl

protected URL toInternalVfsUrl()
                        throws MalformedURLException,
                               URISyntaxException
Get internal representation of vfs url.

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
Returns:
the url
Throws:
MalformedURLException - for any error constructing the URL
URISyntaxException - for an error parsing the URI
IOException

getVfsUrl

protected URL getVfsUrl()
Get VFS url.

Returns:
vfs url

setVfsUrl

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

Parameters:
vfsUrl - vfs url

getVirtualFile

public VirtualFile getVirtualFile()
Description copied from interface: VirtualFileHandler
Get the virtual file wrapper

Specified by:
getVirtualFile in interface VirtualFileHandler
Returns:
the wrapper

getParent

public VirtualFileHandler getParent()
                             throws IOException
Get this handler's parent. If this handler represents a root of the context mounted within another context a parent from the outer context will be returned.

Specified by:
getParent in interface VirtualFileHandler
Returns:
parent handler
Throws:
IOException - for any error

getVFSContext

public VFSContext getVFSContext()
Get this handler's most outer context (contexts can be mounted one within other).

Specified by:
getVFSContext in interface VirtualFileHandler
Returns:
context

getLocalVFSContext

public VFSContext getLocalVFSContext()
Get this handler's local context

Returns:
context

increment

protected int increment()
Increment the reference count

Returns:
the resulting count

decrement

protected int decrement()
Decrement the reference count

Returns:
the resulting count

checkClosed

protected void checkClosed()
                    throws IllegalStateException
Check whether we are closed

Throws:
IllegalStateException - when closed

getReferences

protected int getReferences()
Get the references count.

Returns:
the ref count

cleanup

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

Specified by:
cleanup in interface VirtualFileHandler

isTemporary

protected boolean isTemporary()
Is the handler temporary.

Returns:
true if temporary, false otherwise

close

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

Specified by:
close in interface VirtualFileHandler

doClose

protected void doClose()
The real close


delete

public boolean delete(int gracePeriod)
               throws IOException
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
Parameters:
gracePeriod - max time to wait for any locks
Returns:
true if file was deleted, false otherwise
Throws:
IOException - if an error occurs

structuredFindChild

public VirtualFileHandler structuredFindChild(String path)
                                       throws IOException
Structured implementation of get child

Parameters:
path - the path
Returns:
the handler or null if it doesn't exist
Throws:
IOException - for any error accessing the virtual file system
IllegalArgumentException - for a null name

simpleFindChild

public VirtualFileHandler simpleFindChild(String path)
                                   throws IOException
Simple implementation of findChild

Parameters:
path - the path
Returns:
the handler
Throws:
IOException - for any error accessing the virtual file system
IllegalArgumentException - for a null name

replaceChild

public void replaceChild(VirtualFileHandler original,
                         VirtualFileHandler replacement)
Description copied from interface: VirtualFileHandler
Replace child.

Specified by:
replaceChild in interface VirtualFileHandler
Parameters:
original - the original
replacement - the replacement

internalReplaceChild

protected void internalReplaceChild(VirtualFileHandler original,
                                    VirtualFileHandler replacement)
Replace original child with unpacked replacement.

Parameters:
original - the original
replacement - the replacement

toString

public String toString()
Overrides:
toString in class Object

toStringLocal

public String toStringLocal()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


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