FileDocCategorySizeDatePackage
SnmpIpAddress.javaAPI DocJava SE 5 API5972Fri Aug 26 14:55:02 BST 2005com.sun.jmx.snmp

SnmpIpAddress

public class SnmpIpAddress extends SnmpOid
Represents an SNMP IpAddress.

This API is a Sun Microsystems internal API and is subject to change without notice.

version
4.10 12/19/03
author
Sun Microsystems, Inc

Fields Summary
static final String
name
Name of the type.
Constructors Summary
public SnmpIpAddress(byte[] bytes)
Constructs a new SnmpIpAddress from the specified bytes array.

param
bytes The four bytes composing the address.
exception
IllegalArgumentException The length of the array is not equal to four.

	buildFromByteArray(bytes);
    
public SnmpIpAddress(long addr)
Constructs a new SnmpIpAddress from the specified long value.

param
addr The initialization value.

	int address = (int)addr ;
	byte[] ipaddr = new byte[4];

	ipaddr[0] = (byte) ((address >>> 24) & 0xFF);
	ipaddr[1] = (byte) ((address >>> 16) & 0xFF);
	ipaddr[2] = (byte) ((address >>> 8) & 0xFF);
	ipaddr[3] = (byte) (address & 0xFF);
    
	buildFromByteArray(ipaddr);
    
public SnmpIpAddress(String dotAddress)
Constructs a new SnmpIpAddress from a dot-formatted String. The dot-formatted String is formulated x.x.x.x .

param
dotAddress The initialization value.
exception
IllegalArgumentException The string does not correspond to an ip address.

	super(dotAddress) ;
	if ((componentCount > 4) ||
	    (components[0] > 255) ||
	    (components[1] > 255) ||
	    (components[2] > 255) ||
	    (components[3] > 255)) {
	    throw new IllegalArgumentException(dotAddress) ;
	}
    
public SnmpIpAddress(long b1, long b2, long b3, long b4)
Constructs a new SnmpIpAddress from four long values.

param
b1 Byte 1.
param
b2 Byte 2.
param
b3 Byte 3.
param
b4 Byte 4.
exception
IllegalArgumentException A value is outside of [0-255].

	super(b1, b2, b3, b4) ;
	if ((components[0] > 255) ||
	    (components[1] > 255) ||
	    (components[2] > 255) ||
	    (components[3] > 255)) {
	    throw new IllegalArgumentException() ;
	}
    
Methods Summary
public static voidappendToOid(SnmpOid source, SnmpOid dest)
Appends an SnmpOid representing an SnmpIpAddress to another OID.

param
source An OID representing an SnmpIpAddress value.
param
dest Where source should be appended.

	if (source.getLength() != 4) {
	    throw new IllegalArgumentException() ;
	}
	dest.append(source) ;
    
private voidbuildFromByteArray(byte[] bytes)
Build Ip address from byte array.

	if (bytes.length != 4) {
	    throw new IllegalArgumentException() ;
	}
	components = new long[4] ;
	componentCount= 4;
	components[0] = (bytes[0] >= 0) ? bytes[0] : bytes[0] + 256 ;
	components[1] = (bytes[1] >= 0) ? bytes[1] : bytes[1] + 256 ;
	components[2] = (bytes[2] >= 0) ? bytes[2] : bytes[2] + 256 ;
	components[3] = (bytes[3] >= 0) ? bytes[3] : bytes[3] + 256 ;
    
public byte[]byteValue()
Converts the address value to its byte array form.

return
The byte array representation of the value.

	byte[] result = new byte[4] ;
	result[0] = (byte)components[0] ;
	result[1] = (byte)components[1] ;
	result[2] = (byte)components[2] ;
	result[3] = (byte)components[3] ;
    
	return result ;
    
public final java.lang.StringgetTypeName()
Returns a textual description of the type object.

return
ASN.1 textual description.

	return name ;
    
public static intnextOid(long[] index, int start)
Scans an index OID, skips the address value and returns the position of the next value.

param
index The index array.
param
start The position in the index array.
return
The position of the next value.
exception
SnmpStatusException There is no address value available at the start position.

	if (start + 4 <= index.length) {
	    return start + 4 ;
	}
	else {
	    throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
	}
    
public java.lang.StringstringValue()
Converts the address to its String form. Same as toString(). Exists only to follow a naming scheme.

return
The String representation of the value.

	return toString() ;
    
public static SnmpOidtoOid(long[] index, int start)
Extracts the ip address from an index OID and returns its value converted as an SnmpOid.

param
index The index array.
param
start The position in the index array.
return
The OID representing the ip address value.
exception
SnmpStatusException There is no ip address value available at the start position.

	if (start + 4 <= index.length) {
	    try {
		return new SnmpOid(
				   index[start],
				   index[start+1],
				   index[start+2],
				   index[start+3]) ;
	    }
	    catch(IllegalArgumentException e) {
		throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
	    }
	}
	else {
	    throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
	}