com.adventnet.snmp.mibs
Class LeafSyntax

java.lang.Object
  |
  +--com.adventnet.snmp.mibs.LeafSyntax
Direct Known Subclasses:
JdbcLeafSyntax, 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.

It implements parsing of the definition for the object syntax for both OBJECT-TYPE and Textual Conventions.

The typical API user will use the createVariable and checkValue methods in SNMP operations.

See Also:
Serialized Form

Field Summary
(package private)  java.lang.String equivName
          Equivalent SNMP type name
(package private)  long MAX
          Maximum value allowed for integer type syntaxes
(package private)  long MIN
          Minimum value allowed for integer type syntaxes
(package private)  java.lang.String name
          The name of this LeafSyntax instance
(package private)  int node_type
          The node_type values are defined in MIBConstants.
(package private)  RangeList range
           
(package private)  int size
          Maximum Size restriction for string type syntaxes
(package private)  LeafSyntax syntax
           
(package private)  byte type
          the SNMP type defined by the SnmpAPI types
 
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
 
Constructor Summary
(package private) LeafSyntax()
          This is dummy constructor being added to fix compilation.
(package private) LeafSyntax(byte type, java.lang.String name, RangeList range)
          Instantiate a LeafSyntax element of the specified type and name and Range.
(package private) LeafSyntax(int type, java.lang.String name, RangeList range)
          Instantiate a LeafSyntax element of the specified type and name and Range.
(package private) LeafSyntax(java.lang.String nam, byte Type)
          First of two constructors, to help define basic types.
 
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.
(package private)  SnmpVar createvariable(java.lang.String value, java.lang.String enc)
           
 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.
(package private)  java.lang.String getBaseSyntaxName()
           
(package private)  boolean getBITSRange(java.lang.String val)
           
 java.lang.String getDescription()
          Returns the description of the syntax.
 int[] getEnumint()
          Gives all the values present for an enumerated syntax.
 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.
(package private)  RangeList getRange()
          the range is particular to the LeafSyntax object.
 java.lang.String[] getRangeItems()
          Gets the range constraints available for this syntax.
 int getSize()
          Gives the maximum size restriction for this syntax.
(package private)  byte getSnmpType(int nodeType)
          Converts the node type value to the corresponding SnmpAPI type value;
 LeafSyntax getSyntax()
          Gives the syntax for this leafSyntax Object.
 byte getType()
          Retrieves the SNMP ASN.1 tag value for this syntax.
(package private)  java.lang.String getTypeStr(int type)
           
(package private)  void initializeMINandMAXvalues()
           
 boolean isConstrained()
          Checks whether the syntax has some range/size limitations explicitly defined in the MIB.
 boolean isEnumerated()
          Checks whether the syntax is enumerated.
(package private)  boolean isFixedLen()
           
(package private)  boolean isFixedLength(long[] inst, java.util.Vector indexMibNodes)
           
 boolean isRanged()
          Checks to see if this syntax has size or value limitations.
(package private)  LeafSyntax readType(com.adventnet.snmp.mibs.mibparser.BaseSyntax bs, java.lang.Object parentType, MibModule module)
           
(package private)  LeafSyntax readType(java.io.DataInputStream inp, java.lang.Object parentType, MibModule module)
          Reads in a syntax element.
(package private)  void setEquivname(java.lang.String equivName)
          Set equivalent SNMP type name
(package private)  void setMax(long MAX)
          Set maximum value allowed for integer type syntaxes
(package private)  void setMin(long MIN)
          Set minimum value allowed for integer type syntaxes
(package private)  void setName(java.lang.String name)
          Set the name of this LeafSyntax instance
(package private)  void setRange(RangeList range)
          Sets the range object for this syntax element.
(package private)  void setSize(int size)
          Set maximum Size restriction for string type syntaxes
(package private)  void setSyntax(LeafSyntax syn)
           
(package private)  void setType(byte type)
          Set the SNMP type defined by the SnmpAPI types
(package private)  long[] stringToArray(java.lang.String str)
           
 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
 

Field Detail

name

java.lang.String name
The name of this LeafSyntax instance

type

byte type
the SNMP type defined by the SnmpAPI types

equivName

java.lang.String equivName
Equivalent SNMP type name

size

int size
Maximum Size restriction for string type syntaxes

MIN

long MIN
Minimum value allowed for integer type syntaxes

MAX

long MAX
Maximum value allowed for integer type syntaxes

syntax

LeafSyntax syntax

range

RangeList range

node_type

int node_type
The node_type values are defined in MIBConstants.
Constructor Detail

LeafSyntax

LeafSyntax()
This is dummy constructor being added to fix compilation. Remove it when done with

LeafSyntax

LeafSyntax(java.lang.String nam,
           byte Type)
First of two constructors, to help define basic types.
Parameters:
nam - the syntax name for the object
Type - the basic type for the object. Could be any of SnmpAPI.IPADDRESS, SnmpAPI.GAUGE, SnmpAPI.COUNTER, SnmpAPI.TIMETICKS, SnmpAPI.UINTEGER32 SnmpAPI.COUNTER64

LeafSyntax

LeafSyntax(int type,
           java.lang.String name,
           RangeList range)
Instantiate a LeafSyntax element of the specified type and name and Range. Do not use this for TCs etc. It will be broken in such a case

LeafSyntax

LeafSyntax(byte type,
           java.lang.String name,
           RangeList range)
Instantiate a LeafSyntax element of the specified type and name and Range. Do not use this for TCs etc. It will be broken in such a case. For Agent Requirement
Method Detail

getName

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

setName

void setName(java.lang.String name)
Set the name of this LeafSyntax instance

getDescription

public java.lang.String getDescription()
Returns the description of the syntax. for example, "OCTET STRING (SIZE (0..255))"
Returns:
the syntax description

getType

public byte getType()
Retrieves the SNMP ASN.1 tag value for this syntax.

The following table lists the syntax, corresponding tag values and the equivalent SnmpAPI types.

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

setType

void setType(byte type)
Set the SNMP type defined by the SnmpAPI types

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

setEquivname

void setEquivname(java.lang.String equivName)
Set equivalent SNMP type name

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 the syntax is not enumerated.
See Also:
getLabel(int), getEnumint()

getEnumint

public int[] getEnumint()
Gives all the values present for an enumerated syntax.

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()

setSize

void setSize(int size)
Set maximum Size restriction for string type syntaxes

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()

setMin

void setMin(long MIN)
Set minimum value allowed for integer type syntaxes

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()

setMax

void setMax(long MAX)
Set maximum value allowed for integer type syntaxes

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

SnmpVar createvariable(java.lang.String value,
                       java.lang.String enc)
                 throws SnmpException

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.

The following table lists the syntax and and their corresponding SnmpVar object.

SyntaxCorresponding SnmpVar Object
OCTET STRING/BITSSnmpString
INTEGER/Integer32SnmpInt
Unsigned32SnmpUnsignedInt
Counter/Counter32 SnmpCounter
Gauge/Gauge32SnmpGauge
Counter64SnmpCounter64
OBJECT IDENTIFIERSnmpOID
IpAddressSnmpIpAddress
NetworkAddressSnmpNetworkAddress
OpaqueSnmpOpaque

For creating variable for the syntax INTEGER, Counter, Counter32, Counter64, Gauge, Gauge32, TimeTicks input string can be given 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

If you want to set the value for IpAddress in the hexformat, then the value should contain 4 bytes and the value should be enclosed within single quotes and should end with "h" or "H". for example, '80C60164`h or '80C60164`H

If you want to set the value for IpAddress in the binary format, then the value should contain 4 bytes and the value should be enclosed within single quotes and should end with "b" or "B". for example, '10000000110001100000000101100100'b or '10000000110001100000000101100100'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 example, if the byte array contains 0a,0b,0c,0d,0e,0f, then the value is set as '0a:0b:0c:0d:0e:0f'

Parameters:
value - the string representation of the value.
Returns:
the SnmpVar instance for the value.
Throws:
SnmpException - is thrown on format errors.
See Also:
createVariable(String,String)

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.

If you want to get all the enumerated labels, the method getEnumlables() can be used.

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

getInt

public int getInt(java.lang.String s)
Gets the int value of the label argument.

If you want to get all the enumerated values, the method getEnumint() can be used.

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

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 if enumerated or if the syntax does not have the range restriction.
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.

stringToArray

long[] stringToArray(java.lang.String str)

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

setSyntax

void setSyntax(LeafSyntax syn)

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.

getRange

RangeList getRange()
the range is particular to the LeafSyntax object. this returns that.

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.

setRange

void setRange(RangeList range)
Sets the range object for this syntax element.

readType

LeafSyntax readType(java.io.DataInputStream inp,
                    java.lang.Object parentType,
                    MibModule module)
              throws java.io.IOException
Reads in a syntax element. This could be a plain Integer or a ranged type. If it is a TC then we need to retrieve the syntax element and if their is a range associated with it, then clone the TC element and add the range to the TC. the parentType denotes a node or may be another TC.

readType

LeafSyntax readType(com.adventnet.snmp.mibs.mibparser.BaseSyntax bs,
                    java.lang.Object parentType,
                    MibModule module)

initializeMINandMAXvalues

void initializeMINandMAXvalues()

getSnmpType

byte getSnmpType(int nodeType)
Converts the node type value to the corresponding SnmpAPI type value;

getTypeStr

java.lang.String getTypeStr(int type)

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.

getBITSRange

boolean getBITSRange(java.lang.String val)

getBaseSyntaxName

java.lang.String getBaseSyntaxName()

isFixedLength

boolean isFixedLength(long[] inst,
                      java.util.Vector indexMibNodes)

isFixedLen

boolean isFixedLen()