uk.ac.ic.doc.automed.wrappers
Class XMLSchemaWrapper

java.lang.Object
  extended by uk.ac.ic.doc.automed.wrappers.AutoMedWrapper
      extended by uk.ac.ic.doc.automed.wrappers.XMLSchemaWrapper
All Implemented Interfaces:
CacheUser

public class XMLSchemaWrapper
extends AutoMedWrapper

Author:
Andrew Charles Smith - acs203 This class provides methods to wrap an XML file constrained by an XML Schema in Automed.

Field Summary
private  Construct att
           
private  Construct ce
           
(package private)  Document doc
          An internal representation of the XSDOM document
static java.lang.String driverString
           
private  java.util.HashMap elementHash
           
(package private)  org.w3c.dom.Document inputDoc
          An internal representation of the Schema document
private  Construct key
           
private  Construct keyref
           
private  Construct multiparentLink
           
private  Construct multiparentNode
           
private  java.lang.String nsprefix
          The ns prefix used by the schema doc
private  java.util.HashMap parentNodeIdsHash
           
static java.lang.String protocolString
           
private  Construct recursiveDepth
           
private  Construct rootElement
           
private static char separator
          The separator for a query
private  int tempNo
           
private static java.lang.String unNamedComplexType
           
(package private)  org.w3c.dom.Document xmlDoc
          An internal representation of the XML document
private  java.lang.String xmlRootElementName
           
private  Model xs
           
(package private)  org.apache.xerces.xs.XSModel xsm
          The schema model for the XML doc loaded in
 
Fields inherited from class uk.ac.ic.doc.automed.wrappers.AutoMedWrapper
am, awf, debug, driver, emptyKeyProtection, emptyKeys, optionKeyProtection, optionKeys, optionSet, password, protocol, s, url, username
 
Constructor Summary
XMLSchemaWrapper()
          Creates a new, empty instance of XMLSchemaWrapper
XMLSchemaWrapper(AccessMethod am, java.lang.String password)
          This constructor is used when wrapping or querying the schema
 
Method Summary
protected  void connect()
          Check that the XML file exists
private  java.lang.String createXPath(SchemaObject so, java.lang.String currentPath)
           
private  ComplexType createXSDOMComplexType(org.apache.xerces.xs.XSComplexTypeDefinition xsct)
          Create a new XSDOM complexType
 void createXSDOMRepresentation(org.apache.xerces.xs.XSModel xsModel)
          Create an internal representation of the XML Schema.
 ASG executeIQL(ASG q)
          Execute an IQL query on the datasource.
 ASG executeIQL(ASG q, QueryProcessorConfiguration qr)
           
 ASG executeXMLSchemaQuery(ASG ASGquery)
          Given an IQL query, this method queries the XML file, then returns the answer in ASG format.
private  void findKey(org.apache.xerces.xs.XSIDCDefinition idc)
          Find the XSDOM constructs that make up this XS key
private  void findKeyRef(org.apache.xerces.xs.XSIDCDefinition idc)
          Find the XSDOM constructs that make up this XS keyRef
private  ComplexType findSelectorCT(org.apache.xerces.xs.XSIDCDefinition idc)
          Find the CT associated with the selector for this idc
private  Attribute getAttribute(org.apache.xerces.xs.XSAttributeUse attUse)
          Create an XSDOM attribute from the XMLSchema
protected  AutoMedWrapperFactory getDefaultWrapperFactory()
          Return the default AutoMedWrapperFactory that is used to generate Schema instances from information in a data sources
 Document getDoc()
          Return the XSDOM document
private  Element getElement(org.apache.xerces.xs.XSElementDeclaration xst, org.apache.xerces.xs.XSParticle xsp)
          Create an XSDOM element from the XMLSchema
 java.lang.String getProtocolName()
          Returns the protocol typeName for the XMLSchemaWrapper
private  SchemaObject hasAKey(SchemaObject so)
           
