org.jdesktop.swing.data
Class MetaData

java.lang.Object
  extended byorg.jdesktop.swing.data.MetaData
Direct Known Subclasses:
EnumeratedMetaData, NumberMetaData, StringMetaData

public class MetaData
extends Object

Class for representing the meta-data for an field in a data model. A "field" may map to a column on a RowSet, a property on a JavaBean, or some other descrete data element on a data model. The meta-data describes aspects of a data field such as it's name, type, and edit constraints. This class may be used when such information isn't encapsulated in the data model object itself and thus must be represented in an external object. Meta-data is intended only for holding state about a data model element and is not intended for implementing application semantics.

A meta-data object should be initialized at a minimum with a name, class, and label. Additional meta-data properties can be set as necessary. For example:


     MetaData metaData = new MetaData("firstname", String.class,
                                      "First Name");
     metaData.setRequired(true);
 
If the associated data model field requires application-specific validation logic to verify the correctness of a potential value, one or more Validator instances can be added to the meta-data object. Example:

     MetaData metaData = new MetaData("creditcard", String.class,
                                      "Credit Card Number"
     metaData.setRequired(true);
     metaData.addValidator(new MyCreditCardValidator());
 


Field Summary
protected  Converter converter
           
protected  Object decodeFormat
           
protected  Object encodeFormat
           
protected  Class klass
           
protected  String label
           
protected  int maxValueCount
           
protected  int minValueCount
           
protected  String name
           
protected  PropertyChangeSupport pcs
           
protected  boolean readOnly
           
protected  ArrayList validators
           
 
Constructor Summary
MetaData()
          Instantiates a meta-data object with a default name "value" and a default field class equal to java.lang.String.
MetaData(String name)
          Instantiates a meta-data object with the specified name and a default field class equal to java.lang.String.
MetaData(String name, Class klass)
          Instantiates a meta-data object with the specified name and field class.
MetaData(String name, Class klass, String label)
          Instantiates a meta-data object with the specified name, field class, and label.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener pcl)
          Adds the specified property change listener to this meta-data object.
 void addValidator(Validator validator)
          Adds the specified validator for this meta-data.
 Converter getConverter()
          Gets the meta-data's converter, which performs conversions between string values and objects of the associated data field's type.
 Object getDecodeFormat()
          Gets the meta-data's decode format which is used when converting values from a string representation.
 Class getElementClass()
          Gets the meta-data's "elementClass" property which indicates the type of the associated data field.
 Object getEncodeFormat()
          Gets the meta-data's encode format which is used when converting values to a string representation.
 String getLabel()
          Gets the meta-data's "label" property, which provides a label for the associated data field.
 int getMaxValueCount()
          Gets the meta-data's "maxValueCount" property, which indicates the maximum number of values permitted for the data field.
 int getMinValueCount()
          Gets the meta-data's "minValueCount" property, which indicates the minimum number of values required for the data field.
 String getName()
          Gets the meta-data "name" property which indicates the logical name of the associated data field.
 PropertyChangeListener[] getPropertyChangeListeners()
           
 Validator[] getValidators()
           
 boolean isReadOnly()
          Gets the meta-data's "readOnly" property which indicates whether or not the associated data field's value cannot be modified.
 boolean isRequired()
          Convenience method for calculating whether the "minValueCount" property is greater than 0.
 void removePropertyChangeListener(PropertyChangeListener pcl)
          Removes the specified property change listener from this meta-data object.
 void removeValidator(Validator validator)
          Removes the specified validator for this meta-data.
 void setConverter(Converter converter)
          Sets the meta-data's converter.
 void setDecodeFormat(Object format)
          Sets the meta-data's decode format which is used when converting values from a string representation.
 void setElementClass(Class klass)
          Sets the meta-data's "elementClass" property.
 void setEncodeFormat(Object format)
          Sets the meta-data's encode format which is used when converting values to a string representation.
 void setLabel(String label)
          Sets the meta-data's "label" property.
 void setMaxValueCount(int maxValueCount)
          Sets the meta-data's "maxValueCount" property.
 void setMinValueCount(int minValueCount)
          Sets the meta-data's "minValueCount" property.
 void setName(String name)
          Sets the meta-data "name" property.
 void setReadOnly(boolean readOnly)
          Sets the meta-data's "readOnly" property.
 void setRequired(boolean required)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected String name

