Package org.beanio.internal.parser
Class MarshallingContext
- java.lang.Object
-
- org.beanio.internal.parser.ParsingContext
-
- 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 whenwriteRecord()
is called to write a record object to the configuredRecordWriter
.- Since:
- 2.0
-
-
Field Summary
-
Fields inherited from class org.beanio.internal.parser.ParsingContext
MARSHALLING, UNMARSHALLING
-
-
Constructor Summary
Constructors Constructor Description MarshallingContext()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
clear()
Clear is invoked after each bean object (record or group) is marshalled.java.lang.Object
getBean()
Returns the bean object to marshal.java.lang.String
getComponentName()
Returns the component name of the record or group to marshal.char
getMode()
Returns the parsing mode.protected abstract java.lang.Object
getRecordObject()
Returns the record object to pass to theRecordWriter
whenwriteRecord()
is called.RecordWriter
getRecordWriter()
Returns theRecordWriter
to write to.TextLengthCounter
getTextLengthCounter()
void
setBean(java.lang.Object bean)
Sets the bean object to marshal.void
setComponentName(java.lang.String componentName)
Sets the component name of the record or group to marshal.void
setRecordWriter(RecordWriter recordWriter)
Set theRecordWriter
to write to.java.lang.String[]
toArray(java.lang.Object record)
Converts a record object to aString[]
.org.w3c.dom.Document
toDocument(java.lang.Object record)
Converts a record object to aDocument
.java.util.List<java.lang.String>
toList(java.lang.Object record)
Converts a record object to aList
.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
-
-
-
-
Method Detail
-
getMode
public final char getMode()
Description copied from class:ParsingContext
Returns the parsing mode.- Specified by:
getMode
in classParsingContext
- Returns:
- either
ParsingContext.UNMARSHALLING
orParsingContext.MARSHALLING
-
getTextLengthCounter
public TextLengthCounter getTextLengthCounter()
-
clear
public void clear()
Clear is invoked after each bean object (record or group) is marshalled.- Overrides:
clear
in classParsingContext
-
writeRecord
public void writeRecord() throws java.io.IOException
Writes the current record object to the record writer. This method will invoke thegetRecordObject()
method.- Throws:
java.io.IOException
- if an I/O error occurs
-
getRecordObject
protected abstract java.lang.Object getRecordObject()
Returns the record object to pass to theRecordWriter
whenwriteRecord()
is called.- Returns:
- the record object
-
toArray
public java.lang.String[] toArray(java.lang.Object record)
Converts a record object to aString[]
.- Parameters:
record
- the record object to convert- Returns:
- the
String
array result, or null if not supported
-
toList
public java.util.List<java.lang.String> toList(java.lang.Object record)
Converts a record object to aList
.- Parameters:
record
- the record object to convert- Returns:
- the
List
result, or null if not supported
-
toDocument
public org.w3c.dom.Document toDocument(java.lang.Object record)
Converts a record object to aDocument
.- Parameters:
record
- the record object to convert- Returns:
- the
Document
result, or null if not supported
-
getComponentName
public java.lang.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(java.lang.String componentName)
Sets the component name of the record or group to marshal.- Parameters:
componentName
- the component name to marshal
-
getBean
public java.lang.Object getBean()
Returns the bean object to marshal.- Returns:
- the bean object to marshal
-
setBean
public void setBean(java.lang.Object bean)
Sets the bean object to marshal.- Parameters:
bean
- the bean object
-
getRecordWriter
public RecordWriter getRecordWriter()
Returns theRecordWriter
to write to.- Returns:
- the
RecordWriter
-
setRecordWriter
public void setRecordWriter(RecordWriter recordWriter)
Set theRecordWriter
to write to.- Parameters:
recordWriter
- theRecordWriter
-
-