Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.objectstyle.cayenne.util
Class ResourceLocator

    java.lang.Object
      org.objectstyle.cayenne.util.ResourceLocator

Direct Known Subclasses:
  WebApplicationResourceLocator

    public class ResourceLocator

extends java.lang.Object

Utility class to find resources (files, etc.), using a preconfigured strategy.

Author:
  Andrei Adamchik

Nested Class Summary
`protected static class` | `ResourceLocator.PredicateLogger` Custom logger that can be dynamically turned on/off by evaluating a Predicate.

Field Summary
`protected java.util.List` | `additionalClassPaths`
`protected java.util.List` | `additionalFilesystemPaths`
`protected java.lang.ClassLoader` | `classLoader`
`protected boolean` | `skipAbsolutePath`
`protected boolean` | `skipClasspath`
`protected boolean` | `skipCurrentDirectory`
`protected boolean` | `skipHomeDirectory`

Constructor Summary
`ResourceLocator()` Creates new ResourceLocator with default lookup policy including user home directory, current directory and CLASSPATH.

Method Summary
`void` | `addClassPath(java.lang.String customPath)` Adds a custom path for class path lookups.
`void` | `addFilesystemPath(java.io.File path)` Adds the given directory as a path for filesystem lookups.
`void` | `addFilesystemPath(java.lang.String path)` Adds the given String as a custom path for filesystem lookups.
`static java.lang.String` | `classBaseUrl(java.lang.Class aClass)` Returns a base URL as a String from which this class was loaded.
`java.net.URL` | `findDirectoryResource(java.lang.String name)` Returns a directory resource URL using the lookup strategy configured for this ResourceLocator or `null` if no readable resource can be found for the given name.
`static java.io.File` | `findFileInCurrentDirectory(java.lang.String name)` Looks up a file in the current directory.
`static java.io.File` | `findFileInFileSystem(java.lang.String name)` Looks up a file in the filesystem.
`static java.io.File` | `findFileInHomeDirectory(java.lang.String name)` Looks up a file in the user home directory.
`java.net.URL` | `findResource(java.lang.String name)` Returns a resource URL using the lookup strategy configured for this Resourcelocator or `null` if no readable resource can be found for the given name.
`static java.io.InputStream` | `findResourceInClasspath(java.lang.String name)` Returns a resource as InputStream if it is found in CLASSPATH or `null` otherwise.
`static java.io.InputStream` | `findResourceInFileSystem(java.lang.String name)` Returns a resource as InputStream if it is found in the filesystem or `null` otherwise.
`java.io.InputStream` | `findResourceStream(java.lang.String name)` Returns an InputStream on the found resource using the lookup strategy configured for this ResourceLocator or `null` if no readable resource can be found for the given name.
`static java.net.URL` | `findURLInClassLoader(java.lang.String name, java.lang.ClassLoader loader)` Looks up the URL for the named resource using the specified ClassLoader.
`static java.net.URL` | `findURLInClasspath(java.lang.String name)` Looks up the URL for the named resource using this class' ClassLoader.
`java.lang.ClassLoader` | `getClassLoader()` Returns the ClassLoader associated with this ResourceLocator.
`void` | `setClassLoader(java.lang.ClassLoader classLoader)` Sets ClassLoader used to locate resources.
`void` | `setSkipAbsolutePath(boolean skipAbsPath)` Sets "skipAbsolutePath" property.
`void` | `setSkipClasspath(boolean skipClasspath)` Sets "skipClasspath" property.
`void` | `setSkipCurrentDirectory(boolean skipCurDir)` Sets "skipCurrentDirectory" property.
`void` | `setSkipHomeDirectory(boolean skipHomeDir)` Sets "skipHomeDirectory" property.
`boolean` | `willSkipAbsolutePath()` Returns true if no lookups are performed using path as absolute path.
`boolean` | `willSkipClasspath()` Returns true if no lookups are performed in the classpath.
`boolean` | `willSkipCurrentDirectory()` Returns true if no lookups are performed in the current directory.
`boolean` | `willSkipHomeDirectory()` Returns true if no lookups are performed in the user home directory.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### skipAbsolutePath

    protected boolean skipAbsolutePath

### skipClasspath

    protected boolean skipClasspath

### skipCurrentDirectory

    protected boolean skipCurrentDirectory

### skipHomeDirectory

    protected boolean skipHomeDirectory

### additionalClassPaths

    protected java.util.List additionalClassPaths

### additionalFilesystemPaths

    protected java.util.List additionalFilesystemPaths

### classLoader

    protected java.lang.ClassLoader classLoader

Constructor Detail

### ResourceLocator

    public ResourceLocator()

  Creates new ResourceLocator with default lookup policy including user home directory, current directory and CLASSPATH.

Method Detail

