org.rimudb.configuration
Class AbstractXmlLoader

java.lang.Object
  extended by org.rimudb.configuration.AbstractXmlLoader
Direct Known Subclasses:
CompoundDatabaseLoader, DBCopyLoader

public abstract class AbstractXmlLoader
extends java.lang.Object

This abstract class performs the load an XML document from either the classpath, file system or a URL. It can also perform validation of the document against an array of schemas. It first attempts to validate using the name of the schema referenced in the document, but will fall back to trying to validate against the schemas returned by the abstract method getSchemas(). The load() method is responsible for loading the file. Given a filename, it attempts to locate that file in several different ways. If the filename begins with 'classpath:' it will attempt to load the filename as a resource. If the filename begins with 'file:' or 'http:', it will attempt to load the file name as a URL. If the filename begins with none of these, it will attempt to load it from the local file system. If that fails, it will attempt to load it as a resource from the classpath.

Author:
Simon Ritchie

Constructor Summary
AbstractXmlLoader()
           
 
Method Summary
 java.lang.String getDocumentSchema()
           
 java.lang.String getFilename()
          Return the CompoundDatabase filename.
protected abstract  java.lang.String[] getSchemas()
          Return an array of schemas to validate against.
 boolean isValidateXML()
           
 org.w3c.dom.Document load()
          Load the XML file using various strategies to locate it.
 java.lang.String lookupSchemaByValidation(org.w3c.dom.Document document)
          Validate the schema and return the schema that matches by trial and error.
 java.lang.String lookupSchemaVersion(org.w3c.dom.Element root)
          Determine the XML schema version from the XML document without validating.
 void setDocumentSchema(java.lang.String validatedAgainstSchema)
           
 void setFilename(java.lang.String filename)
          Set the CompoundDatabase filename.
 void setValidateXML(boolean validateXML)
          Set the validate XML property.
protected  org.xml.sax.SAXParseException validate(org.w3c.dom.Document document, java.lang.String compoundDbSchemaUrl)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractXmlLoader

public AbstractXmlLoader()
Method Detail

getSchemas

protected abstract java.lang.String[] getSchemas()
Return an array of schemas to validate against. Validation will be attempted in the order the schemas are returned.

Returns:
String[] Valid schemas

load

public org.w3c.dom.Document load()
                          throws java.lang.Exception
Load the XML file using various strategies to locate it. If the filename begins with 'classpath:' it will attempt to load the filename as a resource. If the filename begins with 'file:' or 'http:', it will attempt to load the file name as a URL. If the filename begins with none of these, it will attempt to load it from the local file system. If that fails, it will attempt to load it as a resource from the classpath.

Throws:
java.lang.Exception

setFilename

public void setFilename(java.lang.String filename)
Set the CompoundDatabase filename.

Parameters:
filename - String

getFilename

public java.lang.String getFilename()
Return the CompoundDatabase filename.

Returns:
String

setValidateXML

public void setValidateXML(boolean validateXML)
Set the validate XML property. This will cause the load() method to validate the XML document against the XML schema.

Parameters:
validateXML - boolean

isValidateXML

public boolean isValidateXML()

lookupSchemaByValidation

public java.lang.String lookupSchemaByValidation(org.w3c.dom.Document document)
                                          throws java.lang.Exception
Validate the schema and return the schema that matches by trial and error. If the document cannot be validated against possible schemas then throw an Exception.

Parameters:
document - Document
Returns:
String
Throws:
java.lang.Exception

lookupSchemaVersion

public java.lang.String lookupSchemaVersion(org.w3c.dom.Element root)
Determine the XML schema version from the XML document without validating.

Parameters:
root - Element
Returns:
String

validate

protected org.xml.sax.SAXParseException validate(org.w3c.dom.Document document,
                                                 java.lang.String compoundDbSchemaUrl)
                                          throws java.lang.Exception
Parameters:
document -
compoundDbSchemaUrl -
Returns:
SAXParseException
Throws:
java.lang.Exception

setDocumentSchema

public void setDocumentSchema(java.lang.String validatedAgainstSchema)

getDocumentSchema

public java.lang.String getDocumentSchema()


Copyright © 2008-2011 Simon Ritchie. All Rights Reserved.