klass

protected Class klass

label

protected String label

converter

protected Converter converter

decodeFormat

protected Object decodeFormat

encodeFormat

protected Object encodeFormat

readOnly

protected boolean readOnly

minValueCount

protected int minValueCount

maxValueCount

protected int maxValueCount

validators

protected ArrayList validators

pcs

protected PropertyChangeSupport pcs
Constructor Detail

MetaData

public MetaData()
Instantiates a meta-data object with a default name "value" and a default field class equal to java.lang.String. This provides the no-argument constructor required for JavaBeans. It is recommended that the program explicitly set a meaningful "name" property.


MetaData

public MetaData(String name)
Instantiates a meta-data object with the specified name and a default field class equal to java.lang.String.

Parameters:
name - String containing the name of the data field

MetaData

public MetaData(String name,
                Class klass)
Instantiates a meta-data object with the specified name and field class.

Parameters:
name - String containing the name of the data field
klass - Class indicating type of data field

MetaData

public MetaData(String name,
                Class klass,
                String label)
Instantiates a meta-data object with the specified name, field class, and label.

Parameters:
name - String containing the name of the data field
klass - Class indicating type of data field
label - String containing the user-displayable label for the data field
Method Detail

getName

public String getName()
Gets the meta-data "name" property which indicates the logical name of the associated data field.

Returns:
String containing the name of the data field.
See Also:
setName(java.lang.String)

setName

public void setName(String name)
Sets the meta-data "name" property.

Parameters:
name - String containing the name of the data field
See Also:
getName()

getElementClass

public Class getElementClass()
Gets the meta-data's "elementClass" property which indicates the type of the associated data field. The default field class is java.lang.String.

Returns:
Class indicating type of data field
See Also:
setElementClass(java.lang.Class)

setElementClass

public void setElementClass(Class klass)
Sets the meta-data's "elementClass" property. This set method is provided for meta-data bean initialization only; the field class is not intended to be modified after initialization, since other aspects of a meta-data object may depend on this type setting.

Parameters:
klass - Class indicating type of data field
See Also:
getElementClass()

getLabel

public String getLabel()
Gets the meta-data's "label" property, which provides a label for the associated data field. The label is intended for display to the end-user and may be localized. If no label has been explicitly set, then the meta-data's name is returned.

Returns:
String containing the user-displayable label for the data field
See Also:
setLabel(java.lang.String)

setLabel

public void setLabel(String label)
Sets the meta-data's "label" property.

Parameters:
label - String containing the user-displable label for the data field
See Also:
getLabel()

getConverter

public Converter getConverter()
Gets the meta-data's converter, which performs conversions between string values and objects of the associated data field's type. If no converter was explicitly set on this meta-data object, this method will retrieve a default converter for this data field's type from the converter registry. If no default converter is registered, this method will return null.

Returns:
Converter used to perform conversions between string values and objects of this field's type
See Also:
Converters.get(java.lang.Class), setConverter(org.jdesktop.swing.data.Converter), getElementClass()

setConverter

public void setConverter(Converter converter)
Sets the meta-data's converter.

Parameters:
converter - Converter used to perform conversions between string values and objects of this field's type
See Also:
getConverter()

getDecodeFormat

public Object getDecodeFormat()
Gets the meta-data's decode format which is used when converting values from a string representation. This property must be used when conversion requires format information on how the string representation is structured. For example, a decode format should be used when decoding date values. The default decode format is null.

Returns:
format object used to describe format for string-to-object conversion
See Also:
setDecodeFormat(java.lang.Object)

