org.opennms.bb.dp.events
Class EventParamValue

java.lang.Object
  |
  +--org.opennms.bb.dp.events.EventParamValue
All Implemented Interfaces:
Serializable

public class EventParamValue
extends Object
implements Serializable

This class is built to encapsulate parameter value from the event stream. Each parameter value encapsulates a type, encoding, and actual value. The value's class can be determined by the type. The encoding rules all for types, like SnmpOpaque, to be encoded as text even if they contain binary data.

Version:
CVS $Revision: 1.4 $
Author:
Brian Weaver, OpenNMS
See Also:
Serialized Form

Field Summary
private static char[] BASE64_CHARS
          The base64 encoding map.
private static char BASE64_PAD
          The base64 padding character
private static byte[] BASE64_VALUES
           
private  int m_encoding
          The textual encoding that should be used with this encapsulated object.
private  int m_type
          The type of the encapsulated object.
private  Object m_value
          The encapsulated object for this parameter.
static int TYPE_INT
          Defines the value as a 32-bit integer value.
static String[] TYPE_NAMES
          This member defines all the appropriate names for the defined types.
static int TYPE_SNMP_COUNTER32
          Defines the encasulated value as an instance of an SnmpCopunter32 object.
static int TYPE_SNMP_COUNTER64
          Defines the encasulated value as an instance of an SnmpCounter64 object.
static int TYPE_SNMP_GAUGE32
          Defines the encasulated value as an instance of an SnmpGauge32 object.
static int TYPE_SNMP_INT32
          Defines a 32-bit SNMP integer value.
static int TYPE_SNMP_IPADDRESS
          Defines the encasulated value as an instance of an SnmpIpAddress object.
static int TYPE_SNMP_NULL
          Defines the encasulated value as an instance of an SnmpNull object.
static int TYPE_SNMP_OBJECT_IDENTIFIER
          Defines the encapsulated value as an instance of an SnmpObjectId object.
static int TYPE_SNMP_OCTET_STRING
          Defines the encapsulated value as an SnmpOctetString instance.
static int TYPE_SNMP_OPAQUE
          Defines the encasulated value as an instance of an SnmpOpaque object.
static int TYPE_SNMP_TIMETICKS
          Defines the encasulated value as an instance of an SnmpTimeTicks object.
static int TYPE_STRING
          This is the default type for a parameter value from the Event DTD.
static int XML_ENCODING_BASE64
          The value should be encoded using a base64 encoding method.
static String[] XML_ENCODING_NAMES
          The attribute values for the encoding type as they appear in the Event DTD.
static int XML_ENCODING_TEXT
          The value should be encoded using a plain textual string in the XML Document.
 
Constructor Summary
EventParamValue()
          Builds a new instance of an encapsulated parameter from an event stream.
EventParamValue(int type, int encoding, Object value)
          Constructs a new instance of an encapsulated value.
EventParamValue(int type, Object value)
          Constructs a new parameter instance with the specified type and encapsulated object.
EventParamValue(Object value)
          Constructs a new parameter instance with the specified type and encapsulated object.
 
Method Summary
static byte[] decodeBase64(char[] data)
          Decodes a character array into the corresponding byte array.
static char[] encodeBase64(byte[] data)
          Encodes the passed byte array using the base64 rules.
static char[] filterBase64(char[] data)
          Filters an existing buffer that was encoded using base64 to only the appropriate characters.
 int getEncoding()
          Returns the encoding to be used when written to an XML event stream.
 int getType()
          Returns the type for the encapsulated object.
 Object getValue()
          Returns the encapsualted value.
(package private)  void serializeToXML(PrintStream ps)
          Writes self to event stream
 void set(int type, int encoding, Object value)
          Sets the object instance to an encapsulated value.
 void set(int type, Object value)
          Sets the object instance to the specified type and encapsulated object.
 void setEncoding(int encoding)
          Sets the encoding to be used when written to an XML event stream.
 void setType(int type)
          Sets the encapsulated type.
 void setValue(Object value)
          Sets the encapsulate value.
 String toString()
          Converts the value of the instance to a string representation in the correct encoding system.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

TYPE_STRING

public static final int TYPE_STRING

This is the default type for a parameter value from the Event DTD. The basic value is represented by a java.lang.String object.


TYPE_INT

public static final int TYPE_INT

Defines the value as a 32-bit integer value. The type returned by the call to get value will be a java.lang.Integer object.


TYPE_SNMP_INT32

public static final int TYPE_SNMP_INT32

Defines a 32-bit SNMP integer value. A SnmpInt32 object is the instance encapsulated by the parameter instance.


TYPE_SNMP_OCTET_STRING

public static final int TYPE_SNMP_OCTET_STRING

Defines the encapsulated value as an SnmpOctetString instance.


TYPE_SNMP_NULL

public static final int TYPE_SNMP_NULL

Defines the encasulated value as an instance of an SnmpNull object.


TYPE_SNMP_OBJECT_IDENTIFIER

public static final int TYPE_SNMP_OBJECT_IDENTIFIER

Defines the encapsulated value as an instance of an SnmpObjectId object.


TYPE_SNMP_IPADDRESS

public static final int TYPE_SNMP_IPADDRESS

Defines the encasulated value as an instance of an SnmpIpAddress object.


TYPE_SNMP_COUNTER32

public static final int TYPE_SNMP_COUNTER32

Defines the encasulated value as an instance of an SnmpCopunter32 object.


