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, updateReferencesequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic boolean hasContent(ParsingContext context)
ParserhasContent in interface Parsercontext - the ParsingContextpublic int type()
Propertytype in interface PropertyProperty.SIMPLE, Property.COMPLEX, Property.AGGREGATION_ARRAY, Property.COLLECTION,
Property.AGGREGATION_COLLECTION, or Property.MAPpublic boolean isOptional()
ParserisOptional in interface Parserpublic boolean matches(UnmarshallingContext context)
matches in interface Parsercontext - the UnmarshallingContext containing the record to matchprotected boolean isMatch(String text)
text - the field text to testpublic boolean marshal(MarshallingContext context)
Parsermarshal in interface Parsercontext - the MarshallingContextpublic boolean hasNext(UnmarshallingContext context)
public boolean unmarshal(UnmarshallingContext context)
Parserunmarshal in interface Parsercontext - the UnmarshallingContextprotected 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)
PropertyProperty.getValue(ParsingContext) should
return null, or Value.MISSING for lazy property values.clearValue in interface ParserclearValue in interface Propertycontext - the ParsingContextpublic Object createValue(ParsingContext context)
PropertycreateValue in interface Propertycontext - the ParsingContextpublic Object getValue(ParsingContext context)
PropertyWhen 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 ParsergetValue in interface Propertycontext - the ParsingContextValue.MISSING if not present in the stream,
or Value.INVALID if the field was invalidpublic void setValue(ParsingContext context, Object value)
PropertysetValue in interface ParsersetValue in interface Propertycontext - the ParsingContextvalue - the property valueprotected boolean isSupportedChild(Component child)
TreeNodeTreeNode.add(TreeNode).isSupportedChild in class ParserComponentchild - 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)
ComponentregisterLocals in class Componentlocals - set of local variablespublic void setPropertyType(Class<?> type)
public Class<?> getPropertyType()
public boolean isIdentifier()
PropertyisIdentifier in interface ParserisIdentifier in interface Propertypublic void setIdentifier(boolean recordIdentifier)
setIdentifier in interface Propertypublic 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 Propertypublic void setAccessor(PropertyAccessor accessor)
setAccessor in interface Propertypublic Object getDefaultValue()
public void setDefaultValue(Object defaultValue)
defaultValue - the default valuepublic TypeHandler getHandler()
public void setHandler(TypeHandler handler)
protected void toParamString(StringBuilder s)
TreeNodeTreeNode.toString() to append node parameters to the output.toParamString in class TreeNode<Component>s - the output to appendpublic int getSize()
ParserThe 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)