BeanIO 2.0.4

org.beanio.internal.parser
Class MarshallingContext

java.lang.Object
  extended by org.beanio.internal.parser.ParsingContext
      extended by org.beanio.internal.parser.MarshallingContext
Direct Known Subclasses:
DelimitedMarshallingContext, FixedLengthMarshallingContext, JsonMarshallingContext, XmlMarshallingContext

public abstract class MarshallingContext
extends ParsingContext

Stores context information needed to marshal a bean object.

Subclasses must implement getRecordObject() which is invoked when writeRecord() is called to write a record object to the configured RecordWriter.

Since:
2.0
Author:
Kevin Seim

Field Summary
 
Fields inherited from class org.beanio.internal.parser.ParsingContext
MARSHALLING, UNMARSHALLING
 
Constructor Summary
MarshallingContext()
          Constructs a new MarshallingContext.
 
Method Summary
 void clear()
          Clear is invoked after each record is marshalled.
 Object getBean()
          Returns the bean object to marshal.
 String getComponentName()
          Returns the component name of the record or group to marshal.
 char getMode()
          Returns the parsing mode.
protected abstract  Object getRecordObject()
          Returns the record object to pass to the RecordWriter when writeRecord() is called.
 RecordWriter getRecordWriter()
          Returns the RecordWriter to write to.
 void setBean(Object bean)
          Sets the bean object to marshal.
 void setComponentName(String componentName)
          Sets the component name of the record or group to marshal.
 void setRecordWriter(RecordWriter recordWriter)
          Set the RecordWriter to write to.
 String[] toArray(Object record)
          Converts a record object to a String[].
 Document toDocument(Object record)
          Converts a record object to a Document.
 List<String> toList(Object record)
          Converts a record object to a List.
 void writeRecord()
          Writes the current record object to the record writer.
 
Methods inherited from class org.beanio.internal.parser.ParsingContext
createHeap, getAdjustedFieldPosition, getLocal, getRelativeFieldIndex, isRepeating, popIteration, pushIteration, setLocal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MarshallingContext

public MarshallingContext()
Constructs a new MarshallingContext.

Method Detail

getMode

public final char getMode()
Description copied from class: ParsingContext
Returns the parsing mode.

Specified by:
getMode in class ParsingContext
Returns:
either ParsingContext.UNMARSHALLING or ParsingContext.MARSHALLING

clear

public void clear()
Clear is invoked after each record is marshalled.


writeRecord

public void writeRecord()
                 throws IOException
Writes the current record object to the record writer. This method will invoke the getRecordObject() method.

Throws:
IOException - if an I/O error occurs

getRecordObject

protected abstract Object getRecordObject()
Returns the record object to pass to the RecordWriter when writeRecord() is called.

Returns:
the record object

toArray

public String[] toArray(Object record)
Converts a record object to a String[].

Parameters:
record - the record object to convert
Returns:
the String array result, or null if not supported

toList

public List<String> toList(Object record)
Converts a record object to a List.

Parameters:
record - the record object to convert
Returns:
the List result, or null if not supported

toDocument

public Document toDocument(Object record)
Converts a record object to a Document.

Parameters:
record - the record object to convert
Returns:
the Document result, or null if not supported

getComponentName

public String getComponentName()
Returns the component name of the record or group to marshal. May be null if not specified.

Returns:
the component name to marshal

setComponentName

public void setComponentName(String componentName)
Sets the component name of the record or group to marshal.

Parameters:
componentName - the component name to marshal

getBean

public Object getBean()
Returns the bean object to marshal.

Returns:
the bean object to marshal

setBean

public void setBean(Object bean)
Sets the bean object to marshal.

Parameters:
bean - the bean object

getRecordWriter

public RecordWriter getRecordWriter()
Returns the RecordWriter to write to.

Returns:
the RecordWriter

setRecordWriter

public void setRecordWriter(RecordWriter recordWriter)
Set the RecordWriter to write to.

Parameters:
recordWriter - the RecordWriter

BeanIO 2.0.4

Copyright © 2010-2013 Kevin Seim