com.caucho.vfs
Class MergePath

java.lang.Object
  extended by com.caucho.vfs.Path
      extended by com.caucho.vfs.FilesystemPath
          extended by com.caucho.vfs.MergePath
All Implemented Interfaces:
java.lang.Comparable<Path>

public class MergePath
extends FilesystemPath

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

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();
 

MergePath corresponds to the "merge:" Vfs schema

   Path path = Vfs.lookup("merge:(../custom-foo;foo)");
 

Since:
Resin 1.2, Resin 3.0.10 merge: schema

Field Summary
 
Fields inherited from class com.caucho.vfs.FilesystemPath
_bindRoot, _pathname, _root, _userPath
 
Fields inherited from class com.caucho.vfs.Path
_pathSeparatorChar, _schemeMap, _separatorChar, L
 
Constructor Summary
MergePath()
          Creates a new merge path.
 
Method Summary
 void addClassPath()
          Adds the classpath as paths in the MergePath.
 void addClassPath(java.lang.ClassLoader loader)
          Adds the classpath for the loader as paths in the MergePath.
 void addClassPath(java.lang.String classpath)
          Adds the classpath for the loader as paths in the MergePath.
 void addLocalClassPath()
          Adds the classpath as paths in the MergePath.
 void addLocalClassPath(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.
 void addResourceClassPath(java.lang.ClassLoader loader)
          Adds the classpath for the loader as paths in the MergePath.
 boolean canRead()
          Returns true if the best path can be read.
 boolean canWrite()
          Returns true if the best path can be written to.
 PersistentDependency createDepend()
          Creates a dependency.
 boolean exists()
          True if any file matching this path exists.
 Path fsWalk(java.lang.String userPath, java.util.Map<java.lang.String,java.lang.Object> attributes, java.lang.String path)
          Walking down the path just extends the path.
 Path getBestPath()
          Returns the first matching 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<Path> getMergePaths()
          Return the list of paths searched in the merge path.
 java.lang.String getNativePath()
          Returns the full native path name of the best path.
 java.lang.String getRelativePath()
          Returns the relative path into the merge path.
 java.util.ArrayList<Path> getResources()
          Returns all the resources matching the path.
 java.util.ArrayList<Path> getResources(java.lang.String pathName)
          Returns all the resources matching the path.
 java.lang.String getScheme()
          Returns the scheme of the best path.
 java.lang.String getURL()
          Returns the URL of the best path.
 Path getWritePath()
          Returns the first matching 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()
          List the merged directories.
 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.
 Path schemeWalk(java.lang.String userPath, java.util.Map<java.lang.String,java.lang.Object> attributes, java.lang.String filePath, int offset)
          schemeWalk is called by Path for a scheme lookup like file:/tmp/foo
 java.lang.String toString()
          Returns a name for the path
 
Methods inherited from class com.caucho.vfs.FilesystemPath
bind, createRoot, equals, getParent, getPath, getRoot, getTail, getUserPath, hashCode, normalizePath, normalizePath, setUserPath
 
Methods inherited from class com.caucho.vfs.Path
cacheCopy, canExecute, changeGroup, changeGroup, changeOwner, changeOwner, chmod, clearStatusCache, compareTo, copy, createLink, createNewFile, createRoot, createTempFile, escapeURL, getAttribute, getAttributeNames, getBlockCount, getBlockSize, getCache, getCertificates, getContentType, getCrc64, getCreateTime, getDevice, getDeviceId, getDiskSpaceFree, getDiskSpaceTotal, getFileSeparatorChar, getGroup, getHost, getInode, getLastAccessTime, getLastStatusChangeTime, getMode, getNewlineString, getNumberOfLinks, getObject, getOwner, getPathSeparatorChar, getPort, getQuery, getSchemeMap, getSeparatorChar, getUser, getUserDir, getValue, isBlockDevice, isCharacterDevice, isExecutable, isFIFO, isHardLink, isLink, isObject, isPathCacheable, isSocket, isSymbolicLink, isWindows, isWindowsInsecure, iterator, lookup, lookup, lookup, lookupImpl, lookupNative, lookupNative, lookupRelativeNativePath, openAppend, openFileRandomAccess, openMemoryMappedFile, openRandomAccess, openRead, openReadWrite, openReadWrite, openReadWrite, openWrite, putCache, readLink, realPath, removeAll, renameTo, scanScheme, setDefaultSchemeMap, setExecutable, setLastModified, setObject, setTestWindows, setValue, truncate, truncate, unbind, writeToStream, 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

schemeWalk

public Path schemeWalk(java.lang.String userPath,
                       java.util.Map<java.lang.String,java.lang.Object> attributes,
                       java.lang.String filePath,
                       int offset)
schemeWalk is called by Path for a scheme lookup like file:/tmp/foo

Overrides:
schemeWalk in class FilesystemPath
Parameters:
userPath - the user's lookup() path
attributes - the user's attributes
filePath - the actual lookup() path
offset - offset into filePath
Returns:
the found path

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()
Adds the classpath as paths in the MergePath.


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.

addResourceClassPath

public void addResourceClassPath(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.

addLocalClassPath

public void addLocalClassPath()
Adds the classpath as paths in the MergePath.


addLocalClassPath

public void addLocalClassPath(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.

addClassPath

public void addClassPath(java.lang.String classpath)
Adds the classpath for the loader as paths in the MergePath.

Parameters:
classpath - class loader whose classpath should be used to search.

getMergePaths

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


fsWalk

public Path fsWalk(java.lang.String userPath,
                   java.util.Map<java.lang.String,java.lang.Object> attributes,
                   java.lang.String path)
Walking down the path just extends the path. It won't be evaluated until opening.

Specified by:
fsWalk in class FilesystemPath
Parameters:
userPath - the exact string passed by the user's lookup()
attributes - the user's new attributes
path - the normalized real path
Returns:
the matching path

getScheme

public java.lang.String getScheme()
Returns the scheme of the best path.

Specified by:
getScheme in class Path

getFullPath

public java.lang.String getFullPath()
Returns the full path name of the best path.

Overrides:
getFullPath in class FilesystemPath

getNativePath

public java.lang.String getNativePath()
Returns the full native path name of the best path.

Overrides:
getNativePath in class Path

getURL

public java.lang.String getURL()
Returns the URL of the best path.

Overrides:
getURL in class Path

getRelativePath

public java.lang.String getRelativePath()
Returns the relative path into the merge path.

Overrides:
getRelativePath in class Path

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
Returns:
0 for non-files

getLastModified

public long getLastModified()
Returns the last modified time of the best path.

Overrides:
getLastModified in class 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

getResources

public java.util.ArrayList<Path> getResources(java.lang.String pathName)
Returns all the resources matching the path.

Overrides:
getResources in class Path

getResources

public java.util.ArrayList<Path> getResources()
Returns all the resources matching the path.

Overrides:
getResources in class Path

list

public java.lang.String[] list()
                        throws java.io.IOException
List the merged directories.

Overrides:
list in class Path
Returns:
The contents of this directory or null if the path does not refer to a directory.
Throws:
java.io.IOException

mkdir

public boolean mkdir()
              throws java.io.IOException
XXX: Probably should mkdir in the first path

Overrides:
mkdir in class Path
Returns:
true if successful.
Throws:
java.io.IOException

mkdirs

public boolean mkdirs()
               throws java.io.IOException
XXX: Probably should mkdir in the first path

Overrides:
mkdirs in class Path
Returns:
true if successful.
Throws:
java.io.IOException

remove

public boolean remove()
               throws java.io.IOException
Remove the matching path.

Overrides:
remove in class Path
Returns:
true if successful
Throws:
java.io.IOException

renameTo

public boolean renameTo(Path path)
                 throws java.io.IOException
Renames the path.

Overrides:
renameTo in class Path
Returns:
true if successful
Throws:
java.io.IOException

openReadImpl

public StreamImpl openReadImpl()
                        throws java.io.IOException
Opens the best path for reading.

Overrides:
openReadImpl in class Path
Throws:
java.io.IOException

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
Throws:
java.io.IOException

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
Throws:
java.io.IOException

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
Throws:
java.io.IOException

getWritePath

public Path getWritePath()
Returns the first matching path.


createDepend

public PersistentDependency createDepend()
Creates a dependency.

Overrides:
createDepend in class Path

getBestPath

public Path getBestPath()
Returns the first matching path.


toString

public java.lang.String toString()
Returns a name for the path

Overrides:
toString in class Path