BeanIO 2.0.4

org.beanio.internal.parser
Class Segment

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.Segment
All Implemented Interfaces:
Cloneable, Iterable<Component>, Parser, Replicateable
Direct Known Subclasses:
Record

public class Segment
extends ParserComponent

A segment is used aggregate other Parser components, such as fields and other segments.

A segment may be bound to a Property by calling setProperty(Property).

Repeating segments will always marshal a value when marshal(MarshallingContext) is called. If not repeating, lazy segments are only marshalled if hasContent(ParsingContext) returns true.

Since:
2.0
Author:
Kevin Seim

Constructor Summary
Segment()
          Constructs a new Segment.
 
Method Summary
 void clearValue(ParsingContext context)
          Clears the current property value.
 Property getProperty()
           
 int getSize()
          Returns the size of a single occurrence of this element, which is used to offset field positions for repeating segments and fields.
 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 isExistencePredetermined()
           
 boolean isIdentifier()
          Returns whether this parser or any descendant of this parser is used to identify a record during unmarshalling.
 boolean isLazy()
          Returns whether this node must exist during unmarshalling.
 boolean isRepeating()
           
 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<?>> locals)
          Called by a stream to register variables stored in the parsing context.
 void setExistencePredetermined(boolean existencePredetermined)
           
 void setIdentifier(boolean identifier)
           
 void setLazy(boolean lazy)
           
 void setProperty(Property property)
           
 void setRepeating(boolean repeating)
           
 void setSize(int size)
           
 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.
 boolean unmarshal(UnmarshallingContext context)
          Unmarshals a record.
 
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.Parser
getName
 

Constructor Detail

Segment

public Segment()
Constructs a new Segment.

Method Detail

clearValue

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

Parameters:
context - the ParsingContext

matches

public boolean matches(UnmarshallingContext context)
Description copied from interface: Parser
Returns whether this parser and its children match a record being unmarshalled.

Parameters:
context - the UnmarshallingContext
Returns:
true if matched, false otherwise

unmarshal

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

Parameters:
context - the UnmarshallingContext
Returns:
true if this component was present in the unmarshalled record, or false otherwise

marshal

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

Parameters:
context - the MarshallingContext
Returns:
whether a value was marshalled
Throws:
IOException - if an I/O error occurs

hasContent

public boolean hasContent(ParsingContext context)
Description copied from interface: Parser
Returns whether this parser or any of its descendant have content for marshalling.

Parameters:
context - the ParsingContext
Returns:
true if there is content for marshalling, false otherwise

getValue

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

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.

Parameters:
context - the ParsingContext
value - the property value

getProperty

public Property getProperty()

setProperty

public void setProperty(Property property)

isLazy

public boolean isLazy()
Description copied from interface: Parser
Returns whether this node must exist during unmarshalling.

Returns:
true if this node is optional during unmarshalling, false otherwise

setLazy

public void setLazy(boolean lazy)

setSize

public void setSize(int size)

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.

Returns:
the size of this parser element

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.

Returns:
true if this parser or any descendant is used to identify a record

setIdentifier

public void setIdentifier(boolean identifier)

registerLocals

public void registerLocals(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 class Component
Parameters:
locals - set of local variables

isExistencePredetermined

public boolean isExistencePredetermined()

setExistencePredetermined

public void setExistencePredetermined(boolean existencePredetermined)

isRepeating

public boolean isRepeating()

setRepeating

public void setRepeating(boolean repeating)

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