uk.ac.bbk.dcs.automed.xml.wrappers
Class XMLDSSFromXMLSchema

java.lang.Object
  extended by uk.ac.bbk.dcs.automed.xml.wrappers.XMLDSSFromXMLSchema

public class XMLDSSFromXMLSchema
extends java.lang.Object

Parses an XML Schema and creates the corresponding XMLDSS in DOM format.

IMPORTANT: an XML Schema that passes through this algorithm with no exceptions/errors is not to be considered valid!

Features not yet supported:

Model groups: all model group declarations are treated as 'all' model group declarations, as this is the way the XMLDSS of a given XML file would be created. This means that the special behaviour of choice group and this of nesting model groups is ignored.

Wildcards: if the XML Schema contains any element or attribute wildcards, it will obviously ignore them, as it will not know what content to create.

Ignored declarations: the following declarations are ignored, as they obviously do not contribute to the XMLDSS content.

Should any unexpected behaviour of the algorithm occur (error/exception/unexpected XMLDSS) please contact the author of the class, specifying the problem and supplying the XML Schema used.

Author:
Lucas Zamboulis

Field Summary
private static int attNum
           
private static java.util.HashMap complexTypesDepth
           
private static int elemNum
           
private static java.util.HashSet ignorableDeclarations
           
protected static java.util.logging.Logger logger
           
private static int MAX_DEPTH
           
private static java.util.HashMap namedAttributeGroups
           
private static java.util.HashMap namedAttributes
           
private static java.util.HashMap namedElements
           
private static java.util.HashMap namedModelGroups
           
private static java.util.HashMap namedTypes
           
private static java.lang.String prefix
           
private static java.util.List primitiveTypes
           
 
Constructor Summary
private XMLDSSFromXMLSchema()
           
 
Method Summary
private static void addMixedContent(org.w3c.dom.Document xmldss, org.w3c.dom.Element xmldssElement)
           
private static org.w3c.dom.Element appendChildElement(org.w3c.dom.Document xmldss, org.w3c.dom.Node parent, java.lang.String name)
           
private static void appendChildText(org.w3c.dom.Document xmldss, org.w3c.dom.Node xmldssElement)
           
private static org.w3c.dom.Element getChildElementByTagName(org.w3c.dom.Node parent, java.lang.String name)
           
static org.w3c.dom.Document getXMLDSSDoc(java.lang.String URI, java.lang.String schemaName, java.lang.String xsdRootName)
           
private static void preProcessing(org.w3c.dom.Document xsd, java.lang.String URI, java.lang.String schemaName, java.lang.String xsdRootName)
           
private static void processComplexContentDeclaration(org.w3c.dom.Document xmldss, org.w3c.dom.Element complexContentElement, org.w3c.dom.Element xmldssElement)
           
private static void processComplexTypeDeclaration(org.w3c.dom.Document xmldss, org.w3c.dom.Element xmldssElement, org.w3c.dom.Element complexType)
           
private static void processElementDeclaration(org.w3c.dom.Document xmldss, org.w3c.dom.Element xsdElement, org.w3c.dom.Element xmldssElement)
          If element does not reference a named type, process its type Else, find the referenced type and process it.
private static void processGroupContentDeclaration(org.w3c.dom.Document xmldss, org.w3c.dom.Element groupContentElement, org.w3c.dom.Element xmldssElement)
           
private static void processNamedType(org.w3c.dom.Document xmldss, org.w3c.dom.Element xmldssElement, java.lang.String typeName)
          Depending on the type of an element (primitive, simple, complex), different type processing occurs
private static void processSimpleContentDeclaration(org.w3c.dom.Document xmldss, org.w3c.dom.Element simpleContentElement, org.w3c.dom.Element xmldssElement)
          Simple content means that the element has only character data content, with no children (may have attributes).
private static void processSimpleTypeDeclaration(org.w3c.dom.Element xmldssElement, org.w3c.dom.Element simpleType)
           
private static void processUnnamedType(org.w3c.dom.Document xmldss, org.w3c.dom.Element xsdElement, org.w3c.dom.Element xmldssElement)
           
private static void setAttribute(org.w3c.dom.Element xmldssElement, java.lang.String attName, java.lang.String attValue)
           
private static void showHashMap(java.lang.String s, java.util.HashMap m)
           
private static org.w3c.dom.Document translate(org.w3c.dom.Document xsd, java.lang.String xsdRootName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static java.util.logging.Logger logger

namedElements

private static java.util.HashMap namedElements

namedAttributes

private static java.util.HashMap namedAttributes

namedTypes

private static java.util.HashMap namedTypes

namedModelGroups

private static java.util.HashMap namedModelGroups

namedAttributeGroups

private static java.util.HashMap namedAttributeGroups

ignorableDeclarations

private static java.util.HashSet ignorableDeclarations

prefix

private static java.lang.String prefix

MAX_DEPTH

private static int MAX_DEPTH

complexTypesDepth

private static java.util.HashMap complexTypesDepth

primitiveTypes

private static java.util.List primitiveTypes

elemNum

private static int elemNum

attNum

private static int attNum
Constructor Detail

XMLDSSFromXMLSchema

private XMLDSSFromXMLSchema()
Method Detail

getXMLDSSDoc

public static org.w3c.dom.Document getXMLDSSDoc(java.lang.String URI,
                                                java.lang.String schemaName,
                                                java.lang.String xsdRootName)
                                         throws XMLException
Throws:
XMLException

preProcessing

private static void preProcessing(org.w3c.dom.Document xsd,
                                  java.lang.String URI,
                                  java.lang.String schemaName,
                                  java.lang.String xsdRootName)
                           throws XMLException
Throws:
XMLException

translate

private static org.w3c.dom.Document translate(org.w3c.dom.Document xsd,
                                              java.lang.String xsdRootName)
                                       throws XMLException
Parameters:
xsd - the XML Schema to be translated into XMLDSS
Returns:
the XMLDSS corresponding to the input XML Schema, in DOM format
Throws:
XMLException

processElementDeclaration

private static void processElementDeclaration(org.w3c.dom.Document xmldss,
                                              org.w3c.dom.Element xsdElement,
                                              org.w3c.dom.Element xmldssElement)
                                       throws XMLException
If element does not reference a named type, process its type Else, find the referenced type and process it.

Throws:
XMLException

processNamedType

private static void processNamedType(org.w3c.dom.Document xmldss,
                                     org.w3c.dom.Element xmldssElement,
                                     java.lang.String typeName)
                              throws XMLException
Depending on the type of an element (primitive, simple, complex), different type processing occurs

Parameters:
xmldssElement - the element with type typeName
typeName - the name of the type
Throws:
XMLException

processUnnamedType

private static void processUnnamedType(org.w3c.dom.Document xmldss,
                                       org.w3c.dom.Element xsdElement,
                                       org.w3c.dom.Element xmldssElement)
                                throws XMLException
Throws:
XMLException

processSimpleTypeDeclaration

private static void processSimpleTypeDeclaration(org.w3c.dom.Element xmldssElement,
                                                 org.w3c.dom.Element simpleType)

processComplexTypeDeclaration

private static void processComplexTypeDeclaration(org.w3c.dom.Document xmldss,
                                                  org.w3c.dom.Element xmldssElement,
                                                  org.w3c.dom.Element complexType)
                                           throws XMLException
Throws:
XMLException

setAttribute

private static void setAttribute(org.w3c.dom.Element xmldssElement,
                                 java.lang.String attName,
                                 java.lang.String attValue)

processGroupContentDeclaration

private static void processGroupContentDeclaration(org.w3c.dom.Document xmldss,
                                                   org.w3c.dom.Element groupContentElement,
                                                   org.w3c.dom.Element xmldssElement)
                                            throws XMLException
Throws:
XMLException

processSimpleContentDeclaration

private static void processSimpleContentDeclaration(org.w3c.dom.Document xmldss,
                                                    org.w3c.dom.Element simpleContentElement,
                                                    org.w3c.dom.Element xmldssElement)
                                             throws XMLException
Simple content means that the element has only character data content, with no children (may have attributes). Any extension/restriction happens on the data type. We therefore need only check for added/removed attributes and add a child text node.

Throws:
XMLException

processComplexContentDeclaration

private static void processComplexContentDeclaration(org.w3c.dom.Document xmldss,
                                                     org.w3c.dom.Element complexContentElement,
                                                     org.w3c.dom.Element xmldssElement)
                                              throws XMLException
Throws:
XMLException

addMixedContent

private static void addMixedContent(org.w3c.dom.Document xmldss,
                                    org.w3c.dom.Element xmldssElement)

getChildElementByTagName

private static org.w3c.dom.Element getChildElementByTagName(org.w3c.dom.Node parent,
                                                            java.lang.String name)

appendChildElement

private static org.w3c.dom.Element appendChildElement(org.w3c.dom.Document xmldss,
                                                      org.w3c.dom.Node parent,
                                                      java.lang.String name)
Parameters:
parent - the parent node (element or document)
name - the name of the node to be created and appended as a child to argument parent
Returns:
the created and appended element

appendChildText

private static void appendChildText(org.w3c.dom.Document xmldss,
                                    org.w3c.dom.Node xmldssElement)

showHashMap

private static void showHashMap(java.lang.String s,
                                java.util.HashMap m)