org.openadaptor.dataobjects
Class SimpleDataObject

java.lang.Object
  extended by org.openadaptor.dataobjects.AbstractDataObject
      extended by org.openadaptor.dataobjects.SimpleDataObject
All Implemented Interfaces:
java.io.Serializable, DataObject
Direct Known Subclasses:
MessageDataObject

public class SimpleDataObject
extends AbstractDataObject
implements java.io.Serializable

The SimpleDataObject extends the AbstractDataObject class to provide a concrete implementation of the DataObject interface. It adds an SDOType instance variable to define the type of the DataObject, and adds a new method "addAttributeValue" which adds an attribute to the SDOType and sets the value for that instance at the same time. In addition it provides some useful general-purpose class methods for comparing attribute values and sdisplaying debugging information about individual DataObjects.

Version:
1.1
Author:
Fred Perry, Tim Bissell
See Also:
AbstractDataObject, Serialized Form

Field Summary
(package private) static long serialVersionUID
           
protected  SDOType type
          The DOType of this instance
 
Fields inherited from class org.openadaptor.dataobjects.AbstractDataObject
log, values
 
Constructor Summary
  SimpleDataObject(DOType type)
          Creates a new SimpleDataObject instance with the SDOType type.
  SimpleDataObject(SDOType type)
          Creates a new SimpleDataObject instance with the SDOType type.
protected SimpleDataObject(SDOType type, java.util.Hashtable values)
          Creates a new SimpleDataObject instance with the type and attribute values.
  SimpleDataObject(java.lang.String newTypename)
          Creates a new SimpleDataObject instance with a new SDOType named from newTypeName.
 
Method Summary
protected static java.lang.String _debugString(DataObject obj, int indent)
          Produce a terse dump of the attributes names and value in obj.
 void addAttributeValue(java.lang.String attrName, java.lang.Object value)
          If an attribute name does not exists, create it and set it to value.
 void addAttributeValue(java.lang.String attrName, java.lang.Object value, DOType valueType)
          If an attribute name does not exists, create it and set it to value.
 DataObject cloneEmpty()
          Returns another object of this type with the same DOType, but no values.
static boolean compareAttributes(DataObject obj1, DataObject obj2, java.lang.String attrName)
           
 void copyValues(DataObject dob)
           
static java.lang.String debugString(DataObject obj)
          Produce a terse dump of the attributes names and value in obj.
static java.lang.String debugString(DataObject[] dobs)
          Produce a terse dump of the DataObjects in dobs.
static DataObject[] deepArrayCopy(DataObject[] dobs)
          ** Array copy **
static CollectionDataObject deepCollectionCopy(CollectionDataObject dob)
          ** Collection copy **
static SimpleDataObject deepCopy(DataObject dob)
          ** Unary copy **
static DOType getDOType(DataObject[] dobs)
          Returns the DOType shared by all the objects in the array, or null if not all the same.
protected static java.lang.String getIndentStr(int indent)
          Returns a string of indent spaces in length Note that indent is constrained to a range of 0 to about 40, the string returned will contain between 0 and about 40 spaces.
 DOType getType()
          Get the type for this object, this is analogous to the "class" of the DataObject.
 boolean isPresent(java.lang.String name)
           
 
Methods inherited from class org.openadaptor.dataobjects.AbstractDataObject
equals, getAttributePathValue, getAttributeValue, isAssociativeArrayIndexing, isNullValue, main, replaceAssociativeArrayIndexFrom, setAssociativeArrayIndexing, setAttributePathValue, setAttributeValue, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

type

protected SDOType type
The DOType of this instance

Constructor Detail

SimpleDataObject

public SimpleDataObject(java.lang.String newTypename)
Creates a new SimpleDataObject instance with a new SDOType named from newTypeName. Note that the type name is not checked for validity; you can pass null or a string containing spaces or starting with digits. These problems will only be flagged if you try and serialise the DataObject (using XMLFormatter, for example).

Parameters:
newTypename - String containing name for new SDOType.

SimpleDataObject

public SimpleDataObject(DOType type)
                 throws InvalidParameterException
Creates a new SimpleDataObject instance with the SDOType type. If type is not an SDOType, an SDOType copy is made of it.

Parameters:
type - SDOType type for this instance.
Throws:
InvalidParameterException - If there was a problem making an SDOType copy of type.

