public abstract class LexURIFile
extends java.lang.Object
Some example URIs are:
Since a SchemeFile represents a file or directory, this abstract class is based on the methods in the java.io.File class with some additional methods.
The implementing class must extend the LexURIFile class and implement all abstract classes.
VersaLex URI File System Interface Description
VLTrader and Harmony have has a method for accessing files using java code outside of the typical VersaLex jars. These custom-written classes are accessed based on the scheme at the start of the URI found in a host Inbox / Outbox or the source / destination specified in an action. A file system type URI may also be used for local user folders.
The Java classes that are called are configured in system properties.
These properties are typically configured with -D parameters. These system
properties can also be configured in the system.properties file
found in the conf/ folder under VersaLex. When VersaLex detects
a URI, it will check if associated classes have been configured for that
scheme.
Four system properties are used to configure a single scheme. The property name is all lowercase including the scheme name. The property values are mixed case.
| System Property | Required | Description |
|---|---|---|
| cleo.uri.scheme.file | Yes | This property defines the custom class to be used as the File
object. This custom class must extend
cleo.lexicom.beans.LexURIFile. LexURIFile is an abstract
class that extends
java.io.File.
The suggested class name for this class is
com.companyabc.scheme.SchemeFile.
The schemeFile class must implement two constructors:
|
| cleo.uri.scheme.inputstream | Yes | This property defines the custom class to be used for the
InputStream object. This custom class must extend
java.io.InputStream.
The SchemeInputStream class must implement one constructor:
The SchemeInputStream class must override all the java.io.InputStream methods:
The suggested class name for this class is com.companyabc.scheme.SchemeInputStream. |
| cleo.uri.scheme.outputstream | Yes | This property defines the custom class to be used for the
OutputStream object. This custom class must extend
java.io.OutputStream.
The SchemeOutputStream class must implement one constructor:
The SchemeOutputStream class must override all the java.io.OutputStream methods: The suggested class name for this class is com.companyabc.scheme.SchemeOutputStream. |
| cleo.uri.scheme.classpath | No | This property defines the Java class path to the jars containing this scheme implementation. It can also contain any other jars needed for this scheme. The jar file(s) can be in any location accessible by the VersaLex application. If you wish to locate the jars within the VersaLex software installation folder, the suggested location is the lib\uri\ folder under the VersaLex installation folder. A separate class loader is used for each scheme. If certain jar files need to be loaded by the base class loader (such as GlassFish jar files for the JMS scheme), then these jars should be specified using the system property cleo.additional.classpath (see below). |
Example: For the hdfs scheme, the system properties could be defined using the following command line parameters
An additional system property can be used to configure other jar files that need to be included the base class path.
| System Property | Required | Description |
|---|---|---|
| cleo.additional.classpath | No | This property defines a list of additional JAR files that need to be included the base class path. These classes will be appended to the end of the VersaLex class path. The JAR file paths are separated by the path separator character. On UNIX systems, this character is ':' and on Microsoft Windows systems it is ';'. |
Example: For a JMS scheme using GlassFish, the system property could be defined using the following command line parameter
| Constructor and Description |
|---|
LexURIFile(java.lang.String uri)
Creates a LexURIFile object using the provided URI.
|
LexURIFile(java.lang.String parentURI,
java.lang.String child)
Creates a LexURIFile object using the provided parent URI and child.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canBeLocalUserRoot()
Returns whether or not this scheme can be used as a Local User Root.
|
abstract boolean |
canRead()
Tests whether the application can read the directory or file represented
by this SchemeFile.
|
abstract boolean |
canWrite()
Tests whether the application can modify the directory or file represented
by this SchemeFile.
|
abstract int |
compareTo(LexURIFile pathname)
Compares the URIs of two LexURIFiles lexicographically.
|
abstract boolean |
createNewFile()
Creates a new, empty file named by this SchemeFile if and only if
a file with this name does not yet exist.
|
static void |
debug(boolean always,
java.lang.String message)
Writes a message to the VersaLex debug file.
|
static void |
debug(boolean always,
java.lang.String message,
java.lang.Throwable ex)
Writes a message and exception to the VersaLex debug file.
|
static void |
debug(java.lang.String message)
Writes a message to the VersaLex debug file.
|
static void |
debug(java.lang.String message,
java.lang.Throwable ex)
Writes a message and exception to the VersaLex debug file.
|
static void |
debugWriter(java.lang.String message,
java.lang.Throwable ex) |
abstract boolean |
delete()
Deletes the file.
|
abstract boolean |
equals(java.lang.Object obj)
Tests this SchemeFile for equality with the given object.
|
abstract boolean |
exists()
Tests whether the directory or file exists.
|
abstract LexURIFile |
getAbsoluteFile()
Returns the absolute form of this SchemeFile.
|
abstract java.lang.String |
getAbsolutePath()
Returns the SchemeFile's absolute URI string of this
SchemeFile.
|
abstract LexURIFile |
getCanonicalFile()
Returns the canonical form of this SchemeFile.
|
abstract java.lang.String |
getCanonicalPath()
Returns the canonical pathname string of this SchemeFile.
|
abstract LexWildcardInfo |
getLexWildcardInfo()
Returns an object representing the wildcard information in the URI.
|
abstract java.lang.String |
getName()
Returns the name of the file.
|
java.lang.String |
getParameters()
Returns parameters of the URI.
|
abstract java.lang.String |
getParent()
Returns the parent of the directory or file.
|
abstract LexURIFile |
getParentFile()
Returns the SchemeFile object of this SchemeFile's parent,
or
null if this pathname does not name a parent
directory. |
abstract java.lang.String |
getPath()
Converts this SchemeFile object into a URI string.
|
java.lang.String |
getPathWithoutParameters()
Returns URI with parameters removed.
|
abstract LexFileType |
getType()
Returns the LexFileType for this SchemeFile.
|
java.lang.String |
getUnderlyingPath()
Returns the absolute path of the underlying file (if possible) of
this SchemeFile.
|
abstract java.lang.Exception |
getURIException()
Returns an exception generated during the SchemeFile constructor.
|
int |
hashCode()
Computes a hash code for this URI.
|
abstract boolean |
isAbsolute()
Returns
true since all URI strings will be absolute. |
abstract boolean |
isDirectory()
Tests whether this SchemeFile represents a directory.
|
abstract boolean |
isFile()
Tests whether this SchemeFile represents a file.
|
abstract boolean |
isHidden()
Tests whether the file named by this SchemeFile is a hidden file.
|
abstract long |
lastModified()
Returns the time that the SchemeFile was last modified.
|
abstract long |
length()
Returns the length of the file represented by this SchemeFile.
|
abstract java.lang.String[] |
list()
Returns an array of strings naming the files and directories in the
directory represented by this SchemeFile.
|
java.lang.String[] |
list(java.io.FilenameFilter filter)
Returns an array of strings naming the files and directories in the
directory represented by this SchemeFile that satisfy the specified
filter.
|
abstract LexURIFile[] |
listFiles()
Returns an array of SchemeFile objects in the directory denoted by
this SchemeFile.
|
LexURIFile[] |
listFiles(java.io.FilenameFilter filter)
Returns an array of abstract pathnames denoting the files and
directories in the directory denoted by this this SchemeFile that
satisfy the specified filter.
|
abstract LexURIFile[] |
listFiles(LexURIFileFilter filter)
Returns an array of SchemeFile objects filtered by the
LexURIFileFilter.
|
abstract boolean |
mkdir()
Creates the directory named by this SchemeFile.
|
abstract boolean |
mkdirs()
Creates the directory named by this abstract pathname, including any
necessary but nonexistent parent directories.
|
static int |
paramsIndex(java.lang.String uriString)
Finds the index of the ?
|
abstract boolean |
renameTo(LexURIFile dest)
Renames the SchemeFile
If renaming is not supported,
true should be returned. |
static java.lang.String |
sanitizeFilename(java.lang.String name)
Sanitizes the
name string so it can be used as a filename. |
abstract boolean |
setLastModified(long time)
Sets the last-modified time of the file or directory named by this
SchemeFile.
|
abstract boolean |
setReadable(boolean readable)
A method to set the owner's read permission for this SchemeFile.
|
abstract boolean |
setReadable(boolean readable,
boolean ownerOnly)
Sets the owner's or everybody's read permission for this SchemeFile.
|
abstract boolean |
setReadOnly()
Marks the file or directory named by this SchemeFile so that
only read operations are allowed.
|
boolean |
setWritable(boolean writable)
A method to set the owner's write permission for this SchemeFile.
|
abstract java.lang.String |
toString()
Returns the URI string of this SchemeFile.
|
public LexURIFile(java.lang.String uri)
The uri in this case could represent a directory or a file. This constructor should not be called directly but should be called through the super() function of the class extending LexURIFile.
uri - String containing the URI representing the directory or file.public LexURIFile(java.lang.String parentURI,
java.lang.String child)
The parentURI in this case represents a directory. The
child represents the file within the parent directory.
This constructor should not be called directly but should be called
through the super() function of the class extending LexURIFile.
parentURI - String containing the URI representing a directory.child - String containing the filename portion of the URI. This
should only be the name and not include the parameter name.public abstract boolean canRead()
For a queue/pipe/database, this could always return true
and let any failures occur through the SchemeInputStream.
true if the directory or file represented by
this SchemeFile exists and can be read by the application;
false otherwisepublic abstract boolean canWrite()
For a queue/pipe/database, this could always return true
and let any failures occur through the SchemeOutputStream.
true if the scheme system actually
contains this directory or file and the application is allowed
to write to the directory or file; false otherwise.public abstract int compareTo(LexURIFile pathname)
pathname - The SchemeFile to be compared to this
SchemeFilepublic abstract boolean createNewFile()
throws java.io.IOException
For queues, pipes, and databases, this method may do nothing besides return the boolean value.
true if the named file does not exist and was successfully
created; false if the named file already existsjava.io.IOException - If an I/O error occurredpublic abstract boolean delete()
true if the file or directory is successfully
deleted; false otherwisepublic abstract boolean equals(java.lang.Object obj)
true if the argument is not null and is a SchemeFile
that denotes the same directory or file as this SchemeFile.equals in class java.lang.Objectobj - object to be compared with this SchemeFiletrue if the objects are the same;
false otherwisepublic abstract boolean exists()
For queues/pipes/databases: If a specific filename
is included in the SchemeFile's URI, then this checks for that
specific item in the queue/pipe/database exists. If the
SchemeFile represents a directory, then this returns
true if the queue/pipe/database table exists.
true if the file or directory exists;
false otherwisepublic abstract LexURIFile getAbsoluteFile()
new SchemeFile(this.LexURIFile.getAbsolutePath()).
Since SchemeFile extends LexURIFile, a SchemeFile can and should be returned.
public abstract java.lang.String getAbsolutePath()
Since the URI is already absolute, then the pathname string is simply
returned as if by the method.LexURIFile.getPath()
public java.lang.String getUnderlyingPath()
public abstract LexURIFile getCanonicalFile()
new SchemeFile(this.LexURIFile.getCanonicalPath()).
Since SchemeFile extends LexURIFile, a SchemeFile can and should be returned.
public abstract java.lang.String getCanonicalPath()
throws java.io.IOException
Since the SchemeFile is already absolute, then the pathname
string is simply returned as if by the
method.LexURIFile.getPath()
java.io.IOException - If an I/O error occurredpublic abstract java.lang.String getName()
For a file system, this would be the last portion of the filename path. For a queue/pipe/database, this is filename portion of the URI not including the parameter name.
Examples:
getName() would return test.edi
getName() would return *.edi
getName() would return [test.edi]
public abstract java.lang.String getParent()
For a file system, this would be all but the last portion of the filename path.
For a queue/pipe/database:
null is returned.
Examples:
getParent() would return msmq:DIRECT=OS:.\private$\Outbox
getParent() would return null
getParent() would return jms:jndi:jms/InboxQueue?jndiConnectionFactoryName=jms/ConnectionFactory&filenameProp=filename
public abstract LexURIFile getParentFile()
null if this pathname does not name a parent
directory.
Since SchemeFile extends LexURIFile, a SchemeFile can and should be returned.
If this SchemeFile has a parent, then this is equivalent to
new SchemeFile(this..LexURIFile.getParent())
null if this
SchemeFile does not name a parentpublic abstract java.lang.String getPath()
public java.lang.String getPathWithoutParameters()
public java.lang.String getParameters()
public static int paramsIndex(java.lang.String uriString)
uriString - String containing the URI
NOTE: If wildcards are used within the path, then either URI parameters
must be specified or ? must be added at the end of the path.
In other words, the right-most ? must signal the start of the
parameters (even if there aren't any parameters).public abstract boolean isAbsolute()
true since all URI strings will be absolute.truepublic abstract boolean isDirectory()
For file systems, returns true if this SchemeFile
item exists and is a directory.
For queues/pipes/databases, returns false if the
SchemeFile is meant to represent a message/item/record in the
queue/pipe/database. It returns true if the
SchemeFile is meant to represent the queue/pipe/database table
itself.
true if the SchemeFile represents a directory;
false otherwisepublic abstract boolean isFile()
For file systems, returns true if this SchemeFile
item exists and is a file.
For queues/pipes/databases, returns true if the
SchemeFile is meant to represent a message/item/record in the
queue/pipe/database. It returns false if the
SchemeFile is meant to represent the queue/pipe/database table
itself.
true if the SchemeFile represents a directory;
false otherwisepublic abstract boolean isHidden()
For file systems, the definition of hidden is operating system dependant.
For queues/pipes/databases, this would normally always return
false
true if the item is hidden;
false otherwisepublic abstract long lastModified()
For file systems, this would be the last modified timestamp on the file.
For queues/pipes/databases, this could be the time when the message/item/record was added to the queue/pipe/database.
long value representing the time the
SchemeFile was last modified, measured in milliseconds
since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the
file does not exist or if an I/O error occurspublic abstract long length()
For queues/pipes/databases, this would be the length, in bytes, of the message/item/database field. For file systems, this would be the length, in bytes, of the file.
public abstract java.lang.String[] list()
If this SchemeFile does not represent a directory, then this
method returns null. Otherwise an array of strings is
returned, one for each file or directory in the directory.
For file systems, names denoting the directory itself and the directory's parent directory are not included in the result. Each string is a file name rather than a complete path.
For queues/pipes/databases, each string is a complete path including the file name. The URI should also include any additional information uniquely identifying the item such as a message ID or database primary key. This is because the filename is not necessarily unique in these systems.
For example:
If the list() was called for a URI of
msmq:DIRECT=OS:.\private$\Outbox
The following is an example of return values:
There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.
public abstract LexURIFile[] listFiles()
If this SchemeFile does not denote a directory, then this
method returns null. Otherwise an array of
SchemeFile objects is returned, one for each file or
directory in the directory. Pathnames denoting the directory itself and the
directory's parent directory are not included in the result.
There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.
Since SchemeFile extends LexURIFile, an array of SchemeFile can and should be returned.
null if this SchemeFile does not
denote a directory, or if an I/O error occurs.public abstract LexURIFile[] listFiles(LexURIFileFilter filter)
Since SchemeFile extends LexURIFile, an array of SchemeFile can and should be returned.
The SchemeFile code should perform something similar to the following to determine if the LexURIFile (SchemeFile) is acceptable to be returned in the array.
The following example is for an Hdfs scheme.
public HdfsFile[] listFiles(LexURIFileFilter filter) {
// Throw SecurityException if URI was bad in constructor
if (this.uriSyntaxException != null)
throw new SecurityException(this.uriSyntaxException);
// Build list of all items
String[] uriFileList = this.list();
if (uriFileList == null)
return null;
// Build list of acceptable items
ArrayList<HdfsFile> fileList = new ArrayList<HdfsFile>();
for (int ii = 0; ii < uriFileList.length; ii++) {
HdfsFile hdfsFile = new HdfsFile(uriFileList[ii]);
if ((filter == null) || (filter.accept(hdfsFile)))
fileList.add(hdfsFile);
}
// Return array of accepted items
return fileList.toArray(new HdfsFile[fileList.size()]);
}
filter - A LexURIFileFilter implemented with VersaLex. The
SchemeFile implementation should call
filter.accept(lexURIFile) method to determine if this
SchemeFile should be included in the return array.public abstract boolean mkdir()
For SchemeFile types that do not support subdirectories, such
as queues/pipes/databases, this should return true.
true if the directory was created;
false otherwisepublic abstract boolean mkdirs()
For SchemeFile types that do not support subdirectories, such
as queues/pipes/databases, this should return true.
true if the directory was created, along with all
necessary parent directories; false otherwisepublic abstract boolean renameTo(LexURIFile dest)
If renaming is not supported, true should be returned.
dest - The new name (contained within the SchemeFile) for
the named filetrue if the renaming succeeded or is not supported;
false otherwisepublic abstract boolean setLastModified(long time)
If setting the last modified time is not supported, then either
true can be returned or a SecurityException may be
thrown.
time - The new last-modified time, measured in milliseconds since
the epoch (00:00:00 GMT, January 1, 1970)true if the operation succeeded;
false otherwisepublic abstract boolean setReadable(boolean readable)
If this is not supported for the scheme, then either true
can be returned or a SecurityException may be thrown.
readable - If true, sets the access permission to
allow read operations; if false to disallow
read operationstrue if the operation succeeded or is not supportedpublic abstract boolean setReadable(boolean readable,
boolean ownerOnly)
If this is not supported for the scheme, then either true
can be returned or a SecurityException may be thrown.
readable - If true, sets the access permission to allow
read operations; if false to disallow read
operationsownerOnly - If true, the read permission applies only to
the owner's read permission; otherwise, it applies to
everybody. If the underlying file system can not
distinguish the owner's read permission from that of
others, then the permission will apply to everybody,
regardless of this value.true if the operation succeeded or is not supportedpublic abstract boolean setReadOnly()
If this is not supported for the scheme, then either true
can be returned or a SecurityException may be thrown.
true if the operation succeeded or is not supported;
false otherwisepublic boolean setWritable(boolean writable)
If this is not supported for the scheme, then either true
can be returned or a SecurityException may be thrown.
*
NOTE: The default implementation of this method ALWAYS throws an exception.
writable - If true, sets the access permission to
allow write operations; if false to disallow
write operationstrue if the operation succeeded or is not supportedpublic abstract java.lang.String toString()
LexURIFile.getPath() method.toString in class java.lang.Objectpublic java.lang.String[] list(java.io.FilenameFilter filter)
LexURIFile.list() method, except that the strings in the
returned array must satisfy the filter. If the given
filter is null then all names are accepted.
Otherwise, a name satisfies the filter if and only if the value
true results when the
FilenameFilter.accept()
method of the filter is invoked on this
abstract pathname and the name of a file or directory in the directory
that it denotes.
NOTES:
filter - A filename filterfilter. The array will be empty if
the directory is empty or if no names were accepted by the
filter. Returns null if this abstract pathname
does not denote a directory, or if an I/O error occurs.public LexURIFile[] listFiles(java.io.FilenameFilter filter)
LexURIFile.listFiles() method, except
that the pathnames in the returned array must satisfy the filter.
If the given filter is null then all
pathnames are accepted. Otherwise, a pathname satisfies the filter
if and only if the value true results when the
FilenameFilter.accept()
method of the filter is
invoked on this abstract pathname and the name of a file or
directory in the directory that it denotes.
NOTE: The default implementation of this method ALWAYS throws an exception.
filter - A filename filternull if this abstract pathname
does not denote a directory, or if an I/O error occurs.public int hashCode()
This is implemented in LexURIFile and can be overridden if needed.
hashCode in class java.lang.Objectpublic abstract LexFileType getType()
This should return one of the following depending on the type of the implemented scheme:
Although databases are described in the javadocs as not having
subdirectories, it would be possible to have a directory-like structure
by storing the directory path in the database. If your intent is to
support subdirectories using a database, then the LexFileType
returned should be LexFileType.FILESYSTEM and the URI
should be something that resembles a file system. Such as:
myDB:\SomeDir\SubDir1\SubDir2\filename
public abstract java.lang.Exception getURIException()
If there is a problem with the URI, an exception should not be thrown during the constructor. Instead the exception should be saved and getURIException() should return this exception. In addition, if any method is called after a constructor with a bad URI, the saved exception should be thrown at the time the method is called.
null should be returned.public abstract LexWildcardInfo getLexWildcardInfo()
This should interrogate the URI and return a LexWildcardInfo object
created with LexWildcardInfo(String path, String wildcard). If there
is no wildcard ('*', '?', or '[regex]') in the filename portion of the
URI, then a null object should be returned. If a wildcard
exists in the filename portion of the URI, the path should be
a valid URI without the filename parameter. The wildcard
would be the value portion of the filename parameter.
Examples:
null object as there is no wildcard.
LexWildcardInfo
object if a wildcard is present or null otherwise.public boolean canBeLocalUserRoot()
public static java.lang.String sanitizeFilename(java.lang.String name)
name string so it can be used as a filename.
This function returns a string with the following characters replaced with an underscore ( _ ):
: \ / * ? | < > "
name - String to sanitize to become a valid filename.public static void debug(java.lang.String message)
Writes to the VersaLex debug file if the Debug Option, URI, is enabled and the System Debug Level is Debug or higher.
message - Message to write to the debug file.public static void debug(boolean always,
java.lang.String message)
If always is true, then it writes to the VersaLex
debug file even if the Debug Option, URI, is not enabled.
However, the System Debug Level must be Debug or higher in order
for the message to be logged.
always - Set to true if you want to write to the debug
file regardless of the state of the URI Debug Option.message - Message to write to the debug file.public static void debug(java.lang.String message,
java.lang.Throwable ex)
Writes the message and execption to the VersaLex debug file if the Debug Option, URI, is enabled and the System Debug Level is Debug or higher.
message - Message to write to the debug file.ex - Exception to be logged.public static void debug(boolean always,
java.lang.String message,
java.lang.Throwable ex)
If always is true, then it writes the message and
exception to the VersaLex debug file even if the Debug Option, URI,
is not enabled. However, the System Debug Level must be Debug or
higher in order for the message to be logged.
always - Set to true if you want to write to the debug file
regardless of the state of the URI Debug Option.message - Message to write to the debug file.ex - Exception to be logged.public static void debugWriter(java.lang.String message,
java.lang.Throwable ex)