ewe.data
Class DataObject

java.lang.Object
  extended byewe.data.DataObject
All Implemented Interfaces:
Comparable, Copyable, DataUnit
Direct Known Subclasses:
Decimal, Double, EditableObject, LiveObject, Long, LookupData, Property, SerialPortSpecs, TextFormatter, Time, Vector

public class DataObject
extends Object
implements DataUnit

This is an object which completely implements the DataUnit interface. The following is the default behavior.

getNew() will use the Reflection API to attempt to create a new instance of the object via a public default constructor. If successful, the object created will be returned.

getCopy() will call first call getNew() and then invoke copyFrom() on the created object passing it this object as a parameter.

copyFrom(Object other) envokes the ewe.util.Utils.copy(Object source,Object dest) with this as the destination and the "other"

compareTo() returns 0 if the two Objects are the same object, or 1 otherwise.

equals() returns true if compareTo() returns 0.


Constructor Summary
DataObject()
           
 
Method Summary
 boolean _getSetField(String fieldName, Wrapper wrapper, boolean isGet)
          This is used for data transfer using a ewe.reflect.FieldTransfer object.
static String appendAllFields(String fieldName, Object dataObject, boolean declaredOnly)
           
 int compareTo(Object other)
          Compare this object with another.
protected  void copied(Object from)
          This method is called after the base implementation of copyFrom() is executed.
 void copyFrom(Object other)
          Copy all appropriate data from another object.
 boolean equals(Object other)
          Returns if this object is considered equal to the other object.
 Object getCopy()
          Return a copy of this object.
 Field getDeclaredField(String fieldName, String baseClassName)
          Get a declared field for this object for the specified baseClassName.
 Object getDeclaredFieldValue(String fieldName, String baseClassName)
          This returns the value of a declared field as an object.
 Wrapper getDeclaredFieldValue(String fieldName, Wrapper destination, String baseClassName)
          Get the value of a declared field in a Wrapper object.
static String getFieldList(Object objectOrClass, boolean declaredOnly)
          Get a comma separated list of fields for the specified object.
static String getFieldList(Object reflectOrClass, Object dataObject, boolean declaredOnly)
           
 String getMyFieldList(String baseClassName)
          Gets the declared field list for a particular class in the class hierarchy of this LiveObject.
 Object getNew()
          Return a new Object which is of the same class as the original.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, toString
 

Constructor Detail

DataObject

public DataObject()
Method Detail

getCopy

public Object getCopy()
Description copied from interface: Copyable
Return a copy of this object.

Specified by:
getCopy in interface Copyable

copyFrom

public void copyFrom(Object other)
Description copied from interface: DataUnit
Copy all appropriate data from another object.

Specified by:
copyFrom in interface DataUnit

compareTo

public int compareTo(Object other)
Description copied from interface: Comparable
Compare this object with another. It should return: less than 0 if this object is considered LESS than the "other" object; greater than 0 if this object is considered GREATER than the "other" object; 0 if this object is considered EQUAL to the "other" object. (i.e. it is an implicit subtraction).

Specified by:
compareTo in interface Comparable

equals

public boolean equals(Object other)
Description copied from class: Object
Returns if this object is considered equal to the other object.

Overrides:
equals in class Object
Parameters:
other - Another object to compare to.
Returns:
true if this object is considered equal to the other object.

getNew

public Object getNew()
Description copied from interface: DataUnit
Return a new Object which is of the same class as the original.

Specified by:
getNew in interface DataUnit

_getSetField

public boolean _getSetField(String fieldName,
                            Wrapper wrapper,
                            boolean isGet)
This is used for data transfer using a ewe.reflect.FieldTransfer object. It is used if the programmer requests a field transfer but there is no such field in the object. In that case the _getSetField() method will be called and the programmer can programatically get/set the field data.

By default this method calls getProperties() and then calls the _getSetField() method in PropertyList.

Parameters:
fieldName - The name of the field.
wrapper - A wrapper containing the data to be assigned to the field or the wrapper into which you should place the field data.
isGet - if this is true then it is a get operation (in which case you should set the wrapper value to be the field value) if it is false it is a set operation and the wrapper contains the field value to assign to the field.
Returns:
the Object should return true if the field data was successfully transfered, false if not.

getFieldList

public static String getFieldList(Object objectOrClass,
                                  boolean declaredOnly)
Get a comma separated list of fields for the specified object.

Parameters:
objectOrClass - the object, or Class of the object, or Reflect of the object.
declaredOnly - if this is true only the field declared by the class (not those inherited) are used.
Returns:
a comma separatedlist of fields (e.g. "name,age,dob").

getFieldList

public static String getFieldList(Object reflectOrClass,
                                  Object dataObject,
                                  boolean declaredOnly)

getMyFieldList

public String getMyFieldList(String baseClassName)
                      throws IllegalArgumentException
Gets the declared field list for a particular class in the class hierarchy of this LiveObject.

Parameters:
baseClassName - This should be the last part of the class name or the fully qualified class name. For example if the object is of type samples.data.PersonInfo, the baseClassName can be "PersonInfo".
Returns:
A comma separated list of field names.
Throws:
IllegalArgumentException - If the baseClassName does not appear in the class hierarchy.

getDeclaredField

public Field getDeclaredField(String fieldName,
                              String baseClassName)
                       throws IllegalArgumentException
Get a declared field for this object for the specified baseClassName.

Parameters:
fieldName - The fieldName
baseClassName - This should be the last part of the class name or the fully qualified class name. For example if the object is of type samples.data.PersonInfo, the baseClassName can be "PersonInfo".
Returns:
the Field or null if no declared field of that name was found.
Throws:
IllegalArgumentException - If the baseClassName does not appear in the class hierarchy.

getDeclaredFieldValue

public Wrapper getDeclaredFieldValue(String fieldName,
                                     Wrapper destination,
                                     String baseClassName)
                              throws IllegalArgumentException
Get the value of a declared field in a Wrapper object.

Parameters:
fieldName - The fieldName
destination - a destination wrapper for the value. This can be null in which case a new one will be created.
baseClassName - This should be the last part of the class name or the fully qualified class name. For example if the object is of type samples.data.PersonInfo, the baseClassName can be "PersonInfo".
Returns:
a Wrapper containing the field value or null if the field does not exist, or if the field value could not be retrieved.
Throws:
IllegalArgumentException - If the baseClassName does not appear in the class hierarchy.

getDeclaredFieldValue

public Object getDeclaredFieldValue(String fieldName,
                                    String baseClassName)
                             throws IllegalArgumentException
This returns the value of a declared field as an object. If the declared field is not of an object type, it will return null;

Parameters:
fieldName - The fieldName
baseClassName - This should be the last part of the class name or the fully qualified class name. For example if the object is of type samples.data.PersonInfo, the baseClassName can be "PersonInfo".
Returns:
The object value of the field or null if the field does not exist, or could not be accessed or was not an object type.
Throws:
IllegalArgumentException - If the baseClassName does not appear in the class hierarchy.

appendAllFields

public static String appendAllFields(String fieldName,
                                     Object dataObject,
                                     boolean declaredOnly)

copied

protected void copied(Object from)
This method is called after the base implementation of copyFrom() is executed. It gives you a chance to do extra work after the standard field by field copy is done.

Parameters:
from - The object that data was copied from.