public class MibLoader
extends java.lang.Object
The MIB loader searches for MIB files in a specific order. First, the file system directories in the search path are scanned for files with the same name as the MIB module being imported. This search ignores any file name extensions and compares the base file name in case-insensitive mode. If this search fails, the resource directories are searched for a file having the exact name of the MIB module being imported (case sensitive). The last step, if both the previous ones have failed, is to open the files in the search path one by one to check the MIB module names specified inside. Note that this may be slow for large directories with many files, and it is therefore recommended to always name the MIB files according to their module name.
The MIB loader is not thread-safe, i.e. it cannot be used concurrently in multiple threads.
Constructor and Description |
---|
MibLoader()
Creates a new MIB loader.
|
Modifier and Type | Method and Description |
---|---|
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.
|
void |
addResourceDir(java.lang.String dir)
Adds a directory to the MIB resource search path.
|
Mib[] |
getAllMibs()
Returns all previously loaded MIB files.
|
MibContext |
getDefaultContext()
Returns the default MIB context.
|
java.io.File[] |
getDirs()
Returns all the directories in the MIB search path.
|
Mib |
getMib(java.io.File file)
Returns a previously loaded MIB file.
|
Mib |
getMib(java.lang.String name)
Returns a previously loaded MIB file.
|
java.util.Map<java.lang.String,Mib> |
getMibs()
Returns a map of all MIB names and MIB files.
|
java.util.Map<java.lang.String,Mib> |
getMibs(boolean loaded)
Returns a map of all MIBs explicitly (or implicitly) loaded.
|
java.util.Map<java.lang.String,Mib> |
getMibs(java.io.File file)
Returns a map of all MIBs from a file.
|
ObjectIdentifierValue |
getOid(java.lang.String oid)
Searches the OID tree from the loaded MIB files for the best
matching value.
|
java.lang.String[] |
getResourceDirs()
Returns all the directories in the MIB resource path.
|
ObjectIdentifierValue |
getRootOid()
Returns the "iso" root object identifier value (OID).
|
boolean |
hasDir(java.io.File dir)
Checks if a directory is in the MIB search path.
|
boolean |
hasResourceDir(java.lang.String dir)
Checks if a directory is in the MIB resource path.
|
Mib |
load(java.io.File file)
Loads a MIB file.
|
Mib |
load(MibSource src)
Loads a MIB.
|
Mib |
load(java.io.Reader input)
Loads a MIB file from the specified input reader.
|
Mib |
load(java.lang.String name)
Loads a MIB file with the specified base name.
|
Mib |
load(java.net.URL url)
Loads a MIB file from the specified URL.
|
void |
removeAllDirs()
Removes all directories from the MIB search path.
|
void |
removeAllResourceDirs()
Removes all directories from the MIB resource search path.
|
void |
removeDir(java.io.File dir)
Removes a directory from the MIB search path.
|
void |
removeResourceDir(java.lang.String dir)
Removes a directory from the MIB resource search path.
|
void |
reset()
Resets this loader.
|
void |
unload(java.io.File file)
Unloads a MIB.
|
void |
unload(Mib mib)
Unloads a MIB.
|
void |
unload(java.lang.String name)
Unloads a MIB.
|
void |
unloadAll()
Unloads all MIBs loaded by this loaded (since the last reset).
|
public boolean hasDir(java.io.File dir)
dir
- the directory or file to checkpublic java.io.File[] getDirs()
public void addDir(java.io.File dir)
dir
- the directory to addpublic void addDirs(java.io.File[] dirs)
dirs
- the directories to addpublic void addAllDirs(java.io.File dir)
dir
- the directory to addpublic void removeDir(java.io.File dir)
dir
- the directory to removepublic void removeAllDirs()
public boolean hasResourceDir(java.lang.String dir)
dir
- the directory to checkpublic java.lang.String[] getResourceDirs()
public void addResourceDir(java.lang.String dir)
dir
- the resource directory to addpublic void removeResourceDir(java.lang.String dir)
dir
- the resource directory to removepublic void removeAllResourceDirs()
public void reset()
Note that this is not the same operation as unloadAll, since the MIB files previously loaded will be unaffected by this this method (i.e. they remain possible to use). If the purpose is to free all memory used by the loaded MIB files, use the unloadAll() method instead.
unloadAll()
public MibContext getDefaultContext()
public ObjectIdentifierValue getOid(java.lang.String oid)
oid
- the numeric OID string to search forObjectIdentifierValue.find(String)
public ObjectIdentifierValue getRootOid()
getOid(String)
,
getDefaultContext()
public Mib getMib(java.lang.String name)
name
- the MIB (module) namepublic Mib getMib(java.io.File file)
Note that if the file contained several MIB modules, this method will only return the first one. Use getMibs(File) to retrieve all.
file
- the MIB filepublic java.util.Map<java.lang.String,Mib> getMibs()
public java.util.Map<java.lang.String,Mib> getMibs(java.io.File file)
file
- the MIB filepublic java.util.Map<java.lang.String,Mib> getMibs(boolean loaded)
loaded
- the explicitly loaded MIB flagMib.isLoaded()
public Mib[] getAllMibs()
public Mib load(java.lang.String name) throws java.io.IOException, MibLoaderException
name
- the MIB name (filename without extension)java.io.IOException
- if the MIB file couldn't be found in the
MIB search pathMibLoaderException
- if the MIB file couldn't be loaded
correctlypublic Mib load(java.io.File file) throws java.io.IOException, MibLoaderException
Note that if a file contains several MIB modules, this method will only return the first one (although all are loaded). Use getMibs(File) to retrieve all.
file
- the MIB filejava.io.IOException
- if the MIB file couldn't be readMibLoaderException
- if the MIB file couldn't be loaded
correctlypublic Mib load(java.net.URL url) throws java.io.IOException, MibLoaderException
Note that if the URL data contains several MIB modules, this method will only return the first one (although all are loaded).
url
- the URL containing the MIBjava.io.IOException
- if the MIB URL couldn't be readMibLoaderException
- if the MIB file couldn't be loaded
correctlypublic Mib load(java.io.Reader input) throws java.io.IOException, MibLoaderException
Note that if the input data contains several MIB modules, this method will only return the first one (although all are loaded).
input
- the input stream containing the MIBjava.io.IOException
- if the input stream couldn't be readMibLoaderException
- if the MIB file couldn't be loaded
correctlypublic Mib load(MibSource src) throws java.io.IOException, MibLoaderException
Note that if the source contains several MIB modules, this method will only return the first one (although all are loaded).
src
- the MIB sourcejava.io.IOException
- if the MIB couldn't be foundMibLoaderException
- if one of the MIB:s couldn't be
loaded correctlypublic void unload(java.lang.String name) throws MibLoaderException
name
- the MIB nameMibLoaderException
- if the MIB couldn't be unloaded
due to dependencies from other loaded MIBsreset()
public void unload(java.io.File file) throws MibLoaderException
file
- the MIB fileMibLoaderException
- if the MIB couldn't be unloaded
due to dependencies from other loaded MIBsreset()
public void unload(Mib mib) throws MibLoaderException
mib
- the MIBMibLoaderException
- if the MIB couldn't be unloaded
due to dependencies from other loaded MIBsreset()
public void unloadAll()
In order to just reset the MIB loader to force re-loading of MIB files, use the reset() method instead which will leave the MIBs unaffected.
reset()