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
ACollectionParserprovides iteration support for aSegmentorField, and is optionally bound to aCollectiontype property value.A
CollectionParsermust 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 voidclearValue(ParsingContext context)Clears the current property value.protected java.util.Collection<java.lang.Object>createCollection()java.lang.ObjectcreateValue(ParsingContext context)Creates the property value and returns it.booleandefines(java.lang.Object value)protected java.util.Collection<java.lang.Object>getCollection(ParsingContext context)Returns the collection value being parsed.intgetIterationSize()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.ObjectgetValue(ParsingContext context)Returns the unmarshalled property value.booleanhasContent(ParsingContext context)Returns whether this parser or any of its descendant have content for marshalling.protected booleanisInvalid(ParsingContext context)Returns whether this iteration contained invalid values when last unmarshalled.booleanisProperty()Returns whether this iteration is a property of a bean object.protected intlength(java.lang.Object value)Returns the length of aggregation.protected booleanmarshal(MarshallingContext context, Parser delegate, int minOccurs, int maxOccurs)booleanmatches(UnmarshallingContext context)Returns whether this parser and its children match a record being unmarshalled.voidregisterLocals(java.util.Set<ParserLocal<? extends java.lang.Object>> locals)Called by a stream to register variables stored in the parsing context.voidsetType(java.lang.Class<?> collectionType)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.inttype()Returns the property type.protected booleanunmarshal(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:ParserClears the current property value.- Specified by:
clearValuein interfaceParser- Specified by:
clearValuein interfaceProperty- Overrides:
clearValuein classDelegatingParser- Parameters:
context- theParsingContext
-
defines
public boolean defines(java.lang.Object value)
-
matches
public boolean matches(UnmarshallingContext context)
Description copied from interface:ParserReturns whether this parser and its children match a record being unmarshalled.- Specified by:
matchesin interfaceParser- Overrides:
matchesin 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:
marshalin classAggregation- Throws:
java.io.IOException
-
unmarshal
protected boolean unmarshal(UnmarshallingContext context, Parser delegate, int minOccurs, int maxOccurs)
- Specified by:
unmarshalin classAggregation
-
isProperty
public boolean isProperty()
Returns whether this iteration is a property of a bean object.- Specified by:
isPropertyin 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:AggregationReturns the length of aggregation.- Specified by:
lengthin 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:PropertyCreates 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:ParserReturns the unmarshalled property value.- Specified by:
getValuein interfaceParser- Specified by:
getValuein interfaceProperty- Overrides:
getValuein classDelegatingParser- 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.- Specified by:
setValuein interfaceParser- Specified by:
setValuein interfaceProperty- Overrides:
setValuein classAggregation- Parameters:
context- theParsingContextvalue- the property value
-
createCollection
protected java.util.Collection<java.lang.Object> createCollection()
-
type
public int type()
Description copied from interface:PropertyReturns the property type.
-
getIterationSize
public int getIterationSize()
Description copied from interface:IterationReturns 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: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 classAggregation- Parameters:
locals- set of local variables
-
hasContent
public boolean hasContent(ParsingContext context)
Description copied from interface:ParserReturns whether this parser or any of its descendant have content for marshalling.- Specified by:
hasContentin interfaceParser- Overrides:
hasContentin 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:TreeNodeCalled byTreeNode.toString()to append node parameters to the output.- Overrides:
toParamStringin classAggregation- Parameters:
s- the output to append
-
-