org.ipdr.common
Class CompositeData

java.lang.Object
  extended by org.ipdr.common.CompositeData
Direct Known Subclasses:
FNFData

public class CompositeData
extends java.lang.Object

This class represents an arbitrary collection of structured data. The data is built from the basic data types as outlined in the Java Management Extensions (JMX) 1.0 Specification Chapter 3, OpenMBeans.

A CompositeData object is self describing, utilizing a CompositeType class which describes what fields are in an object, and based on order, how they are layed out.

The structure of a given instance of the CompositeData object is determined when it is constructed. The type and object array are immutable. Entries within the object array may be overridden, but they are constrained according to the CompositeType information.

This implementation diverges from the JMX 1.0 spec in that it will allow values of fields within the object to be modified. This can simplify management of frequently constructed objects in some instance.


Field Summary
protected  java.lang.Object[] fields_
          The fields within this Composite Data
protected  CompositeType type_
          The type of this Composite Data
 
Constructor Summary
CompositeData(java.lang.Object[] fields, CompositeType type)
          Builds a composite type from the supplied array of objects and the type specifier.
 
Method Summary
protected  void assertCompositeType(OpenType type, java.lang.Object obj)
          This method will throw an exception if the Data Object is not compatable with the Composite Type object.
protected  void assertObject(OpenType type, java.lang.Object obj)
          This method will throw an exception if the Data Object is not compatable with the Type object.
protected  void assertOpenType(OpenType type, java.lang.Object obj)
          This method will throw an exception if the Data Object is not compatable with the Type object.
 java.lang.Object getField(int fieldPosition)
          Returns the object at the given index.
 java.lang.Object getField(java.lang.String fieldName)
          Returns the object for the named field.
 CompositeType getType()
          Retreives the type list which describes the layout of data for this CompositeType.
static void main(java.lang.String[] args)
          Simple demonstration entry point.
 void setField(java.lang.String fieldName, java.lang.Object obj)
          Method to set the Data object at the named field.
 java.lang.String toString()
          Utility method for displaying types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type_

protected CompositeType type_
The type of this Composite Data


fields_

protected java.lang.Object[] fields_
The fields within this Composite Data

Constructor Detail

CompositeData

public CompositeData(java.lang.Object[] fields,
                     CompositeType type)
              throws BadCompositeException,
                     IPDRException
Builds a composite type from the supplied array of objects and the type specifier. The two must be in agreement.

Parameters:
fields - Object Array
type - Object of CompositeType
Throws:
BadCompositeException - when array of objects is null or the Data and Type are not in agreement.
IPDRException - when a IPDR functionality related exception occurs
Method Detail

assertObject

protected void assertObject(OpenType type,
                            java.lang.Object obj)
                     throws BadCompositeException,
                            IPDRException
This method will throw an exception if the Data Object is not compatable with the Type object.

Parameters:
type - The OpenType
obj - The Data Object
Throws:
BadCompositeException - when the TypeCode is not recognised or when the Data and Type are not in agreement
IPDRException - when a IPDR functionality related exception occurs

assertOpenType

protected void assertOpenType(OpenType type,
                              java.lang.Object obj)
                       throws BadCompositeException,
                              IPDRException
This method will throw an exception if the Data Object is not compatable with the Type object.

Parameters:
type - The OpenType
obj - The Data Object
Throws:
BadCompositeException - when the TypeCode is not recognised or when the Data and Type are not in agreement
IPDRException - when a IPDR functionality related exception occurs

assertCompositeType

protected void assertCompositeType(OpenType type,
                                   java.lang.Object obj)
                            throws BadCompositeException,
                                   IPDRException
This method will throw an exception if the Data Object is not compatable with the Composite Type object.

Parameters:
type - The OpenType
obj - The Data Object
Throws:
BadCompositeException - when the TypeCode is not recognised or when the Data and Type are not in agreement
IPDRException - when a IPDR functionality related exception occurs

getType

public CompositeType getType()
Retreives the type list which describes the layout of data for this CompositeType. The returned array should not be altered.

Returns:
The Type

getField

public java.lang.Object getField(java.lang.String fieldName)
                          throws BadCompositeException
Returns the object for the named field.

Parameters:
fieldName - The field name
Returns:
The field value
Throws:
BadCompositeException - when the field does not exist.

getField

public java.lang.Object getField(int fieldPosition)
Returns the object at the given index.

Parameters:
fieldPosition - The field's position
Returns:
The field value

setField

public void setField(java.lang.String fieldName,
                     java.lang.Object obj)
              throws BadCompositeException,
                     IPDRException
Method to set the Data object at the named field.

Parameters:
fieldName - The field name
obj - The new field value
Throws:
BadCompositeException - when the field does not exist.
IPDRException

toString

public java.lang.String toString()
Utility method for displaying types. Use XML style output.

Overrides:
toString in class java.lang.Object
Returns:
String representation of the CompositeData

main

public static void main(java.lang.String[] args)
Simple demonstration entry point. Creates a CompositeData with all of the basic types. Then it invokes toString() method on constructed type to display.