Class MetaschemaXmlReader
java.lang.Object
gov.nist.secauto.metaschema.databind.io.xml.MetaschemaXmlReader
- All Implemented Interfaces:
IParsingContext<org.codehaus.stax2.XMLEventReader2,
,IXmlProblemHandler> IXmlParsingContext
Supports reading XML-based Metaschema module instances.
-
Constructor Summary
ConstructorDescriptionMetaschemaXmlReader
(org.codehaus.stax2.XMLEventReader2 reader, URI source) Construct a new Module-aware XML parser using the default problem handler.MetaschemaXmlReader
(org.codehaus.stax2.XMLEventReader2 reader, URI source, IXmlProblemHandler problemHandler) Construct a new Module-aware parser. -
Method Summary
Modifier and TypeMethodDescriptionA handler that provides callbacks used to resolve parsing issues.org.codehaus.stax2.XMLEventReader2
The parser used for reading data associated with the supported format.Get the URI-based resource read by this parser.protected boolean
isNextInstance
(IBoundInstanceModel<?> targetInstance) Determine if the next data to read corresponds to the next model instance.<CLASS> CLASS
read
(IBoundDefinitionModelComplex definition) Parses XML into a bound object based on the provideddefinition
.protected void
readFlagInstances
(IBoundDefinitionModelComplex targetDefinition, IBoundObject targetObject, StartElement start) Read the XML attribute data described by thetargetDefinition
and apply it to the providedtargetObject
.<T> boolean
readItems
(IBoundInstanceModel<T> instance, IBoundObject parentObject, boolean parseGrouping) Read the data associated with theinstance
and apply it to the providedparentObject
.protected void
readModelInstances
(IBoundDefinitionModelAssembly targetDefinition, IBoundObject targetObject) Read the XML element data described by thetargetDefinition
and apply it to the providedtargetObject
.
-
Constructor Details
-
MetaschemaXmlReader
Construct a new Module-aware XML parser using the default problem handler.- Parameters:
reader
- the XML reader to parse withsource
- the resource being parsed- See Also:
-
MetaschemaXmlReader
public MetaschemaXmlReader(@NonNull org.codehaus.stax2.XMLEventReader2 reader, @NonNull URI source, @NonNull IXmlProblemHandler problemHandler) Construct a new Module-aware parser.- Parameters:
reader
- the XML reader to parse withsource
- the resource being parsedproblemHandler
- the problem handler implementation to use
-
-
Method Details
-
getReader
Description copied from interface:IParsingContext
The parser used for reading data associated with the supported format.- Specified by:
getReader
in interfaceIParsingContext<org.codehaus.stax2.XMLEventReader2,
IXmlProblemHandler> - Returns:
- the parser
-
getSource
Description copied from interface:IParsingContext
Get the URI-based resource read by this parser.- Specified by:
getSource
in interfaceIParsingContext<org.codehaus.stax2.XMLEventReader2,
IXmlProblemHandler> - Returns:
- the resource URI
-
getProblemHandler
Description copied from interface:IParsingContext
A handler that provides callbacks used to resolve parsing issues.- Specified by:
getProblemHandler
in interfaceIParsingContext<org.codehaus.stax2.XMLEventReader2,
IXmlProblemHandler> - Returns:
- the configured handler
-
read
@NonNull public <CLASS> CLASS read(@NonNull IBoundDefinitionModelComplex definition) throws IOException Parses XML into a bound object based on the provideddefinition
.Parses the
XMLStreamConstants.START_DOCUMENT
, any processing instructions, and the element.- Specified by:
read
in interfaceIXmlParsingContext
- Type Parameters:
CLASS
- the returned object type- Parameters:
definition
- the definition describing the element data to read- Returns:
- the parsed object
- Throws:
IOException
- if an error occurred while parsing the input
-
readFlagInstances
protected void readFlagInstances(@NonNull IBoundDefinitionModelComplex targetDefinition, @NonNull IBoundObject targetObject, @NonNull StartElement start) throws IOException, XMLStreamException Read the XML attribute data described by thetargetDefinition
and apply it to the providedtargetObject
.- Parameters:
targetDefinition
- the Module definition that describes the syntax of the data to readtargetObject
- the Java object that data parsed by this method will be stored instart
- the containing XML element that was previously parsed- Throws:
IOException
- if an error occurred while parsing the inputXMLStreamException
- if an error occurred while parsing XML events
-
readModelInstances
protected void readModelInstances(@NonNull IBoundDefinitionModelAssembly targetDefinition, @NonNull IBoundObject targetObject) throws IOException Read the XML element data described by thetargetDefinition
and apply it to the providedtargetObject
.- Parameters:
targetDefinition
- the Module definition that describes the syntax of the data to readtargetObject
- the Java object that data parsed by this method will be stored in- Throws:
IOException
- if an error occurred while parsing the input
-
isNextInstance
protected boolean isNextInstance(@NonNull IBoundInstanceModel<?> targetInstance) throws XMLStreamException Determine if the next data to read corresponds to the next model instance.- Parameters:
targetInstance
- the model instance that describes the syntax of the data to read- Returns:
true
if the Module instance needs to be parsed, orfalse
otherwise- Throws:
XMLStreamException
- if an error occurred while parsing XML events
-
readItems
public <T> boolean readItems(@NonNull IBoundInstanceModel<T> instance, @NonNull IBoundObject parentObject, boolean parseGrouping) throws IOException Read the data associated with theinstance
and apply it to the providedparentObject
.- Specified by:
readItems
in interfaceIXmlParsingContext
- Type Parameters:
T
- the item Java type- Parameters:
instance
- the instance to parse data forparentObject
- the Java object that data parsed by this method will be stored inparseGrouping
- iftrue
parse the instance's grouping element orfalse
otherwise- Returns:
true
if the instance was parsed, orfalse
if the data did not contain information for this instance- Throws:
IOException
- if an error occurred while parsing the input
-