net.percederberg.mibble
Class MibLoader

java.lang.Object
  extended bynet.percederberg.mibble.MibLoader

public class MibLoader
extends java.lang.Object

A MIB file loader. This class contains a search path for locating MIB files, and also holds a refererence to previously loaded MIB files to avoid loading the same file multiple times. The MIB search path consists of directories with MIB files that can be imported into another MIB. If an import isn't found in the search path, the default IANA and IETF MIB directories are searched. Note that these files are normally stored as resources together with the compiled code.

The MIB loader is not thread-safe, i.e. it cannot be used concurrently in multiple threads.

Since:
2.0

Constructor Summary
MibLoader()
          Creates a new MIB loader.
 
Method Summary
 void addAllDirs(java.io.File dir)
          Adds a directory and all subdirectories to the MIB search path.
 void addDir(java.io.File dir)
          Adds a directory to the MIB search path.
 void addDirs(java.io.File[] dirs)
          Adds directories to the MIB search path.
 MibContext getDefaultContext()
          Returns the default MIB context.
 Mib getMib(java.lang.String name)
          Returns a previously loaded MIB file.
 Mib load(java.io.File file)
          Loads a MIB file.
 Mib load(java.lang.String name)
          Loads a MIB file.
 void removeAllDirs()
          Removes all directories from the MIB search path.
 void removeDir(java.io.File dir)
          Removes a directory from the MIB search path.
 void reset()
          Resets this loader.
 void scheduleLoad(java.io.File file)
          Schedules the loading of a MIB file.
 void scheduleLoad(java.lang.String name)
          Schedules the loading of a MIB file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MibLoader

public MibLoader()
Creates a new MIB loader.

Method Detail

addDir

public void addDir(java.io.File dir)
Adds a directory to the MIB search path.

Parameters:
dir - the directory to add

addDirs

public void addDirs(java.io.File[] dirs)
Adds directories to the MIB search path.

Parameters:
dirs - the directories to add

addAllDirs

public void addAllDirs(java.io.File dir)
Adds a directory and all subdirectories to the MIB search path.

Parameters:
dir - the directory to add

removeDir

public void removeDir(java.io.File dir)
Removes a directory from the MIB search path.

Parameters:
dir - the directory to remove

removeAllDirs

public void removeAllDirs()
Removes all directories from the MIB search path.


reset

public void reset()
Resets this loader. This means that all references to previuos MIB files will be removed, forcing a reload of any imported MIB.


getDefaultContext

public MibContext getDefaultContext()
Returns the default MIB context. This context contains the symbols that are predefined for all MIB:s (such as 'iso').

Returns:
the default MIB context

getMib

public Mib getMib(java.lang.String name)
Returns a previously loaded MIB file. If the MIB file hasn't been loaded, null will be returned.

Parameters:
name - the MIB name
Returns:
the MIB container if found, or null otherwise

load

public Mib load(java.lang.String name)
         throws java.io.FileNotFoundException,
                MibLoaderException
Loads a MIB file. The file is searched for in the MIB search path.

Parameters:
name - the MIB name (filename without extension)
Returns:
the MIB file loaded
Throws:
java.io.FileNotFoundException - if the MIB file couldn't be found in the MIB search path
MibLoaderException - if the MIB file couldn't be loaded correctly

load

public Mib load(java.io.File file)
         throws java.io.FileNotFoundException,
                MibLoaderException
Loads a MIB file.

Parameters:
file - the MIB file
Returns:
the MIB file loaded
Throws:
java.io.FileNotFoundException - if the MIB file couldn't be found
MibLoaderException - if the MIB file couldn't be loaded correctly

scheduleLoad

public void scheduleLoad(java.lang.String name)
                  throws java.io.FileNotFoundException
Schedules the loading of a MIB file. The file is added to the queue of MIB files to be loaded, unless it is already loaded or in the queue. The file is searched for in the MIB search path.

Parameters:
name - the MIB name (filename without extension)
Throws:
java.io.FileNotFoundException - if the MIB file couldn't be found in the MIB search path

scheduleLoad

public void scheduleLoad(java.io.File file)
Schedules the loading of a MIB file. The file is added to the queue of MIB files to be loaded, unless it is already loaded or in the queue.

Parameters:
file - the MIB file