TYPE_SNMP_GAUGE32

public static final int TYPE_SNMP_GAUGE32

Defines the encasulated value as an instance of an SnmpGauge32 object.


TYPE_SNMP_TIMETICKS

public static final int TYPE_SNMP_TIMETICKS

Defines the encasulated value as an instance of an SnmpTimeTicks object.


TYPE_SNMP_OPAQUE

public static final int TYPE_SNMP_OPAQUE

Defines the encasulated value as an instance of an SnmpOpaque object.


TYPE_SNMP_COUNTER64

public static final int TYPE_SNMP_COUNTER64

Defines the encasulated value as an instance of an SnmpCounter64 object.


TYPE_NAMES

public static final String[] TYPE_NAMES

This member defines all the appropriate names for the defined types. These string values match the names as they appear in the Event DTD for an encoded parameter value.


XML_ENCODING_TEXT

public static final int XML_ENCODING_TEXT

The value should be encoded using a plain textual string in the XML Document.


XML_ENCODING_BASE64

public static final int XML_ENCODING_BASE64

The value should be encoded using a base64 encoding method.


XML_ENCODING_NAMES

public static final String[] XML_ENCODING_NAMES

The attribute values for the encoding type as they appear in the Event DTD.


BASE64_CHARS

private static final char[] BASE64_CHARS

The base64 encoding map. Using 6-bit values it is possible to map 24-bits into 4 characters. If there are not sufficent amount of bits to makeup six then it is padded with BASE64_PAD.


BASE64_VALUES

private static final byte[] BASE64_VALUES

BASE64_PAD

private static final char BASE64_PAD
The base64 padding character

m_type

private int m_type
The type of the encapsulated object.

m_encoding

private int m_encoding
The textual encoding that should be used with this encapsulated object.

m_value

private Object m_value
The encapsulated object for this parameter.
Constructor Detail

EventParamValue

public EventParamValue()

Builds a new instance of an encapsulated parameter from an event stream. The default instance contains an encapsulated empty string, type == TYPE_STRING, and encoding == XML_ENCODING_TEXT.


EventParamValue

public EventParamValue(Object value)

Constructs a new parameter instance with the specified type and encapsulated object. The encoding type is infered from the passed type.

Parameters:
value - The value to encapsulate.

EventParamValue

public EventParamValue(int type,
                       Object value)

Constructs a new parameter instance with the specified type and encapsulated object. The encoding type is infered from the passed type.

Parameters:
type - The type of the encapsulate value.
value - The value to encapsulate.

EventParamValue

public EventParamValue(int type,
                       int encoding,
                       Object value)
Constructs a new instance of an encapsulated value. The passed parameters define the type, encoding, and value of the new instance.
Parameters:
type - The type of the encapsulate object.
encoding - The encoding to use with XML.
value - The value to encapsulate.
Method Detail

serializeToXML

void serializeToXML(PrintStream ps)
Writes self to event stream

getType

public int getType()
Returns the type for the encapsulated object.

setType

public void setType(int type)
Sets the encapsulated type.
Parameters:
type - The new type for the instance.

getEncoding

public int getEncoding()
Returns the encoding to be used when written to an XML event stream.

setEncoding

public void setEncoding(int encoding)
Sets the encoding to be used when written to an XML event stream.
Parameters:
encoding - The new encoding format.

getValue

public Object getValue()
Returns the encapsualted value.

setValue

public void setValue(Object value)
Sets the encapsulate value.
Parameters:
value - The new value for the instance.

set

public void set(int type,
                Object value)

Sets the object instance to the specified type and encapsulated object. The encoding type is infered from the passed type.

Parameters:
type - The type of the encapsulate value.
value - The value to encapsulate.

set

public void set(int type,
                int encoding,
                Object value)
Sets the object instance to an encapsulated value. The passed parameters define the type, encoding, and value of the new instance.
Parameters:
type - The type of the encapsulate object.
encoding - The encoding to use with XML.
value - The value to encapsulate.

encodeBase64

public static char[] encodeBase64(byte[] data)

Encodes the passed byte array using the base64 rules. The base64 encoding schema is performed by grouping the bytes in to 6-bit quantities and then encoding them.

For more information see RFC1341 for the format used for base64 encoding.

Parameters:
data - The input byte array
Returns:
The converted data in a character stream.

decodeBase64

public static byte[] decodeBase64(char[] data)

Decodes a character array into the corresponding byte array. The buffer must be an intergral number of 4 character. I.E. size mod 4 is equal to zero or an exception will be thrown. Likewise, if there is an invalid character in the input array then an exception will be thrown.

Parameters:
data - The data stream to be filtered.
Returns:
The coverted array of bytes.
Throws:
IllegalArgumentException - Thrown if an invalid buffer that cannot be decoded is passed.

filterBase64

public static char[] filterBase64(char[] data)

Filters an existing buffer that was encoded using base64 to only the appropriate characters. This is useful for removing whitespace, character returns, and other chaff if it is in the string before passing it to the decoding routine.

If a correct buffer cannot be build (size % 4 != 0) then an exception will be thrown.

Parameters:
data - The data stream to be filtered.
Returns:
The filtered array of characters.
Throws:
IllegalArgumentException - Thrown if an invalid buffer that cannot be filtered is passed.

toString

public String toString()
Converts the value of the instance to a string representation in the correct encoding system.
Overrides:
toString in class Object