Class XMIReader

  extended by org.xml.sax.helpers.DefaultHandler
      extended by com.sdmetrics.util.SAXHandler
          extended by com.sdmetrics.model.XMIReader
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class XMIReader
extends SAXHandler

Reads an XMI source file, processing it as specified by an XMI transformation file. The UML model elements retrieved from the file are stored in a Model.

In the XMI, design information for one model element is spread across a number of XML elements in the XML tree. Therefore, a DOM XML parser would be a reasonable choice to use for processing an XMI file. DOM parsers read the entire tree and store it in memory. However, XMI files can become large, and we usually only need a fraction of the information contained in an XMI file, so this is not economical.

Therefore, a deliberate choice was made to use a SAX XML parser. The SAX parser reads one XML element at the time, and we need to keep track of the context in which an XML element is embedded. This is done using a stack holding the model elements to process, and the state at which processing is for each model element on the stack.

Nested Class Summary
static interface XMIReader.ProgressMessageHandler
          Message handler for progress messages of the XMI parser.
Field Summary
Fields inherited from class com.sdmetrics.util.SAXHandler
Constructor Summary
XMIReader(XMITransformations trans, Model model)
Method Summary
 void characters(char[] ch, int start, int length)
          Processes text between XML element tags.
 void endDocument()
          Performs the post-processing after the entire XMI file has been read.
 void endElement(java.lang.String uri, java.lang.String local, java.lang.String raw)
          Processes the closing tag of an XML element.
 int getNumberOfElements()
          Gets the number of elements that have been extracted.
 void setProgressMessageHandler(XMIReader.ProgressMessageHandler handler)
          Registers a message handler for the XMI reader to report progress to.
 void startDocument()
          Prepare parser for new XMI file.
 void startElement(java.lang.String uri, java.lang.String local, java.lang.String raw, org.xml.sax.Attributes attrs)
          Processes the opening tag of an XML element in the XMI source file.
Methods inherited from class com.sdmetrics.util.SAXHandler
checkVersion, reportError, setDocumentLocator
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public XMIReader(XMITransformations trans,
                 Model model)
trans - The XMI transformations to use.
model - The model that will contain the extracted model elements.
Method Detail


public void setProgressMessageHandler(XMIReader.ProgressMessageHandler handler)
Registers a message handler for the XMI reader to report progress to.

handler - The message handler.


public int getNumberOfElements()
Gets the number of elements that have been extracted.

number of elements extracted from the XMI file


public void startDocument()
Prepare parser for new XMI file.

Specified by:
startDocument in interface org.xml.sax.ContentHandler
startDocument in class org.xml.sax.helpers.DefaultHandler


public void startElement(java.lang.String uri,
                         java.lang.String local,
                         java.lang.String raw,
                         org.xml.sax.Attributes attrs)
                  throws org.xml.sax.SAXException
Processes the opening tag of an XML element in the XMI source file. Depending on the parser state, this either creates a new model element, or adds information from a child or grandchild node of the XMI tree to the current model element.

Specified by:
startElement in interface org.xml.sax.ContentHandler
startElement in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException - An error occurred during the evaluation of a conditional XMI transformation.


public void characters(char[] ch,
                       int start,
                       int length)
Processes text between XML element tags.

Specified by:
characters in interface org.xml.sax.ContentHandler
characters in class org.xml.sax.helpers.DefaultHandler


public void endElement(java.lang.String uri,
                       java.lang.String local,
                       java.lang.String raw)
Processes the closing tag of an XML element. If the end of the definition of the model element on the top of the stack has been reached, add this element to the Model.

Specified by:
endElement in interface org.xml.sax.ContentHandler
endElement in class org.xml.sax.helpers.DefaultHandler


public void endDocument()
Performs the post-processing after the entire XMI file has been read. Process the elements on the deferredRelations list, and cross-references all model element links.

Specified by:
endDocument in interface org.xml.sax.ContentHandler
endDocument in class org.xml.sax.helpers.DefaultHandler