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
BaseParserFactory
implementation.A
StreamConfig
is "compiled" into aStream
in two passes. First, aPreprocessor
is 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 Aggregation
createAggregation(PropertyConfig config, Property property)
Creates an iteration for a repeating segment or field.protected abstract FieldFormat
createFieldFormat(FieldConfig config, java.lang.Class<?> type)
Creates a format specificFieldFormat
.protected Preprocessor
createPreprocessor(StreamConfig config)
Creates a stream configuration pre-processor.protected Property
createProperty(PropertyConfig config)
Creates a property for holding other properties.protected RecordAggregation
createRecordAggregation(PropertyConfig config, Property property)
Creates an aggregation for a repeating record or group.protected abstract RecordFormat
createRecordFormat(RecordConfig config)
Creates a format specificRecordFormat
.protected RecordParserFactory
createRecordParserFactory(StreamConfig config)
Creates theRecordParserFactory
for a stream configuration.Stream
createStream(StreamConfig config)
Creates a new stream definition based on a stream configuration.protected abstract StreamFormat
createStreamFormat(StreamConfig config)
Creates a format specificStreamFormat
.protected void
finalizeGroup(GroupConfig config)
Finalizes a group configuration after its children have been processed.protected void
finalizeGroup(GroupConfig config, Group group)
Invoked byfinalizeGroupMain(GroupConfig)
to allow subclasses to perform further finalization of the createdGroup
.protected void
finalizeGroupIteration(GroupConfig config, Property property)
protected Property
finalizeGroupMain(GroupConfig config)
protected void
finalizeRecord(RecordConfig config)
Finalizes a record configuration after its children have been processed.protected void
finalizeRecord(RecordConfig config, Record record)
Invoked byfinalizeRecord(RecordConfig)
to allow subclasses to perform further finalization of the createdRecord
.protected void
finalizeRecordIteration(RecordConfig config, Property property)
protected Property
finalizeRecordMain(RecordConfig config)
protected void
finalizeSegment(SegmentConfig config)
Finalizes a segment configuration after its children have been processed.protected void
finalizeSegment(SegmentConfig config, Segment segment)
Invoked byfinalizeSegmentMain(SegmentConfig)
to allow subclasses to perform further finalization of the createdSegment
.protected void
finalizeSegmentIteration(SegmentConfig config, Property property)
Called byfinalizeSegment(SegmentConfig)
to finalize segment iteration.protected Property
finalizeSegmentMain(SegmentConfig config)
Called byfinalizeSegment(SegmentConfig)
to finalize the segment component.protected void
finalizeStream(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 RecordParserFactory
getDefaultRecordParserFactory()
Returns the defaultRecordParserFactory
.protected java.lang.reflect.Field
getField(java.lang.String property)
Returns the non-finalField
for a given property name from the current bean class on the property stack.protected void
handleConstant(ConstantConfig config)
Processes a constant configuration.protected void
handleField(FieldConfig config)
Processes a field configuration.protected void
initializeGroup(GroupConfig config)
Initializes a group configuration before its children have been processed.protected void
initializeGroupIteration(GroupConfig config, Property property)
protected void
initializeGroupMain(GroupConfig config, Property property)
protected void
initializeRecord(RecordConfig config)
Initializes a record configuration before its children have been processed.protected void
initializeRecordIteration(RecordConfig config, Property property)
protected void
initializeRecordMain(RecordConfig config, Property property)
protected void
initializeSegment(SegmentConfig config)
Initializes a segment configuration before its children have been processed.protected void
initializeSegmentIteration(SegmentConfig config, Property property)
Called byinitializeSegment(SegmentConfig)
to initialize segment iteration.protected void
initializeSegmentMain(SegmentConfig config, Property property)
Called byinitializeSegment(SegmentConfig)
to initialize the segment.protected void
initializeStream(StreamConfig config)
Initializes a stream configuration before its children have been processed.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.boolean
isReadEnabled()
Returns whether the stream definition must support reading an input stream.protected boolean
isSegmentRequired(SegmentConfig config)
boolean
isWriteEnabled()
Returns whether the stream definition must support writing to an output stream.protected java.lang.Object
parseDefaultValue(Field field, java.lang.String text)
Parses a default field value.protected Component
popParser()
Removes the last component added to the parser stack.protected Property
popProperty()
Removes the last component added to the property stack.protected void
pushParser(Component component)
Adds a component to the parser stack.protected void
pushProperty(Component component)
Adds a component to the property stack.protected void
reflectAggregationType(PropertyConfig config, Aggregation aggregation, Property property)
protected java.lang.Class<?>
reflectCollectionType(Property iteration, Property property, java.lang.String getter, java.lang.String setter)
protected void
reflectPropertyType(PropertyConfig config, Property property)
Sets the property type and accessor using bean introspection.protected void
reflectRecordAggregationType(PropertyConfig config, RecordAggregation aggregation, Property property)
void
setClassLoader(java.lang.ClassLoader classLoader)
Sets theClassLoader
to use for resolving configured class names.void
setTypeHandlerFactory(TypeHandlerFactory typeHandlerFactory)
Sets the type handler factory to use to create the stream definition.protected void
updateConstructor(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:
createStream
in 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
- theBean
to check
-
initializeStream
protected void initializeStream(StreamConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupport
Initializes a stream configuration before its children have been processed.- Overrides:
initializeStream
in classProcessorSupport
- Parameters:
config
- the stream configuration to process- Throws:
BeanIOConfigurationException
-
finalizeStream
protected void finalizeStream(StreamConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupport
Finalizes a stream configuration after its children have been processed.- Overrides:
finalizeStream
in classProcessorSupport
- Parameters:
config
- the stream configuration to finalize- Throws:
BeanIOConfigurationException
-
initializeGroup
protected void initializeGroup(GroupConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupport
Initializes a group configuration before its children have been processed.- Overrides:
initializeGroup
in 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:ProcessorSupport
Finalizes a group configuration after its children have been processed.- Overrides:
finalizeGroup
in 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
- theGroup
being finalized
-
initializeRecord
protected void initializeRecord(RecordConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupport
Initializes a record configuration before its children have been processed.- Overrides:
initializeRecord
in 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:ProcessorSupport
Finalizes a record configuration after its children have been processed.- Overrides:
finalizeRecord
in 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
- theRecord
being finalized
-
initializeSegment
protected final void initializeSegment(SegmentConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupport
Initializes a segment configuration before its children have been processed.- Overrides:
initializeSegment
in 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
- theProperty
bound 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:ProcessorSupport
Finalizes a segment configuration after its children have been processed.- Overrides:
finalizeSegment
in 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:ProcessorSupport
Processes a field configuration.- Overrides:
handleField
in classProcessorSupport
- Parameters:
config
- the field configuration to process- Throws:
BeanIOConfigurationException
-
handleConstant
protected void handleConstant(ConstantConfig config) throws BeanIOConfigurationException
Description copied from class:ProcessorSupport
Processes a constant configuration.- Overrides:
handleConstant
in 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-finalField
for a given property name from the current bean class on the property stack.- Parameters:
property
- the propety name- Returns:
- the property
Field
or null if not found
-
createProperty
protected Property createProperty(PropertyConfig config)
Creates a property for holding other properties.- Parameters:
config
- thePropertyConfig
- Returns:
- the created
Property
or null if thePropertyConfig
was 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:
setTypeHandlerFactory
in interfaceParserFactory
- Parameters:
typeHandlerFactory
- theTypeHandlerFactory
to use to create the stream definition
-
isReadEnabled
public boolean isReadEnabled()
Returns whether the stream definition must support reading an input stream.- Returns:
true
if 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:
true
if the stream definition must support writing to an output stream
-
createRecordParserFactory
protected RecordParserFactory createRecordParserFactory(StreamConfig config)
Creates theRecordParserFactory
for a stream configuration.- Parameters:
config
- the stream configuration- Returns:
- the created
RecordParserFactory
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader classLoader)
Description copied from interface:ParserFactory
Sets theClassLoader
to use for resolving configured class names.- Specified by:
setClassLoader
in interfaceParserFactory
- Parameters:
classLoader
- theClassLoader
-
-