SimpleDataObject

public SimpleDataObject(SDOType type)
Creates a new SimpleDataObject instance with the SDOType type.

Parameters:
type - SDOType type for this instance.

SimpleDataObject

protected SimpleDataObject(SDOType type,
                           java.util.Hashtable values)
Creates a new SimpleDataObject instance with the type and attribute values. This method is protected as it is only intended for use by trusted code; no validity checking on the contents if the values Hashtable takes place.

Parameters:
type - SDOType type for this instance.
Method Detail

getDOType

public static DOType getDOType(DataObject[] dobs)
Returns the DOType shared by all the objects in the array, or null if not all the same. The array can contain null elements, which are ignored, and the DOTypes are compared using equals(), not ==.

Parameters:
dobs - DataObject array to be checked.
Returns:
the common DOType of the array, or null if there is none.

compareAttributes

public static boolean compareAttributes(DataObject obj1,
                                        DataObject obj2,
                                        java.lang.String attrName)
                                 throws InvalidParameterException
Throws:
InvalidParameterException

debugString

public static java.lang.String debugString(DataObject obj)
Produce a terse dump of the attributes names and value in obj. The attributes are on separate lines, indented by indent spaces. Nested DataObject arrays are indented by two spaces.

Parameters:
obj - DataObject to be dumped.
Returns:
String representation of obj.

debugString

public static java.lang.String debugString(DataObject[] dobs)
Produce a terse dump of the DataObjects in dobs.

Parameters:
dobs - DataObject Array to be dumped.
Returns:
String representation of dobs.

_debugString

protected static java.lang.String _debugString(DataObject obj,
                                               int indent)
Produce a terse dump of the attributes names and value in obj. The attributes are on separate lines, indented by indent spaces. Nested DataObject arrays are indented by two spaces.

Parameters:
obj - DataObject to be dumped.
indent - level of indent for this object
Returns:
String representation of obj (returns null pointer for null object).

getIndentStr

protected static java.lang.String getIndentStr(int indent)
Returns a string of indent spaces in length Note that indent is constrained to a range of 0 to about 40, the string returned will contain between 0 and about 40 spaces.


cloneEmpty

public DataObject cloneEmpty()
Returns another object of this type with the same DOType, but no values. This enables factory classes to create new DataObjects of the same type.

Specified by:
cloneEmpty in interface DataObject
Overrides:
cloneEmpty in class AbstractDataObject
Returns:
New empty DataObject of same class.

getType

public DOType getType()
Get the type for this object, this is analogous to the "class" of the DataObject.

Specified by:
getType in interface DataObject
Specified by:
getType in class AbstractDataObject
Returns:
DOType representing this DataObject's type

copyValues

public void copyValues(DataObject dob)

addAttributeValue

public void addAttributeValue(java.lang.String attrName,
                              java.lang.Object value)
                       throws InvalidParameterException
If an attribute name does not exists, create it and set it to value. If it already exists, just set its value.

Parameters:
attrName - Attribute name
value - New attribute value
Throws:
InvalidParameterException - If an attribute with that name exists, and its type does not match value's type.

addAttributeValue

public void addAttributeValue(java.lang.String attrName,
                              java.lang.Object value,
                              DOType valueType)
                       throws InvalidParameterException
If an attribute name does not exists, create it and set it to value. If valueType is not null, check it matches the value type. If value is null, use valueType to determine the attribute type. If it already exists, just set its value.

Parameters:
attrName - Attribute name
value - New attribute value
valueType - New attribute type
Throws:
InvalidParameterException - If an attribute with that name exists, and its type does not match value's type or valueType, or if both value and valueType are null, so we cannot determine the type of attribute to create.

isPresent

public boolean isPresent(java.lang.String name)

deepArrayCopy

public static DataObject[] deepArrayCopy(DataObject[] dobs)
                                  throws DataObjectException
** Array copy **

Throws:
DataObjectException

deepCollectionCopy

public static CollectionDataObject deepCollectionCopy(CollectionDataObject dob)
                                               throws DataObjectException
** Collection copy **

Throws:
DataObjectException

deepCopy

public static SimpleDataObject deepCopy(DataObject dob)
                                 throws DataObjectException
** Unary copy **

Throws:
DataObjectException