public class XMIReader extends SAXHandler
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.
Modifier and Type | Class and Description |
---|---|
static interface |
XMIReader.ProgressMessageHandler
Message handler for progress messages of the XMI parser.
|
locator
Constructor and Description |
---|
XMIReader(XMITransformations trans,
Model model)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
buildSAXException, checkVersion, reportError, setDocumentLocator
public XMIReader(XMITransformations trans, Model model)
trans
- The XMI transformations to use.model
- The model that will contain the extracted model elements.public void setProgressMessageHandler(XMIReader.ProgressMessageHandler handler)
handler
- The message handler.public int getNumberOfElements()
public void startDocument()
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
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)
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)
Model
.endElement
in interface org.xml.sax.ContentHandler
endElement
in class org.xml.sax.helpers.DefaultHandler
public void endDocument()
endDocument
in interface org.xml.sax.ContentHandler
endDocument
in class org.xml.sax.helpers.DefaultHandler