com.adventnet.snmp.mibs
Class LeafSyntax
com.adventnet.snmp.mibs.LeafSyntax
- All Implemented Interfaces:
- java.lang.Cloneable, java.io.Serializable
- Direct Known Subclasses:
- MibTC
- public class LeafSyntax
- implements java.io.Serializable, java.lang.Cloneable
This class represents the syntax of a leaf node in a MIB module.
If the appropriate MIB is loaded,
the LeafSyntax instance for an ObjectID could be obtained from the
MibOperations object using the following method.
mibOperations.getLeafSyntax(SnmpOID);
The LeafSyntax instance for a MIB Node can be obtained from the
MibNode instance using the following method.
mibNode.getSyntax();
Once you have the LeafSyntax instance for a node, you can
create new SNMP variables with the given syntax,
check syntax rules on variables, and
get more information on the syntax.
- See Also:
- Serialized Form
Method Summary |
boolean |
checkValue(int i)
Checks to see if the integer value argument is in the
defined range for this syntax definition. |
boolean |
checkValue(java.lang.String s)
Checks to see if the String value argument is in the
defined range for this syntax definition. |
java.lang.Object |
clone()
Creates and returns a copy of this object. |
SnmpVar |
createVariable(java.lang.String value)
Instantiates and returns an SnmpVar of type specified by this Syntax. |
SnmpVar |
createVariable(java.lang.String value,
java.lang.String enc)
Instantiates and returns an SnmpVar of type specified by this Syntax
with respect to the encoding scheme. |
java.util.Vector |
decodeInstanceString(java.lang.String instance,
java.util.Vector indexMibNodes)
Decodes an instance string based on the instance and indexMibNodes. |
int[] |
encodeInstanceString(java.util.Vector indexVector,
java.util.Vector indexMibNodes)
Encodes an instance string based on the indexVector and indexMibNodes. |
java.lang.String |
getDescription()
Returns the description of the syntax. |
int[] |
getEnumint()
Gets the values for each of the enumerated integer values |
java.lang.String[] |
getEnumlabels()
Gets the labels for each of the enumerated integer values |
java.lang.String |
getEquivname()
Gets the equivalent SNMP type name. |
int |
getInt(java.lang.String s)
Gets the int value of the label argument. |
java.lang.String |
getLabel(int val)
Gets the label corresponding to the integer value argument. |
long |
getMax()
Gives the maximum value allowed for integer type syntaxes |
long |
getMin()
Gives the minimum value allowed for integer type syntaxes |
java.lang.String |
getName()
Returns the name of this LeafSyntax instance. |
java.lang.String[] |
getRangeItems()
Gets the range constraints available for this syntax. |
int |
getSize()
Gives the maximum Size restriction for this syntax. |
LeafSyntax |
getSyntax()
Gives the syntax for this leafSyntax Object. |
byte |
getType()
Retrieves the SNMP ASN.1 tag value for this syntax. |
boolean |
isConstrained()
Checks to see if the syntax has some range/size limitations
explicitly defined in the MIB. |
boolean |
isEnumerated()
Checks to see if the syntax is enumerated. |
boolean |
isRanged()
Checks to see if this syntax has size or value limitations. |
java.lang.String |
toString()
Returns the syntax name for display purposes. |
java.lang.String |
toTagString()
Gives the detailed description of this syntax. |
getName
public java.lang.String getName()
- Returns the name of this LeafSyntax instance.
getDescription
public java.lang.String getDescription()
- Returns the description of the syntax.
e.g. "OCTET STRING (SIZE (0..255))"
getType
public byte getType()
- Retrieves the SNMP ASN.1 tag value for this syntax.
syntax tagvalue equivalent SnmpAPI types
INTEGER/Integer32 0x02 SnmpAPI.INTEGER
OCTET STRING/BITS 0x04 SnmpAPI.STRING
NULL 0x05 SnmpAPI.NULL
OBJECT IDENTIFIER 0x06 SnmpAPI.OBJID
IpAddress 0x40 SnmpAPI.IPADDRESS
NetworkAddress 0x40 SnmpAPI.NETWORKADDRESS
Counter/Counter32 0x41 SnmpAPI.COUNTER
Unsigned32 0x42 SnmpAPI.UNSIGNED32
Gauge/Gauge32 0x42 SnmpAPI.GAUGE
TimeTicks 0x43 SnmpAPI.TIMETICKS
Opaque 0x44 SnmpAPI.OPAQUE
Counter64 0x46 SnmpAPI.COUNTER64
- Returns:
- the type value of this syntax in bytes
getEquivname
public java.lang.String getEquivname()
- Gets the equivalent SNMP type name.
Using this method we can get the base datatype of a TC
- Returns:
- the base syntax as a String
getEnumlabels
public java.lang.String[] getEnumlabels()
- Gets the labels for each of the enumerated integer values
- Returns:
- string array of the enumerated labels.
null, if not an enumerated integer - See Also:
getLabel(int)
getEnumint
public int[] getEnumint()
- Gets the values for each of the enumerated integer values
- Returns:
- integer array of enumerated integers.
null, if not an enumerated integer. - See Also:
getInt(java.lang.String)
getSize
public int getSize()
- Gives the maximum Size restriction for this syntax.
- Returns:
- the size restriction of the datatypes in bytes.
- See Also:
getMin()
,
getMax()
getMin
public long getMin()
- Gives the minimum value allowed for integer type syntaxes
- Returns:
- the minimum value in bytes.
getMax
public long getMax()
- Gives the maximum value allowed for integer type syntaxes
- Returns:
- the maximum value in bytes.
createVariable
public SnmpVar createVariable(java.lang.String value,
java.lang.String enc)
throws SnmpException
- Instantiates and returns an SnmpVar of type specified by this Syntax
with respect to the encoding scheme. The SnmpVar object is initialized
to a value specified in the argument string.
- Parameters:
value
- the string representation of the value.enc
- the string for the encoding scheme to be used.- Returns:
- the SnmpVar instance for the value.
- Throws:
SnmpException
- is thrown on format errors.
createVariable
public SnmpVar createVariable(java.lang.String value)
throws SnmpException
- Instantiates and returns an SnmpVar of type specified by this Syntax.
The SnmpVar variable is initialized to a value specified
in the argument string.
Depending on the ASN.1 tag value of this syntax, the corresponding
SnmpVar object will be created.
OCTET STRING/BITS SnmpString
INTEGER/Integer32 SnmpInt
Unsigned32 SnmpUnsignedInt
Counter/Counter32 SnmpCounter
Gauge/Gauge32 SnmpGauge
Counter64 SnmpCounter64
The input string we can give in Hex or binary format.
In hex format, the value is enclosed within the single quotes
and endswith "h" or "H".
For example, '64'h or'64'H
For the binary format, the value is enclosed with single quotes
and endswith "b" or "B".
For example, '01100100'b or '01100100'B
The byte string can be set for the OCTET STRING, the value should
be enclosed within the quotes and each octets should be separated
by colon.
For exaple, if we want to set the byte[] value to OCTET STRING object
'0a:0b:0c:0d:0e:0f' then this value set as the byte array value.
- Parameters:
value
- the string representation of the value.- Returns:
- the SnmpVar instance for the value.
- Throws:
SnmpException
- is thrown on format errors.
toString
public java.lang.String toString()
- Returns the syntax name for display purposes.
Same as the getName() method
- See Also:
getName()
toTagString
public java.lang.String toTagString()
- Gives the detailed description of this syntax.
- Returns:
- the string representation of the description
of syntax. e.g. DisplayString (SIZE (0..255))
getLabel
public java.lang.String getLabel(int val)
- Gets the label corresponding to the integer value argument.
- Parameters:
val
- the integer value which ought to be one of the enumerations.- Returns:
- the string representing this value
null if not an enumerated integer or if the value is not found.
getInt
public int getInt(java.lang.String s)
- Gets the int value of the label argument.
- Parameters:
s
- the string value which should be one of the enumerations.- Returns:
- the integer corresponding to the label.
returns -1 if not found or if not an enumerated integer.
checkValue
public boolean checkValue(int i)
- Checks to see if the integer value argument is in the
defined range for this syntax definition.
- Parameters:
i
- the integer value.- Returns:
- true if it is in the enumeration list or
if within max size limits(includes boundary values)
false otherwise.
checkValue
public boolean checkValue(java.lang.String s)
- Checks to see if the String value argument is in the
defined range for this syntax definition.
- Parameters:
s
- the string value.- Returns:
- true if in the enumeration list(if exists)
or if within max size limit for the syntax string
false otherwise.
isConstrained
public boolean isConstrained()
- Checks to see if the syntax has some range/size limitations
explicitly defined in the MIB. For example, if a node is defined
with a syntax INTEGER, then it will take the standard/default range
(-2147483648 .. 2147483647). In this case, this method will
return false as there is no range constraints explicitly
imposed on the syntax in the MIB.
- Returns:
- true if the range restrictions is defined explicitly.
false otherwise.
isEnumerated
public boolean isEnumerated()
- Checks to see if the syntax is enumerated.
- Returns:
- true if the syntax contains the enum labels.
false otherwise.
isRanged
public boolean isRanged()
- Checks to see if this syntax has size or value limitations.
such as 1..32 or 4 | 6..7 etc.
Note that this method returns true for basic integer types
as well since they have constraints on their values in terms
of numeric ranges. The distinguishing factor to be used for
numeric types is the isEnumerated method. The isRanged will
be true for all numeric types except Counter64 which require
special handling because of the absence of primitive java unsigned
type.
- Returns:
- true if the syntax has range restrictions.
false otherwise. - See Also:
isEnumerated()
encodeInstanceString
public int[] encodeInstanceString(java.util.Vector indexVector,
java.util.Vector indexMibNodes)
throws java.lang.NumberFormatException
- Encodes an instance string based on the indexVector and indexMibNodes.
The instance int array should be concatenated to the oid int array to get
the complete oid. For example if the tcpConnTable has the following entry.
tcpConnState |
tcpConnLocalAddress |
tcpConnLocalPort |
tcpConnRemAddress |
tcpConnRemPort |
established(5) |
128.253.154.64 |
23 |
128.253.154.3 |
1111 |
In this case assuming you wish to obtain the instance corresponding to the
particular tcpConnRemAddress. The index for tcpConnTable and hence the
indexNodes vector will contain nodes corresponding to tcpConnLocalAddress,
tcpConnLocalPort, tcpConnRemAddress tcpConnRemPort in that order.
The indexVector will contain the following SnmpVar objects.
SnmpIpAddress corresponding to 128.253.154.64 .
SnmpInt corresponding to port 23 .
SnmpIpAddress corresponding to 128.253.154.3 and.
SnmpInt corresponding to port 1111 .
These should be in this very order.
The return value in this case will contain the int array containing
128.253.154.64.23.128.253.154.3.1111 , the subids forming components
of the array.
- Parameters:
indexVector
- Vector of SnmpVar instances. Each instance should
correspond to the index component value.indexMibNodes
- Vector containing the nodes corresponding to the
index MibNodes.- Returns:
- the instance string.
decodeInstanceString
public java.util.Vector decodeInstanceString(java.lang.String instance,
java.util.Vector indexMibNodes)
throws java.lang.NumberFormatException
- Decodes an instance string based on the instance and indexMibNodes.
- Parameters:
instance
- the encoded instance StringindexMibNodes
- Vector containing the nodes corresponding to the index MibNodes.- Returns:
- Vector of SnmpVar values for the index nodes.
getSyntax
public LeafSyntax getSyntax()
- Gives the syntax for this leafSyntax Object. The
idea is that each LeafSyntax could be a Textual-Convention.
In such a cases the textual convention's syntax will be applicable.
However if the textual convention's syntax is another textual
convention then we have a case where it should be possible to derive
the syntax tree without going into a cyclic loop. :-<<
- Returns:
- LeafSyntax object for this syntax.
getRangeItems
public java.lang.String[] getRangeItems()
- Gets the range constraints available for this syntax.
For example if a syntax has a range like (0 .. 255 | 400 .. 500)
then this method will return an array containing two components
namely "0 .. 255" and "400 .. 500".
- Returns:
- the string array of range constraints.
null, if there are no range restrictions.
clone
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
- Creates and returns a copy of this object.
- Returns:
- the copy of this LeafSyntax object.
- Throws:
java.lang.CloneNotSupportedException
- is thrown if the object's class does not support the
Cloneable interface.
Copyright (c)AdventNet Inc., 1996-2004