BeanIO 2.0.4

org.beanio.internal.config.xml
Class XmlMappingParser

java.lang.Object
  extended by org.beanio.internal.config.xml.XmlMappingParser
All Implemented Interfaces:
StringUtil.PropertySource

public class XmlMappingParser
extends Object
implements StringUtil.PropertySource

Parses a mapping file into BeanIOConfig objects. A BeanIOConfig is produced for each mapping file imported by the mapping file being parsed, and the entire collection is returned from loadConfiguration(InputStream, Properties)

This class is not thread safe and a new instance should be created for parsing each input stream.

Since:
1.2.1
Author:
Kevin Seim

Constructor Summary
XmlMappingParser(ClassLoader classLoader, XmlMappingReader reader)
          Constructs a new XmlMappingParser.
 
Method Summary
protected  void addProperties(ComponentConfig config, Element element)
          Parses bean properties from the given DOM element.
protected  BeanConfig createBeanFactory(Element element)
          Parses a Bean from a DOM element.
protected  ConstantConfig createConstantConfig(Element element)
          Parses a constant component configuration from a DOM element.
protected  FieldConfig createFieldConfig(Element element)
          Parses a field configuration from a DOM element.
protected  GroupConfig createGroupConfig(Element element)
          Parses a group configuration from a DOM element.
protected  TypeHandlerConfig createHandlerConfig(Element element)
          Parses a TypeHandlerConfig from a DOM element.
protected  Properties createProperties(Element element)
          Parses Properties from a DOM element.
protected  RecordConfig createRecordConfig(Element element)
          Parses a record configuration from the given DOM element.
protected  SegmentConfig createSegmentConfig(Element element)
          Parses a segment component configuration from a DOM element.
protected  StreamConfig createStreamConfig(Element element)
          Parses a StreamConfig from a DOM element.
protected  void createTemplate(Element element)
          Adds a template to the active mapping.
protected  XmlMapping getMapping()
          Returns the mapping file information actively being parsed, which may change when one mapping file imports another.
protected  int getPositionOffset()
          Returns the amount to offset a field position, which is calculated according to included template offset configurations.
 String getProperty(String key)
          Returns the property value for a given key.
protected  XmlMapping importConfiguration(Element element)
          Parses an import DOM element and loads its mapping file.
protected  void includeTemplate(ComponentConfig config, Element element)
          Includes a template.
protected  void includeTemplate(ComponentConfig config, String template, int offset)
          Includes a template.
 Collection<BeanIOConfig> loadConfiguration(InputStream in, Properties properties)
          Reads a mapping file input stream and returns a collection of BeanIO configurations, one for the input stream and one for each imported mapping file (if specified).
protected  void loadMapping(Element element)
          Parses a BeanIO configuration from a DOM element.
protected  void loadMapping(InputStream in)
          Loads a mapping file from an input stream.
protected  void pop()
          Completes the parsing of an imported mapping file.
protected  XmlMapping push(String name, String location)
          Initiates the parsing of an imported mapping file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlMappingParser

public XmlMappingParser(ClassLoader classLoader,
                        XmlMappingReader reader)
Constructs a new XmlMappingParser.

Parameters:
classLoader - the ClassLoader for loading imported resources
reader - the XML mapping reader for reading XML mapping files into a DOM object
Method Detail

loadConfiguration

public Collection<BeanIOConfig> loadConfiguration(InputStream in,
                                                  Properties properties)
                                           throws IOException,
                                                  BeanIOConfigurationException
Reads a mapping file input stream and returns a collection of BeanIO configurations, one for the input stream and one for each imported mapping file (if specified).

Parameters:
in - the input stream to read
properties - the Properties to use for property substitution
Returns:
the collection of parsed BeanIO configuration objects
Throws:
IOException - if an I/O error occurs
BeanIOConfigurationException - if the configuration is invalid

push

protected final XmlMapping push(String name,
                                String location)
Initiates the parsing of an imported mapping file.

After parsing completes, pop() must be invoked before continuing.