private  boolean inmultiparentLink(SchemaObject so)
           
private  ASG multiparentLinkQuery(java.lang.String parentElement, java.lang.String queryElement)
           
private  ASG parentsQuery(java.lang.String childName)
           
private  java.util.ArrayList processModelGroupInComplexType(org.apache.xerces.xs.XSModelGroup modelgroup)
           
private  ASG recursiveDepthQuery(java.lang.String childName)
           
private  ASG rootNodeQuery()
           
private  void setupElementHash()
           
private  org.apache.xerces.xs.XSModel validateDoc()
          Parse the XML Schema for this XML document
private  ASG xmlSchemaQuery(java.lang.String queryElement, SchemaObject keyNode, SchemaObject parentKeyNode, Construct constructType, java.lang.String typeName, boolean simpleContent)
          Non root node query
 
Methods inherited from class uk.ac.ic.doc.automed.wrappers.AutoMedWrapper
atDebugLevel, cacheWrapper, costIQL, deleteIQL, executeIQL, executeIQLIncrementally, executeLocalQuery, executeSourceIQL, getAccessMethod, getAutoMedPeerInstance, getAutoMedWrapper, getAutoMedWrapper, getAutoMedWrapperFactory, getDrivers, getMetadata, getOption, getOptionKeyProtection, getOptionKeys, getProtocol, getQueryParser, getRange, getSchema, getSchema, getURL, getUserName, insertIQL, newAutoMedSchema, newAutoMedWrapper, newAutoMedWrapper, newAutoMedWrapper, newAutoMedWrapperInstance, registerWrapper, selectNewAutoMedWrapper, selectNewAutoMedWrapper, setDebugLevel, setOption
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tempNo

private int tempNo

driverString

public static final java.lang.String driverString
See Also:
Constant Field Values

protocolString

public static final java.lang.String protocolString
See Also:
Constant Field Values

unNamedComplexType

private static final java.lang.String unNamedComplexType
See Also:
Constant Field Values

doc

Document doc
An internal representation of the XSDOM document


inputDoc

org.w3c.dom.Document inputDoc
An internal representation of the Schema document


xmlDoc

org.w3c.dom.Document xmlDoc
An internal representation of the XML document


separator

private static char separator
The separator for a query


xsm

org.apache.xerces.xs.XSModel xsm
The schema model for the XML doc loaded in


nsprefix

private java.lang.String nsprefix
The ns prefix used by the schema doc


xmlRootElementName

private java.lang.String xmlRootElementName

elementHash

private java.util.HashMap elementHash

parentNodeIdsHash

private java.util.HashMap parentNodeIdsHash

xs

private Model xs

rootElement

private Construct rootElement

ce

private Construct ce

att

private Construct att

key

private Construct key

keyref

private Construct keyref

multiparentNode

private Construct multiparentNode

multiparentLink

private Construct multiparentLink

recursiveDepth

private Construct recursiveDepth
Constructor Detail

XMLSchemaWrapper

public XMLSchemaWrapper()
Creates a new, empty instance of XMLSchemaWrapper


XMLSchemaWrapper

public XMLSchemaWrapper(AccessMethod am,
                        java.lang.String password)
                 throws DataSourceException,
                        NotFoundException
This constructor is used when wrapping or querying the schema

Throws:
DataSourceException
NotFoundException
Method Detail

getDoc

public Document getDoc()
Return the XSDOM document


getDefaultWrapperFactory

protected AutoMedWrapperFactory getDefaultWrapperFactory()
Description copied from class: AutoMedWrapper
Return the default AutoMedWrapperFactory that is used to generate Schema instances from information in a data sources

Specified by:
getDefaultWrapperFactory in class AutoMedWrapper

getProtocolName

public java.lang.String getProtocolName()
Returns the protocol typeName for the XMLSchemaWrapper

