Package org.beanio.internal.parser
Class Group
- java.lang.Object
-
- org.beanio.internal.util.TreeNode<Component>
-
- org.beanio.internal.parser.Component
-
- org.beanio.internal.parser.ParserComponent
-
- org.beanio.internal.parser.Group
-
- All Implemented Interfaces:
java.lang.Cloneable
,java.lang.Iterable<Component>
,Parser
,Selector
,Replicateable
public class Group extends ParserComponent implements Selector
A Group holds child nodes including records and other groups. This class is the dynamic counterpart to theGroupDefinition
and holds the current state of a group node during stream processing.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description Group()
Constructs a newGroup
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearValue(ParsingContext context)
Clears the current property value.Selector
close(ParsingContext context)
Checks for any unsatisfied components before the stream is closed.int
getCount(ParsingContext context)
Returns the number of times this component was matched within the current iteration of its parent component.protected java.lang.String
getKey(java.lang.String namespace, java.lang.String name)
Returns a Map key for accessing state information for this Node.int
getMaxOccurs()
Returns the maximum number of occurrences of this component (within the context of its parent).int
getMinOccurs()
Returns the minimum number of occurrences of this component (within the context of its parent).int
getOrder()
Returns the order of this component (within the context of its parent).Property
getProperty()
Returns theProperty
mapped to this component, or null if there is no property mapping.int
getSize()
Returns the size of a single occurrence of this element, which is used to offset field positions for repeating segments and fields.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.boolean
isIdentifier()
Returns whether this parser or any descendant of this parser is used to identify a record during unmarshalling.boolean
isMaxOccursReached(ParsingContext context)
Tests if the max occurs has been reached for this node.boolean
isOptional()
Returns whether this node must exist during unmarshalling.boolean
isRecordGroup()
Returns whether this component is a record group.protected boolean
isSupportedChild(Component child)
Returns whether a node is a supported child of this node.boolean
marshal(MarshallingContext context)
Marshals a record.Selector
matchAny(UnmarshallingContext context)
Finds a parser that matches the input record.boolean
matches(UnmarshallingContext context)
Returns whether this parser and its children match a record being unmarshalled.Selector
matchNext(MarshallingContext context)
Finds a parser for marshalling a bean object.Selector
matchNext(UnmarshallingContext context)
Finds a parser for unmarshalling a record based on the current state of the stream.void
registerLocals(java.util.Set<ParserLocal<?>> locals)
Called by a stream to register variables stored in the parsing context.void
reset(ParsingContext context)
Resets the component count of this Selector's children.void
restoreState(ParsingContext context, java.lang.String namespace, java.util.Map<java.lang.String,java.lang.Object> state)
Restores a Map of previously stored state information.void
setCount(ParsingContext context, int count)
Sets the number of times this component was matched within the current iteration of its parent component.void
setMaxOccurs(int maxOccurs)
void
setMinOccurs(int minOccurs)
void
setOrder(int order)
void
setProperty(Property property)
void
setValue(ParsingContext context, java.lang.Object value)
Sets the property value for marshaling.void
skip(UnmarshallingContext context)
Skips a record or group of records.protected void
toParamString(java.lang.StringBuilder s)
Called byTreeNode.toString()
to append node parameters to the output.boolean
unmarshal(UnmarshallingContext context)
Unmarshals a record.void
updateState(ParsingContext context, java.lang.String namespace, java.util.Map<java.lang.String,java.lang.Object> state)
Updates a Map with the current state of the Marshaller.-
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
-
marshal
public boolean marshal(MarshallingContext context) throws java.io.IOException
Description copied from interface:Parser
Marshals a record.- Specified by:
marshal
in interfaceParser
- Parameters:
context
- theMarshallingContext
- Returns:
- whether a value was marshalled
- Throws:
java.io.IOException
- if an I/O error occurs
-
skip
public void skip(UnmarshallingContext context)
Description copied from interface:Selector
Skips a record or group of records.- Specified by:
skip
in interfaceSelector
- Parameters:
context
- theUnmarshallingContext
-
unmarshal
public boolean unmarshal(UnmarshallingContext context)
Description copied from interface:Parser
Unmarshals a record.- Specified by:
unmarshal
in interfaceParser
- Parameters:
context
- theUnmarshallingContext
- Returns:
true
if this component was present in the unmarshalled record, orfalse
otherwise
-
matchAny
public Selector matchAny(UnmarshallingContext context)
Description copied from interface:Selector
Finds a parser that matches the input record. This method is invoked whenSelector.matchNext(UnmarshallingContext)
returns null, in order to differentiate between unexpected and unidentified record types.- Specified by:
matchAny
in interfaceSelector
- Parameters:
context
- theUnmarshallingContext
- Returns:
- the matched
Selector
-
matchNext
public Selector matchNext(UnmarshallingContext context)
Description copied from interface:Selector
Finds a parser for unmarshalling a record based on the current state of the stream.- Specified by:
matchNext
in interfaceSelector
- Parameters:
context
- theUnmarshallingContext
- Returns:
- the matched
Selector
for unmarshalling the record
-
matchNext
public Selector matchNext(MarshallingContext context)
Description copied from interface:Selector
Finds a parser for marshalling a bean object. If matched by this Selector, the method should set the bean object on the property tree and return itself.- Specified by:
matchNext
in interfaceSelector
- Parameters:
context
- theMarshallingContext
- Returns:
- the matched
Selector
for marshalling the bean object
-
reset
public void reset(ParsingContext context)
Description copied from interface:Selector
Resets the component count of this Selector's children.- Specified by:
reset
in interfaceSelector
- Parameters:
context
- theParsingContext
-
close
public Selector close(ParsingContext context)
Description copied from interface:Selector
Checks for any unsatisfied components before the stream is closed.- Specified by:
close
in interfaceSelector
- Parameters:
context
- theParsingContext
- Returns:
- the first unsatisfied node
-
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
- Parameters:
context
- theUnmarshallingContext
- Returns:
- true if matched, false otherwise
-
isMaxOccursReached
public boolean isMaxOccursReached(ParsingContext context)
Tests if the max occurs has been reached for this node.- Specified by:
isMaxOccursReached
in interfaceSelector
- Parameters:
context
- theParsingContext
- Returns:
- true if max occurs has been reached
-
getSize
public int getSize()
Description copied from interface:Parser
Returns 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.
-
updateState
public void updateState(ParsingContext context, java.lang.String namespace, java.util.Map<java.lang.String,java.lang.Object> state)
Updates a Map with the current state of the Marshaller. Used for creating restartable Writers for Spring Batch.- Specified by:
updateState
in interfaceSelector
- Parameters:
namespace
- a String to prefix all state keys withstate
- the Map to update with the latest statecontext
- theParsingContext
- Since:
- 1.2
-
restoreState
public void restoreState(ParsingContext context, java.lang.String namespace, java.util.Map<java.lang.String,java.lang.Object> state)
Restores a Map of previously stored state information. Used for restarting XML writers from Spring Batch.- Specified by:
restoreState
in interfaceSelector
- Parameters:
namespace
- a String to prefix all state keys withstate
- the Map containing the state to restorecontext
- theParsingContext
- Since:
- 1.2
-
getKey
protected java.lang.String getKey(java.lang.String namespace, java.lang.String name)
Returns a Map key for accessing state information for this Node.- Parameters:
namespace
- the assigned namespace for the keyname
- the state information to access- Returns:
- the fully qualified key
-
isRecordGroup
public boolean isRecordGroup()
Description copied from interface:Selector
Returns whether this component is a record group.- Specified by:
isRecordGroup
in interfaceSelector
- Returns:
- true if this component is a record group, false otherwise
-
getMinOccurs
public int getMinOccurs()
Description copied from interface:Selector
Returns the minimum number of occurrences of this component (within the context of its parent).- Specified by:
getMinOccurs
in interfaceSelector
- Returns:
- the minimum occurrences
-
setMinOccurs
public void setMinOccurs(int minOccurs)
-
getMaxOccurs
public int getMaxOccurs()
Description copied from interface:Selector
Returns the maximum number of occurrences of this component (within the context of its parent).- Specified by:
getMaxOccurs
in interfaceSelector
- Returns:
- the maximum occurrences
-
setMaxOccurs
public void setMaxOccurs(int maxOccurs)
-
getOrder
public int getOrder()
Description copied from interface:Selector
Returns the order of this component (within the context of its parent).
-
setOrder
public void setOrder(int order)
-
getCount
public int getCount(ParsingContext context)
Description copied from interface:Selector
Returns the number of times this component was matched within the current iteration of its parent component.- Specified by:
getCount
in interfaceSelector
- Parameters:
context
- theParsingContext
- Returns:
- the match count
-
setCount
public void setCount(ParsingContext context, int count)
Description copied from interface:Selector
Sets the number of times this component was matched within the current iteration of its parent component.- Specified by:
setCount
in interfaceSelector
- Parameters:
context
- theParsingContext
count
- the new match count
-
clearValue
public void clearValue(ParsingContext context)
Description copied from interface:Parser
Clears the current property value.- Specified by:
clearValue
in interfaceParser
- Parameters:
context
- theParsingContext
-
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
- Parameters:
context
- theParsingContext
value
- 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
- Parameters:
context
- theParsingContext
- Returns:
- the property value
-
getProperty
public Property getProperty()
Description copied from interface:Selector
Returns theProperty
mapped to this component, or null if there is no property mapping.- Specified by:
getProperty
in interfaceSelector
- Returns:
- the
Property
mapped to this component
-
setProperty
public void setProperty(Property property)
-
isOptional
public boolean isOptional()
Description copied from interface:Parser
Returns whether this node must exist during unmarshalling.- Specified by:
isOptional
in interfaceParser
- Returns:
- true if this node is optional during unmarshalling, false otherwise
-
isIdentifier
public boolean isIdentifier()
Description copied from interface:Parser
Returns whether this parser or any descendant of this parser is used to identify a record during unmarshalling.- Specified by:
isIdentifier
in interfaceParser
- Returns:
- true if this parser or any descendant is used to identify a record
-
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
- Parameters:
context
- theParsingContext
- Returns:
- true if there is content for marshalling, false otherwise
-
registerLocals
public void registerLocals(java.util.Set<ParserLocal<?>> 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 classComponent
- Parameters:
locals
- set of local variables
-
isSupportedChild
protected boolean isSupportedChild(Component child)
Description copied from class:TreeNode
Returns whether a node is a supported child of this node. Called byTreeNode.add(TreeNode)
.- Overrides:
isSupportedChild
in classParserComponent
- Parameters:
child
- the node to test- Returns:
- true if the child is allowed
-
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 classTreeNode<Component>
- Parameters:
s
- the output to append
-
-