Package org.beanio.internal.config.xml
Class XmlMappingParser
- java.lang.Object
-
- org.beanio.internal.config.xml.XmlMappingParser
-
- All Implemented Interfaces:
StringUtil.PropertySource
public class XmlMappingParser extends java.lang.Object implements StringUtil.PropertySource
Parses a mapping file intoBeanIOConfigobjects. ABeanIOConfigis produced for each mapping file imported by the mapping file being parsed, and the entire collection is returned fromloadConfiguration(InputStream, Properties)This class is not thread safe and a new instance should be created for parsing each input stream.
- Since:
- 1.2.1
-
-
Constructor Summary
Constructors Constructor Description XmlMappingParser(java.lang.ClassLoader classLoader, XmlMappingReader reader)Constructs a newXmlMappingParser.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddProperties(ComponentConfig config, org.w3c.dom.Element element)Parses bean properties from the given DOM element.protected BeanConfigcreateBeanFactory(org.w3c.dom.Element element)Parses aBeanfrom a DOM element.protected ConstantConfigcreateConstantConfig(org.w3c.dom.Element element)Parses a constant component configuration from a DOM element.protected FieldConfigcreateFieldConfig(org.w3c.dom.Element element)Parses a field configuration from a DOM element.protected GroupConfigcreateGroupConfig(org.w3c.dom.Element element)Parses a group configuration from a DOM element.protected TypeHandlerConfigcreateHandlerConfig(org.w3c.dom.Element element)Parses aTypeHandlerConfigfrom a DOM element.protected java.util.PropertiescreateProperties(org.w3c.dom.Element element)ParsesPropertiesfrom a DOM element.protected RecordConfigcreateRecordConfig(org.w3c.dom.Element element)Parses a record configuration from the given DOM element.protected SegmentConfigcreateSegmentConfig(org.w3c.dom.Element element)Parses a segment component configuration from a DOM element.protected StreamConfigcreateStreamConfig(org.w3c.dom.Element element)Parses aStreamConfigfrom a DOM element.protected voidcreateTemplate(org.w3c.dom.Element element)Adds a template to the active mapping.protected XmlMappinggetMapping()Returns the mapping file information actively being parsed, which may change when one mapping file imports another.protected intgetPositionOffset()Returns the amount to offset a field position, which is calculated according to included template offset configurations.java.lang.StringgetProperty(java.lang.String key)Returns the property value for a given key.protected XmlMappingimportConfiguration(org.w3c.dom.Element element)Parses animportDOM element and loads its mapping file.protected voidincludeTemplate(ComponentConfig config, java.lang.String template, int offset)Includes a template.protected voidincludeTemplate(ComponentConfig config, org.w3c.dom.Element element)Includes a template.java.util.Collection<BeanIOConfig>loadConfiguration(java.io.InputStream in, java.util.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 voidloadMapping(java.io.InputStream in)Loads a mapping file from an input stream.protected voidloadMapping(org.w3c.dom.Element element)Parses a BeanIO configuration from a DOM element.protected voidpop()Completes the parsing of an imported mapping file.protected XmlMappingpush(java.lang.String name, java.lang.String location)Initiates the parsing of an imported mapping file.
-
-
-
Constructor Detail
-
XmlMappingParser
public XmlMappingParser(java.lang.ClassLoader classLoader, XmlMappingReader reader)Constructs a newXmlMappingParser.- Parameters:
classLoader- theClassLoaderfor loading imported resourcesreader- the XML mapping reader for reading XML mapping files into a DOM object
-
-
Method Detail
-
loadConfiguration
public java.util.Collection<BeanIOConfig> loadConfiguration(java.io.InputStream in, java.util.Properties properties) throws java.io.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 readproperties- thePropertiesto use for property substitution- Returns:
- the collection of parsed BeanIO configuration objects
- Throws:
java.io.IOException- if an I/O error occursBeanIOConfigurationException- if the configuration is invalid
-
push
protected final XmlMapping push(java.lang.String name, java.lang.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 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)- 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(java.io.InputStream in) throws java.io.IOExceptionLoads a mapping file from an input stream.- Parameters:
in- the input stream to read- Throws:
java.io.IOException- if an I/O error occurs
-
loadMapping
protected void loadMapping(org.w3c.dom.Element element)
Parses a BeanIO configuration from a DOM element.- Parameters:
element- the root 'beanio' DOM element to parse
-
importConfiguration
protected final XmlMapping importConfiguration(org.w3c.dom.Element element)
Parses animportDOM element and loads its mapping file.- Parameters:
element- theimportDOM element- Returns:
- a new
BeanIOConfigfor the imported resource or file
-
createHandlerConfig
protected TypeHandlerConfig createHandlerConfig(org.w3c.dom.Element element)
Parses aTypeHandlerConfigfrom a DOM element.- Parameters:
element- the DOM element to parse- Returns:
- the new
TypeHandlerConfig
-
createTemplate
protected void createTemplate(org.w3c.dom.Element element)
Adds a template to the active mapping.- Parameters:
element- the DOM element that defines the template
-
createBeanFactory
protected BeanConfig createBeanFactory(org.w3c.dom.Element element)
Parses aBeanfrom a DOM element.- Parameters:
element- the DOM element to parse- Returns:
- the new
Bean
-
createProperties
protected java.util.Properties createProperties(org.w3c.dom.Element element)
ParsesPropertiesfrom a DOM element.- Parameters:
element- the DOM element to parse- Returns:
- the new
Properties
-
createStreamConfig
protected StreamConfig createStreamConfig(org.w3c.dom.Element element)
Parses aStreamConfigfrom a DOM element.- Parameters:
element- thestreamDOM element to parse- Returns:
- the new
StreamConfig
-
createGroupConfig
protected GroupConfig createGroupConfig(org.w3c.dom.Element element)
Parses a group configuration from a DOM element.- Parameters:
element- thegroupDOM element to parse- Returns:
- the parsed group configuration
-
createRecordConfig
protected RecordConfig createRecordConfig(org.w3c.dom.Element element)
Parses a record configuration from the given DOM element.- Parameters:
element- therecordDOM element to parse- Returns:
- the parsed record configuration
-
addProperties
protected void addProperties(ComponentConfig config, org.w3c.dom.Element element)
Parses bean properties from the given DOM element.- Parameters:
config- the enclosing bean configuration to add the properties toelement- thebeanorrecordDOM element to parse
-
includeTemplate
protected void includeTemplate(ComponentConfig config, org.w3c.dom.Element element)
Includes a template.- Parameters:
config- the parent bean configurationelement- theincludeDOM element to parse
-
includeTemplate
protected void includeTemplate(ComponentConfig config, java.lang.String template, int offset)
Includes a template.- Parameters:
config- the parent bean configurationtemplate- the name of the template to includeoffset- the value to offset configured positions by
-
createSegmentConfig
protected SegmentConfig createSegmentConfig(org.w3c.dom.Element element)
Parses a segment component configuration from a DOM element.- Parameters:
element- thesegmentDOM element to parse- Returns:
- the parsed segment configuration
- Since:
- 2.0
-
createFieldConfig
protected FieldConfig createFieldConfig(org.w3c.dom.Element element)
Parses a field configuration from a DOM element.- Parameters:
element- thefieldDOM element to parse- Returns:
- the parsed field configuration
-
createConstantConfig
protected ConstantConfig createConstantConfig(org.w3c.dom.Element element)
Parses a constant component configuration from a DOM element.- Parameters:
element- thepropertyDOM element to parse- Returns:
- the parsed constant configuration
- Since:
- 2.0
-
getProperty
public java.lang.String getProperty(java.lang.String key)
Description copied from interface:StringUtil.PropertySourceReturns the property value for a given key.- Specified by:
getPropertyin interfaceStringUtil.PropertySource- Parameters:
key- the property key- Returns:
- the property value
-
-