public abstract class ParserFactorySupport extends ProcessorSupport implements ParserFactory
ParserFactory
implementation.
A StreamConfig
is "compiled" into a Stream
in two passes. First, a
Preprocessor
is used to validate and set default configuration settings. And
secondly, the finalized configuration is walked again (using a ProcessorSupport
,
to create the parser and property tree structure. As components are initialized they can
be added to the tree structure using stacks with the pushParser(Component)
and
pushProperty(Component)
methods. After a component is finalized, it should be
removed from the stack using the popParser()
or popProperty()
method.
Type | Property and Description |
---|---|
protected Property |
pop
Removes the last component added to the property stack.
|
Constructor and Description |
---|
ParserFactorySupport()
Constructs a new ParserFactory.
|
Modifier and Type | Method and Description |
---|---|
protected Aggregation |
createAggregation(PropertyConfig config,
Property property)
Creates an iteration for a repeating segment or field.
|
protected abstract FieldFormat |
createFieldFormat(FieldConfig config,
Class<?> type)
Creates a format specific
FieldFormat . |
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 specific
RecordFormat . |
protected RecordParserFactory |
createRecordParserFactory(StreamConfig config)
Creates the
RecordParserFactory 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 specific
StreamFormat . |
protected void |
finalizeGroup(GroupConfig config)
Finalizes a group configuration after its children have been processed.
|
protected void |
finalizeGroup(GroupConfig config,
Group group)
Invoked by
finalizeGroupMain(GroupConfig) to allow subclasses to perform
further finalization of the created Group . |
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 by
finalizeRecord(RecordConfig) to allow subclasses to perform
further finalization of the created Record . |
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 by
finalizeSegmentMain(SegmentConfig) to allow subclasses to perform
further finalization of the created Segment . |
protected void |
finalizeSegmentIteration(SegmentConfig config,
Property property)
Called by
finalizeSegment(SegmentConfig) to finalize segment iteration. |
protected Property |
finalizeSegmentMain(SegmentConfig config)
Called by
finalizeSegment(SegmentConfig) to finalize the segment component. |
protected void |
finalizeStream(StreamConfig config)
Finalizes a stream configuration after its children have been processed.
|
protected Class<?> |
getBeanClass(PropertyConfig config)
Returns the bean class for a segment configuration.
|
protected abstract RecordParserFactory |
getDefaultRecordParserFactory()
Returns the default
RecordParserFactory . |
protected Field |
getField(String property)
Returns the non-final
Field 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 by
initializeSegment(SegmentConfig) to initialize segment iteration. |
protected void |
initializeSegmentMain(SegmentConfig config,
Property property)
Called by
initializeSegment(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 Object |
parseDefaultValue(Field field,
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 Class<?> |
reflectCollectionType(Property iteration,
Property property,
String getter,
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(ClassLoader classLoader)
Sets the
ClassLoader 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 a
Bean 's constructor if one or more of its properties are
constructor arguments. |
getParent, handleComponent, process
protected Property popProperty
public ParserFactorySupport()
public Stream createStream(StreamConfig config) throws BeanIOConfigurationException
createStream
in interface ParserFactory
config
- the stream configurationStream
BeanIOConfigurationException
- if the configuration is invalidprotected Preprocessor createPreprocessor(StreamConfig config)
config
- the stream configuration to pre-processPreprocessor
protected abstract StreamFormat createStreamFormat(StreamConfig config)
StreamFormat
.config
- the stream configurationStreamFormat
protected abstract RecordFormat createRecordFormat(RecordConfig config)
RecordFormat
.config
- the record configurationRecordFormat
protected abstract FieldFormat createFieldFormat(FieldConfig config, Class<?> type)
FieldFormat
.config
- the field configurationtype
- the property type, or null if not bound to a propertyFieldFormat
protected void pushParser(Component component)
component
- the component to addprotected Component popParser()
protected void pushProperty(Component component)
component
- the component to addprotected Property popProperty()
protected boolean isBound()
protected void updateConstructor(Bean bean)
Bean
's constructor if one or more of its properties are
constructor arguments.bean
- the Bean
to checkprotected void initializeStream(StreamConfig config) throws BeanIOConfigurationException
ProcessorSupport
initializeStream
in class ProcessorSupport
config
- the stream configuration to processBeanIOConfigurationException
protected void finalizeStream(StreamConfig config) throws BeanIOConfigurationException
ProcessorSupport
finalizeStream
in class ProcessorSupport
config
- the stream configuration to finalizeBeanIOConfigurationException
protected void initializeGroup(GroupConfig config) throws BeanIOConfigurationException
ProcessorSupport
initializeGroup
in class ProcessorSupport
config
- the group configuration to processBeanIOConfigurationException
protected void initializeGroupIteration(GroupConfig config, Property property)
protected void initializeGroupMain(GroupConfig config, Property property)
protected void finalizeGroup(GroupConfig config) throws BeanIOConfigurationException
ProcessorSupport
finalizeGroup
in class ProcessorSupport
config
- the group configuration to finalizeBeanIOConfigurationException
protected Property finalizeGroupMain(GroupConfig config)
protected void finalizeGroupIteration(GroupConfig config, Property property)
protected void finalizeGroup(GroupConfig config, Group group)
finalizeGroupMain(GroupConfig)
to allow subclasses to perform
further finalization of the created Group
.config
- the group configurationgroup
- the Group
being finalizedprotected void initializeRecord(RecordConfig config) throws BeanIOConfigurationException
ProcessorSupport
initializeRecord
in class ProcessorSupport
config
- the record configuration to processBeanIOConfigurationException
protected void initializeRecordIteration(RecordConfig config, Property property)
protected void initializeRecordMain(RecordConfig config, Property property)
protected void finalizeRecord(RecordConfig config) throws BeanIOConfigurationException
ProcessorSupport
finalizeRecord
in class ProcessorSupport
config
- the record configuration to processBeanIOConfigurationException
protected Property finalizeRecordMain(RecordConfig config)
protected void finalizeRecordIteration(RecordConfig config, Property property)
protected void finalizeRecord(RecordConfig config, Record record)
finalizeRecord(RecordConfig)
to allow subclasses to perform
further finalization of the created Record
.config
- the record configurationrecord
- the Record
being finalizedprotected final void initializeSegment(SegmentConfig config) throws BeanIOConfigurationException
ProcessorSupport
initializeSegment
in class ProcessorSupport
config
- the segment configuration to processBeanIOConfigurationException
protected void initializeSegmentIteration(SegmentConfig config, Property property)
initializeSegment(SegmentConfig)
to initialize segment iteration.config
- the segment configurationproperty
- the Property
bound to the segment, or null if no bean was boundprotected void initializeSegmentMain(SegmentConfig config, Property property)
initializeSegment(SegmentConfig)
to initialize the segment.config
- the segment configurationproperty
- the property bound to the segment, or null if no property was boundprotected boolean isSegmentRequired(SegmentConfig config)
protected final void finalizeSegment(SegmentConfig config) throws BeanIOConfigurationException
ProcessorSupport
finalizeSegment
in class ProcessorSupport
config
- the segment configuration to processBeanIOConfigurationException
protected void finalizeSegmentIteration(SegmentConfig config, Property property)
finalizeSegment(SegmentConfig)
to finalize segment iteration.config
- the segment configurationprotected Property finalizeSegmentMain(SegmentConfig config)
finalizeSegment(SegmentConfig)
to finalize the segment component.config
- the segment configurationprotected void finalizeSegment(SegmentConfig config, Segment segment)
finalizeSegmentMain(SegmentConfig)
to allow subclasses to perform
further finalization of the created Segment
.config
- the segment configurationsegment
- the new Segment
protected void handleField(FieldConfig config) throws BeanIOConfigurationException
ProcessorSupport
handleField
in class ProcessorSupport
config
- the field configuration to processBeanIOConfigurationException
protected void handleConstant(ConstantConfig config) throws BeanIOConfigurationException
ProcessorSupport
handleConstant
in class ProcessorSupport
config
- the constant configuration to processBeanIOConfigurationException
protected Aggregation createAggregation(PropertyConfig config, Property property) throws BeanIOConfigurationException
config
- the property configurationproperty
- the property component, may be null if the iteration is not
a property of its parent beanBeanIOConfigurationException
- if the collection type is invalidprotected void reflectAggregationType(PropertyConfig config, Aggregation aggregation, Property property) throws BeanIOConfigurationException
config
- aggregation
- property
- BeanIOConfigurationException
protected RecordAggregation createRecordAggregation(PropertyConfig config, Property property) throws BeanIOConfigurationException
config
- the record or group configurationproperty
- the property componentRecordAggregation
BeanIOConfigurationException
protected void reflectRecordAggregationType(PropertyConfig config, RecordAggregation aggregation, Property property) throws BeanIOConfigurationException
BeanIOConfigurationException
protected Class<?> reflectCollectionType(Property iteration, Property property, String getter, String setter) throws BeanIOConfigurationException
iteration
- property
- getter
- setter
- BeanIOConfigurationException
protected void reflectPropertyType(PropertyConfig config, Property property) throws BeanIOConfigurationException
config
- the property configurationproperty
- the propertyBeanIOConfigurationException
- if the configured type is not assignable
to the type determined through introspectionprotected Field getField(String property)
Field
for a given property
name from the current bean class on the property stack.property
- the propety nameField
or null if not foundprotected Property createProperty(PropertyConfig config)
config
- the PropertyConfig
Property
or null if the PropertyConfig
was not
bound to a bean classprotected Class<?> getBeanClass(PropertyConfig config)
config
- the property configurationBeanIOConfigurationException
- if the segment configuration is invalidprotected Object parseDefaultValue(Field field, String text)
field
- the fieldtext
- the text to parseprotected abstract RecordParserFactory getDefaultRecordParserFactory()
RecordParserFactory
.RecordParserFactory
public void setTypeHandlerFactory(TypeHandlerFactory typeHandlerFactory)
setTypeHandlerFactory
in interface ParserFactory
typeHandlerFactory
- the TypeHandlerFactory to use to
create the stream definitionpublic boolean isReadEnabled()
public boolean isWriteEnabled()
protected RecordParserFactory createRecordParserFactory(StreamConfig config)
RecordParserFactory
for a stream configuration.config
- the stream configurationRecordParserFactory
public void setClassLoader(ClassLoader classLoader)
ParserFactory
ClassLoader
to use for resolving configured class names.setClassLoader
in interface ParserFactory
classLoader
- the ClassLoader