net.percederberg.mibble

## Class MibLocator

- java.lang.Object
- - net.percederberg.mibble.MibLocator

-     public class MibLocator
      extends java.lang.Object

  A MIB module locator. This class attempts to map MIB module names to files in a directory or on a resource path. It keeps two internal caches; one based on file names, and one based on the first few lines of file content. Each of these caches are created upon first use and the content cache is normally a secondary alternative due to the performance penalty when created.
  Since:
    2.10

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MibLocator(java.lang.ClassLoader classLoader, java.lang.String path)` Creates a new MIB module locator for a resource path on the class path.
    `MibLocator(java.io.File dir)` Creates a new MIB module locator for a file directory.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `MibSource` | `findByContent(java.lang.String mibName)` Searches for a MIB in the content cache.
    `MibSource` | `findByName(java.lang.String mibName)` Searches for a MIB in the file name cache.
    `java.util.Map<java.lang.String,MibSource>` | `getContentMap()` Returns (and creates if needed) the MIB file content map.
    `java.io.File` | `getDir()` Returns the directory or resource path indexed.
    `java.util.Map<java.lang.String,MibSource>` | `getNameMap()` Returns (and creates if needed) the MIB file name map.
    `java.net.URL` | `getUrl()` Returns a URL to the directory or resource path indexed.
    `boolean` | `isResourceDir()` Checks if the class loader is used for locating resources.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MibLocator

          public MibLocator(java.io.File dir)

      Creates a new MIB module locator for a file directory.
      Parameters:
        `dir` - the directory to index

    - #### MibLocator

          public MibLocator(java.lang.ClassLoader classLoader,
                    java.lang.String path)

      Creates a new MIB module locator for a resource path on the class path. Note that the resource path must be unique to a specific JAR (or directory).
      Parameters:
        `classLoader` - the class loader to use
        `path` - the resource path to index

  - ### Method Detail

    - #### isResourceDir

          public boolean isResourceDir()

      Checks if the class loader is used for locating resources.
      Returns:
        true if the directory is a resource path, or false if it represents a local directory

    - #### getDir

          public java.io.File getDir()

      Returns the directory or resource path indexed. If used with a class loader, the file object is be a resource path (not an existing file).
      Returns:
        the directory or resource path indexed

    - #### getUrl

          public java.net.URL getUrl()

      Returns a URL to the directory or resource path indexed. If used with a class loader, the URL may point to a JAR file (with a path suffix). Otherwise, the URL uses the "file:" protocol and points to the absolute file path.
      Returns:
        the URL to the directory or resource path indexed

    - #### getNameMap

          public java.util.Map<java.lang.String,MibSource> getNameMap()

      Returns (and creates if needed) the MIB file name map. This map converts file names to potential MIB module names and maps them to the directory file. The MIB modules names will be all UPPERCASE. Note that there are no guarantees that the returned files are indeed MIB files.
      Returns:
        a map of MIB module names to files

    - #### getContentMap

          public java.util.Map<java.lang.String,MibSource> getContentMap()

      Returns (and creates if needed) the MIB file content map. This map maps MIB module names read from the initial lines of the files to the directory file. Note that there are no absolute guarantees that the returned files are indeed MIB files, only the first few lines will have been read (and only to fetch the MIB module name).
      Returns:
        a map of MIB module names to files

    - #### findByName

          public MibSource findByName(java.lang.String mibName)

      Searches for a MIB in the file name cache. The file name match is case insensitive and ignores file extensions and suffixes. Note that there are no guarantees that the returned file is indeed a MIB file.
      Parameters:
        `mibName` - the MIB name
      Returns:
        the first matching MIB source, or null if no match was found

    - #### findByContent

          public MibSource findByContent(java.lang.String mibName)

      Searches for a MIB in the content cache. This cache is costly to initialize (on first call), but may be more accurate as it is based on the first few lines of each file.
      Parameters:
        `mibName` - the MIB name
      Returns:
        the first matching MIB source, or null if no match was found