BeanIO 1.2.3

org.beanio.parser
Class PropertyDefinition

java.lang.Object
  extended by org.beanio.parser.PropertyDefinition
Direct Known Subclasses:
BeanDefinition, BeanPropertyDefinition, FieldDefinition

public abstract class PropertyDefinition
extends Object

Base class for bean property settings. A property could be a simple field or a bean containing a list of its own properties.

Since:
1.0
Author:
Kevin Seim

Field Summary
protected static String INVALID
          Constant indicating the field did not pass validation.
protected static String MISSING
          Constant indicating the field was not present in the stream
 
Constructor Summary
PropertyDefinition()
          Constructs a new PropertyDefinition.
 
Method Summary
abstract  boolean defines(Object value)
          Tests whether this definition is used to map the given bean or property value.
 Class<? extends Collection<Object>> getCollectionType()
          Returns the collection type of this property, or null if this property is not a collection or array.
 int getLength()
          Returns the maximum length of this property.
 int getMaxOccurs()
          Returns the maximum occurrences of this property in a stream.
 int getMinOccurs()
          Returns the minimum occurrences of this property in a stream.
 String getName()
          Returns the property name.
 PropertyDefinition getParent()
          Returns the parent property definition.
 PropertyDescriptor getPropertyDescriptor()
          Returns the bean property descriptor for getting and setting a value for this property from its enclosing bean class.
 Class<?> getPropertyType()
          Returns the class type of this property, or if this property is a collection, the class type of the collection value.
 boolean isArray()
          Returns true if this property definition is for an array value.
 boolean isBean()
          Returns whether this property describes a complex bean object that holds its own list of properties.
 boolean isCollection()
          Returns true if this property definition is for a collection or array value.
 boolean isConstant()
          Returns whether this property describes a constant value and does not map to field found in the stream.
 boolean isField()
          Returns whether this property describes a field in the mapped stream.
 boolean isLazy()
          Returns true if this property is only written to an output stream if the property value is not null.
 boolean isProperty()
          Returns true if the value parsed by this property definition is a property of its enclosing bean.
 boolean isRecordIdentifier()
          Returns true if the property or any descendant of this property definition is used to identify records.
abstract  boolean matches(Record record)
          Tests if the field text in the record matches this field definition.
protected abstract  Object parsePropertyValue(Record record)
          Parses and validates a field property value from the record.
 Object parseValue(Record record)
          Validates and parses the value of this field from a record.
 void setCollectionType(Class<? extends Collection<Object>> collectionType)
          Sets the collection type of this property.
 void setLazy(boolean lazy)
          Set to true if this property is only written to an output stream if the property value is not null.
 void setLength(int length)
          Sets the (maximum) length of this property.
 void setMaxOccurs(int maxOccurs)
          Sets the maximum occurrences of this property in a stream.
 void setMinOccurs(int minOccurs)
          Sets the minimum occurrences of this property in a stream.
 void setName(String name)
          Sets the property name.
 void setParent(PropertyDefinition parent)
          Sets the parent property definition.
 void setProperty(boolean property)
          Set to true if the value parsed by this property definition is a property of its enclosing bean.
 void setPropertyDescriptor(PropertyDescriptor propertyDescriptor)
          Sets the bean property descriptor for getting and setting a value for this property from its enclosing bean class.
 void setPropertyType(Class<?> type)
          Sets the class type of this property, or if this property is a collection, the class type of the collection value.
 void setRecordIdentifier(boolean recordIdentifier)
          Sets whether this property or any descendant of this property definition is used to identify records.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INVALID

protected static final String INVALID
Constant indicating the field did not pass validation.


MISSING

protected static final String MISSING
Constant indicating the field was not present in the stream

Constructor Detail

PropertyDefinition

public PropertyDefinition()
Constructs a new PropertyDefinition.

Method Detail

isBean

public boolean isBean()
Returns whether this property describes a complex bean object that holds its own list of properties.

Returns:
true if this property describes a bean object

isField

public boolean isField()
Returns whether this property describes a field in the mapped stream.

Returns:
true if this property describes a field in the mapped stream
Since:
1.2

isConstant

public boolean isConstant()
Returns whether this property describes a constant value and does not map to field found in the stream.

Returns:
true if this property describes a constant value
Since:
1.2.1

matches

public abstract boolean matches(Record record)
Tests if the field text in the record matches this field definition.

Parameters:
record - the record containing the field to test
Returns:
true if the text is a match

defines

public abstract boolean defines(Object value)
Tests whether this definition is used to map the given bean or property value. If this property is not used to identify records, the return value of this method is undefined.

Parameters:
value - the bean or property value to test
Returns:
true if this definition is used to map the given value
Since:
1.2

parseValue

public Object parseValue(Record record)
Validates and parses the value of this field from a record. If field validation fails, appropriate field errors are set on the record, and null is returned.

Parameters:
record - the record to parse and update with any field errors
Returns:
the field value, or null if validation failed, or MISSING if the field was not present in the record

parsePropertyValue

protected abstract Object parsePropertyValue(Record record)
Parses and validates a field property value from the record.

