Package org.beanio.internal.parser
Class Segment
- java.lang.Object
-
- org.beanio.internal.util.TreeNode<Component>
-
- org.beanio.internal.parser.Component
-
- org.beanio.internal.parser.ParserComponent
-
- org.beanio.internal.parser.Segment
-
- All Implemented Interfaces:
java.lang.Cloneable,java.lang.Iterable<Component>,Parser,Replicateable
- Direct Known Subclasses:
Record
public class Segment extends ParserComponent
A segment is used aggregate otherParsercomponents, such as fields and other segments.A segment may be bound to a
Propertyby callingsetProperty(Property).Repeating segments will always marshal a value when
marshal(MarshallingContext)is called. If not repeating, lazy segments are only marshalled ifhasContent(ParsingContext)returns true.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description Segment()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearValue(ParsingContext context)Clears the current property value.PropertygetProperty()intgetSize()Returns the size of a single occurrence of this element, which is used to offset field positions for repeating segments and fields.java.lang.ObjectgetValue(ParsingContext context)Returns the unmarshalled property value.booleanhasContent(ParsingContext context)Returns whether this parser or any of its descendant have content for marshalling.booleanisExistencePredetermined()booleanisIdentifier()Returns whether this parser or any descendant of this parser is used to identify a record during unmarshalling.booleanisOptional()Returns whether this node must exist during unmarshalling.booleanisRepeating()booleanmarshal(MarshallingContext context)Marshals a record.booleanmatches(UnmarshallingContext context)Returns whether this parser and its children match a record being unmarshalled.voidregisterLocals(java.util.Set<ParserLocal<?>> locals)Called by a stream to register variables stored in the parsing context.voidsetExistencePredetermined(boolean existencePredetermined)voidsetIdentifier(boolean identifier)voidsetOptional(boolean optional)voidsetProperty(Property property)voidsetRepeating(boolean repeating)voidsetSize(int size)voidsetValue(ParsingContext context, java.lang.Object value)Sets the property value for marshaling.protected voidtoParamString(java.lang.StringBuilder s)Called byTreeNode.toString()to append node parameters to the output.booleanunmarshal(UnmarshallingContext context)Unmarshals a record.-
Methods inherited from class org.beanio.internal.parser.ParserComponent
isSupportedChild
-
Methods inherited from class org.beanio.internal.util.TreeNode
add, clone, find, getChildren, getFirst, getName, isDescendant, iterator, print, print, setName, size, sort, toString, updateReferences
-
-
-
-
Method Detail
-
clearValue
public void clearValue(ParsingContext context)
Description copied from interface:ParserClears the current property value.- Parameters:
context- theParsingContext
-
matches
public boolean matches(UnmarshallingContext context)
Description copied from interface:ParserReturns whether this parser and its children match a record being unmarshalled.- Parameters:
context- theUnmarshallingContext- Returns:
- true if matched, false otherwise
-
unmarshal
public boolean unmarshal(UnmarshallingContext context)
Description copied from interface:ParserUnmarshals a record.- Parameters:
context- theUnmarshallingContext- Returns:
trueif this component was present in the unmarshalled record, orfalseotherwise
-
marshal
public boolean marshal(MarshallingContext context) throws java.io.IOException
Description copied from interface:ParserMarshals a record.- Parameters:
context- theMarshallingContext- Returns:
- whether a value was marshalled
- Throws:
java.io.IOException- if an I/O error occurs
-
hasContent
public boolean hasContent(ParsingContext context)
Description copied from interface:ParserReturns whether this parser or any of its descendant have content for marshalling.- Parameters:
context- theParsingContext- Returns:
- true if there is content for marshalling, false otherwise
-
getValue
public java.lang.Object getValue(ParsingContext context)
Description copied from interface:ParserReturns the unmarshalled property value.- Parameters:
context- theParsingContext- Returns:
- the property value
-
setValue
public void setValue(ParsingContext context, java.lang.Object value)
Description copied from interface:ParserSets the property value for marshaling.- Parameters:
context- theParsingContextvalue- the property value
-
getProperty
public Property getProperty()
-
setProperty
public void setProperty(Property property)
-
isOptional
public boolean isOptional()
Description copied from interface:ParserReturns whether this node must exist during unmarshalling.- Returns:
- true if this node is optional during unmarshalling, false otherwise
-
setOptional
public void setOptional(boolean optional)
-
setSize
public void setSize(int size)
-
getSize
public int getSize()
Description copied from interface:ParserReturns the size of a single occurrence of this element, which is used to offset field positions for repeating segments and fields.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.
- Returns:
- the size of this parser element
-
isIdentifier
public boolean isIdentifier()
Description copied from interface:ParserReturns whether this parser or any descendant of this parser is used to identify a record during unmarshalling.- Returns:
- true if this parser or any descendant is used to identify a record
-
setIdentifier
public void setIdentifier(boolean identifier)
-
registerLocals
public void registerLocals(java.util.Set<ParserLocal<?>> locals)
Description copied from class:ComponentCalled by a stream to register variables stored in the parsing context. This method should be overridden by subclasses that need to register one or more parser context variables.- Overrides:
registerLocalsin classComponent- Parameters:
locals- set of local variables
-
isExistencePredetermined
public boolean isExistencePredetermined()
-
setExistencePredetermined
public void setExistencePredetermined(boolean existencePredetermined)
-
isRepeating
public boolean isRepeating()
-
setRepeating
public void setRepeating(boolean repeating)
-
toParamString
protected void toParamString(java.lang.StringBuilder s)
Description copied from class:TreeNodeCalled byTreeNode.toString()to append node parameters to the output.- Overrides:
toParamStringin classTreeNode<Component>- Parameters:
s- the output to append
-
-