Parameters:
name - the name of the imported mapping file
location - the location of the imported mapping file (this should be an absolute URL so that importing the same mapping more than once can be detected)
Returns:
the new Mapping object pushed onto the stack (this can also be accessed by calling getMapping())
See Also:
pop()

pop

protected final void pop()
Completes the parsing of an imported mapping file.

See Also:
push(String, String)

getMapping

protected final XmlMapping getMapping()
Returns the mapping file information actively being parsed, which may change when one mapping file imports another.

Returns:
the active mapping information

getPositionOffset

protected final int getPositionOffset()
Returns the amount to offset a field position, which is calculated according to included template offset configurations.

Returns:
the current field position offset

loadMapping

protected void loadMapping(InputStream in)
                    throws IOException
Loads a mapping file from an input stream.

Parameters:
in - the input stream to read
Throws:
IOException - if an I/O error occurs

loadMapping

protected void loadMapping(Element element)
Parses a BeanIO configuration from a DOM element.

Parameters:
element - the root 'beanio' DOM element to parse

importConfiguration

protected final XmlMapping importConfiguration(Element element)
Parses an import DOM element and loads its mapping file.

Parameters:
element - the import DOM element
Returns:
a new BeanIOConfig for the imported resource or file

createHandlerConfig

protected TypeHandlerConfig createHandlerConfig(Element element)
Parses a TypeHandlerConfig from a DOM element.

Parameters:
element - the DOM element to parse
Returns:
the new TypeHandlerConfig

createTemplate

protected void createTemplate(Element element)
Adds a template to the active mapping.

Parameters:
element - the DOM element that defines the template

createBeanFactory

protected BeanConfig createBeanFactory(Element element)
Parses a Bean from a DOM element.

Parameters:
element - the DOM element to parse
Returns:
the new Bean

createProperties

protected Properties createProperties(Element element)
Parses Properties from a DOM element.

Parameters:
element - the DOM element to parse
Returns:
the new Properties

createStreamConfig

protected StreamConfig createStreamConfig(Element element)
Parses a StreamConfig from a DOM element.

Parameters:
element - the stream DOM element to parse
Returns:
the new StreamConfig

createGroupConfig

protected GroupConfig createGroupConfig(Element element)
Parses a group configuration from a DOM element.

Parameters:
element - the group DOM element to parse
Returns:
the parsed group configuration

createRecordConfig

protected RecordConfig createRecordConfig(Element element)
Parses a record configuration from the given DOM element.

Parameters:
element - the record DOM element to parse
Returns:
the parsed record configuration

addProperties

protected void addProperties(ComponentConfig config,
                             Element element)
Parses bean properties from the given DOM element.

Parameters:
config - the enclosing bean configuration to add the properties to
element - the bean or record DOM element to parse

includeTemplate

protected void includeTemplate(ComponentConfig config,
                               Element element)
Includes a template.

Parameters:
config - the parent bean configuration
element - the include DOM element to parse

includeTemplate

protected void includeTemplate(ComponentConfig config,
                               String template,
                               int offset)
Includes a template.

Parameters:
config - the parent bean configuration
template - the name of the template to include
offset - the value to offset configured positions by

createSegmentConfig

protected SegmentConfig createSegmentConfig(Element element)
Parses a segment component configuration from a DOM element.

Parameters:
element - the segment DOM element to parse
Returns:
the parsed segment configuration
Since:
2.0

createFieldConfig

protected FieldConfig createFieldConfig(Element element)
Parses a field configuration from a DOM element.

Parameters:
element - the field DOM element to parse
Returns:
the parsed field configuration

createConstantConfig

protected ConstantConfig createConstantConfig(Element element)
Parses a constant component configuration from a DOM element.

Parameters:
element - the property DOM element to parse
Returns:
the parsed constant configuration
Since:
2.0

getProperty

public String getProperty(String key)
Description copied from interface: StringUtil.PropertySource
Returns the property value for a given key.

Specified by:
getProperty in interface StringUtil.PropertySource
Parameters:
key - the property key
Returns:
the property value

BeanIO 2.0.4

Copyright © 2010-2013 Kevin Seim