Package org.beanio.internal.compiler
Class ParserFactorySupport
- java.lang.Object
-
- org.beanio.internal.compiler.ProcessorSupport
-
- org.beanio.internal.compiler.ParserFactorySupport
-
- All Implemented Interfaces:
ParserFactory
- Direct Known Subclasses:
FlatParserFactory,JsonParserFactory,XmlParserFactory
public abstract class ParserFactorySupport extends ProcessorSupport implements ParserFactory
BaseParserFactoryimplementation.A
StreamConfigis "compiled" into aStreamin two passes. First, aPreprocessoris used to validate and set default configuration settings. And secondly, the finalized configuration is walked again (using aProcessorSupport, to create the parser and property tree structure. As components are initialized they can be added to the tree structure using stacks with thepushParser(Component)andpushProperty(Component)methods. After a component is finalized, it should be removed from the stack using thepopParser()orpopProperty()method.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description ParserFactorySupport()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected AggregationcreateAggregation(PropertyConfig config, Property property)Creates an iteration for a repeating segment or field.protected abstract FieldFormatcreateFieldFormat(FieldConfig config, java.lang.Class<?> type)Creates a format specificFieldFormat.protected PreprocessorcreatePreprocessor(StreamConfig config)Creates a stream configuration pre-processor.protected PropertycreateProperty(PropertyConfig config)Creates a property for holding other properties.protected RecordAggregationcreateRecordAggregation(PropertyConfig config, Property property)Creates an aggregation for a repeating record or group.protected abstract RecordFormatcreateRecordFormat(RecordConfig config)Creates a format specificRecordFormat.protected RecordParserFactorycreateRecordParserFactory(StreamConfig config)Creates theRecordParserFactoryfor a stream configuration.StreamcreateStream(StreamConfig config)Creates a new stream definition based on a stream configuration.protected abstract StreamFormatcreateStreamFormat(StreamConfig config)Creates a format specificStreamFormat.protected voidfinalizeGroup(GroupConfig config)Finalizes a group configuration after its children have been processed.protected voidfinalizeGroup(GroupConfig config, Group group)Invoked byfinalizeGroupMain(GroupConfig)to allow subclasses to perform further finalization of the createdGroup.protected voidfinalizeGroupIteration(GroupConfig config, Property property)protected PropertyfinalizeGroupMain(GroupConfig config)protected voidfinalizeRecord(RecordConfig config)Finalizes a record configuration after its children have been processed.protected voidfinalizeRecord(RecordConfig config, Record record)Invoked byfinalizeRecord(RecordConfig)to allow subclasses to perform further finalization of the createdRecord.protected voidfinalizeRecordIteration(RecordConfig config, Property property)protected PropertyfinalizeRecordMain(RecordConfig config)protected voidfinalizeSegment(SegmentConfig config)Finalizes a segment configuration after its children have been processed.protected voidfinalizeSegment(SegmentConfig config, Segment segment)Invoked byfinalizeSegmentMain(SegmentConfig)to allow subclasses to perform further finalization of the createdSegment.protected voidfinalizeSegmentIteration(SegmentConfig config, Property property)Called byfinalizeSegment(SegmentConfig)to finalize segment iteration.protected PropertyfinalizeSegmentMain(SegmentConfig config)Called byfinalizeSegment(SegmentConfig)to finalize the segment component.protected voidfinalizeStream(StreamConfig config)Finalizes a stream configuration after its children have been processed.protected java.lang.Class<?>getBeanClass(PropertyConfig config)Returns the bean class for a segment configuration.protected abstract RecordParserFactorygetDefaultRecordParserFactory()Returns the defaultRecordParserFactory.protected java.lang.reflect.FieldgetField(java.lang.String property)Returns the non-finalFieldfor a given property name from the current bean class on the property stack.protected voidhandleConstant(ConstantConfig config)Processes a constant configuration.protected voidhandleField(FieldConfig config)Processes a field configuration.protected voidinitializeGroup(GroupConfig config)Initializes a group configuration before its children have been processed.protected voidinitializeGroupIteration(GroupConfig config, Property property)protected voidinitializeGroupMain(GroupConfig config, Property property)protected voidinitializeRecord(RecordConfig config)Initializes a record configuration before its children have been processed.protected voidinitializeRecordIteration(RecordConfig config, Property property)protected voidinitializeRecordMain(RecordConfig config, Property property)protected voidinitializeSegment(SegmentConfig config)Initializes a segment configuration before its children have been processed.protected voidinitializeSegmentIteration(SegmentConfig config, Property property)Called byinitializeSegment(SegmentConfig)to initialize segment iteration.protected voidinitializeSegmentMain(SegmentConfig config, Property property)Called byinitializeSegment(SegmentConfig)to initialize the segment.protected voidinitializeStream(StreamConfig config)Initializes a stream configuration before its children have been processed.protected booleanisBound()Returns true if a property has been pushed onto the property stack, indicating that further properties will be bound to a parent property.booleanisReadEnabled()Returns whether the stream definition must support reading an input stream.protected booleanisSegmentRequired(SegmentConfig config)booleanisWriteEnabled()Returns whether the stream definition must support writing to an output stream.protected java.lang.ObjectparseDefaultValue(Field field, java.lang.String text)Parses a default field value.protected ComponentpopParser()Removes the last component added to the parser stack.protected PropertypopProperty()Removes the last component added to the property stack.protected voidpushParser(Component component)Adds a component to the parser stack.protected voidpushProperty(Component component)Adds a component to the property stack.protected voidreflectAggregationType(PropertyConfig config, Aggregation aggregation, Property property)protected java.lang.Class<?>reflectCollectionType(Property iteration, Property property, java.lang.String getter, java.lang.String setter)protected voidreflectPropertyType(PropertyConfig config, Property property)Sets the property type and accessor using bean introspection.protected voidreflectRecordAggregationType(PropertyConfig config, RecordAggregation aggregation, Property property)voidsetClassLoader(java.lang.ClassLoader classLoader)Sets theClassLoaderto use for resolving configured class names.voidsetTypeHandlerFactory(TypeHandlerFactory typeHandlerFactory)Sets the type handler factory to use to create the stream definition.protected voidupdateConstructor(Bean bean)Updates aBean's constructor if one or more of its properties are constructor arguments.-
Methods inherited from class org.beanio.internal.compiler.ProcessorSupport
getParent, handleComponent, process
-
-
-
-
Method Detail
-
createStream
public Stream createStream(StreamConfig config) throws BeanIOConfigurationException
Creates a new stream definition based on a stream configuration.- Specified by:
createStreamin interfaceParserFactory- Parameters:
config- the stream configuration- Returns:
- the new
Stream - Throws:
BeanIOConfigurationException- if the configuration is invalid
-
createPreprocessor
protected Preprocessor createPreprocessor(StreamConfig config)
Creates a stream configuration pre-processor. May be overridden to return a format specific version.- Parameters:
config- the stream configuration to pre-process- Returns:
- the new
Preprocessor
-
createStreamFormat
protected abstract StreamFormat createStreamFormat(StreamConfig config)
Creates a format specificStreamFormat.- Parameters:
config- the stream configuration- Returns:
- the new
StreamFormat
-
createRecordFormat
protected abstract RecordFormat createRecordFormat(RecordConfig config)
Creates a format specificRecordFormat.- Parameters:
config- the record configuration- Returns:
- the new
RecordFormat
-
createFieldFormat
protected abstract FieldFormat createFieldFormat(FieldConfig config, java.lang.Class<?> type)
Creates a format specificFieldFormat.- Parameters:
config- the field configurationtype- the property type, or null if not bound to a property- Returns:
- the new
FieldFormat
-
pushParser
protected void pushParser(Component component)
Adds a component to the parser stack.- Parameters:
component- the component to add
-
popParser
protected Component popParser()
Removes the last component added to the parser stack.- Returns:
- the removed component
-
pushProperty
protected void pushProperty(Component component)
Adds a component to the property stack.- Parameters:
component- the component to add
-
popProperty
protected Property popProperty()
Removes the last component added to the property stack.- Returns:
- the removed component
-
isBound
protected boolean isBound()
Returns true if a property has been pushed onto the property stack, indicating that further properties will be bound to a parent property.- Returns:
- true if a property is currently bound to a parent bean object
-
updateConstructor
protected void updateConstructor(Bean bean)
Updates aBean's constructor if one or more of its properties are constructor arguments.- Parameters:
bean- theBeanto check
-
initializeStream
protected void initializeStream(StreamConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupportInitializes a stream configuration before its children have been processed.- Overrides:
initializeStreamin classProcessorSupport- Parameters:
config- the stream configuration to process- Throws:
BeanIOConfigurationException
-
finalizeStream
protected void finalizeStream(StreamConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupportFinalizes a stream configuration after its children have been processed.- Overrides:
finalizeStreamin classProcessorSupport- Parameters:
config- the stream configuration to finalize- Throws:
BeanIOConfigurationException
-
initializeGroup
protected void initializeGroup(GroupConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupportInitializes a group configuration before its children have been processed.- Overrides:
initializeGroupin classProcessorSupport- Parameters:
config- the group configuration to process- Throws:
BeanIOConfigurationException
-
initializeGroupIteration
protected void initializeGroupIteration(GroupConfig config, Property property)
-
initializeGroupMain
protected void initializeGroupMain(GroupConfig config, Property property)
-
finalizeGroup
protected void finalizeGroup(GroupConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupportFinalizes a group configuration after its children have been processed.- Overrides:
finalizeGroupin classProcessorSupport- Parameters:
config- the group configuration to finalize- Throws:
BeanIOConfigurationException
-
finalizeGroupMain
protected Property finalizeGroupMain(GroupConfig config)
-
finalizeGroupIteration
protected void finalizeGroupIteration(GroupConfig config, Property property)
-
finalizeGroup
protected void finalizeGroup(GroupConfig config, Group group)
Invoked byfinalizeGroupMain(GroupConfig)to allow subclasses to perform further finalization of the createdGroup.- Parameters:
config- the group configurationgroup- theGroupbeing finalized
-
initializeRecord
protected void initializeRecord(RecordConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupportInitializes a record configuration before its children have been processed.- Overrides:
initializeRecordin classProcessorSupport- Parameters:
config- the record configuration to process- Throws:
BeanIOConfigurationException
-
initializeRecordIteration
protected void initializeRecordIteration(RecordConfig config, Property property)
-
initializeRecordMain
protected void initializeRecordMain(RecordConfig config, Property property)
-
finalizeRecord
protected void finalizeRecord(RecordConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupportFinalizes a record configuration after its children have been processed.- Overrides:
finalizeRecordin classProcessorSupport- Parameters:
config- the record configuration to process- Throws:
BeanIOConfigurationException
-
finalizeRecordMain
protected Property finalizeRecordMain(RecordConfig config)
-
finalizeRecordIteration
protected void finalizeRecordIteration(RecordConfig config, Property property)
-
finalizeRecord
protected void finalizeRecord(RecordConfig config, Record record)
Invoked byfinalizeRecord(RecordConfig)to allow subclasses to perform further finalization of the createdRecord.- Parameters:
config- the record configurationrecord- theRecordbeing finalized
-
initializeSegment
protected final void initializeSegment(SegmentConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupportInitializes a segment configuration before its children have been processed.- Overrides:
initializeSegmentin classProcessorSupport- Parameters:
config- the segment configuration to process- Throws:
BeanIOConfigurationException
-
initializeSegmentIteration
protected void initializeSegmentIteration(SegmentConfig config, Property property)
Called byinitializeSegment(SegmentConfig)to initialize segment iteration.- Parameters:
config- the segment configurationproperty- thePropertybound to the segment, or null if no bean was bound
-
initializeSegmentMain
protected void initializeSegmentMain(SegmentConfig config, Property property)
Called byinitializeSegment(SegmentConfig)to initialize the segment.- Parameters:
config- the segment configurationproperty- the property bound to the segment, or null if no property was bound
-
isSegmentRequired
protected boolean isSegmentRequired(SegmentConfig config)
-
finalizeSegment
protected final void finalizeSegment(SegmentConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupportFinalizes a segment configuration after its children have been processed.- Overrides:
finalizeSegmentin classProcessorSupport- Parameters:
config- the segment configuration to process- Throws:
BeanIOConfigurationException
-
finalizeSegmentIteration
protected void finalizeSegmentIteration(SegmentConfig config, Property property)
Called byfinalizeSegment(SegmentConfig)to finalize segment iteration.- Parameters:
config- the segment configuration
-
finalizeSegmentMain
protected Property finalizeSegmentMain(SegmentConfig config)
Called byfinalizeSegment(SegmentConfig)to finalize the segment component.- Parameters:
config- the segment configuration
-
finalizeSegment
protected void finalizeSegment(SegmentConfig config, Segment segment)
Invoked byfinalizeSegmentMain(SegmentConfig)to allow subclasses to perform further finalization of the createdSegment.- Parameters:
config- the segment configurationsegment- the newSegment
-
handleField
protected void handleField(FieldConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupportProcesses a field configuration.- Overrides:
handleFieldin classProcessorSupport- Parameters:
config- the field configuration to process- Throws:
BeanIOConfigurationException
-
handleConstant
protected void handleConstant(ConstantConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupportProcesses a constant configuration.- Overrides:
handleConstantin classProcessorSupport- Parameters:
config- the constant configuration to process- Throws:
BeanIOConfigurationException
-
createAggregation
protected Aggregation createAggregation(PropertyConfig config, Property property) throws BeanIOConfigurationException
Creates an iteration for a repeating segment or field.- Parameters:
config- the property configurationproperty- the property component, may be null if the iteration is not a property of its parent bean- Returns:
- the iteration component
- Throws:
BeanIOConfigurationException- if the collection type is invalid
-
reflectAggregationType
protected void reflectAggregationType(PropertyConfig config, Aggregation aggregation, Property property) throws BeanIOConfigurationException
- Parameters:
config-aggregation-property-- Throws:
BeanIOConfigurationException
-
createRecordAggregation
protected RecordAggregation createRecordAggregation(PropertyConfig config, Property property) throws BeanIOConfigurationException
Creates an aggregation for a repeating record or group.- Parameters:
config- the record or group configurationproperty- the property component- Returns:
- the created
RecordAggregation - Throws:
BeanIOConfigurationException
-
reflectRecordAggregationType
protected void reflectRecordAggregationType(PropertyConfig config, RecordAggregation aggregation, Property property) throws BeanIOConfigurationException
- Throws:
BeanIOConfigurationException
-
reflectCollectionType
protected java.lang.Class<?> reflectCollectionType(Property iteration, Property property, java.lang.String getter, java.lang.String setter) throws BeanIOConfigurationException
- Parameters:
iteration-property-getter-setter-- Returns:
- the reflected property type
- Throws:
BeanIOConfigurationException
-
reflectPropertyType
protected void reflectPropertyType(PropertyConfig config, Property property) throws BeanIOConfigurationException
Sets the property type and accessor using bean introspection.- Parameters:
config- the property configurationproperty- the property- Throws:
BeanIOConfigurationException- if the configured type is not assignable to the type determined through introspection
-
getField
protected java.lang.reflect.Field getField(java.lang.String property)
Returns the non-finalFieldfor a given property name from the current bean class on the property stack.- Parameters:
property- the propety name- Returns:
- the property
Fieldor null if not found
-
createProperty
protected Property createProperty(PropertyConfig config)
Creates a property for holding other properties.- Parameters:
config- thePropertyConfig- Returns:
- the created
Propertyor null if thePropertyConfigwas not bound to a bean class
-
getBeanClass
protected java.lang.Class<?> getBeanClass(PropertyConfig config)
Returns the bean class for a segment configuration.- Parameters:
config- the property configuration- Returns:
- the bean class
- Throws:
BeanIOConfigurationException- if the segment configuration is invalid
-
parseDefaultValue
protected java.lang.Object parseDefaultValue(Field field, java.lang.String text)
Parses a default field value.- Parameters:
field- the fieldtext- the text to parse- Returns:
- the default value
-
getDefaultRecordParserFactory
protected abstract RecordParserFactory getDefaultRecordParserFactory()
Returns the defaultRecordParserFactory.- Returns:
- the
RecordParserFactory
-
setTypeHandlerFactory
public void setTypeHandlerFactory(TypeHandlerFactory typeHandlerFactory)
Sets the type handler factory to use to create the stream definition.- Specified by:
setTypeHandlerFactoryin interfaceParserFactory- Parameters:
typeHandlerFactory- theTypeHandlerFactoryto use to create the stream definition
-
isReadEnabled
public boolean isReadEnabled()
Returns whether the stream definition must support reading an input stream.- Returns:
trueif the stream definition must support reading an input stream
-
isWriteEnabled
public boolean isWriteEnabled()
Returns whether the stream definition must support writing to an output stream.- Returns:
trueif the stream definition must support writing to an output stream
-
createRecordParserFactory
protected RecordParserFactory createRecordParserFactory(StreamConfig config)
Creates theRecordParserFactoryfor a stream configuration.- Parameters:
config- the stream configuration- Returns:
- the created
RecordParserFactory
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader classLoader)
Description copied from interface:ParserFactorySets theClassLoaderto use for resolving configured class names.- Specified by:
setClassLoaderin interfaceParserFactory- Parameters:
classLoader- theClassLoader
-
-