See: Description
Interface | Description |
---|---|
DataTables |
Interface to access all kinds of measurement data (metrics, rule violations,
relation matrices) in a tabular form.
|
Class | Description |
---|---|
ConsoleMessageHandler |
Message handler for console-based applications.
|
MessageHandler |
Class to report progress messages and errors during (lengthy) operations such
as metric calculations.
|
MetricData |
Provides a tabular view of the design measurement data.
|
ModelData |
Provides a tabular view of the analyzed model.
|
Problem |
Stores the details of a problem encountered during metric calculation, rule
checking, etc.
|
RelationMatrices |
Calculates all relation matrices and provides a tabular view of their
contents.
|
RuleData |
Checks the design rules for a model and provides a tabular view of the design
rule violations.
|
Tutorial - How to calculate and use the metric and rule violation data tables.
The following code snippets show how to use the classes to calculate all metrics, rule violations, and relation matrices, and write the data tables to the console.
import sdmetrics.app.ConsoleMessageHandler; import sdmetrics.app.DataTables; import sdmetrics.app.MessageHandler; import sdmetrics.app.MetricData; import sdmetrics.app.ModelData; import sdmetrics.app.RelationMatrices; import sdmetrics.app.RuleData; import sdmetrics.metrics.MatrixEngine; import sdmetrics.metrics.MetricsEngine; import sdmetrics.metrics.RuleEngine;
com.sdmetrics.model
and com.sdmetrics.metrics
show how to parse an XMI file with the UML model and initialize a metrics engine.
MetricsEngine metricsEngine = new MetricsEngine(metricStore, model); RuleEngine ruleEngine = new RuleEngine(metricsEngine); MatrixEngine matrixEngine = new MatrixEngine(metricsEngine);
MessageHandler
msgHandler = new ConsoleMessageHandler() {
/* Override output formatting. */
public void message(String msg, int progress) {
if (msg != null && progress >= 0)
out.println(msg + " (" + progress + "% complete)");
}
};
For applications with a GUI, you could write a message handler that updates
the status and message of a progress bar.
For classMetricData
metrics = new MetricData(metricsEngine); metrics.precalculateMetrics(msgHandler, 0, 70);RuleData
rules = new RuleData(ruleEngine); rules.checkRules(msgHandler, 70, 90);RelationMatrices
matrices = new RelationMatrices(matrixEngine); matrices.calculateMatrices(msgHandler, 90, 100); msgHandler.message("Done.", 100);
MetricData
, pre-calculation of metric data is optional.
For classes RuleData
and RelationMatrices
, you first must check the
rules/calculate the matrices before you can access the data.
printTables
as follows:
public static void printTables(DataTables
data) {
System.out.println("Writing "+data.getTablesDescription());
for (int table = 0; table < data.getNumberOfTables(); table++) {
// write table number and name
System.out.println("Table " + (table + 1) + ": "
+ data.getTableName(table));
// write column headers
System.out.print("Name\t");
for (int col = 0; col < data.getNumberOfColumns(table); col++) {
System.out.print(data.getColumnName(table, col) + "\t");
}
System.out.println();
// write table body
for (int row = 0; row < data.getNumberOfRows(table); row++) {
System.out.print(data.getRowName(table, row) + "\t");
for (int col = 0; col < data.getNumberOfColumns(table); col++) {
System.out.print(data.getValueAt(table, row, col) + "\t");
}
System.out.println();
}
System.out.println();
}
}
With this method in place, we can dump all the data and the UML model itself to the console:
printTables(metrics); printTables(rules); printTables(matrices); printTables(new ModelData(model));
com.sdmetrics.output
provides this facility.