com.caucho.vfs
Class MergePath

java.lang.Object
  |
  +--com.caucho.vfs.Path
        |
        +--com.caucho.vfs.FilesystemPath
              |
              +--com.caucho.vfs.MergePath

public class MergePath
extends FilesystemPath

A merging of several Paths used like a CLASSPATH. When the MergePath is opened, the first path in the list which contains the file will be the opened file.

In the following example, "first" has priority over "second". If test.xml exists in both "first" and "second", the open will return "first/test.xml".

 MergePage merge = new MergePath();
 merge.addMergePath(Vfs.lookup("first");
 merge.addMergePath(Vfs.lookup("second");

 Path path = merge.lookup("test.xml");
 ReadStream is = path.openRead();
 

Since:
Resin 1.2

Fields inherited from class com.caucho.vfs.FilesystemPath
bindRoot, pathname, root, separatorChar, userPath
 
Fields inherited from class com.caucho.vfs.Path
L, schemeMap
 
Constructor Summary
MergePath()
          Creates a new merge path.
 
Method Summary
 void addClassPath(java.lang.ClassLoader loader)
          Adds the classpath for the loader as paths in the MergePath.
 void addMergePath(Path path)
          Adds a new path to the end of the merge path.
 boolean canRead()
          Returns true if the best path can be read.
 boolean canWrite()
          Returns true if the best path can be written to.
 boolean equals(java.lang.Object b)
          Returns true if the best path matches b's best path.
 boolean exists()
          True if any file matching this path exists.
protected  Path fsWalk(java.lang.String userPath, java.util.Map attributes, java.lang.String path)
          Walking down the path just extends the path.
 java.lang.String getFullPath()
          Returns the full path name of the best path.
 long getLastModified()
          Returns the last modified time of the best path.
 long getLength()
          Returns the length of the best path.
 java.util.ArrayList getMergePaths()
          Return the list of paths searched in the merge path.
 java.lang.String getScheme()
          Returns the scheme of the best path.
 int hashCode()
          Returns the hashCode of the best path.
 boolean isDirectory()
          True if the best path is a directory.
 boolean isFile()
          True if the best path is a file.
 java.lang.String[] list()
          Should list the merged directories, but not implemented yet.
 boolean mkdir()
          XXX: Probably should mkdir in the first path
 boolean mkdirs()
          XXX: Probably should mkdir in the first path
 StreamImpl openAppendImpl()
          Opens the best path for appending.
 StreamImpl openReadImpl()
          Opens the best path for reading.
 StreamImpl openReadWriteImpl()
          Opens the best path for reading and writing.
 StreamImpl openWriteImpl()
          Opens the best path for writing.
 boolean remove()
          Remove the matching path.
 boolean renameTo(Path path)
          Renames the path.
 java.lang.String toString()
          Returns a name for the path
 
Methods inherited from class com.caucho.vfs.FilesystemPath
bind, copy, createRoot, getParent, getPath, getTail, getURL, getUserPath, normalizePath, normalizePath, schemeWalk, setUserPath
 
Methods inherited from class com.caucho.vfs.Path
createNewFile, createRoot, createTempFile, getAttribute, getAttributeNames, getContentType, getHost, getNativePath, getObject, getPort, getQuery, getValue, isObject, iterator, lookup, lookup, lookupNative, lookupNative, openAppend, openRead, openReadWrite, openWrite, removeAttribute, renameTo, scanScheme, setAttribute, setLastModified, setObject, setValue, unbind, writeToStream
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MergePath

public MergePath()
Creates a new merge path.
Method Detail

addMergePath

public void addMergePath(Path path)
Adds a new path to the end of the merge path.
Parameters:
path - the new path to search

addClassPath

public void addClassPath(java.lang.ClassLoader loader)
Adds the classpath for the loader as paths in the MergePath.
Parameters:
loader - class loader whose classpath should be used to search.

getMergePaths

public java.util.ArrayList getMergePaths()
Return the list of paths searched in the merge path.

fsWalk

protected Path fsWalk(java.lang.String userPath,
                      java.util.Map attributes,
                      java.lang.String path)
Walking down the path just extends the path. It won't be evaluated until opening.
Overrides:
fsWalk in class FilesystemPath
Following copied from class: com.caucho.vfs.FilesystemPath
Parameters:
userPath - the exact string passed by the user's lookup()
newAttributes - the user's new attributes
newPath - the normalized real path
Returns:
the matching path

getScheme

public java.lang.String getScheme()
Returns the scheme of the best path.
Overrides:
getScheme in class Path

getFullPath

public java.lang.String getFullPath()
Returns the full path name of the best path.
Overrides:
getFullPath in class FilesystemPath

exists

public boolean exists()
True if any file matching this path exists.
Overrides:
exists in class Path

isDirectory

public boolean isDirectory()
True if the best path is a directory.
Overrides:
isDirectory in class Path

isFile

public boolean isFile()
True if the best path is a file.
Overrides:
isFile in class Path

getLength

public long getLength()
Returns the length of the best path.
Overrides:
getLength in class Path
Following copied from class: com.caucho.vfs.Path
Returns:
0 for non-files

getLastModified

public long getLastModified()
Returns the last modified time of the best path.
Overrides:
getLastModified in class Path
Following copied from class: com.caucho.vfs.Path
Returns:
0 for non-files.

canRead

public boolean canRead()
Returns true if the best path can be read.
Overrides:
canRead in class Path

canWrite

public boolean canWrite()
Returns true if the best path can be written to.
Overrides:
canWrite in class Path

list

public java.lang.String[] list()
                        throws java.io.IOException
Should list the merged directories, but not implemented yet. Right now, just lists the best directory.
Overrides:
list in class Path
Following copied from class: com.caucho.vfs.Path
Returns:
The contents of this directory or null if the path does not refer to a directory.

mkdir

public boolean mkdir()
              throws java.io.IOException
XXX: Probably should mkdir in the first path
Overrides:
mkdir in class Path
Following copied from class: com.caucho.vfs.Path
Returns:
true if successful.

mkdirs

public boolean mkdirs()
               throws java.io.IOException
XXX: Probably should mkdir in the first path
Overrides:
mkdirs in class Path
Following copied from class: com.caucho.vfs.Path
Returns:
true if successful.

remove

public boolean remove()
               throws java.io.IOException
Remove the matching path.
Overrides:
remove in class Path
Following copied from class: com.caucho.vfs.Path
Returns:
true if successful.

renameTo

public boolean renameTo(Path path)
                 throws java.io.IOException
Renames the path.
Overrides:
renameTo in class Path
Following copied from class: com.caucho.vfs.Path
Returns:
true if successful

openReadImpl

public StreamImpl openReadImpl()
                        throws java.io.IOException
Opens the best path for reading.
Overrides:
openReadImpl in class Path

openWriteImpl

public StreamImpl openWriteImpl()
                         throws java.io.IOException
Opens the best path for writing. XXX: If the best path doesn't exist, this should probably create the file in the first path.
Overrides:
openWriteImpl in class Path

openReadWriteImpl

public StreamImpl openReadWriteImpl()
                             throws java.io.IOException
Opens the best path for reading and writing. XXX: If the best path doesn't exist, this should probably create the file in the first path.
Overrides:
openReadWriteImpl in class Path

openAppendImpl

public StreamImpl openAppendImpl()
                          throws java.io.IOException
Opens the best path for appending. XXX: If the best path doesn't exist, this should probably create the file in the first path.
Overrides:
openAppendImpl in class Path

hashCode

public int hashCode()
Returns the hashCode of the best path.
Overrides:
hashCode in class FilesystemPath

equals

public boolean equals(java.lang.Object b)
Returns true if the best path matches b's best path.
Overrides:
equals in class FilesystemPath

toString

public java.lang.String toString()
Returns a name for the path
Overrides:
toString in class FilesystemPath