Specified by:
getProtocolName in class AutoMedWrapper
Returns:
the protocol typeName of this wrapper

connect

protected void connect()
                throws DataSourceException
Check that the XML file exists

Specified by:
connect in class AutoMedWrapper
Throws:
DataSourceException - if unable to connect to the data source

validateDoc

private org.apache.xerces.xs.XSModel validateDoc()
                                          throws DataSourceException
Parse the XML Schema for this XML document

Returns:
- the XSModel for this document
Throws:
DataSourceException

findSelectorCT

private ComplexType findSelectorCT(org.apache.xerces.xs.XSIDCDefinition idc)
Find the CT associated with the selector for this idc


findKey

private void findKey(org.apache.xerces.xs.XSIDCDefinition idc)
Find the XSDOM constructs that make up this XS key


findKeyRef

private void findKeyRef(org.apache.xerces.xs.XSIDCDefinition idc)
Find the XSDOM constructs that make up this XS keyRef


getElement

private Element getElement(org.apache.xerces.xs.XSElementDeclaration xst,
                           org.apache.xerces.xs.XSParticle xsp)
                    throws AutoMedException
Create an XSDOM element from the XMLSchema

Throws:
AutoMedException

getAttribute

private Attribute getAttribute(org.apache.xerces.xs.XSAttributeUse attUse)
Create an XSDOM attribute from the XMLSchema


processModelGroupInComplexType

private java.util.ArrayList processModelGroupInComplexType(org.apache.xerces.xs.XSModelGroup modelgroup)
                                                    throws AutoMedException
Throws:
AutoMedException

createXSDOMComplexType

private ComplexType createXSDOMComplexType(org.apache.xerces.xs.XSComplexTypeDefinition xsct)
                                    throws AutoMedException
Create a new XSDOM complexType

Throws:
AutoMedException

createXSDOMRepresentation

public void createXSDOMRepresentation(org.apache.xerces.xs.XSModel xsModel)
                               throws java.lang.Exception
Create an internal representation of the XML Schema. The schema comes from the PSVI of the XML document.

Throws:
java.lang.Exception

hasAKey

private SchemaObject hasAKey(SchemaObject so)
                      throws DataSourceException
Throws:
DataSourceException

inmultiparentLink

private boolean inmultiparentLink(SchemaObject so)

setupElementHash

private void setupElementHash()

executeIQL

public ASG executeIQL(ASG q)
               throws DataSourceException
Description copied from class: AutoMedWrapper
Execute an IQL query on the datasource.

Specified by:
executeIQL in class AutoMedWrapper
Parameters:
q - An IQL query held in an ASG which complies with the limitations of what this wrapper is able to process
Returns:
An ASG containing the results of the query
Throws:
DataSourceException

executeIQL

public ASG executeIQL(ASG q,
                      QueryProcessorConfiguration qr)
               throws DataSourceException
Throws:
DataSourceException

executeXMLSchemaQuery

public ASG executeXMLSchemaQuery(ASG ASGquery)
Given an IQL query, this method queries the XML file, then returns the answer in ASG format.

Parameters:
ASGquery - the IQL query in ASG format
Returns:
the answer to the IQL query in ASG format

rootNodeQuery

private ASG rootNodeQuery()

multiparentLinkQuery

private ASG multiparentLinkQuery(java.lang.String parentElement,
                                 java.lang.String queryElement)

parentsQuery

private ASG parentsQuery(java.lang.String childName)

recursiveDepthQuery

private ASG recursiveDepthQuery(java.lang.String childName)

xmlSchemaQuery

private ASG xmlSchemaQuery(java.lang.String queryElement,
                           SchemaObject keyNode,
                           SchemaObject parentKeyNode,
                           Construct constructType,
                           java.lang.String typeName,
                           boolean simpleContent)
Non root node query


createXPath

private java.lang.String createXPath(SchemaObject so,
                                     java.lang.String currentPath)