org.jcon.data
Class FlattenedBean

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

public class FlattenedBean
extends java.lang.Object
implements Record

This class uses BeanRecord to expose the properties of a provided object. Clients can then supply property names to "flatten" - i.e., bring into the top-level record namespace as fields themselves.

Version:
1.0 10/15/97
Author:
Paul Reavis
See Also:
Serialized Form

Constructor Summary
FlattenedBean()
          Creates a new FlattenedBean with no base bean.
FlattenedBean(java.lang.Class beanClass)
          Creates a new FlattenedBean, creating a new base bean by trying to instantiate an instance of the given class using the default constructor.
FlattenedBean(java.lang.Object bean)
          Creates a new FlattenedBean based on the given bean.
 
Method Summary
 java.lang.Object clone()
          Clones both the FlattenedBean 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.
 void flattenProperty(java.lang.String propertyName)
           
 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

FlattenedBean

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


FlattenedBean

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


FlattenedBean

public FlattenedBean(java.lang.Class beanClass)
Creates a new FlattenedBean, 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,
                          java.lang.IllegalArgumentException
Sets the value for a given field.

Specified by:
setFieldValue in interface Record
Throws:
NoSuchFieldInRecordException
java.lang.IllegalArgumentException

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 FlattenedBean 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.


flattenProperty

public void flattenProperty(java.lang.String propertyName)