www.sdmetrics.com

Package com.sdmetrics.app

Supports the integration of SDMetrics' measurement capabilities into applications.

See:
          Description

Interface Summary
DataTables Interface to access all kinds of measurement data (metrics, rule violations, relation matrices) in a tabular form.
 

Class Summary
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.
 

Package com.sdmetrics.app Description

Supports the integration of SDMetrics' measurement capabilities into applications. The classes in this package simplify the calculation of all metric data, rule violations, and relation matrices. In addition, the classes organize the data in a tabular layout for presentation purposes:

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.

  1. Required imports
    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;
    
  2. Have your UML model an metrics engine ready
    The tutorials for packages 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);
    
  3. Provide a message handler for progress and output messages
    For larger models, calculations to be carried out can take some time. Therefore, the classes in the package regularly emit progress messages. You can display these messages to indicate that the application is still running and what it is currently doing. In this example, we write the progress messages to the console, showing progress as a percentage:
    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.

  4. Calculate the data
    We can now calculate the data. For the progress indication, we assign 70% of the total progress to metrics calculation, 20% to rule checking, and 10% to the calculation of relation matrices.
    MetricData 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);
    
    For class 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.

  5. Access the data
    In this example, we want to write the data tables of metrics, rule violations, relation matrices, and the UML model itself to the console. To this end, we define a method 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));
    
More practical applications of these classes include:


www.sdmetrics.com