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 voidclear()Clear is invoked after each bean object (record or group) is marshalled.java.lang.ObjectgetBean()Returns the bean object to marshal.java.lang.StringgetComponentName()Returns the component name of the record or group to marshal.chargetMode()Returns the parsing mode.protected abstract java.lang.ObjectgetRecordObject()Returns the record object to pass to theRecordWriterwhenwriteRecord()is called.RecordWritergetRecordWriter()Returns theRecordWriterto write to.TextLengthCountergetTextLengthCounter()voidsetBean(java.lang.Object bean)Sets the bean object to marshal.voidsetComponentName(java.lang.String componentName)Sets the component name of the record or group to marshal.voidsetRecordWriter(RecordWriter recordWriter)Set theRecordWriterto write to.java.lang.String[]toArray(java.lang.Object record)Converts a record object to aString[].org.w3c.dom.DocumenttoDocument(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.voidwriteRecord()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:ParsingContextReturns the parsing mode.- Specified by:
getModein classParsingContext- Returns:
- either
ParsingContext.UNMARSHALLINGorParsingContext.MARSHALLING
-
getTextLengthCounter
public TextLengthCounter getTextLengthCounter()
-
clear
public void clear()
Clear is invoked after each bean object (record or group) is marshalled.- Overrides:
clearin classParsingContext
-
writeRecord
public void writeRecord() throws java.io.IOExceptionWrites 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 theRecordWriterwhenwriteRecord()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
Stringarray 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
Listresult, 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
Documentresult, 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 theRecordWriterto write to.- Returns:
- the
RecordWriter
-
setRecordWriter
public void setRecordWriter(RecordWriter recordWriter)
Set theRecordWriterto write to.- Parameters:
recordWriter- theRecordWriter
-
-