|
BeanIO 1.2.3 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.beanio.parser.PropertyDefinition org.beanio.parser.FieldDefinition
public abstract class FieldDefinition
A FieldDefinition is used to parse and format field values that make up a record or bean.
Field Summary | |
---|---|
static char |
LEFT
Left justification |
static char |
RIGHT
Right justification |
Fields inherited from class org.beanio.parser.PropertyDefinition |
---|
INVALID, MISSING |
Constructor Summary | |
---|---|
FieldDefinition()
|
Method Summary | |
---|---|
boolean |
defines(Object value)
Tests whether this definition is used to map the given bean or property value. |
protected String |
formatPaddedNull()
Returns the field text for a padded field when the property value is null. |
protected String |
formatText(String text)
Formats field text. |
String |
formatValue(Object value)
Formats the field value. |
protected String |
getDefaultTextFor(Class<?> type,
char padding)
Returns default unpadded text when the entire field is populated by the padding character. |
Object |
getDefaultValue()
Returns the default value for a field parsed by this field definition when the field text is null or the empty string (after trimming). |
char |
getJustification()
Returns the text justification for this field. |
String |
getLiteral()
Returns the textual literal value the field text must match, or null if no literal validation will be performed. |
int |
getMaxLength()
Returns the maximum length in characters of the field text allowed by this field definition after trimming is performed. |
int |
getMinLength()
Returns the minimum length in characters of the field text allowed by this field definition after trimming is performed.. |
int |
getPaddedLength()
Returns the padded length of this field, or 0 if padding is disabled. |
char |
getPadding()
Returns the character used to pad this field. |
int |
getPosition()
Returns the position of this field within the record. |
String |
getRegex()
Returns the regular expression pattern the field text parsed by this field definition must match. |
protected Pattern |
getRegexPattern()
Returns the regular expression the field text parsed by this field definition must match. |
TypeHandler |
getTypeHandler()
Returns the type handler for this field. |
boolean |
isField()
Returns whether this property describes a field in the mapped stream. |
boolean |
isMatch(Object value)
Tests if the given field value matches this field definition. |
protected boolean |
isMatch(String text)
Returns true if the provided field text is a match for this field definition based on the configured literal value or regular expression. |
protected boolean |
isNilSupported()
Returns whether formatValue(Object) may return TypeHandler.NIL . |
boolean |
isPadded()
Returns whether this field is padded. |
boolean |
isProperty()
Returns true if the value parsed by this field definition is a property of the record bean. |
boolean |
isRequired()
Returns true if this field is required. |
boolean |
isTrim()
Returns true if the field text will be trimmed before validation and type conversion. |
abstract boolean |
matches(Record record)
Tests if the field text in the record matches this field definition. |
protected abstract String |
parseField(Record record)
Parses the raw field text from a record prior to any validation and sets the text on the record. |
protected Object |
parsePropertyValue(Record record)
Parses and validates a field property value from the record. |
protected Object |
parsePropertyValue(Record record,
String fieldText)
Parses and validates a field property value from the given field text. |
void |
setDefaultValue(Object defaultValue)
Sets the default value for a field parsed by this field definition when the field text is null or the empty string (after trimming). |
void |
setJustification(char justification)
Sets the text justification for this field. |
void |
setLiteral(String literal)
Sets the literal text this field must match. |
void |
setMaxLength(int maxLength)
Sets the maximum length in characters of the field text allowed by this field definition after trimming is performed. |
void |
setMinLength(int minLength)
Sets the minimum length in characters of the field text allowed by this field definition after trimming is performed.. |
void |
setPadded(boolean padded)
Sets whether this field is padded. |
void |
setPaddedLength(int length)
Sets the padded length of this field. |
void |
setPadding(char padding)
Sets the character used to pad this field. |
void |
setPosition(int position)
Sets the position of this field within the record beginning at 0. |
void |
setProperty(boolean property)
Set to true if the value parsed by this field definition is a property of the record bean. |
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 |
setRegex(String pattern)
Sets the regular expression pattern the field text parsed by this field definition must match. |
void |
setRequired(boolean required)
Sets to true if this field is required. |
void |
setTrim(boolean trim)
Set to true if the field text should be trimmed before validation and type conversion. |
void |
setTypeHandler(TypeHandler handler)
Sets the type handler for this field. |
protected String |
unpad(String fieldText)
Removes padding from the field text. |
Methods inherited from class org.beanio.parser.PropertyDefinition |
---|
getCollectionType, getLength, getMaxOccurs, getMinOccurs, getName, getParent, getPropertyDescriptor, getPropertyType, isArray, isBean, isCollection, isConstant, isLazy, isRecordIdentifier, parseValue, setCollectionType, setLazy, setLength, setMaxOccurs, setMinOccurs, setName, setParent, setPropertyDescriptor, setRecordIdentifier |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final char LEFT
public static final char RIGHT
Constructor Detail |
---|
public FieldDefinition()
Method Detail |
---|
public boolean isField()
PropertyDefinition
isField
in class PropertyDefinition
public abstract boolean matches(Record record)
matches
in class PropertyDefinition
record
- the record containing the field to test
public boolean defines(Object value)
PropertyDefinition
defines
in class PropertyDefinition
value
- the bean or property value to test
public boolean isMatch(Object value)
value
- the field value to test
protected boolean isMatch(String text)
text
- the field text to test
protected abstract String parseField(Record record)
record
- the record to parse
PropertyDefinition.INVALID
if the field is invalid,
or null if the field is not present in the recordprotected Object parsePropertyValue(Record record)
parsePropertyValue
in class PropertyDefinition
record
- the record to parse
PropertyDefinition.INVALID
if the field was invalid,
or PropertyDefinition.MISSING
if the field was not present in the recordprotected Object parsePropertyValue(Record record, String fieldText)
record
- the record being parsedfieldText
- the field text to parse
PropertyDefinition.INVALID
if the field was invalid,
or PropertyDefinition.MISSING
if the field was not present in the recordpublic String formatValue(Object value)
value
- the field value to format
protected boolean isNilSupported()
formatValue(Object)
may return TypeHandler.NIL
. Returns
false by default, which will convert TypeHandler.NIL to null.
formatValue(Object)
may return TypeHandler.NIL
.protected String formatText(String text)
text
- the field text to format
protected String formatPaddedNull()
protected String unpad(String fieldText)
fieldText
- the field text to remove padding
public int getPosition()
public void setPosition(int position)
position
- the field position, starting at 0public boolean isTrim()
public void setTrim(boolean trim)
trim
- set to true to trim the field textpublic String getLiteral()
public void setLiteral(String literal)
literal
- the literal field textpublic TypeHandler getTypeHandler()
public void setTypeHandler(TypeHandler handler)
handler
- the new type handlerpublic boolean isRequired()
public void setRequired(boolean required)
required
- true if this field is requiredpublic int getMinLength()
public void setMinLength(int minLength)
minLength
- the minimum length in characterspublic int getMaxLength()
public void setMaxLength(int maxLength)
maxLength
- public boolean isProperty()
isProperty
in class PropertyDefinition
public void setProperty(boolean property)
setProperty
in class PropertyDefinition
property
- true if the value parsed by this field definition is a property
of the record beanpublic String getRegex()
public void setRegex(String pattern) throws PatternSyntaxException
pattern
- the regular expression pattern
PatternSyntaxException
- if the pattern is invalidprotected Pattern getRegexPattern()
public Object getDefaultValue()
public void setDefaultValue(Object defaultValue)
defaultValue
- the default valuepublic void setPropertyType(Class<?> type)
PropertyDefinition
setPropertyType
in class PropertyDefinition
type
- the class type of this propertypublic boolean isPadded()
public void setPadded(boolean padded)
padded
- true if this field is paddedpublic char getPadding()
public void setPadding(char padding)
padding
- the padding characterpublic int getPaddedLength()
public void setPaddedLength(int length)
length
- the new padded length of this fieldpublic char getJustification()
LEFT
or RIGHT
public void setJustification(char justification)
justification
- the text justification, LEFT
or RIGHT
protected String getDefaultTextFor(Class<?> type, char padding)
type
- the field property typepadding
- the character used to pad the fixed length field
|
BeanIO 1.2.3 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |