public class Field extends ParserComponent implements Property
A field component does not have any children.
AGGREGATION_ARRAY, AGGREGATION_COLLECTION, AGGREGATION_MAP, COLLECTION, COMPLEX, MAP, SIMPLE
Constructor and Description |
---|
Field()
Constructs a new Field.
|
Modifier and Type | Method and Description |
---|---|
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() |
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 |
isOptional()
Returns whether this node must exist during unmarshalling.
|
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 |
setLazy(boolean lazy) |
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.
|
add, clone, find, getChildren, getFirst, getName, isDescendant, iterator, print, print, setName, size, sort, toString, updateReferences
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
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 isOptional()
Parser
isOptional
in interface Parser
public boolean matches(UnmarshallingContext context)
matches
in interface Parser
context
- the UnmarshallingContext
containing the record to matchprotected boolean isMatch(String text)
text
- the field text to testpublic 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 parseValue.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 formatpublic 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 testpublic String getRegex()
public void setRegex(String pattern) throws PatternSyntaxException
pattern
- the regular expression patternPatternSyntaxException
- 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 boolean isTrim()
public void setTrim(boolean trim)
public boolean isRequired()
public void setRequired(boolean required)
public boolean isLazy()
public void setLazy(boolean lazy)
public int getMinLength()
public void setMinLength(int minLength)
public int getMaxLength()
public void setMaxLength(int maxLength)
public void setRegex(Pattern regex)
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.
public boolean isBound()
public void setBound(boolean property)