Package uk.co.real_logic.sbe.xml
Class XmlSchemaParser
java.lang.Object
uk.co.real_logic.sbe.xml.XmlSchemaParser
Encapsulate the XML Schema parsing for SBE so that other representations may be
used to generate independent representations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringKey for storingErrorHandleras user data in XML document. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckForValidName(Node node, String name) Check name against validity for C++ and Java naming.Scan XML for all message definitions and save in map.Scan XML for all types (encodedDataType, compositeType, enumType, and setType) and save in a map.static StringgetAttributeValue(Node elementNode, String attrName) Helper function that throws an exception when the attribute is not set.static StringgetAttributeValue(Node elementNode, String attrName, String defValue) Helper function that uses a default value when value not set.static StringgetAttributeValueOrNull(Node elementNode, String attrName) Helper function that hides the null return fromNamedNodeMap.getNamedItem(String).static ByteOrdergetByteOrder(String byteOrderName) Helper function to convert a schema byteOrderName into aByteOrder.static StringgetTypesPackageAttribute(Node elementNode) To be used with descendant elements of<types>elements.static voidhandleError(Node node, String msg) Handle an error condition as consequence of parsing.static voidhandleWarning(Node node, String msg) Handle a warning condition as a consequence of parsing.static MessageSchemaparse(InputStream in, ParserOptions options) static MessageSchemaparse(InputSource is, ParserOptions options) Take anInputSourceand parse it generating map of template ID to Message objects, types, and schema.static voidvalidate(String xsdFilename, InputStream in, ParserOptions options) Wraps theInputStreaminto anInputSourceand delegates tovalidate(String, InputSource, ParserOptions).static voidvalidate(String xsdFilename, InputSource is, ParserOptions options) Validate the document against a given schema.
-
Field Details
-
ERROR_HANDLER_KEY
Key for storingErrorHandleras user data in XML document.- See Also:
-
-
Constructor Details
-
XmlSchemaParser
public XmlSchemaParser()
-
-
Method Details
-
validate
public static void validate(String xsdFilename, InputSource is, ParserOptions options) throws Exception Validate the document against a given schema. Errors will be written toSystem.err.- Parameters:
xsdFilename- schema to validate against.is- source from which schema is read. Ideally it will have the systemId property set to resolve relative references.options- to be applied during parsing.- Throws:
Exception- if an error occurs when parsing the document or schema.
-
validate
public static void validate(String xsdFilename, InputStream in, ParserOptions options) throws Exception Wraps theInputStreaminto anInputSourceand delegates tovalidate(String, InputSource, ParserOptions).Note: this method does not set the
InputSource.setSystemId(java.lang.String)property. However, it is recommended to use thevalidate(String, InputSource, ParserOptions)method directly.- Parameters:
xsdFilename- schema to validate against.in- document to be validated.options- to be applied during parsing.- Throws:
Exception- if an error occurs when parsing the document or schema.
-
parse
Take anInputSourceand parse it generating map of template ID to Message objects, types, and schema.- Parameters:
is- source from which schema is read. Ideally it will have the systemId property set to resolve relative references.options- to be applied during parsing.- Returns:
MessageSchemaencoding for the schema.- Throws:
Exception- on parsing error.
-
parse
Wraps theInputStreaminto anInputSourceand delegates toparse(InputSource, ParserOptions).Note: this method does not set the
InputSource.setSystemId(java.lang.String)property. However, it is recommended to use theparse(InputSource, ParserOptions)method directly.- Parameters:
in- stream from which schema is read.options- to be applied during parsing.- Returns:
MessageSchemaencoding for the schema.- Throws:
Exception- on parsing error.
-
findTypes
public static Map<String,Type> findTypes(Document document, XPath xPath) throws XPathExpressionException Scan XML for all types (encodedDataType, compositeType, enumType, and setType) and save in a map.- Parameters:
document- for the XML parsing.xPath- for XPath expression reuse.- Returns:
Mapof nameStringtoType.- Throws:
XPathExpressionException- on parsing error.
-
findMessages
public static Map<Long,Message> findMessages(Document document, XPath xPath, Map<String, Type> typeByNameMap) throws XPathExpressionExceptionScan XML for all message definitions and save in map.- Parameters:
document- for the XML parsing.xPath- for XPath expression reuse.typeByNameMap- to use for Type objects.- Returns:
Mapof schemaId toMessage.- Throws:
XPathExpressionException- on parsing error.
-
handleError
Handle an error condition as consequence of parsing.- Parameters:
node- that is the context of the warning.msg- associated with the error.
-
handleWarning
Handle a warning condition as a consequence of parsing.- Parameters:
node- as the context for the warning.msg- associated with the warning.
-
getAttributeValue
Helper function that throws an exception when the attribute is not set.- Parameters:
elementNode- that should have the attribute.attrName- that is to be looked up.- Returns:
- value of the attribute.
- Throws:
IllegalStateException- if the attribute is not present.
-
getAttributeValue
Helper function that uses a default value when value not set.- Parameters:
elementNode- that should have the attribute.attrName- that is to be looked up.defValue- value to return if not set.- Returns:
- value of the attribute or defValue.
-
getTypesPackageAttribute
To be used with descendant elements of<types>elements. Returns the package attribute value as defined on the ancestor<types>element.- Parameters:
elementNode- the node inside the<types>element.- Returns:
- the package name, or null if not defined.
-
getAttributeValueOrNull
Helper function that hides the null return fromNamedNodeMap.getNamedItem(String).- Parameters:
elementNode- that could be null.attrName- that is to be looked up.- Returns:
- null or value of the attribute.
-
getByteOrder
Helper function to convert a schema byteOrderName into aByteOrder.- Parameters:
byteOrderName- specified as a FIX SBE string.- Returns:
- ByteOrder representation.
-
checkForValidName
Check name against validity for C++ and Java naming. Warning if not valid.- Parameters:
node- to have the name checked.name- of the node to be checked.
-