org.jcon.data
Class BeanRecord

java.lang.Object
  extended by org.jcon.data.BeanRecord
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Record

public class BeanRecord
extends java.lang.Object
implements Record

This is a wrapper class that takes an arbitrary object and determines the editable properties from it using the JavaBeans introspector. This allows us to perform Record operations on objects that don't implement Record directly.

See Also:
Serialized Form

Constructor Summary
BeanRecord()
          Creates a new BeanRecord with no base bean.
BeanRecord(java.lang.Class beanClass)
          Creates a new BeanRecord, creating a new base bean by trying to instantiate an instance of the given class using the default constructor.
BeanRecord(java.lang.Object bean)
          Creates a new BeanRecord based on the given bean.
 
Method Summary
 java.lang.Object clone()
          Clones both the BeanRecord and the subject Record, by setting all editable properties in the clone to match those in the original.
static java.lang.Object cloneBean(java.lang.Object subject)
          Clones an object that's not normally cloneable.
 java.util.Iterator editableFields()
          A list of FieldDefs describing all the editable (readable and writable) in this Record.
 java.util.Map getAllFieldValues()
          Field values for all readable fields.
 java.lang.Object getBean()
          The bean being operated on.
 FieldDef getField(java.lang.String fieldName)
          Returns a FieldDef for the given field.
 java.lang.Object getFieldValue(java.lang.String fieldName)
          Gets the value for a given field.
 java.util.Map getFieldValues()
          Field values for all editable fields.
 java.util.Iterator readableFields()
          A list of FieldDefs describing all the readable fields in this Record.
 void setBean(java.lang.Object newBean)
          The bean being operated on.
 void setFieldValue(java.lang.String fieldName, java.lang.Object value)
          Sets the value for a given field.
 void setFieldValues(java.util.Map newFields)
          Sets field values.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanRecord

public BeanRecord(java.lang.Object bean)
Creates a new BeanRecord based on the given bean.


BeanRecord

public BeanRecord()
Creates a new BeanRecord with no base bean. Be sure to set one, or be ready to take the consequences.


BeanRecord

public BeanRecord(java.lang.Class beanClass)
Creates a new BeanRecord, creating a new base bean by trying to instantiate an instance of the given class using the default constructor.

Method Detail

cloneBean

public static java.lang.Object cloneBean(java.lang.Object subject)
Clones an object that's not normally cloneable. The management assumes no responsibility.


getField

public FieldDef getField(java.lang.String fieldName)
Returns a FieldDef for the given field.

Specified by:
getField in interface Record

readableFields

public java.util.Iterator readableFields()
A list of FieldDefs describing all the readable fields in this Record.

Specified by:
readableFields in interface Record

editableFields

public java.util.Iterator editableFields()
A list of FieldDefs describing all the editable (readable and writable) in this Record.

Specified by:
editableFields in interface Record

getFieldValue

public java.lang.Object getFieldValue(java.lang.String fieldName)
                               throws NoSuchFieldInRecordException
Gets the value for a given field.

Specified by:
getFieldValue in interface Record
Throws:
NoSuchFieldInRecordException

setFieldValue

public void setFieldValue(java.lang.String fieldName,
                          java.lang.Object value)
                   throws NoSuchFieldInRecordException
Sets the value for a given field.

Specified by:
setFieldValue in interface Record
Throws:
NoSuchFieldInRecordException

getFieldValues

public java.util.Map getFieldValues()
Field values for all editable fields.

Specified by:
getFieldValues in interface Record

getAllFieldValues

public java.util.Map getAllFieldValues()
Field values for all readable fields.

Specified by:
getAllFieldValues in interface Record

setFieldValues

public void setFieldValues(java.util.Map newFields)
Sets field values. Unlisted fields are set to null; to leave a field unchanged associate it with a LeaveAloneToken

Invalid fields are ignored.

Specified by:
setFieldValues in interface Record
Parameters:
newFields - A dictionary of fieldnames associated with their values.

clone

public java.lang.Object clone()
Clones both the BeanRecord and the subject Record, by setting all editable properties in the clone to match those in the original. Handy way to clone things that aren't normally cloneable.

Specified by:
clone in interface Record
Overrides:
clone in class java.lang.Object

getBean

public java.lang.Object getBean()
The bean being operated on.


setBean

public void setBean(java.lang.Object newBean)
The bean being operated on.