BeanIO 2.0.4

org.beanio.internal.parser
Class MapParser

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.MapParser
All Implemented Interfaces:
Cloneable, Iterable<Component>, Iteration, Parser, Property, Replicateable

public class MapParser
extends Aggregation

A Parser component for aggregating inline Map objects. For example: key1,field1,key2,field2.

Since:
2.0.1
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
MapParser()
          Constructs a new MapParser.
 
Method Summary
 void clearValue(ParsingContext context)
          Clears the current property value.
protected  Map<Object,Object> createMap()
           
 Object createValue(ParsingContext context)
          Creates the property value and returns it.
 boolean defines(Object value)
           
 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.
 Property getKey()
           
protected  Map<Object,Object> getMap(ParsingContext context)
          Returns the map value being parsed.
 Class<? extends Map<Object,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.
 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 setKey(Property key)
           
 void setType(Class<?> mapType)
          Sets the concrete Map type.
 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

MapParser

public MapParser()
Constructs a new MapParser.

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

getType

public Class<? extends Map<Object,Object>> getType()

setType

public void setType(Class<?> mapType)
Sets the concrete Map type.


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

createMap

protected Map<Object,Object> createMap()

getMap

protected Map<Object,Object> getMap(ParsingContext context)
Returns the map value being parsed.

Returns:
the Map

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

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

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

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

getKey

public Property getKey()

setKey

public void setKey(Property key)

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