Package org.xtce.toolkit
Class XTCEDatabaseParser
- java.lang.Object
-
- org.xtce.toolkit.XTCEDatabaseParser
-
- Direct Known Subclasses:
XTCEDatabase,XTCEDatabaseCompressor,XTCEDatabaseConverter
public abstract class XTCEDatabaseParser extends Object
Helper class to do the XTCE document parsing to support the XTCEDatabase class.- Author:
- dovereem
-
-
Constructor Summary
Constructors Constructor Description XTCEDatabaseParser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description NodeListevaluateXPathQuery(String query)Evaluate an arbitrary XPath Query Expression and return a generic NodeList object back or an exception with an error message.booleangetChanged()Retrieve the changed flag indicating if some part of the XTCE document has changed since it has last been saved.DocumentgetDocument()Method to return the document object from the Document Object Model (DOM) of this XTCE document.ElementgetDocumentElement()Method to return the root document element from the Document Object Model (DOM) of this XTCE document.List<String>getDocumentWarnings()Retrieve the list of warnings and errors that were collected during parsing of the XTCE document by the SAX parser.longgetErrorCount()Retrieve the count of error messages from the parsing.FilegetFilename()Retrieve the current filename, in fully qualified path form, for the XTCE database file that is loaded.StringgetNamespaceFromDocument()Retrieve the XTCE namespace that is applicable to the document that is loaded.StringgetSchemaFromDocument()Retrieve the XTCE schema document that is applicable for this loaded file.booleanisReadOnly()Retrieve the read only flag that was provided when the XTCE document was loaded and parsed.protected SpaceSystemTypeloadDatabase(File dbFile, boolean validateOnLoad, boolean applyXIncludes, boolean readOnly)Protected method to read/parse an XTCE XML document and populate the internal data members for this object.protected SpaceSystemTypeloadDatabase(InputStream dbStream, String path, boolean validateOnLoad, boolean applyXIncludes, boolean readOnly)Protected method to read/parse an XTCE XML document and populate the internal data members for this object.protected SpaceSystemTypeloadDatabase(URL dbLocation, boolean validateOnLoad, boolean applyXIncludes, boolean readOnly)Protected method to read/parse an XTCE XML document and populate the internal data members for this object.protected SpaceSystemTypenewDatabase(String spaceSystemName)Method to create a new XTCE Document in memory, which is always created in an editable state instead of read-only.voidnormalizeDocument()Method to normalize the whitespace in the XML Document Object Model to make saved documents look clean.protected booleanremoveDefaultAttribute(Element element, String name, String value)Remove an attribute node from an element in the Document Object Model when the attribute contains the default value.protected voidrenameElement(Element element, String newName)Rename an Element node in the Document Object Model assuming that it is the XTCE namespace but consider that the XTCE URI might be the default namespace, in which case there is no prefix, or it could have the xtce: prefix.protected voidsaveDatabase(File dbFile)Method to write the current XTCE Document in memory to a File object.voidsetChanged(boolean changedFlag)Set the change flag to indicate whether or not this XTCE document has been changed since the last time it was saved.protected voidsetFilename(File dbFile)Protected method to set a new filename when the database is saved.protected voidupdateHistorySet(List<String> messages)Update the History elements in the XTCE document before saving, only if the document uses the Header element.static List<String>validateDocument(File dbFile, boolean applyXIncludes)Method to perform XML Schema Description (XSD) verification on an arbitrary XTCE document.
-
-
-
Method Detail
-
getFilename
public final File getFilename()
Retrieve the current filename, in fully qualified path form, for the XTCE database file that is loaded.- Returns:
- String containing the name, or an empty string if this is a new database that has not yet been saved to a filesystem.
-
setFilename
protected final void setFilename(File dbFile)
Protected method to set a new filename when the database is saved.- Parameters:
dbFile- File object containing the file that was saved.
-
getChanged
public final boolean getChanged()
Retrieve the changed flag indicating if some part of the XTCE document has changed since it has last been saved.- Returns:
- boolean indicating if a change has been made that has not been yet saved.
-
setChanged
public final void setChanged(boolean changedFlag)
Set the change flag to indicate whether or not this XTCE document has been changed since the last time it was saved.- Parameters:
changedFlag- boolean to use to set the changed flag.
-
getSchemaFromDocument
public final String getSchemaFromDocument()
Retrieve the XTCE schema document that is applicable for this loaded file. TODO: This only returns the default right now, need to work that.- Returns:
- String containing the file and path to the schema document.
-
getNamespaceFromDocument
public final String getNamespaceFromDocument()
Retrieve the XTCE namespace that is applicable to the document that is loaded. TODO: This only returns the default right now, need to work that.- Returns:
- String containing the namespace.
-
getDocumentWarnings
public final List<String> getDocumentWarnings()
Retrieve the list of warnings and errors that were collected during parsing of the XTCE document by the SAX parser.- Returns:
- List of strings that contain the warnings/errors when processing a document, or an empty list if there are none. The return will never be null.
-
getErrorCount
public final long getErrorCount()
Retrieve the count of error messages from the parsing.- Returns:
- long count of the number of messages logged as errors when parsing a document.
-
isReadOnly
public final boolean isReadOnly()
Retrieve the read only flag that was provided when the XTCE document was loaded and parsed. When this flag is true, XPath queries and document saves cannot be used.- Returns:
- boolean indicating if the document was opened read-only.
-
validateDocument
public static List<String> validateDocument(File dbFile, boolean applyXIncludes)
Method to perform XML Schema Description (XSD) verification on an arbitrary XTCE document.- Parameters:
dbFile- File object containing the fully qualified filesystem path to the XTCE document to be verified.applyXIncludes- boolean indicating if the XInclude processing for the loaded file should be applied or ignored.- Returns:
- List of strings that contain the validation warning and error messages from the validator.
-
newDatabase
protected SpaceSystemType newDatabase(String spaceSystemName) throws XTCEDatabaseException
Method to create a new XTCE Document in memory, which is always created in an editable state instead of read-only.- Parameters:
spaceSystemName- Name attribute of the root SpaceSystem element to begin the document.- Returns:
- SpaceSystemType object from the JAXB binding that represents the newly created document.
- Throws:
XTCEDatabaseException- in the event that the DocumentBuilder cannot make a new document or JAXB cannot bind to the new document from the DOM. This is unlikely.
-
loadDatabase
protected SpaceSystemType loadDatabase(File dbFile, boolean validateOnLoad, boolean applyXIncludes, boolean readOnly) throws XTCEDatabaseException
Protected method to read/parse an XTCE XML document and populate the internal data members for this object.- Parameters:
dbFile- File object containing the XTCE XML document to load.validateOnLoad- boolean to indicate if the XML document should be validated through the XML Schema Description (XSD) document that is configured for the XTCEDatabase object. In the future this will be more flexible.applyXIncludes- boolean indicating if the XInclude processing for the loaded file should be applied or ignored.readOnly- boolean indicating if the Document Object Model should be constructed. This is needed for round trip editing, but it is slower than just the pure JAXB implementation.- Returns:
- SpaceSystemType XTCE document element that was loaded.
- Throws:
XTCEDatabaseException- thrown in the event that the document cannot be read or is not sufficiently valid to complete construction of the internal data model.
-
loadDatabase
protected SpaceSystemType loadDatabase(URL dbLocation, boolean validateOnLoad, boolean applyXIncludes, boolean readOnly) throws XTCEDatabaseException
Protected method to read/parse an XTCE XML document and populate the internal data members for this object.- Parameters:
dbLocation- URL containing a location to load the document from.validateOnLoad- boolean to indicate if the XML document should be validated through the XML Schema Description (XSD) document that is configured for the XTCEDatabase object. In the future this will be more flexible.applyXIncludes- boolean indicating if the XInclude processing for the loaded file should be applied or ignored.readOnly- boolean indicating if the Document Object Model should be constructed. This is needed for round trip editing, but it is slower than just the pure JAXB implementation.- Returns:
- SpaceSystemType XTCE document element that was loaded.
- Throws:
XTCEDatabaseException- thrown in the event that the document cannot be read or is not sufficiently valid to complete construction of the internal data model.
-
loadDatabase
protected SpaceSystemType loadDatabase(InputStream dbStream, String path, boolean validateOnLoad, boolean applyXIncludes, boolean readOnly) throws XTCEDatabaseException
Protected method to read/parse an XTCE XML document and populate the internal data members for this object.- Parameters:
dbStream- InputStream object containing the XTCE XML document to load.path- String containing the current working directory for the stream, which is needed for XInclude, or null if not possible to get.validateOnLoad- boolean to indicate if the XML document should be validated through the XML Schema Description (XSD) document that is configured for the XTCEDatabase object. In the future this will be more flexible.applyXIncludes- boolean indicating if the XInclude processing for the loaded file should be applied or ignored.readOnly- boolean indicating if the Document Object Model should be constructed. This is needed for round trip editing, but it is slower than just the pure JAXB implementation.- Returns:
- SpaceSystemType XTCE document element that was loaded.
- Throws:
XTCEDatabaseException- thrown in the event that the document cannot be read or is not sufficiently valid to complete construction of the internal data model.
-
saveDatabase
protected void saveDatabase(File dbFile) throws XTCEDatabaseException
Method to write the current XTCE Document in memory to a File object.- Parameters:
dbFile- File containing the location to write the database XML.- Throws:
XTCEDatabaseException- in the event that the document is opened read-only, in which case the DOM is not loaded or initialized.
-
normalizeDocument
public void normalizeDocument() throws XTCEDatabaseExceptionMethod to normalize the whitespace in the XML Document Object Model to make saved documents look clean.- Throws:
XTCEDatabaseException- in the event that the document is not well formed or it is loaded read-only, in which case the Document Object Model is not in use.
-
getDocumentElement
public final Element getDocumentElement() throws XTCEDatabaseException
Method to return the root document element from the Document Object Model (DOM) of this XTCE document.- Returns:
- Element containing the root SpaceSystem.
- Throws:
XTCEDatabaseException- in the event that the document is opened read-only, in which case the DOM is not loaded or initialized.
-
getDocument
public final Document getDocument() throws XTCEDatabaseException
Method to return the document object from the Document Object Model (DOM) of this XTCE document.- Returns:
- Element containing the root SpaceSystem.
- Throws:
XTCEDatabaseException- in the event that the document is opened read-only, in which case the DOM is not loaded or initialized.
-
evaluateXPathQuery
public NodeList evaluateXPathQuery(String query) throws XTCEDatabaseException
Evaluate an arbitrary XPath Query Expression and return a generic NodeList object back or an exception with an error message.- Parameters:
query- String containing the XPath expression.- Returns:
- NodeList containing 0 or more nodes that were located by the query.
- Throws:
XTCEDatabaseException- in the event that the query contains an error or cannot otherwise be evaluated against the DOM tree.
-
renameElement
protected void renameElement(Element element, String newName) throws XTCEDatabaseException
Rename an Element node in the Document Object Model assuming that it is the XTCE namespace but consider that the XTCE URI might be the default namespace, in which case there is no prefix, or it could have the xtce: prefix.- Parameters:
element- Element to renamenewName- String containing the new element name- Throws:
XTCEDatabaseException- in the event that the document object does not exist because the document is in read-only mode.
-
removeDefaultAttribute
protected boolean removeDefaultAttribute(Element element, String name, String value)
Remove an attribute node from an element in the Document Object Model when the attribute contains the default value.- Parameters:
element- Element object from the DOM to search for the attribute.name- String containing the name of the attribute to check.value- String containing the default value of the attribute.- Returns:
- boolean indicating if the attribute was removed.
-
updateHistorySet
protected void updateHistorySet(List<String> messages) throws XTCEDatabaseException
Update the History elements in the XTCE document before saving, only if the document uses the Header element.- Parameters:
messages- List of strings to add to the HistorySet element with each message being 1 new History element.- Throws:
XTCEDatabaseException- Unlikely to be thrown, but can occur if the document is malformed according to the schema.
-
-