Class MetaschemaXmlReader
- java.lang.Object
-
- gov.nist.secauto.metaschema.databind.io.xml.MetaschemaXmlReader
-
- All Implemented Interfaces:
IParsingContext<org.codehaus.stax2.XMLEventReader2,IXmlProblemHandler>
,IXmlParsingContext
public class MetaschemaXmlReader extends Object implements IXmlParsingContext
-
-
Constructor Summary
Constructors Constructor Description MetaschemaXmlReader(org.codehaus.stax2.XMLEventReader2 reader)
Construct a new Module-aware XML parser using the default problem handler.MetaschemaXmlReader(org.codehaus.stax2.XMLEventReader2 reader, IXmlProblemHandler problemHandler)
Construct a new Module-aware parser.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IXmlProblemHandler
getProblemHandler()
A handler that provides callbacks used to resolve parsing issues.org.codehaus.stax2.XMLEventReader2
getReader()
The parser used for reading data associated with the supported format.protected boolean
isNextInstance(IBoundNamedModelInstance targetInstance)
Determine if the next data to read corresponds to the next model instance.<CLASS> CLASS
read(IAssemblyClassBinding targetDefinition)
Parses XML into a bound object based on the provideddefinition
.<T> T
readDefinitionValue(IClassBinding targetDefinition, Object parentObject, StartElement start)
Reads a XML element storing the associated data in a Java class instance, returning the resulting instance.protected void
readFieldValue(IFieldClassBinding targetDefinition, Object targetObject)
Read the XML element and text data described by thetargetDefinition
and apply it to the providedtargetObject
.protected void
readFlagInstances(IClassBinding targetDefinition, Object targetObject, StartElement start)
Read the XML attribute data described by thetargetDefinition
and apply it to the providedtargetObject
.protected void
readModelInstances(IAssemblyClassBinding targetDefinition, Object targetObject, StartElement start)
Read the XML element data described by thetargetDefinition
and apply it to the providedtargetObject
.protected Object
readModelInstanceValue(IBoundAssemblyInstance instance, Object parentObject, StartElement start)
Read the XML data associated with theinstance
and apply it to the providedparentObject
.protected Object
readModelInstanceValue(IBoundFieldInstance instance, Object parentObject, StartElement start)
Revise<T> T
readModelInstanceValue(IBoundNamedModelInstance instance, Object parentObject, StartElement start)
Read the XML data associated with thetargetInstance
and apply it to the providedparentObject
.protected boolean
readModelInstanceValues(IBoundNamedModelInstance instance, Object parentObject, StartElement start)
Read the data associated with theinstance
and apply it to the providedparentObject
.
-
-
-
Constructor Detail
-
MetaschemaXmlReader
public MetaschemaXmlReader(@NonNull org.codehaus.stax2.XMLEventReader2 reader)
Construct a new Module-aware XML parser using the default problem handler.- Parameters:
reader
- the XML reader to parse with- See Also:
DefaultXmlProblemHandler
-
MetaschemaXmlReader
public MetaschemaXmlReader(@NonNull org.codehaus.stax2.XMLEventReader2 reader, @NonNull IXmlProblemHandler problemHandler)
Construct a new Module-aware parser.- Parameters:
reader
- the XML reader to parse withproblemHandler
- the problem handler implementation to use
-
-
Method Detail
-
getReader
public org.codehaus.stax2.XMLEventReader2 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
-
getProblemHandler
public IXmlProblemHandler 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 IAssemblyClassBinding targetDefinition) throws IOException, XMLStreamException
Parses XML into a bound object based on the provideddefinition
.Parses the
XMLStreamConstants.START_DOCUMENT
, the root element, and theXMLStreamConstants.END_DOCUMENT
.- Type Parameters:
CLASS
- the returned object type- Parameters:
targetDefinition
- the definition describing the root element data to read- Returns:
- the parsed object
- Throws:
XMLStreamException
- if an error occurred while parsing XML eventsIOException
- if an error occurred while parsing the input
-
readDefinitionValue
public <T> T readDefinitionValue(IClassBinding targetDefinition, Object parentObject, StartElement start) throws IOException, XMLStreamException
Description copied from interface:IXmlParsingContext
Reads a XML element storing the associated data in a Java class instance, returning the resulting instance.When called the next
XMLEvent
of theXMLStreamReader2
is expected to be aXMLStreamConstants.START_ELEMENT
that is the XML element associated with the Java class.After returning the next
XMLEvent
of theXMLStreamReader2
is expected to be a the next event after theXMLStreamConstants.END_ELEMENT
for the XMLXMLStreamConstants.START_ELEMENT
element associated with the Java class.- Specified by:
readDefinitionValue
in interfaceIXmlParsingContext
- Type Parameters:
T
- the resulting object type- Parameters:
targetDefinition
- the Module definition that describes the syntax of the data to readparentObject
- the Java object parent of the target object, which can benull
if there is no parentstart
- the XML element start and attribute data previously parsed- Returns:
- the Java object containing the data parsed by this method
- Throws:
IOException
- if an error occurred while parsing the inputXMLStreamException
- if an error occurred while parsing XML events
-
readFlagInstances
protected void readFlagInstances(@NonNull IClassBinding targetDefinition, @NonNull Object 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 IAssemblyClassBinding targetDefinition, @NonNull Object targetObject, @NonNull StartElement start) throws IOException, XMLStreamException
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 instart
- the XML element start and attribute data previously parsed- Throws:
IOException
- if an error occurred while parsing the inputXMLStreamException
- if an error occurred while parsing XML events
-
readFieldValue
protected void readFieldValue(@NonNull IFieldClassBinding targetDefinition, @NonNull Object targetObject) throws IOException
Read the XML element and text 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 IBoundNamedModelInstance 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
-
readModelInstanceValues
protected boolean readModelInstanceValues(@NonNull IBoundNamedModelInstance instance, @NonNull Object parentObject, @NonNull StartElement start) throws IOException, XMLStreamException
Read the data associated with theinstance
and apply it to the providedparentObject
.- Parameters:
instance
- the instance to parse data forparentObject
- the Java object that data parsed by this method will be stored instart
- the XML element start and attribute data previously parsed- 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 inputXMLStreamException
- if an error occurred while parsing XML events
-
readModelInstanceValue
public <T> T readModelInstanceValue(IBoundNamedModelInstance instance, Object parentObject, StartElement start) throws XMLStreamException, IOException
Description copied from interface:IXmlParsingContext
Read the XML data associated with thetargetInstance
and apply it to the providedparentObject
.- Specified by:
readModelInstanceValue
in interfaceIXmlParsingContext
- Type Parameters:
T
- the resulting object type- Parameters:
instance
- the instance to parse data forparentObject
- the Java object that data parsed by this method will be stored instart
- the XML element start and attribute data previously parsed- Returns:
- the Java object read, or
null
if no data was read - Throws:
XMLStreamException
- if an error occurred while parsing XML eventsIOException
- if an error occurred while parsing the input
-
readModelInstanceValue
@Nullable protected Object readModelInstanceValue(@NonNull IBoundAssemblyInstance instance, @NonNull Object parentObject, @NonNull StartElement start) throws XMLStreamException, IOException
Read the XML data associated with theinstance
and apply it to the providedparentObject
.- Parameters:
instance
- the instance to parse data forparentObject
- the Java object that data parsed by this method will be stored instart
- the XML element start and attribute data previously parsed- Returns:
- the Java object read, or
null
if no data was read - Throws:
IOException
- if an error occurred while parsing the inputXMLStreamException
- if an error occurred while parsing XML events
-
readModelInstanceValue
@NonNull protected Object readModelInstanceValue(@NonNull IBoundFieldInstance instance, @NonNull Object parentObject, @NonNull StartElement start) throws XMLStreamException, IOException
ReviseReads an individual XML item from the XML stream.
- Parameters:
instance
- the instance to parse data forparentObject
- the Java object that data parsed by this method will be stored instart
- the XML element start and attribute data previously parsed- Returns:
- the Java object read, or
null
if no data was read - Throws:
IOException
- if an error occurred while parsing the inputXMLStreamException
- if an error occurred while parsing XML events
-
-