JASMI API

com.agentpp.smi
Class SMIRepositoryManager

java.lang.Object
  extended by com.agentpp.smi.SMIRepositoryManager
All Implemented Interfaces:
RepositoryListener, IRepositoryManager, java.util.EventListener

public final class SMIRepositoryManager
extends java.lang.Object
implements IRepositoryManager, RepositoryListener

The SMIRepositoryManager class can be used to access MIB information from a MIB repository. In order to be able to construct an instance of this class a valid license/licenseKey pair is needed. There are two types of license, one allows read access only and the other type provides read-write access to the MIB repository.

Please visit http://www.agentpp.com for information on how to obtain a license.

A MIB repository is a directory on a file system, where compiled MIBs can be stored. That directory is exclusively used. Thus, only compiled MIBs may be stored in that directory.

As of version 1.8 of JASMI, a MIB repository can be any type of persistent storage that supports InputStream and OutputStream.

Version:
2.5
Author:
Frank Fock

Field Summary
 
Fields inherited from interface com.agentpp.smi.IRepositoryManager
NOCHECK_INCONSISTENT_ACCESS, NOCHECK_INCONSISTENT_STATUS, NOCHECK_INCONSISTENT_SYNTAX, NOCHECK_NOT_IN_GROUP
 
Constructor Summary
SMIRepositoryManager(java.lang.String license, java.lang.String licenseKey)
           
 
Method Summary
 void addModule(IModule module)
          Adds a MIB module to the repository.
 IModuleInfo[] addModules(java.io.File file)
          Adds a MIB file to the repository.
 void addRepositoryListener(RepositoryListener l)
          Adds a RepositoryListener to this repository that provides Input- and OutputStreams to read and write MIB modules from persistent storage (i.e. the MIB repository).
 void checkModules(java.io.InputStream file)
          Check whether an InputStream contains valid MIB modules.
 IModuleInfo[] checkModules(java.io.InputStream file, boolean lenientSyntaxCheck)
          Check whether an InputStream contains valid MIB modules.
 java.lang.Integer createModuleID()
          Creates a new unique module ID for the current MIB repository.
 void deleteModule(RepositoryEvent e)
          Requests deletion of the MIB module identified by the module name supplied with the RepositoryEvent object.
 java.lang.String getErrorText(int errorCode, java.lang.String message)
          Get an error text from the error code and error message of the SMIParseException.
 java.lang.String getErrorText(com.agentpp.smiparser.SMIParseException parseException)
          Get an error text for a SMIParseException.
 IObject[] getImportedObjects(java.lang.String moduleName)
          Get those MIBObjects for a MIB module with the specified name, that are imported from other MIBs.
 IObject[] getImportedObjects(java.lang.String moduleName, java.util.Hashtable moduleIDs)
          Get those MIBObjects for a MIB module with the specified name, that are imported from other MIBs.
 int getMaxErrors()
          Returns the maximum number of errors the repository manager will collect until bailing out when parsing/compiling a MIB file.
 IModule getModule(java.lang.String moduleName)
          Return a given MIB module including its objects.
 IModuleInfo[] getModuleInfo(java.io.File file)
          Get MIB module information (module name and imports) from a MIB file.
 IModuleInfo[] getModuleInfo(java.io.InputStream file, java.lang.String name)
          Get MIB module information (module name and imports) from an input stream.
 IModuleInfo[] getModuleInfos()
          Get module information about all MIB modules in the MIB repository.
 java.lang.String[] getModuleNames()
          Return an array of all module names available from the repository managed by the receiver.
 IModule[] getModules()
          Return an array of all MIB modules.
 IModule[] getModules(java.io.InputStream file, ImportModuleListener listener)
          Get the modules contained in a MIB file.
 IObject[] getObjects(java.lang.String moduleName)
          Get the MIBObjects of the MIB module with the given name.
 int getParserOptions()
          Get actual parser options.
 java.io.File getRepositoryDirectory()
          Gets the repository directory used to store compiled MIB modules by default.
 void initialize()
          Initialize the repository, thus remove all modules from the repository.
 boolean isReadOnly()
          Check whether the repository manager can be used to modify a MIB repository or not.
 java.lang.String[] listModuleNames()
          Enumerates the available MIB module names in the repository.
 void open(java.io.File directory)
          Open the MIB Repository located at the given path.
 void readModule(RepositoryEvent e)
          Requests to read a MIB module with the name specified in the supplied event object.
 boolean removeModule(java.lang.String moduleName)
          Remove a module from the repository.
 void removeRepositoryListener(RepositoryListener l)
          Removes a RepositoryListener from this repository.
 void setMaxErrors(int maxErrors)
          Sets the maximum number of errors the repository manager will collect until bailing out when parsing/compiling a MIB file.
 void setParserOptions(int options)
          Set parser options.
 void writeModule(RepositoryEvent e)
          Requests to write a MIB module with the name specified in the supplied event object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SMIRepositoryManager