setDecodeFormat

public void setDecodeFormat(Object format)
Sets the meta-data's decode format which is used when converting values from a string representation.

Parameters:
format - object used to describe format for string-to-object conversion
See Also:
getDecodeFormat(), DateFormat

getEncodeFormat

public Object getEncodeFormat()
Gets the meta-data's encode format which is used when converting values to a string representation. This property must be used when conversion requires format information on how the string representation should be generated. For example, an encode format should be used when encoding date values. The default encode format is null.

Returns:
format object used to describe format for object-to-string conversion
See Also:
setEncodeFormat(java.lang.Object)

setEncodeFormat

public void setEncodeFormat(Object format)
Sets the meta-data's encode format which is used when converting values to a string representation.

Parameters:
format - object used to describe format for object-to-string conversion
See Also:
getEncodeFormat(), DateFormat

isReadOnly

public boolean isReadOnly()
Gets the meta-data's "readOnly" property which indicates whether or not the associated data field's value cannot be modified. The default is false.

Returns:
boolean indicating whether the data field is read-only
See Also:
setReadOnly(boolean)

setReadOnly

public void setReadOnly(boolean readOnly)
Sets the meta-data's "readOnly" property.

Parameters:
readOnly - boolean indicating whether the data field is read-only
See Also:
#getReadOnly

getMinValueCount

public int getMinValueCount()
Gets the meta-data's "minValueCount" property, which indicates the minimum number of values required for the data field. The default is 0, which means a null value is permitted. This property should be set to 1 if the field requires a non-null value.

Returns:
integer indicating the minimum number of values required for the data field
See Also:
setMinValueCount(int)

setMinValueCount

public void setMinValueCount(int minValueCount)
Sets the meta-data's "minValueCount" property.

Parameters:
minValueCount - integer indicating the minimum number of values required for the data field

isRequired

public boolean isRequired()
Convenience method for calculating whether the "minValueCount" property is greater than 0.

Returns:
boolean indicating whether at least one non-null value must be set for the data field

setRequired

public void setRequired(boolean required)

getMaxValueCount

public int getMaxValueCount()
Gets the meta-data's "maxValueCount" property, which indicates the maximum number of values permitted for the data field. The default is 1, which means a single value is permitted. If this property is set to a value greater than 1, then the values will be contained in a List collection.

Returns:
integer indicating the maximum number of values permitted for the data field
See Also:
List, setMaxValueCount(int)

setMaxValueCount

public void setMaxValueCount(int maxValueCount)
Sets the meta-data's "maxValueCount" property.

Parameters:
maxValueCount - integer indicating the maximum number of values permitted for the data field

addValidator

public void addValidator(Validator validator)
Adds the specified validator for this meta-data. A validator object is used to determine whether a particular object is a valid value for the associated data field. A data field may have 0 or more validators.

Parameters:
validator - Validator object which performs validation checks on values being set on the associated data field
See Also:
removeValidator(org.jdesktop.swing.data.Validator), getValidators()

removeValidator

public void removeValidator(Validator validator)
Removes the specified validator for this meta-data.

Parameters:
validator - Validator object which performs validation checks on values being set on the associated data field
See Also:
addValidator(org.jdesktop.swing.data.Validator)

getValidators

public Validator[] getValidators()
Returns:
array containing 0 or more validators set on this meta-data
See Also:
addValidator(org.jdesktop.swing.data.Validator)

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener pcl)
Adds the specified property change listener to this meta-data object.

Parameters:
pcl - PropertyChangeListener object to receive events when meta-data properties change

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener pcl)
Removes the specified property change listener from this meta-data object.

Parameters:
pcl - PropertyChangeListener object to receive events when meta-data properties change

getPropertyChangeListeners

public PropertyChangeListener[] getPropertyChangeListeners()
Returns:
array containing the PropertyChangeListener objects registered on this meta-data object


Copyright 2004 by Sun Microsystems, Inc. All Rights Reserved.