public abstract class MibType
extends java.lang.Object
The best way to extract the specific type information from a MIB type is to check the type instance and then cast the MibType object to the corresponding subtype. Each subtype have very different properties, which is why the API in this class is rather limited. The example below shows some skeleton code for extracting type information.
if (type instanceof SnmpObjectType) { objectType = (SnmpObjectType) type; ... }Another way to check which type is at hand, is to query the type tags with the hasTag() method. In this way it is possible to distinguish between types using the same or a similar primitive ASN.1 type representation (such as DisplayString and IpAddress). This should normally be done in order to create a correct BER- or DER-encoding of the type. The example below illustrates how this could be done.
tag = type.getTag(); if (tag.getCategory() == MibTypeTag.UNIVERSAL) { // Set BER and DER identifier bits 8 & 7 to 00 } else if (tag.getCategory() == MibTypeTag.APPLICATION) { // Set BER and DER identifier bits 8 & 7 to 01 } ... if (!type.isPrimitive()) { // Set BER and DER constructed bit }
Modifier | Constructor and Description |
---|---|
protected |
MibType(java.lang.String name,
boolean primitive)
Creates a new MIB type instance.
|
Modifier and Type | Method and Description |
---|---|
MibType |
createReference()
Creates a type reference to this type.
|
MibType |
createReference(java.util.ArrayList<?> values)
Creates a constrained type reference to this type.
|
MibType |
createReference(Constraint constraint)
Creates a constrained type reference to this type.
|
java.lang.String |
getComment()
Returns the type comment.
|
java.lang.String |
getName()
Returns the type name.
|
MibTypeSymbol |
getReferenceSymbol()
Returns the type reference symbol.
|
MibTypeTag |
getTag()
Returns the type tag.
|
boolean |
hasReferenceTo(java.lang.String name)
Checks if this type referenced the specified type symbol.
|
boolean |
hasReferenceTo(java.lang.String module,
java.lang.String name)
Checks if this type referenced the specified type symbol.
|
boolean |
hasTag(int category,
int value)
Checks if this type has a specific type tag.
|
boolean |
hasTag(MibTypeTag tag)
Checks if this type has a specific type tag.
|
abstract MibType |
initialize(MibSymbol symbol,
MibLoaderLog log)
Initializes the MIB type.
|
abstract boolean |
isCompatible(MibValue value)
Checks if the specified value is compatible with this type.
|
boolean |
isPrimitive()
Checks if this type represents a primitive type.
|
void |
setReferenceSymbol(MibTypeSymbol symbol)
Sets the type reference symbol.
|
void |
setTag(boolean implicit,
MibTypeTag tag)
Sets the type tag.
|
java.lang.String |
toString()
Returns a string representation of this object.
|
protected MibType(java.lang.String name, boolean primitive)
name
- the type nameprimitive
- the primitive type flagpublic abstract MibType initialize(MibSymbol symbol, MibLoaderLog log) throws MibException
NOTE: This is an internal method that should only be called by the MIB loader.
symbol
- the MIB symbol containing this typelog
- the MIB loader logMibException
- if an error was encountered during the
initializationpublic MibType createReference() throws java.lang.UnsupportedOperationException
NOTE: This is an internal method that should only be called by the MIB loader.
java.lang.UnsupportedOperationException
- if a type reference
couldn't be createdpublic MibType createReference(Constraint constraint) throws java.lang.UnsupportedOperationException
NOTE: This is an internal method that should only be called by the MIB loader.
constraint
- the type constraintjava.lang.UnsupportedOperationException
- if a type reference
couldn't be created with constraintspublic MibType createReference(java.util.ArrayList<?> values) throws java.lang.UnsupportedOperationException
NOTE: This is an internal method that should only be called by the MIB loader.
values
- the type value symbolsjava.lang.UnsupportedOperationException
- if a type reference
couldn't be created with value constraintspublic abstract boolean isCompatible(MibValue value)
value
- the value to checkpublic boolean isPrimitive()
public boolean hasTag(MibTypeTag tag)
tag
- the type tag to search forhasTag(int, int)
public boolean hasTag(int category, int value)
category
- the tag category to search forvalue
- the tag value to search forhasTag(MibTypeTag)
public boolean hasReferenceTo(java.lang.String name)
name
- the type symbol namehasTag(int, int)
,
hasTag(MibTypeTag)
,
getReferenceSymbol()
,
SnmpTextualConvention.findReference(MibType)
public boolean hasReferenceTo(java.lang.String module, java.lang.String name)
module
- the type symbol module (MIB) namename
- the type symbol namehasTag(int, int)
,
hasTag(MibTypeTag)
,
getReferenceSymbol()
,
SnmpTextualConvention.findReference(MibType)
public java.lang.String getName()
public MibTypeTag getTag()
public void setTag(boolean implicit, MibTypeTag tag)
NOTE: This is an internal method that should only be called by the MIB loader.
implicit
- the implicit inheritance flagtag
- the new type tagpublic MibTypeSymbol getReferenceSymbol()
In general, this method should be avoided as it is much better to rely on type tags to distinguish between two types with the same base type (such as DisplayString and IpAddress).
getTag()
,
SnmpTextualConvention.findReference(MibType)
public void setReferenceSymbol(MibTypeSymbol symbol)
NOTE: This is an internal method that should only be called by the MIB loader.
symbol
- the referenced type symbolpublic java.lang.String getComment()
public java.lang.String toString()
toString
in class java.lang.Object