public SMIRepositoryManager(java.lang.String license,
                            java.lang.String licenseKey)
Method Detail

open

public void open(java.io.File directory)
          throws java.io.IOException
Description copied from interface: IRepositoryManager
Open the MIB Repository located at the given path.

Specified by:
open in interface IRepositoryManager
Parameters:
directory - a possibly empty directory to store MIB repository data.
Throws:
java.io.IOException - if given MIB repository path is invalid.

addModules

public IModuleInfo[] addModules(java.io.File file)
                         throws com.agentpp.smiparser.SMIParseException
Description copied from interface: IRepositoryManager
Adds a MIB file to the repository.

Specified by:
addModules in interface IRepositoryManager
Parameters:
file - a file containing one or more MIB modules.
Returns:
an array containing ModuleInfo instances with information about the parsed modules contained in file.
Throws:
com.agentpp.smiparser.SMIParseException - if file contains any errors.

addModule

public void addModule(IModule module)
               throws java.io.IOException
Description copied from interface: IRepositoryManager
Adds a MIB module to the repository.

Specified by:
addModule in interface IRepositoryManager
Parameters:
module - an IModule instance that will be written to the MIB repository. RepositoryEvent listeners will be called to provide an alternative output stream.
Throws:
java.io.IOException

getModules

public IModule[] getModules(java.io.InputStream file,
                            ImportModuleListener listener)
                     throws com.agentpp.smiparser.SMIParseException
Description copied from interface: IRepositoryManager
Get the modules contained in a MIB file. The modules will NOT be added to the repository, however the files in the repository will be used the solve any dependencies

Specified by:
getModules in interface IRepositoryManager
Parameters:
file - an InputStream containing one or more MIB modules.
listener - an ImportModuleListener instance used as callback to parse or load objects of imported MIB modules and for creating a module ID for any MIB modules parsed from stream.
Returns:
an array of IModule instances representing all MIB modules defined in file.
Throws:
com.agentpp.smiparser.SMIParseException - if any syntax or semantic error has been detected in file.

checkModules

public void checkModules(java.io.InputStream file)
                  throws com.agentpp.smiparser.SMIParseException
Description copied from interface: IRepositoryManager
Check whether an InputStream contains valid MIB modules.

Specified by:
checkModules in interface IRepositoryManager
Parameters:
file - an InputStream containing SMIv1/v2 MIB module(s).
Throws:
com.agentpp.smiparser.SMIParseException - if file has an error.

checkModules

public IModuleInfo[] checkModules(java.io.InputStream file,
                                  boolean lenientSyntaxCheck)
                           throws com.agentpp.smiparser.SMIParseException
Description copied from interface: IRepositoryManager
Check whether an InputStream contains valid MIB modules.

Specified by:
checkModules in interface IRepositoryManager
Parameters:
file - an InputStream containing SMIv1/v2 MIB module(s).
lenientSyntaxCheck - if true the syntax checking is minimal, otherwise it is the default (SMI standard).
Returns:
returns information about the contained MIB modules.
Throws:
com.agentpp.smiparser.SMIParseException - if the syntax check fails.

getModuleInfo

public IModuleInfo[] getModuleInfo(java.io.File file)
                            throws com.agentpp.smiparser.SMIParseException
Description copied from interface: IRepositoryManager
Get MIB module information (module name and imports) from a MIB file.

Specified by:
getModuleInfo in interface IRepositoryManager
Parameters:
file - a SMIv1/v2 MIB File instance.
Returns:
an array of IModuleInfo instances.
Throws:
com.agentpp.smiparser.SMIParseException - if file contains any errors.

getModuleInfo

public IModuleInfo[] getModuleInfo(java.io.InputStream file,
                                   java.lang.String name)
                            throws com.agentpp.smiparser.SMIParseException
Description copied from interface: IRepositoryManager
Get MIB module information (module name and imports) from an input stream.

Specified by:
getModuleInfo in interface IRepositoryManager
Parameters:
file - an InputStream instance containing SMIv1/v2 MIB modules.
name - a String representing name of the source, for example the path of a FileInputStream.
Returns:
an array of IModuleInfo instances.
Throws:
com.agentpp.smiparser.SMIParseException - if inputStream contains any errors.

getModuleInfos

