BeanIO 2.0.4

org.beanio.internal.compiler
Class ParserFactorySupport

java.lang.Object
  extended by org.beanio.internal.compiler.ProcessorSupport
      extended by org.beanio.internal.compiler.ParserFactorySupport
All Implemented Interfaces:
ParserFactory
Direct Known Subclasses:
FlatParserFactory, JsonParserFactory, XmlParserFactory

public abstract class ParserFactorySupport
extends ProcessorSupport
implements ParserFactory

Base 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.

Since:
2.0
Author:
Kevin Seim

Constructor Summary
ParserFactorySupport()
          Constructs a new ParserFactory.
 
Method Summary
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, boolean required)
          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)
           
protected  void 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)
           
protected  void 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)
          Called by finalizeSegment(SegmentConfig) to finalize segment iteration.
protected  void 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 public 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  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.
 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.
 
Methods inherited from class org.beanio.internal.compiler.ProcessorSupport
getParent, handleComponent, process
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParserFactorySupport

public ParserFactorySupport()
Constructs a new ParserFactory.

Method Detail

createStream

public Stream createStream(StreamConfig config)
                    throws BeanIOConfigurationException
Creates a new stream definition based on a stream configuration.

Specified by:
createStream in interface ParserFactory
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 specific StreamFormat.

Parameters:
config - the stream configuration
Returns:
the new StreamFormat

createRecordFormat

protected abstract RecordFormat createRecordFormat(RecordConfig config)
Creates a format specific RecordFormat.

Parameters:
config - the record configuration
Returns:
the new RecordFormat

createFieldFormat

protected abstract FieldFormat createFieldFormat(FieldConfig config,
                                                 Class<?> type)
Creates a format specific FieldFormat.

Parameters:
config - the field configuration
type - 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

updateConstructor

protected void updateConstructor(Bean bean)
Updates a Bean's constructor if one or more of its properties are constructor arguments.

Parameters:
bean - the Bean to check

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

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 class ProcessorSupport
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 class ProcessorSupport
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 class ProcessorSupport
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 class ProcessorSupport
Parameters:
config - the group configuration to finalize
Throws:
BeanIOConfigurationException

finalizeGroupMain

protected void finalizeGroupMain(GroupConfig config)

finalizeGroupIteration

protected void finalizeGroupIteration(GroupConfig config)

finalizeGroup

protected void finalizeGroup(GroupConfig config,
                             Group group)
Invoked by finalizeGroupMain(GroupConfig) to allow subclasses to perform further finalization of the created Group.

Parameters:
config - the group configuration
group - the Group 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 class ProcessorSupport
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 class ProcessorSupport
Parameters:
config - the record configuration to process
Throws:
BeanIOConfigurationException

finalizeRecordMain

protected void finalizeRecordMain(RecordConfig config)

finalizeRecordIteration

protected void finalizeRecordIteration(RecordConfig config)

finalizeRecord

protected void finalizeRecord(RecordConfig config,
                              Record record)
Invoked by finalizeRecord(RecordConfig) to allow subclasses to perform further finalization of the created Record.

Parameters:
config - the record configuration
record - the Record 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 class ProcessorSupport
Parameters:
config - the segment configuration to process
Throws:
BeanIOConfigurationException

initializeSegmentIteration

protected void initializeSegmentIteration(SegmentConfig config,
                                          Property property)
Called by initializeSegment(SegmentConfig) to initialize segment iteration.

Parameters:
config - the segment configuration
property - the Property bound to the segment, or null if no bean was bound

initializeSegmentMain

protected void initializeSegmentMain(SegmentConfig config,
                                     Property property)
Called by initializeSegment(SegmentConfig) to initialize the segment.

Parameters:
config - the segment configuration
property - 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 class ProcessorSupport
Parameters:
config - the segment configuration to process
Throws:
BeanIOConfigurationException

finalizeSegmentIteration

protected void finalizeSegmentIteration(SegmentConfig config)
Called by finalizeSegment(SegmentConfig) to finalize segment iteration.

Parameters:
config - the segment configuration

finalizeSegmentMain

protected void finalizeSegmentMain(SegmentConfig config)
Called by finalizeSegment(SegmentConfig) to finalize the segment component.

Parameters:
config - the segment configuration

finalizeSegment

protected void finalizeSegment(SegmentConfig config,
                               Segment segment)
Invoked by finalizeSegmentMain(SegmentConfig) to allow subclasses to perform further finalization of the created Segment.

Parameters:
config - the segment configuration
segment - the new Segment

handleField

protected void handleField(FieldConfig config)
                    throws BeanIOConfigurationException
Description copied from class: ProcessorSupport
Processes a field configuration.

Overrides:
handleField in class ProcessorSupport
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 class ProcessorSupport
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 configuration
property - 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

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 configuration
property - the property component
Returns:
the created RecordAggregation
Throws:
BeanIOConfigurationException

reflectCollectionType

protected Class<?> reflectCollectionType(Property iteration,
                                         Property property,
                                         String getter,
                                         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 configuration
property - the property
Throws:
BeanIOConfigurationException - if the configured type is not assignable to the type determined through introspection

getField

protected Field getField(String property)
Returns the public non-final Field 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,
                                  boolean required)
Creates a property for holding other properties.

Parameters:
config - the PropertyConfig
required - whether the property is required and should always be instantiated
Returns:
the created Property or null if the PropertyConfig was not bound to a bean class

getBeanClass

protected 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 Object parseDefaultValue(Field field,
                                   String text)
Parses a default field value.

Parameters:
field - the field
text - the text to parse
Returns:
the default value

getDefaultRecordParserFactory

protected abstract RecordParserFactory getDefaultRecordParserFactory()
Returns the default RecordParserFactory.

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 interface ParserFactory
Parameters:
typeHandlerFactory - the TypeHandlerFactory 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 the RecordParserFactory for a stream configuration.

Parameters:
config - the stream configuration
Returns:
the created RecordParserFactory

setClassLoader

public void setClassLoader(ClassLoader classLoader)
Description copied from interface: ParserFactory
Sets the ClassLoader to use for resolving configured class names.

Specified by:
setClassLoader in interface ParserFactory
Parameters:
classLoader - the ClassLoader

BeanIO 2.0.4

Copyright © 2010-2013 Kevin Seim