|
www.sdmetrics.com | |||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||
See:
Description
| Interface Summary | |
| XMIReader.ProgressMessageHandler | Interface with a callback method for the XMI reader to report progress to. |
| Class Summary | |
| ElementPool | Class to store the model elements of the UML design to be analyzed. |
| MetaModel | Class to read the SDMetrics UML metamodel from the metamodel definition file, and store the model for retrieval. |
| ModelElement | Represent a model element in a UML design. |
| VersionChecker | Class to check the version attribute of an SDMetrics project file. |
| XMIReader | Reads the XMI source file, processing it as specified by the XMI transformation file. |
| XMITransformations | Reads the XMI transformation file and stores its contents, and provide access to the XMI transformations defined in the file. |
This package implements the UML model of SDMetrics,
and provides the XMI import.

Tutorial - how to read an XMI file
The following code snippets show how to parse an XMI file and access the model information.
import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.XMLReader; import sdmetrics.model.*;
XMLReader parser; // Code to init your SAX parser, which will look something like this: SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(false); SAXParser saxParser = spf.newSAXParser(); parser = saxParser.getXMLReader(); parser.setErrorHandler(your_error_handler_object);
MetaModel mm = new MetaModel();
parser.setContentHandler(mm);
parser.parse("the_metamodel_definition_file.xml");
XMITransformations trans=new XMITransformations(mm);
parser.setContentHandler(trans);
parser.parse("the_xmi_transformation_file.xml");
// create the element pool to store the model elementsElementPoolpool=new ElementPool(mm); // create XMI reader to parse the XMI file and populate the element poolXMIReaderxmir = new XMIReader(mm,trans,pool); // optionally, register a message handler to intercept the XMIReader's progress messages xmir.setProgressMessageHandler(new XMIReader.ProgressMessageHandler() { public void reportXMIProgress(String msg) { System.out.println(msg); } }); // and parse the file parser.setContentHandler(xmir); parser.parse("the_XMI_file.xmi");
String[] filters={"#.java","#.javax","#.org.xml"};
pool.setFilter(filters,true,true,true);
// iterate over all model element types in the meta model
for(int type=0; type<mm.getNumberOfTypes(); type++) {
System.out.println("Elements of type: "+mm.getTypeName(type));
java.util.ArrayList elements=pool.getAcceptedElements(type);
// iterate over all model elements of the current type that
// also passed the element filter
for(int el=0; el<elements.size(); el++) {
ModelElement me = (ModelElement) elements.get(el);
System.out.println("Element name: "+me.getName()+" ");
// write out the value of each attribute of the current model element
for (int attr = 0; attr < mm.getAttributeCount(type); attr++) {
System.out.print(" Attribute: " + mm.getAttributeName(type, attr));
if (mm.isSetAttribute(type, attr))
System.out.println(" Set Value: " + me.getSetAttribute(attr));
else if (mm.isRefAttribute(type, attr)) {
System.out.print(" References: ");
ModelElement referenced = me.getRefAttribute(attr);
System.out.println(
(referenced == null) ? "nothing" : referenced.getFullName());
}
else
System.out.println(" Value: " + me.getXMLAttribute(attr));
}
}
}
|
www.sdmetrics.com | |||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||