| java.lang.Object org.cougaar.util.ConfigFinder org.cougaar.util.jar.JarConfigFinder
JarConfigFinder | public class JarConfigFinder extends ConfigFinder (Code) | | JarConfigFinder provides utilities to search for a named file in several specified
locations, returning the first location where a file by that name is found.
Files are found and opened by the open() method.
JarConfigFinder searches an ordered list of configuration paths to locate files.
Each element in the list is a URL pointing to a file or a directory, and may
reference one of the following elements:
- A simple file
- A signed or unsigned jar file in a file system or available through an HTTP connection
- A local directory
The configuration path is a semi-colon ordered list of these URL elements.
The search is performed by looking at the URL elements from left to right.
- If the element is a simple file and the name matches the requested file,
the file is returned.
- If the element is a jar file, the JarConfigFinder attempts to locate
a file in the jar file that matches the name of the requested file.
The jar file can be opened in a file system or through an HTTP connection.
- If the element is a directory in a file system, the JarConfigFinder
attempts to locate a matching (unsigned) file in that directory.
The JarConfigFinder also looks up all jar files contained in that
directory and tries to find a matching file in one of those jar files.
Properties:
- If the org.cougaar.util.jar.jarFilesOnly is set to true,
JarConfigFinder returns files contained in JAR files only
- If the org.cougaar.config.signedOnly property is set to true,
the SecureConfigFinder returns only files that have been signed.
|
Field Summary | |
protected File | _jarFileCacheDirectory A directory to store files extracted from JAR files, so that we
can return a File reference to the client. | protected File | _tmpBaseDirectory Parent directory to _tmpDirectory and _jarFileCacheDirectory,
specified by getTmpBaseDirectoryName(). | protected File | _tmpDirectory A directory to extract files from JAR files, before they are
moved to the _jarFileCacheDirectory. |
Constructor Summary | |
public | JarConfigFinder() | public | JarConfigFinder(String path) | public | JarConfigFinder(String path, Map props) | public | JarConfigFinder(String module, String path) | public | JarConfigFinder(String module, String path, Map props) Constructs a JarConfigFinder that will first search within the specified module,
and then in the directories on the given search path, using the given
Property substitutions.
When searching the given module, we search the following 4 directories (if defined) before any other directories:
- $INSTALL/$module/configs/$CONFIG
- $INSTALL/$module/configs
- $INSTALL/$module/data/$CONFIG
- $INSTALL/$module/data
Parameters: module - Name of the module to use for module-specific configs. |
_jarFileCacheDirectory | protected File _jarFileCacheDirectory(Code) | | A directory to store files extracted from JAR files, so that we
can return a File reference to the client.
|
_tmpBaseDirectory | protected File _tmpBaseDirectory(Code) | | Parent directory to _tmpDirectory and _jarFileCacheDirectory,
specified by getTmpBaseDirectoryName(). If null, we will
use the system-defined tmp directory (see File.createTempFile).
|
_tmpDirectory | protected File _tmpDirectory(Code) | | A directory to extract files from JAR files, before they are
moved to the _jarFileCacheDirectory.
|
JarConfigFinder | public JarConfigFinder(String path, Map props)(Code) | | Alias for JarConfigFinder(null, path, props)
|
JarConfigFinder | public JarConfigFinder(String module, String path)(Code) | | Alias for JarConfigFinder(module, path, Configuration.getDefaultProperties())
|
JarConfigFinder | public JarConfigFinder(String module, String path, Map props)(Code) | | Constructs a JarConfigFinder that will first search within the specified module,
and then in the directories on the given search path, using the given
Property substitutions.
When searching the given module, we search the following 4 directories (if defined) before any other directories:
- $INSTALL/$module/configs/$CONFIG
- $INSTALL/$module/configs
- $INSTALL/$module/data/$CONFIG
- $INSTALL/$module/data
Parameters: module - Name of the module to use for module-specific configs. If null, no module-specific paths are added. Parameters: path - Configuration path string. If null, defaults to Configuration.getConfigPath() Parameters: props - Properties to use for configpath variable substitutions |
acceptAbsoluteFileNames | protected boolean acceptAbsoluteFileNames()(Code) | | Determines if ConfigFinder client may specify absolute file names.
|
appendJarFiles | protected void appendJarFiles(URL[] jarFiles)(Code) | | |
createJarFileCacheDirectory | protected void createJarFileCacheDirectory()(Code) | | create a set of uniquely-named temporary directories for
our use.
|
find | public URL find(String aURL) throws IOException(Code) | | Attempt to find the URL which would be opened by the open method.
Note that this must actually attempt to open the various URLs
under consideration, so this is not an inexpensive operation.
The file being searched should be specified as one of:
- The name of the file being searched, e.g. just the last name in the pathname's name sequence.
For example, a component might lookup a file by specifying "config.txt"
- The last few elements in the pathname of the file being searched.
For example, a component might lookup a file by specifying "org/cougaar/config.txt"
- The full URL of the file in the JAR file
For example, a component might lookup a file by specifying
"jar:file://usr/local/cougaar/configs.jar!org/cougaar/config.txt"
Parameters: aURL - The name of a file being searched |
getJarFile | protected JarFile getJarFile(File aFile)(Code) | | Return a JarFile if the file is really a Jar file.
Return null otherwise.
|
getTmpBaseDirectoryName | protected String getTmpBaseDirectoryName()(Code) | | Return a pathname to use as the directory argument for File.createTempFile.
to construct _tmpBaseDirectory.
If null, then we'll use the system-defined tmp directory location
The default implementation returns the value of the system property "org.cougaar.workspace"
if defined, otherwise null.
|
isValidUrl | protected boolean isValidUrl(URL aUrl)(Code) | | Determines if a simple configuration file can be loaded.
When signed jar files are used, files that are not in signed jar files
are not loaded. However, there might be exceptions to the rule and
specific files may be authorized even if they are not signed.
By default, the base JarConfigFinder always allows unsigned jar files.
Parameters: aUrl - The URL of a configuration file |
jarFilesOnly | protected boolean jarFilesOnly()(Code) | | Determines if configuration files must be stored in signed jar files.
true if configuration files must be in signed jar files only |
launchJarInfoCleanupThread | protected void launchJarInfoCleanupThread()(Code) | | |
locateFile | public File locateFile(String aFilename)(Code) | | Locate an actual file in the config path.
Parameters: aFilename - The name of a file being searched |
locateFileInFileElement | protected URL locateFileInFileElement(URL base, String aFileName)(Code) | | |
locateFileInHttpElement | protected URL locateFileInHttpElement(URL base, String aFileName)(Code) | | |
locateFileInJarFile | protected URL locateFileInJarFile(String aFileName, JarFileInfo entry)(Code) | | Attempts to locate a file in a JAR file.
Parameters: aFileName - the name of a file being searched. Parameters: entry - a cache entry representing a JAR file the URL of the file in the JAR file, if an entry was found.null if no entry was found in the JAR file. |
locateFileInPathElement | protected URL locateFileInPathElement(URL base, String aFileName)(Code) | | Parameters: base - - The path element where to search files. Parameters: aFileName - - The name of a file to search.If aFileName is null, then no search is performed. The pathelement is still added to the cache. |
open | public InputStream open(String aURL) throws IOException(Code) | | Opens an InputStream to access the named file. The file is sought
in all the places specified in configPath.
The file being searched should be specified as one of:
- The name of the file being searched, e.g. just the last name in the pathname's name sequence.
For example, a component might lookup a file by specifying "config.txt"
- The last few elements in the pathname of the file being searched.
For example, a component might lookup a file by specifying "org/cougaar/config.txt"
- The full URL of the file in the JAR file
For example, a component might lookup a file by specifying
"jar:file://usr/local/cougaar/configs.jar!org/cougaar/config.txt"
Parameters: aURL - The name of a file being searched throws: FileNotFoundException - if the resource cannot be found. |
refreshJarFileCache | protected void refreshJarFileCache()(Code) | | Add Jar files back to the cache of Jar files.
|
resolveUrl | protected URL resolveUrl(String aFileName)(Code) | | Resolve a logical reference to a URL
Parameters: aFileName - the name of a file to be resolved null if no file can be found at that location |
verifyInputStream | protected void verifyInputStream(URL aURL) throws IOException, GeneralSecurityException(Code) | | Verify the integrity of the data contained at a URL.
Some integrity issues might be discovered late when reading
an input stream. For example, digest errors are discovered
when the entire stream has been read. This gives the opportunity
for a secure file finder to verify the data before the stream
is returned to the caller.
Does nothing in the default implementation, but should typically be
defined in a derived class.
Parameters: aURL - the URL to check. exception: IOException - if an IO Exception occurs while opening the stream exception: GeneralSecurityException - if there was a problem while checkingthe integrity of the input stream. |
|
|