### findResourceInClasspath

    public static java.io.InputStream findResourceInClasspath(java.lang.String name)

  Returns a resource as InputStream if it is found in CLASSPATH or `null` otherwise. Lookup is normally performed in all JAR and ZIP files and directories available to the ClassLoader.

### findResourceInFileSystem

    public static java.io.InputStream findResourceInFileSystem(java.lang.String name)

  Returns a resource as InputStream if it is found in the filesystem or `null` otherwise. Lookup is first performed relative to the user's home directory (as defined by "user.home" system property), and then relative to the current directory.

### findFileInFileSystem

    public static java.io.File findFileInFileSystem(java.lang.String name)

  Looks up a file in the filesystem. First looks in the user home directory, then in the current directory.

  Returns:
    file object matching the name, or null if file can not be found or if it is not readable.
  See Also:
    `findFileInHomeDirectory(String)`, `findFileInCurrentDirectory(String)`

### findFileInHomeDirectory

    public static java.io.File findFileInHomeDirectory(java.lang.String name)

  Looks up a file in the user home directory.

  Returns:
    file object matching the name, or `null` if `file` cannot be found or is not readable.

### findFileInCurrentDirectory

    public static java.io.File findFileInCurrentDirectory(java.lang.String name)

  Looks up a file in the current directory.

  Returns:
    file object matching the name, or `null` if `file` can not be found is not readable.

### findURLInClasspath

    public static java.net.URL findURLInClasspath(java.lang.String name)

  Looks up the URL for the named resource using this class' ClassLoader.

### findURLInClassLoader

    public static java.net.URL findURLInClassLoader(java.lang.String name,
                                                    java.lang.ClassLoader loader)

  Looks up the URL for the named resource using the specified ClassLoader.

### classBaseUrl

    public static java.lang.String classBaseUrl(java.lang.Class aClass)

  Returns a base URL as a String from which this class was loaded. This is normally a JAR or a file URL, but it is ClassLoader dependent.

### findResourceStream

    public java.io.InputStream findResourceStream(java.lang.String name)

  Returns an InputStream on the found resource using the lookup strategy configured for this ResourceLocator or `null` if no readable resource can be found for the given name.

### findResource

    public java.net.URL findResource(java.lang.String name)

  Returns a resource URL using the lookup strategy configured for this Resourcelocator or `null` if no readable resource can be found for the given name.

### findDirectoryResource

    public java.net.URL findDirectoryResource(java.lang.String name)

  Returns a directory resource URL using the lookup strategy configured for this ResourceLocator or `null` if no readable resource can be found for the given name. The returned resource is assumed to be a directory, so the returned URL will be in a directory format (with "/" at the end).

### willSkipHomeDirectory

    public boolean willSkipHomeDirectory()

  Returns true if no lookups are performed in the user home directory.

### setSkipHomeDirectory

    public void setSkipHomeDirectory(boolean skipHomeDir)

  Sets "skipHomeDirectory" property.

### willSkipCurrentDirectory

    public boolean willSkipCurrentDirectory()

  Returns true if no lookups are performed in the current directory.

### setSkipCurrentDirectory

    public void setSkipCurrentDirectory(boolean skipCurDir)

  Sets "skipCurrentDirectory" property.

### willSkipClasspath

    public boolean willSkipClasspath()

  Returns true if no lookups are performed in the classpath.

### setSkipClasspath

    public void setSkipClasspath(boolean skipClasspath)

  Sets "skipClasspath" property.

### getClassLoader

    public java.lang.ClassLoader getClassLoader()

  Returns the ClassLoader associated with this ResourceLocator.

### setClassLoader

    public void setClassLoader(java.lang.ClassLoader classLoader)

  Sets ClassLoader used to locate resources. If `null` is passed, the ClassLoader of the ResourceLocator class will be used.

### willSkipAbsolutePath

    public boolean willSkipAbsolutePath()

  Returns true if no lookups are performed using path as absolute path.

### setSkipAbsolutePath

    public void setSkipAbsolutePath(boolean skipAbsPath)

  Sets "skipAbsolutePath" property.

### addClassPath

    public void addClassPath(java.lang.String customPath)

  Adds a custom path for class path lookups. Format should be "my/package/name" without leading "/".

### addFilesystemPath

    public void addFilesystemPath(java.lang.String path)

  Adds the given String as a custom path for filesystem lookups. The path can be relative or absolute and is not checked for existence.

  Throws:
    `java.lang.IllegalArgumentException` - if `path` is `null`.

### addFilesystemPath

    public void addFilesystemPath(java.io.File path)

  Adds the given directory as a path for filesystem lookups. The directory is checked for existence.

  Throws:
    `java.lang.IllegalArgumentException` - if `path` is `null`, not a directory or not readable.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2006 ObjectStyle.org All Rights Reserved.