public class XmlMappingParser extends Object implements StringUtil.PropertySource
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.
Constructor and Description |
---|
XmlMappingParser(ClassLoader classLoader,
XmlMappingReader reader)
Constructs a new XmlMappingParser.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public XmlMappingParser(ClassLoader classLoader, XmlMappingReader reader)
classLoader
- the ClassLoader
for loading imported resourcesreader
- the XML mapping reader for reading XML mapping files
into a DOM objectpublic Collection<BeanIOConfig> loadConfiguration(InputStream in, Properties properties) throws IOException, BeanIOConfigurationException
in
- the input stream to readproperties
- the Properties
to use for property substitutionIOException
- if an I/O error occursBeanIOConfigurationException
- if the configuration is invalidprotected final XmlMapping push(String name, String location)
After parsing completes, pop()
must be invoked
before continuing.
name
- the name of the imported mapping filelocation
- 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)getMapping()
)pop()
protected final void pop()
push(String, String)
protected final XmlMapping getMapping()
protected final int getPositionOffset()
protected void loadMapping(InputStream in) throws IOException
in
- the input stream to readIOException
- if an I/O error occursprotected void loadMapping(Element element)
element
- the root 'beanio' DOM element to parseprotected final XmlMapping importConfiguration(Element element)
element
- the import DOM elementprotected TypeHandlerConfig createHandlerConfig(Element element)
element
- the DOM element to parseprotected void createTemplate(Element element)
element
- the DOM element that defines the templateprotected BeanConfig createBeanFactory(Element element)
element
- the DOM element to parseprotected Properties createProperties(Element element)
element
- the DOM element to parseprotected StreamConfig createStreamConfig(Element element)
element
- the stream DOM element to parseprotected GroupConfig createGroupConfig(Element element)
element
- the group DOM element to parseprotected RecordConfig createRecordConfig(Element element)
element
- the record DOM element to parseprotected void addProperties(ComponentConfig config, Element element)
config
- the enclosing bean configuration to add the properties toelement
- the bean or record DOM element to parseprotected void includeTemplate(ComponentConfig config, Element element)
config
- the parent bean configurationelement
- the include DOM element to parseprotected void includeTemplate(ComponentConfig config, String template, int offset)
config
- the parent bean configurationtemplate
- the name of the template to includeoffset
- the value to offset configured positions byprotected SegmentConfig createSegmentConfig(Element element)
element
- the segment DOM element to parseprotected FieldConfig createFieldConfig(Element element)
element
- the field DOM element to parseprotected ConstantConfig createConstantConfig(Element element)
element
- the property DOM element to parsepublic String getProperty(String key)
StringUtil.PropertySource
getProperty
in interface StringUtil.PropertySource
key
- the property key