BeanIO 2.0.4

org.beanio.internal.parser
Class CollectionParser

java.lang.Object
  extended by org.beanio.internal.util.TreeNode<Component>
      extended by org.beanio.internal.parser.Component
          extended by org.beanio.internal.parser.ParserComponent
              extended by org.beanio.internal.parser.DelegatingParser
                  extended by org.beanio.internal.parser.Aggregation
                      extended by org.beanio.internal.parser.CollectionParser
All Implemented Interfaces:
Cloneable, Iterable<Component>, Iteration, Parser, Property, Replicateable
Direct Known Subclasses:
ArrayParser

public class CollectionParser
extends Aggregation

A CollectionParser provides iteration support for a Segment or Field, and is optionally bound to a Collection type property value.

A CollectionParser must contain exactly one child ParserComponent.

Since:
2.0
Author:
Kevin Seim

Field Summary
 
Fields inherited from class org.beanio.internal.parser.Aggregation
maxOccurs, minOccurs
 
Fields inherited from interface org.beanio.internal.parser.Property
AGGREGATION_ARRAY, AGGREGATION_COLLECTION, AGGREGATION_MAP, COLLECTION, COMPLEX, MAP, SIMPLE
 
Constructor Summary
CollectionParser()
          Constructs a new CollectionParser.
 
Method Summary
 void clearValue(ParsingContext context)
          Clears the current property value.
protected  Collection<Object> createCollection()
           
 Object createValue(ParsingContext context)
          Creates the property value and returns it.
 boolean defines(Object value)
           
protected  Collection<Object> getCollection(ParsingContext context)
          Returns the collection value being parsed.
 int getIterationIndex(ParsingContext context)
          Returns the index of the current iteration relative to its parent.
 int getIterationSize()
          Returns the size of the components that make up a single iteration.
 Object getNullValue()
           
 Class<? extends Collection<Object>> getType()
           
 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.
 boolean marshal(MarshallingContext context)
          Marshals a record.
 boolean matches(UnmarshallingContext context)
          Returns whether this parser and its children match a record being unmarshalled.
 void registerLocals(Set<ParserLocal<? extends Object>> locals)
          Called by a stream to register variables stored in the parsing context.
 void setType(Class<?> collectionType)
           
 void setValue(ParsingContext context, Object value)
          Sets the property value for marshaling.
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.
 
Methods inherited from class org.beanio.internal.parser.Aggregation
getAccessor, getMaxOccurs, getMinOccurs, isIdentifier, isLazy, setAccessor, setIdentifier, setMaxOccurs, setMinOccurs
 
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, iterator, print, setName, size, sort, toString, updateReferences
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.beanio.internal.parser.Property
getName
 
Methods inherited from interface org.beanio.internal.parser.Parser
getName
 

Constructor Detail

CollectionParser

public CollectionParser()
Constructs a new CollectionParser.

Method Detail

clearValue

public void clearValue(ParsingContext context)
Description copied from interface: Parser
Clears the current property value.

Specified by:
clearValue in interface Parser
Specified by:
clearValue in interface Property
Overrides:
clearValue in class DelegatingParser
Parameters:
context - the ParsingContext

defines

public boolean defines(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 interface Parser
Overrides:
matches in class DelegatingParser
Parameters:
context - the UnmarshallingContext
Returns:
true if matched, false otherwise

marshal

public boolean marshal(MarshallingContext context)
                throws IOException
Description copied from interface: Parser
Marshals a record.

Specified by:
marshal in interface Parser
Overrides:
marshal in class DelegatingParser
Parameters:
context - the MarshallingContext
Returns:
whether a value was marshalled
Throws:
IOException - if an I/O error occurs

unmarshal

public boolean unmarshal(UnmarshallingContext context)
Description copied from interface: Parser
Unmarshals a record.

Specified by:
unmarshal in interface Parser
Overrides:
unmarshal in class DelegatingParser
Parameters:
context - the UnmarshallingContext
Returns:
true if this component was present in the unmarshalled record, or false otherwise

isProperty

public boolean isProperty()
Returns whether this iteration is a property of a bean object.

Specified by:
isProperty in class Aggregation
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 Collection<Object> getCollection(ParsingContext context)
Returns the collection value being parsed.

Returns:
the Collection

setType

public void setType(Class<?> collectionType)

getType

public Class<? extends Collection<Object>> getType()

getNullValue

public Object getNullValue()

createValue

public Object createValue(ParsingContext context)
Description copied from interface: Property
Creates the property value and returns it.

Parameters:
context - the ParsingContext
Returns:
the property value

getValue

public Object getValue(ParsingContext context)
Description copied from interface: Parser
Returns the unmarshalled property value.

Specified by:
getValue in interface Parser
Specified by:
getValue in interface Property
Overrides:
getValue in class DelegatingParser
Parameters:
context - the ParsingContext
Returns:
the property value

setValue

public void setValue(ParsingContext context,
                     Object value)
Description copied from interface: Parser
Sets the property value for marshaling.

Specified by:
setValue in interface Parser
Specified by:
setValue in interface Property
Overrides:
setValue in class DelegatingParser
Parameters:
context - the ParsingContext
value - the property value

createCollection

protected Collection<Object> createCollection()

type

public int type()
Description copied from interface: Property
Returns the property type.

Returns:
Property.SIMPLE, Property.COMPLEX, Property.AGGREGATION_ARRAY, Property.COLLECTION, Property.AGGREGATION_COLLECTION, or Property.MAP

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

getIterationIndex

public int getIterationIndex(ParsingContext context)
Description copied from interface: Iteration
Returns the index of the current iteration relative to its parent.

Returns:
the index of the current iteration

registerLocals

public void registerLocals(Set<ParserLocal<? extends 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 class Component
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 interface Parser
Overrides:
hasContent in class DelegatingParser
Parameters:
context - the ParsingContext
Returns:
true if there is content for marshalling, false otherwise

toParamString

protected void toParamString(StringBuilder s)
Description copied from class: TreeNode
Called by TreeNode.toString() to append node parameters to the output.

Overrides:
toParamString in class TreeNode<Component>
Parameters:
s - the output to append

BeanIO 2.0.4

Copyright © 2010-2013 Kevin Seim