|
BeanIO 2.0.4 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.beanio.internal.util.TreeNode<Component> org.beanio.internal.parser.Component org.beanio.internal.parser.ParserComponent org.beanio.internal.parser.Field
public class Field
A parser for marshalling and unmarshalling a single field in a record. A field is usually, but optionally, bound to a simple property value.
A field component does not have any children.
Field Summary |
---|
Fields inherited from interface org.beanio.internal.parser.Property |
---|
AGGREGATION_ARRAY, AGGREGATION_COLLECTION, AGGREGATION_MAP, COLLECTION, COMPLEX, MAP, SIMPLE |
Constructor Summary | |
---|---|
Field()
Constructs a new Field. |
Method Summary | |
---|---|
void |
clearValue(ParsingContext context)
Clears the property value. |
Object |
createValue(ParsingContext context)
Creates the property value and returns it. |
boolean |
defines(Object value)
|
protected String |
formatValue(Object value)
Formats a field/property value. |
PropertyAccessor |
getAccessor()
|
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). |
FieldFormat |
getFormat()
|
TypeHandler |
getHandler()
|
String |
getLiteral()
|
int |
getMaxLength()
|
int |
getMinLength()
|
Class<?> |
getPropertyType()
|
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. |
int |
getSize()
Returns the size of a single occurrence of this element, which is used to offset field positions for repeating segments and fields. |
Class<?> |
getType()
|
Object |
getValue(ParsingContext context)
Returns the value of this property. |
boolean |
hasContent(ParsingContext context)
Returns whether this parser or any of its descendant have content for marshalling. |
boolean |
hasNext(UnmarshallingContext context)
|
boolean |
isBound()
|
boolean |
isIdentifier()
Returns whether this property or any of its descendants are used to identify a bean object. |
boolean |
isLazy()
Returns whether this node must exist during unmarshalling. |
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. |
boolean |
isRequired()
|
protected boolean |
isSupportedChild(Component child)
Returns whether a node is a supported child of this node. |
boolean |
isTrim()
|
boolean |
marshal(MarshallingContext context)
Marshals a record. |
boolean |
matches(UnmarshallingContext context)
Tests if the field text in the record matches this field. |
protected Object |
parseValue(UnmarshallingContext context,
String fieldText)
Parses and validates a field property value from the given field text. |
void |
registerLocals(Set<ParserLocal<? extends Object>> locals)
Called by a stream to register variables stored in the parsing context. |
void |
setAccessor(PropertyAccessor accessor)
|
void |
setBound(boolean property)
|
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 |
setFormat(FieldFormat format)
|
void |
setHandler(TypeHandler handler)
|
void |
setIdentifier(boolean recordIdentifier)
|
void |
setLiteral(String literal)
|
void |
setMaxLength(int maxLength)
|
void |
setMinLength(int minLength)
|
void |
setPropertyType(Class<?> type)
|
void |
setRegex(Pattern regex)
|
void |
setRegex(String pattern)
Sets the regular expression pattern the field text parsed by this field definition must match. |
void |
setRequired(boolean required)
|
void |
setTrim(boolean trim)
|
void |
setType(Class<?> type)
|
void |
setValue(ParsingContext context,
Object value)
Sets the property value (before marshalling). |
protected void |
toParamString(StringBuilder s)
Called by TreeNode.toString() to append node parameters to the output. |
int |
type()
Returns the property type. |
boolean |
unmarshal(UnmarshallingContext context)
Unmarshals a record. |
Methods inherited from class org.beanio.internal.util.TreeNode |
---|
add, clone, find, getChildren, getFirst, getName, iterator, print, setName, size, sort, toString, updateReferences |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.beanio.internal.parser.Property |
---|
getName |
Methods inherited from interface org.beanio.internal.parser.Parser |
---|
getName |
Constructor Detail |
---|
public Field()
Method Detail |
---|
public boolean hasContent(ParsingContext context)
Parser
hasContent
in interface Parser
context
- the ParsingContext
public int type()
Property
type
in interface Property
Property.SIMPLE
, Property.COMPLEX
, Property.AGGREGATION_ARRAY
, Property.COLLECTION
,
Property.AGGREGATION_COLLECTION
, or Property.MAP
public boolean isLazy()
Parser
isLazy
in interface Parser
public boolean defines(Object value)
defines
in interface Property
public boolean matches(UnmarshallingContext context)
matches
in interface Parser
context
- the UnmarshallingContext
containing the record to match
protected boolean isMatch(String text)
text
- the field text to test
public boolean marshal(MarshallingContext context)
Parser
marshal
in interface Parser
context
- the MarshallingContext
public boolean hasNext(UnmarshallingContext context)
public boolean unmarshal(UnmarshallingContext context)
Parser
unmarshal
in interface Parser
context
- the UnmarshallingContext
protected Object parseValue(UnmarshallingContext context, String fieldText)
context
- the UnmarshallingContext
to report field errors tofieldText
- the field text to parse
Value.INVALID
if the field was invalid,
or Value.MISSING
if the field was not present in the recordprotected String formatValue(Object value)
value
- the property value to format
public void clearValue(ParsingContext context)
Property
Property.getValue(ParsingContext)
should
return null, or Value.MISSING
for lazy property values.
clearValue
in interface Parser
clearValue
in interface Property
context
- the ParsingContext
public Object createValue(ParsingContext context)
Property
createValue
in interface Property
context
- the ParsingContext
public Object getValue(ParsingContext context)
Property
When unmarshalling, this method should return Value.MISSING
if the field
was not present in the stream. Or if present, but has no value, null should be returned.
When marshalling, this method should return Value.MISSING
for any optional
segment bound to a bean object, or null if required. Null field properties should
always return Value.MISSING
.
getValue
in interface Parser
getValue
in interface Property
context
- the ParsingContext
Value.MISSING
if not present in the stream,
or Value.INVALID
if the field was invalidpublic void setValue(ParsingContext context, Object value)
Property
setValue
in interface Parser
setValue
in interface Property
context
- the ParsingContext
value
- the property valueprotected boolean isSupportedChild(Component child)
TreeNode
TreeNode.add(TreeNode)
.
isSupportedChild
in class ParserComponent
child
- the node to test
public String getRegex()
public void setRegex(String pattern) throws PatternSyntaxException
pattern
- the regular expression pattern
PatternSyntaxException
- if the pattern is invalidprotected Pattern getRegexPattern()
public void registerLocals(Set<ParserLocal<? extends Object>> locals)
Component
registerLocals
in class Component
locals
- set of local variablespublic void setPropertyType(Class<?> type)
public Class<?> getPropertyType()
public boolean isIdentifier()
Property
isIdentifier
in interface Parser
isIdentifier
in interface Property
public void setIdentifier(boolean recordIdentifier)
setIdentifier
in interface Property
public FieldFormat getFormat()
public void setFormat(FieldFormat format)
public String getLiteral()
public void setLiteral(String literal)
public Class<?> getType()
getType
in interface Property
public boolean isTrim()
public void setTrim(boolean trim)
public boolean isRequired()
public void setRequired(boolean required)
public int getMinLength()
public void setMinLength(int minLength)
public int getMaxLength()
public void setMaxLength(int maxLength)
public void setRegex(Pattern regex)
public void setType(Class<?> type)
setType
in interface Property
public PropertyAccessor getAccessor()
getAccessor
in interface Property
public void setAccessor(PropertyAccessor accessor)
setAccessor
in interface Property
public Object getDefaultValue()
public void setDefaultValue(Object defaultValue)
defaultValue
- the default valuepublic TypeHandler getHandler()
public void setHandler(TypeHandler handler)
protected void toParamString(StringBuilder s)
TreeNode
TreeNode.toString()
to append node parameters to the output.
toParamString
in class TreeNode<Component>
s
- the output to appendpublic int getSize()
Parser
The concept of size is dependent on the stream format. The size of an element in a fixed length stream format is determined by the length of the element in characters, while other stream formats calculate size based on the number of fields. Some stream formats, such as XML, may ignore size settings.
getSize
in interface Parser
public boolean isBound()
public void setBound(boolean property)
|
BeanIO 2.0.4 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |