www.sdmetrics.com

sdmetrics.model
Class XMIReader

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--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 org.xml.sax.helpers.DefaultHandler

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

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
          Interface with a callback method for the XMI reader to report progress to.
 
Constructor Summary
XMIReader(MetaModel mm, XMITransformations trans, ElementPool pool)
           
 
Method Summary
 void characters(char[] ch, int start, int length)
          SAX Parser handler: process PCDATA with the currently active "ctext" trigger.
 void endDocument()
          SAX parser handler: end of the document.
 void endElement(java.lang.String uri, java.lang.String local, java.lang.String raw)
          SAX Parser handler: end of an XML element.
 void setProgressMessageHandler(XMIReader.ProgressMessageHandler handler)
          Set the message handler for the XMI reader to report progress to.
 void startDocument()
          SAX Parser handler: prepare parser for new document.
 void startElement(java.lang.String uri, java.lang.String local, java.lang.String raw, org.xml.sax.Attributes attrs)
          SAX Parser handler: process an XML element in the XMI source file.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMIReader

public XMIReader(MetaModel mm,
                 XMITransformations trans,
                 ElementPool pool)
Parameters:
mm - Metamodel on which the XMI transformations are based.
trans - Object that knows the available XMI transformations.
pool - The element pool to store the extracted model elements.
Method Detail

setProgressMessageHandler

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

Parameters:
handler - The message handler.

startDocument

public void startDocument()
SAX Parser handler: prepare parser for new document.

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

startElement

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
SAX Parser handler: process an XML element in the XMI source file. Depending on the state of parsing either create a new model element, or add 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
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException - An error occurred during the evaluation of a conditional XMI transformation.

characters

public void characters(char[] ch,
                       int start,
                       int length)
SAX Parser handler: process PCDATA with the currently active "ctext" trigger.

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

endElement

public void endElement(java.lang.String uri,
                       java.lang.String local,
                       java.lang.String raw)
                throws org.xml.sax.SAXException
SAX Parser handler: end 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 or the ElementPool and pull it from the stack.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException - The XML element holds relevant PCDATA for an unknown attribute of the model element

endDocument

public void endDocument()
SAX parser handler: end of the document. Process the elements on the deferredRelations list, and crossreference the elements in the pool.

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

www.sdmetrics.com