com.boylesoftware.cb2
Class DataModel

java.lang.Object
  extended bycom.boylesoftware.cb2.DataModel
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
DynamicDataModel, UserBasicDM, UserRoleBasicDM

public abstract class DataModel
extends java.lang.Object
implements java.io.Serializable

Parent class for Data Models used by the DAO.

Version:
$Id: DataModel.java,v 1.5 2004/05/19 14:24:05 levahim Exp $
Author:
Lev Himmelfarb
See Also:
DAO, Serialized Form

Constructor Summary
DataModel()
           
 
Method Summary
 java.lang.String[] diff(DataModel dm)
          Finds fields that have different values in this DM and the specified one, which must belong to the exactly same class.
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this data model.
 java.lang.Object getField(java.lang.String name)
          Gets a field's value by its name.
 int hashCode()
          Returns hash code of the data model.
 void setField(java.lang.String name, java.lang.Object value)
          Sets new value to a field via reflection.
 java.lang.String toString()
          Gives string representation of the data model including values of all its fields.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataModel

public DataModel()
Method Detail

hashCode

public int hashCode()
Returns hash code of the data model. This implementation actually returns the hash code of the model's string representation returned by toString method making two data models equal if they contain the same data.

Note, that this method is not very effective. Its performace greatly depends on the amount of data in the DM, so try to avoid using large DMs in hash-like data structures.

Returns:
the model's hash code.

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this data model. This implementation checks if obj is a reference to the same instance as this one, then, if it is not so, it checks if obj belongs to the exactly same class and if its string representation is the same.

Parameters:
obj - data model, to which to compare this one.
Returns:
true if obj equals to this data model, that is it is not null, has the same type and the same string representation.

toString

public java.lang.String toString()
Gives string representation of the data model including values of all its fields. The output includes nested DMs as well.

Note, that the resulting string generated by this method can be HUGE.

Returns:
string representation of the data model.

diff

public java.lang.String[] diff(DataModel dm)
Finds fields that have different values in this DM and the specified one, which must belong to the exactly same class.

This method ignores all array and nested DM fields.

Parameters:
dm - another DM.
Returns:
array of names of fields that have different values in this and the specified DM. Returns an empty array if the DMs are equal (equal, but excluding nested DMs, as opposed to the equals method, which compares string representations of the DMs that include values from all nested DMs and arrays of nested DMs).
Throws:
java.lang.IllegalArgumentException - if type of the specified DM is different from the type of this one.

getField

public java.lang.Object getField(java.lang.String name)
                          throws java.lang.NoSuchFieldException
Gets a field's value by its name.

Parameters:
name - name of a DM field.
Returns:
the field's value.
Throws:
java.lang.NoSuchFieldException - if no public field with the specified name is defined in the DM.

setField

public void setField(java.lang.String name,
                     java.lang.Object value)
              throws java.lang.NoSuchFieldException
Sets new value to a field via reflection. This method uses set method of java.lang.reflect.Field, and therefore all features of the the set method apply to this method as well.

Parameters:
name - DM field's name.
value - new value.
Throws:
java.lang.NoSuchFieldException - if no public field with the specified name is defined in the DM.


Copyright © 2002,2003,2004 - Boyle Software, Inc.