Parameters:
record - the record to parse
Returns:
the parsed field value, or INVALID if the field was invalid, or MISSING if the field was not present in the record

getName

public String getName()
Returns the property name.

Returns:
the property name

setName

public void setName(String name)
Sets the property name.

Parameters:
name - the new property name

getPropertyDescriptor

public PropertyDescriptor getPropertyDescriptor()
Returns the bean property descriptor for getting and setting a value for this property from its enclosing bean class. May be null if the property is not a property of its enclosing bean class.

Returns:
the bean property descriptor

setPropertyDescriptor

public void setPropertyDescriptor(PropertyDescriptor propertyDescriptor)
Sets the bean property descriptor for getting and setting a value for this property from its enclosing bean class. May be set to null if this property is not a property of its enclosing bean class.

Parameters:
propertyDescriptor - the bean property descriptor

isProperty

public boolean isProperty()
Returns true if the value parsed by this property definition is a property of its enclosing bean.

Returns:
true if the value parsed by this property definition is a property of its enclosing bean

setProperty

public void setProperty(boolean property)
Set to true if the value parsed by this property definition is a property of its enclosing bean.

Parameters:
property - true if the value parsed by this property definition is a property of its enclosing bean

getPropertyType

public Class<?> getPropertyType()
Returns the class type of this property, or if this property is a collection, the class type of the collection value. May be null if this property is not a property of its enclosing bean.

Returns:
the class type of this property

setPropertyType

public void setPropertyType(Class<?> type)
Sets the class type of this property, or if this property is a collection, the class type of the collection value. If this property is not a property of its enclosing bean, the class type may be set to null.

Parameters:
type - the class type of this property

getLength

public int getLength()
Returns the maximum length of this property.

Returns:
the maximum length of this property
See Also:
setLength(int)

setLength

public void setLength(int length)
Sets the (maximum) length of this property.

Delimited fields always have a length of 1, and fixed length fields have a configurable

For delimited records, the length is the number of fields. For fixed length records, the length is the number of characters. Thus a delimited field always has length of 1, while a fixed length field is configurable. For bean definitions, the length is the sum of all of its children.

Length is used to offset repeating fields that belong to a collection. All bean definitions for a collection type of with a collection type for a parent must have a fixed length. The value -1 may be returned in other cases.

Parameters:
length - the length of the fields that make up this bean definition

setParent

public void setParent(PropertyDefinition parent)
Sets the parent property definition.

Parameters:
parent - the parent property definition

getParent

public PropertyDefinition getParent()
Returns the parent property definition.

Returns:
the parent property definition

getCollectionType

public Class<? extends Collection<Object>> getCollectionType()
Returns the collection type of this property, or null if this property is not a collection or array.

Returns:
the collection type, or TypeUtil.ARRAY_TYPE if this property is an array, or null

setCollectionType

public void setCollectionType(Class<? extends Collection<Object>> collectionType)
Sets the collection type of this property. Or if this property is an array, the collection type should be set to TypeUtil.ARRAY_TYPE. The collection type must be a concrete Collection implementation, and cannot be abstract or an interface.

Parameters:
collectionType - the collection type of this property, or TypeUtil.ARRAY_TYPE for arrays

isCollection

public boolean isCollection()
Returns true if this property definition is for a collection or array value.

Returns:
true if this property is a collection type

isArray

public boolean isArray()
Returns true if this property definition is for an array value.

Returns:
true if this property is an array type

getMinOccurs

public int getMinOccurs()
Returns the minimum occurrences of this property in a stream. Always 1 unless this property is a collection.

Returns:
the minimum occurrences of this property

setMinOccurs

public void setMinOccurs(int minOccurs)
Sets the minimum occurrences of this property in a stream. Must be 1 unless this property is a collection.

Parameters:
minOccurs - the minimum occurrences of this property

getMaxOccurs

public int getMaxOccurs()
Returns the maximum occurrences of this property in a stream. Always 1 unless this property is a collection.

Returns:
the maximum occurrences of this property

setMaxOccurs

public void setMaxOccurs(int maxOccurs)
Sets the maximum occurrences of this property in a stream. Must be 1 unless this property is a collection.

Parameters:
maxOccurs - the maximum occurrences of this property

isLazy

public boolean isLazy()
Returns true if this property is only written to an output stream if the property value is not null.

Returns:
true if writing null property values to an output stream is suppressed

setLazy

public void setLazy(boolean lazy)
Set to true if this property is only written to an output stream if the property value is not null.

Parameters:
lazy - true to suppress writing null property values to an output stream

isRecordIdentifier

public boolean isRecordIdentifier()
Returns true if the property or any descendant of this property definition is used to identify records.

Returns:
true if this property or any descendant of this property definition is used to identify records
Since:
1.2

setRecordIdentifier

public void setRecordIdentifier(boolean recordIdentifier)
Sets whether this property or any descendant of this property definition is used to identify records.

Parameters:
recordIdentifier - true if this property or any descendant of this property definition is used to identify records
Since:
1.2

BeanIO 1.2.3

Copyright © 2010-2012 Kevin Seim