public IModuleInfo[] getModuleInfos()
                             throws java.io.IOException
Description copied from interface: IRepositoryManager
Get module information about all MIB modules in the MIB repository.

Specified by:
getModuleInfos in interface IRepositoryManager
Returns:
a possibly empty array of IModuleInfo instances.
Throws:
java.io.IOException - if the MIB repository is invalid or on any other IO error.

removeModule

public boolean removeModule(java.lang.String moduleName)
                     throws java.io.IOException
Description copied from interface: IRepositoryManager
Remove a module from the repository.

Specified by:
removeModule in interface IRepositoryManager
Parameters:
moduleName - the name of the victim.
Returns:
true if the module could be removed, false if it could not be found or if only read access to the MIB repository is granted.
Throws:
java.io.IOException

initialize

public void initialize()
                throws java.io.IOException
Description copied from interface: IRepositoryManager
Initialize the repository, thus remove all modules from the repository. (Note: This method has no effect in read-only mode.)

Specified by:
initialize in interface IRepositoryManager
Throws:
java.io.IOException - thrown if an exception occured while accessing the MIB repository.

getModules

public IModule[] getModules()
                     throws java.io.IOException
Description copied from interface: IRepositoryManager
Return an array of all MIB modules.

Specified by:
getModules in interface IRepositoryManager
Returns:
an array of IModule instances.
Throws:
java.io.IOException

getModule

public IModule getModule(java.lang.String moduleName)
                  throws java.io.IOException
Description copied from interface: IRepositoryManager
Return a given MIB module including its objects.

Specified by:
getModule in interface IRepositoryManager
Parameters:
moduleName - a module name.
Returns:
the MIBModule instance with the given module name, or null if such a module could not be found.
Throws:
java.io.IOException

getModuleNames

public java.lang.String[] getModuleNames()
                                  throws java.io.IOException
Description copied from interface: IRepositoryManager
Return an array of all module names available from the repository managed by the receiver.

Specified by:
getModuleNames in interface IRepositoryManager
Returns:
an array of module names.
Throws:
java.io.IOException

getObjects

public IObject[] getObjects(java.lang.String moduleName)
                     throws java.io.IOException
Description copied from interface: IRepositoryManager
Get the MIBObjects of the MIB module with the given name.

Specified by:
getObjects in interface IRepositoryManager
Parameters:
moduleName - the name of a MIB module.
Returns:
an array of MIBObjects.
Throws:
java.io.IOException

getImportedObjects

public IObject[] getImportedObjects(java.lang.String moduleName)
                             throws java.io.IOException
Description copied from interface: IRepositoryManager
Get those MIBObjects for a MIB module with the specified name, that are imported from other MIBs.

Specified by:
getImportedObjects in interface IRepositoryManager
Parameters:
moduleName - the name of a MIB module.
Returns:
an array of IObject instances.
Throws:
java.io.IOException

getImportedObjects

public IObject[] getImportedObjects(java.lang.String moduleName,
                                    java.util.Hashtable moduleIDs)
                             throws java.io.IOException
Description copied from interface: IRepositoryManager
Get those MIBObjects for a MIB module with the specified name, that are imported from other MIBs.

Specified by:
getImportedObjects in interface IRepositoryManager
Parameters:
moduleName - the name of a MIB module.
moduleIDs - an empty Hashtable. On return, it contains a mapping from all module names of the visited MIB modules to their respective module IDs.
Returns:
an array of IObject instances.
Throws:
java.io.IOException

isReadOnly

public boolean isReadOnly()
Check whether the repository manager can be used to modify a MIB repository or not.

Returns:
true if MIB repositories cannot be changed (read-only) and false if the repository manager can be used to compile MIBs into a repository (read-write).

getErrorText

public java.lang.String getErrorText(com.agentpp.smiparser.SMIParseException parseException)
Description copied from interface: IRepositoryManager
Get an error text for a SMIParseException.

Specified by:
getErrorText in interface IRepositoryManager
Parameters:
parseException - a com.agentpp.smiparser.SMIParseException.
Returns:
an error text.

getErrorText

public java.lang.String getErrorText(int errorCode,
                                     java.lang.String message)
Description copied from interface: IRepositoryManager
Get an error text from the error code and error message of the SMIParseException.

Specified by:
getErrorText in interface IRepositoryManager
Parameters:
errorCode - the errorCode from a com.agentpp.smiparser.SMIParseException.
message - the message of a com.agentpp.smiparser.SMIParseException.
Returns:
an error text.

setParserOptions

