Package org.beanio.internal.parser
Class CollectionParser
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,java.lang.Iterable<Component>
,Iteration
,Parser
,Property
,Replicateable
- Direct Known Subclasses:
ArrayParser
public class CollectionParser extends Aggregation
ACollectionParser
provides iteration support for aSegment
orField
, and is optionally bound to aCollection
type property value.A
CollectionParser
must contain exactly one childParserComponent
.- Since:
- 2.0
-
-
Field Summary
-
Fields inherited from class org.beanio.internal.parser.Aggregation
lazy, occurs
-
Fields inherited from interface org.beanio.internal.parser.Property
AGGREGATION_ARRAY, AGGREGATION_COLLECTION, AGGREGATION_MAP, COLLECTION, COMPLEX, MAP, SIMPLE
-
-
Constructor Summary
Constructors Constructor Description CollectionParser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearValue(ParsingContext context)
Clears the current property value.protected java.util.Collection<java.lang.Object>
createCollection()
java.lang.Object
createValue(ParsingContext context)
Creates the property value and returns it.boolean
defines(java.lang.Object value)
protected java.util.Collection<java.lang.Object>
getCollection(ParsingContext context)
Returns the collection value being parsed.int
getIterationSize()
Returns the size of the components that make up a single iteration.java.lang.Class<? extends java.util.Collection<java.lang.Object>>
getType()
java.lang.Object
getValue(ParsingContext context)
Returns the unmarshalled property value.boolean
hasContent(ParsingContext context)
Returns whether this parser or any of its descendant have content for marshalling.protected boolean
isInvalid(ParsingContext context)
Returns whether this iteration contained invalid values when last unmarshalled.boolean
isProperty()
Returns whether this iteration is a property of a bean object.protected int
length(java.lang.Object value)
Returns the length of aggregation.protected boolean
marshal(MarshallingContext context, Parser delegate, int minOccurs, int maxOccurs)
boolean
matches(UnmarshallingContext context)
Returns whether this parser and its children match a record being unmarshalled.void
registerLocals(java.util.Set<ParserLocal<? extends java.lang.Object>> locals)
Called by a stream to register variables stored in the parsing context.void
setType(java.lang.Class<?> collectionType)
void
setValue(ParsingContext context, java.lang.Object value)
Sets the property value for marshaling.protected void
toParamString(java.lang.StringBuilder s)
Called byTreeNode.toString()
to append node parameters to the output.int
type()
Returns the property type.protected boolean
unmarshal(UnmarshallingContext context, Parser delegate, int minOccurs, int maxOccurs)
-
Methods inherited from class org.beanio.internal.parser.Aggregation
getAccessor, getIterationIndex, getMaxOccurs, getMinOccurs, getOccurs, isDynamicIteration, isIdentifier, isLazy, isOptional, marshal, setAccessor, setIdentifier, setIterationIndex, setLazy, setMaxOccurs, setMinOccurs, setOccurs, unmarshal
-
Methods inherited from class org.beanio.internal.parser.DelegatingParser
getParser, getSize
-
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:Parser
Clears the current property value.- Specified by:
clearValue
in interfaceParser
- Specified by:
clearValue
in interfaceProperty
- Overrides:
clearValue
in classDelegatingParser
- Parameters:
context
- theParsingContext
-
defines
public boolean defines(java.lang.Object value)
-
matches
public boolean matches(UnmarshallingContext context)
Description copied from interface:Parser
Returns whether this parser and its children match a record being unmarshalled.- Specified by:
matches
in interfaceParser
- Overrides:
matches
in classDelegatingParser
- Parameters:
context
- theUnmarshallingContext
- Returns:
- true if matched, false otherwise
-
marshal
protected boolean marshal(MarshallingContext context, Parser delegate, int minOccurs, int maxOccurs) throws java.io.IOException
- Specified by:
marshal
in classAggregation
- Throws:
java.io.IOException
-
unmarshal
protected boolean unmarshal(UnmarshallingContext context, Parser delegate, int minOccurs, int maxOccurs)
- Specified by:
unmarshal
in classAggregation
-
isProperty
public boolean isProperty()
Returns whether this iteration is a property of a bean object.- Specified by:
isProperty
in classAggregation
- Returns:
- true if this iteration is a property, false otherwise
-
isInvalid
protected boolean isInvalid(ParsingContext context)
Returns whether this iteration contained invalid values when last unmarshalled.- Returns:
- true if this iteration contained invalid values
-
getCollection
protected java.util.Collection<java.lang.Object> getCollection(ParsingContext context)
Returns the collection value being parsed.- Returns:
- the
Collection
-
length
protected int length(java.lang.Object value)
Description copied from class:Aggregation
Returns the length of aggregation.- Specified by:
length
in classAggregation
- Parameters:
value
- the aggregation value- Returns:
- the length
-
setType
public void setType(java.lang.Class<?> collectionType)
-
getType
public java.lang.Class<? extends java.util.Collection<java.lang.Object>> getType()
-
createValue
public java.lang.Object createValue(ParsingContext context)
Description copied from interface:Property
Creates the property value and returns it.- Parameters:
context
- theParsingContext
- Returns:
- the property value
-
getValue
public java.lang.Object getValue(ParsingContext context)
Description copied from interface:Parser
Returns the unmarshalled property value.- Specified by:
getValue
in interfaceParser
- Specified by:
getValue
in interfaceProperty
- Overrides:
getValue
in classDelegatingParser
- Parameters:
context
- theParsingContext
- Returns:
- the property value
-
setValue
public void setValue(ParsingContext context, java.lang.Object value)
Description copied from interface:Parser
Sets the property value for marshaling.- Specified by:
setValue
in interfaceParser
- Specified by:
setValue
in interfaceProperty
- Overrides:
setValue
in classAggregation
- Parameters:
context
- theParsingContext
value
- the property value
-
createCollection
protected java.util.Collection<java.lang.Object> createCollection()
-
type
public int type()
Description copied from interface:Property
Returns the property type.
-
getIterationSize
public int getIterationSize()
Description copied from interface:Iteration
Returns the size of the components that make up a single iteration.- Returns:
- the iteration size
-
registerLocals
public void registerLocals(java.util.Set<ParserLocal<? extends java.lang.Object>> locals)
Description copied from class:Component
Called 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:
registerLocals
in classAggregation
- Parameters:
locals
- set of local variables
-
hasContent
public boolean hasContent(ParsingContext context)
Description copied from interface:Parser
Returns whether this parser or any of its descendant have content for marshalling.- Specified by:
hasContent
in interfaceParser
- Overrides:
hasContent
in classDelegatingParser
- Parameters:
context
- theParsingContext
- Returns:
- true if there is content for marshalling, false otherwise
-
toParamString
protected void toParamString(java.lang.StringBuilder s)
Description copied from class:TreeNode
Called byTreeNode.toString()
to append node parameters to the output.- Overrides:
toParamString
in classAggregation
- Parameters:
s
- the output to append
-
-