com.adventnet.snmp.mibs
Class LeafSyntax

java.lang.Object
  |
  +--com.adventnet.snmp.mibs.LeafSyntax
All Implemented Interfaces:
java.lang.Cloneable, com.adventnet.snmp.mibs.mibparser.MIBConstants, java.io.Serializable
Direct Known Subclasses:
MibTC

public class LeafSyntax
extends java.lang.Object
implements java.io.Serializable, com.adventnet.snmp.mibs.mibparser.MIBConstants, 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

Field Summary
 
Fields inherited from interface com.adventnet.snmp.mibs.mibparser.MIBConstants
ACCESS_ACCESSIBLE_FOR_NOTIFY, ACCESS_NOT_ACCESSIBLE, ACCESS_NOT_IMPLEMENTED, ACCESS_READ_CREATE, ACCESS_READ_ONLY, ACCESS_READ_WRITE, ACCESS_WRITE_ONLY, accessStr, AGENT_CAPABILITIES, alphaStr, BITSTRING, COUNTER, COUNTER32, COUNTER64, GAUGE, GAUGE32, INTEGER, INTEGER32, IPADDRESS, macroStr, MODULE_COMPLIANCE, MODULE_IDENTITY, NETWORKADDRESS, NOTIFICATION_GROUP, NOTIFICATION_TYPE, NULL, numericStr, OBJECT_GROUP, OBJECT_IDENTIFIER, OBJECT_IDENTITY, OBJECT_TYPE, OCTETSTRING, OPAQUE, SEQUENCE, STATUS_CURRENT, STATUS_DEPRECATED, STATUS_MANDATORY, STATUS_OBSOLETE, STATUS_OPTIONAL, statusStr, TEXTUAL_CONVENTION, TIMETICKS, TRAP_TYPE, UNSIGNED32
 
Method Summary
 boolean checkValue(int i)
          Checks whether the integer value argument is in the defined range for this syntax definition.
 boolean checkValue(java.lang.String s)
          Checks whether 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()
          Gives all the labels present for an enumerated syntax.
 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 the syntaxes.
 long getMin()
          Gives the minimum value allowed for all the 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 whether the syntax has some range/size limitations explicitly defined in the MIB.
 boolean isEnumerated()
          Checks whether 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.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getName

public java.lang.String getName()
Returns the name of this LeafSyntax instance.

Returns:
the syntax name

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.

In case of MultiLevel-TC, returns the syntax of base TC.
For example, if the syntax of TC "LevelB" is "LevelA" whose syntax is OCTET STRING,
then this method will return OCTET STRING.

Returns:
the base syntax as a String

getEnumlabels

public java.lang.String[] getEnumlabels()
Gives all the labels present for an enumerated syntax.

For example, if the syntax is INTEGER { up(1), down(2), testing(3) }
then the String array contain the following values
"up", "down" and "testing"

If you want to get a particular enumerated label, then you can use the method getLabel(int).
The method getEnumint() can be used to get the enumerated values available for an enumerated syntax.

Returns:
string array of the enumerated labels.
null, if not an enumerated integer.
See Also:
getLabel(int), getEnumint()

getEnumint

public int[] getEnumint()
Gets the values for each of the enumerated integer values

For example, if the syntax is INTEGER { up(1), down(2), testing(3) }
then the integer array contain the following values
'1', '2' and '3'

If you want to get a particular enumerated value, then you can use the method getInt(String).
The method getEnumlabels() can be used to get the enumerated labels available for an enumerated syntax.

Returns:
integer array of enumerated integers.
null, if the syntax is not enumerated.
See Also:
getInt(java.lang.String), #getEnumlables

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 all the syntaxes.

For the enumerated syntaxes, returns the minimum of the enumerated values.
For example, if the syntax is INTEGER { up(1), down(2), testing(3) } this method will return 1.

Returns:
the minimum value in bytes.
See Also:
getMax()

getMax

public long getMax()
Gives the maximum value allowed for the syntaxes.

For the enumerated syntaxes, returns the maximum of the enumerated values.
For example, if the syntax is INTEGER { up(1), down(2), testing(3) } this method will return 3.

Returns:
the maximum value in bytes.
See Also:
getMin()

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.
See Also:
createVariable(String)

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

Overrides:
toString in class java.lang.Object
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 whether the integer value argument is in the defined range for this syntax definition.

In case of enumerated syntax, if the input argument is any one of the enumerated value, then this method will return true.

For other syntaxes, if the value is between the maximum and minimum values or if it is one of the maximum and minimum values, then this will return true.

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 whether the String value argument is in the defined range for this syntax definition.

NOTE : This method is supposed to be used for the enumerated syntax where the input is the any one of the enumerated label. When used for any other syntaxes, this method checks whether the length of the input String argument exceeds the maximum size of the syntax.

Parameters:
s - the string value.
Returns:
true if in the enumeration list(if exists) or if the value is within max size limit for the syntax string
false otherwise.

isConstrained

public boolean isConstrained()
Checks whether the syntax has some range/size limitations explicitly defined in the MIB.

For example, if a node is defined with a syntax INTEGER, eventhough it has a standard/default range (-2147483648 .. 2147483647), 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 whether 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.

By default all the basic integer types have constraints on their values in terms of numeric ranges and hence this method will return true for all the basic integer datatypes.

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 tcpConnRemAddress. The index for tcpConnTable and hence the indexNodes vector will contain nodes corresponding to tcpConnLocalAddress, tcpConnLocalPort, tcpConnRemAddress and 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.
java.lang.NumberFormatException

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.

For the syntax OCTET STRING and OBJECT IDENTIFIER, the length value has to be prepended before the instance value, unless it is defined IMPLIED.

If the SIZE clause is present with fixed length, the length need not be prepended before the instance value.

For example, if the syntax of the index node is OCTET STRING and if String value is "test", then the instance String must be "4.116.101.115.116".

If the index node is IMPLIED or if the syntax has a fixed length as defined in the MIB, then the length value need not be prepended and the instance String can be either "116.101.115.116" or "4.116.101.115.116".

Parameters:
instance - the encoded instance String
indexMibNodes - Vector containing the nodes corresponding to the index MibNodes.
Returns:
Vector of SnmpVar values for the index nodes.
Throws:
throws - NumberFormatException
java.lang.NumberFormatException

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.

Overrides:
clone in class java.lang.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-2006