public void setParserOptions(int options)
Description copied from interface: IRepositoryManager
Set parser options. A value of 0 will activate all checks. Checks can be individually disabled by bitwise OR of the corresponding constants defined in this interface.

Specified by:
setParserOptions in interface IRepositoryManager
Parameters:
options - a bitwise OR of option values.

getParserOptions

public int getParserOptions()
Description copied from interface: IRepositoryManager
Get actual parser options.

Specified by:
getParserOptions in interface IRepositoryManager
Returns:
the actual parser options as an integer value.

getRepositoryDirectory

public java.io.File getRepositoryDirectory()
Description copied from interface: IRepositoryManager
Gets the repository directory used to store compiled MIB modules by default. If MIB modules should be stored and loaded in/from a different location or media, a RepositoryListener has to be added by using the IRepositoryManager.addRepositoryListener(com.agentpp.smi.event.RepositoryListener) method.

Specified by:
getRepositoryDirectory in interface IRepositoryManager
Returns:
a File instance representing a directory.

removeRepositoryListener

public void removeRepositoryListener(RepositoryListener l)
Description copied from interface: IRepositoryManager
Removes a RepositoryListener from this repository. If no listeners are left, MIB modules will be read and written from the default MIB repository directory.

Specified by:
removeRepositoryListener in interface IRepositoryManager
Parameters:
l - a RepositoryListener.

addRepositoryListener

public void addRepositoryListener(RepositoryListener l)
Description copied from interface: IRepositoryManager
Adds a RepositoryListener to this repository that provides Input- and OutputStreams to read and write MIB modules from persistent storage (i.e. the MIB repository). This can be used, for example, to store and read compiled MIB modules from JAR or ZIP files instead from a directory, which is the default.

Specified by:
addRepositoryListener in interface IRepositoryManager
Parameters:
l - a RepositoryListener that provides InputStreams and OutputStreams on demand to read or write a precompiled MIB module identified by its name from persistent storage.

writeModule

public void writeModule(RepositoryEvent e)
Description copied from interface: RepositoryListener
Requests to write a MIB module with the name specified in the supplied event object. Implementors of this method should set the OutputStream member of the supplied event object.

Specified by:
writeModule in interface RepositoryListener
Parameters:
e - a RepositoryEvent with the module name of the MIB module that should be written to persistent storage. The implementor of this interface should set the OutputStream of event.

readModule

public void readModule(RepositoryEvent e)
Description copied from interface: RepositoryListener
Requests to read a MIB module with the name specified in the supplied event object. Implementors of this method should set the InputStream member of the supplied event object.

Specified by:
readModule in interface RepositoryListener
Parameters:
e - a RepositoryEvent with the module name of the MIB module that should be read from persistent storage. The implementor of this interface should set the InputStream of event.

deleteModule

public void deleteModule(RepositoryEvent e)
Description copied from interface: RepositoryListener
Requests deletion of the MIB module identified by the module name supplied with the RepositoryEvent object.

Specified by:
deleteModule in interface RepositoryListener
Parameters:
e - a RepositoryEvent with the module name of the MIB module that should be removed from persistent MIB repository storage. If a listener has successfully removed the module, it must set the corresponding flag in the supplied event object.

setMaxErrors

public void setMaxErrors(int maxErrors)
Sets the maximum number of errors the repository manager will collect until bailing out when parsing/compiling a MIB file.

Parameters:
maxErrors - the maximum number of errors detected for each MIB file.
Since:
2.0

getMaxErrors

public int getMaxErrors()
Returns the maximum number of errors the repository manager will collect until bailing out when parsing/compiling a MIB file.

Returns:
the maximum number of errors detected for each MIB file.
Since:
2.0

createModuleID

public java.lang.Integer createModuleID()
                                 throws java.io.IOException
Description copied from interface: IRepositoryManager
Creates a new unique module ID for the current MIB repository. Calling this method is required to allocate a new module ID for a IModule instance when this instance has been created programmatically by using means provided by the JASMI Ext API for example.

When parsing MIB modules from a text source file, a module ID is automatically allocated.

When a MIB module is removed from a IB repository, its module ID is freed and can be reused again for any other new module.

Specified by:
createModuleID in interface IRepositoryManager
Returns:
a unique module ID number for this MIB repository.
Throws:
java.io.IOException

listModuleNames

public java.lang.String[] listModuleNames()
Description copied from interface: RepositoryListener
Enumerates the available MIB module names in the repository.

Specified by:
listModuleNames in interface RepositoryListener
Returns:
a list of MIB module names or null if that method is not supported by the listener.

JASMI API

JASMI 3
Copyright 2001-2010 Frank Fock
All Rights Reserved