FileDocCategorySizeDatePackage
ReportProperties.javaAPI DocAndroid 1.5 API21678Wed May 06 22:41:16 BST 2009com.vladium.emma.report

ReportProperties

public abstract class ReportProperties extends Object implements com.vladium.emma.IAppErrorCodes
author
Vlad Roubtsov, (C) 2003

Fields Summary
public static final IProperties.IMapper
REPORT_PROPERTY_MAPPER
private static final boolean
REMOVE_DUPLICATE_COLUMNS
private static final com.vladium.util.ObjectIntMap
COLUMNS
Constructors Summary
private ReportProperties()

Methods Summary
private static java.lang.StringgetReportProperty(com.vladium.util.IProperties properties, java.lang.String type, java.lang.String key, boolean allowBlank)

        return getReportProperty (properties, type, key, allowBlank, null);
    
private static java.lang.StringgetReportProperty(com.vladium.util.IProperties properties, java.lang.String type, java.lang.String key, boolean allowBlank, java.lang.String dflt)

        if ($assert.ENABLED) $assert.ASSERT (properties != null, "null input: properties");
        if ($assert.ENABLED) $assert.ASSERT (key != null, "null input: key");
        
        final String result = properties.getProperty (IReportProperties.PREFIX.concat (type).concat (".").concat (key), dflt);
        
        if (! allowBlank && (result != null) && (result.trim ().length () == 0))
            return dflt;
        else
            return result;
    
public static com.vladium.emma.report.ReportProperties$ParsedPropertiesparseProperties(com.vladium.util.IProperties properties, java.lang.String type)

        if ($assert.ENABLED) $assert.ASSERT (properties != null, "properties = null");
        
        final ParsedProperties result = new ParsedProperties ();
        {
            result.setOutEncoding (getReportProperty (properties, type, IReportProperties.OUT_ENCODING, false));
        }
        
        // TODO: outDirName is no longer supported
        
        {
            final String outDirName = getReportProperty (properties, type, IReportProperties.OUT_DIR, true);
            final String outFileName = getReportProperty (properties, type, IReportProperties.OUT_FILE, false);
    
            // renormalize the out dir and file combination:
        
            if (outFileName != null)
            {
                final File fullOutFile = Files.newFile (outDirName, outFileName);
                
                final File dir = fullOutFile.getParentFile ();
                if (dir != null) result.setOutDir (dir);
            
                result.setOutFile (new File (fullOutFile.getName ()));
            }
            else if (outDirName != null)
            {
                result.setOutDir (new File (outDirName));
            }
        }

        {
            final String unitsType = getReportProperty (properties, type, IReportProperties.UNITS_TYPE, true, IReportProperties.DEFAULT_UNITS_TYPE);
            result.setUnitsType (IReportProperties.COUNT_UNITS.equals (unitsType) ? IItemAttribute.UNITS_COUNT : IItemAttribute.UNITS_INSTR);
            
            // TODO: invalid setting not checked
        }
        {
            /* view type is no longer a user-overridable property [it is driven by SourceFile attribute presence]

            final String viewType = getReportProperty (properties, type, IReportProperties.VIEW_TYPE, IReportProperties.DEFAULT_VIEW_TYPE);
            result.setViewType (IReportProperties.SRC_VIEW.equals (viewType) ? IReportDataView.HIER_SRC_VIEW : IReportDataView.HIER_CLS_VIEW);
            */
            
            result.setViewType (IReportDataView.HIER_SRC_VIEW);
        } 
        
        {
            final String hideClasses = getReportProperty (properties, type, IReportProperties.HIDE_CLASSES, true, IReportProperties.DEFAULT_HIDE_CLASSES);
            result.setHideClasses (Property.toBoolean (hideClasses));
        
            // TODO: log this
            if (result.getViewType () == IReportDataView.HIER_CLS_VIEW)
                result.setHideClasses (false);
        }
        {
            final String depth = getReportProperty (properties, type, IReportProperties.DEPTH, false, IReportProperties.DEFAULT_DEPTH);
            
            if (IReportProperties.DEPTH_ALL.equals (depth))
                result.setDepth (AllItem.getTypeMetadata ().getTypeID ());
            else if (IReportProperties.DEPTH_PACKAGE.equals (depth))
                result.setDepth (PackageItem.getTypeMetadata ().getTypeID ());
            else if (IReportProperties.DEPTH_SRCFILE.equals (depth))
                result.setDepth (SrcFileItem.getTypeMetadata ().getTypeID ());
            else if (IReportProperties.DEPTH_CLASS.equals (depth))
                result.setDepth (ClassItem.getTypeMetadata ().getTypeID ());
            else if (IReportProperties.DEPTH_METHOD.equals (depth))
                result.setDepth (MethodItem.getTypeMetadata ().getTypeID ());
            else
                // TODO: properly prefixes prop name
                throw new EMMARuntimeException (INVALID_PARAMETER_VALUE, new Object [] {IReportProperties.DEPTH, depth});
        }
        
        if (result.getHideClasses () &&
           (result.getViewType () == IReportDataView.HIER_SRC_VIEW) &&
           (result.getDepth () == IItemMetadata.TYPE_ID_CLASS))
        {
            result.setDepth (IItemMetadata.TYPE_ID_SRCFILE);
        }
        
        final Set /* String */ columnNames = new HashSet ();
        {
            final String columnList = getReportProperty (properties, type, IReportProperties.COLUMNS, false, IReportProperties.DEFAULT_COLUMNS);
            final IntVector _columns = new IntVector ();
            
            final int [] out = new int [1];
            
            for (StringTokenizer tokenizer = new StringTokenizer (columnList, ","); tokenizer.hasMoreTokens (); )
            {
                final String columnName = tokenizer.nextToken ().trim ();
                if (! COLUMNS.get (columnName, out))
                {
                    // TODO: generate the entire enum list in the err msg
                    throw new EMMARuntimeException (INVALID_COLUMN_NAME, new Object [] {columnName});
                }
                
                if (! REMOVE_DUPLICATE_COLUMNS || ! columnNames.contains (columnName))
                {
                    columnNames.add (columnName);
                    _columns.add (out [0]);
                }
            }
            
            result.setColumnOrder (_columns.values ());
        }
        // [assertion: columnNames contains all columns for the report (some
        // may get removed later by individual report generators if some debug info
        // is missing)]
        
        {
            final String sortList = getReportProperty (properties, type, IReportProperties.SORT, false, IReportProperties.DEFAULT_SORT);
            final IntVector _sort = new IntVector ();
            
            final int [] out = new int [1];
            
            for (StringTokenizer tokenizer = new StringTokenizer (sortList, ","); tokenizer.hasMoreTokens (); )
            {
                final String sortSpec = tokenizer.nextToken ().trim ();
                final String columnName;
                final int dir;
                
                switch (sortSpec.charAt (0))
                {
                    case IReportProperties.ASC:
                    {
                        dir = +1;
                        columnName = sortSpec.substring (1);
                    }
                    break;
                    
                    case IReportProperties.DESC:
                    {
                        dir = -1;
                        columnName = sortSpec.substring (1);
                    }
                    break;
                    
                    default:
                    {
                        dir = +1;
                        columnName = sortSpec;
                    }
                    break;
                    
                } // end of switch
                
                // silently ignore columns not in the column list:
                if (columnNames.contains (columnName))
                {
                    COLUMNS.get (columnName, out);
                    
                    _sort.add (out [0]);    // sort attribute ID
                    _sort.add (dir);        // sort direction
                }
                
                result.setSortOrder (_sort.values ());
            }
        }
        {
            final String metricList = getReportProperty (properties, type, IReportProperties.METRICS, true, IReportProperties.DEFAULT_METRICS);
            final IntIntMap _metrics = new IntIntMap ();
            
            final int [] out = new int [1];
            
            // TODO: perhaps should throw on invalid input here
            for (StringTokenizer tokenizer = new StringTokenizer (metricList, ","); tokenizer.hasMoreTokens (); )
            {
                final String metricSpec = tokenizer.nextToken ().trim ();
                final String columnName;
                final double criterion;
                
                final int separator = metricSpec.indexOf (IReportProperties.MSEPARATOR);
                if (separator > 0) // silently ignore invalid entries
                {
                    // silently ignore invalid cutoff values:
                    try
                    {
                        criterion = Double.parseDouble (metricSpec.substring (separator + 1));
                        if ((criterion < 0.0) || (criterion > 101.0)) continue;
                    }
                    catch (NumberFormatException nfe)
                    {
                        nfe.printStackTrace (System.out);
                        continue;
                    }
                    
                    columnName = metricSpec.substring (0, separator);
                    
                    // silently ignore columns not in the column list:
                    if (columnNames.contains (columnName))
                    {
                        COLUMNS.get (columnName, out);
                    
                        _metrics.put (out [0], (int) Math.round (((criterion * IItem.PRECISION) / 100.0)));
                    }
                }
            }
                                        
            result.setMetrics (_metrics);
        }
        
        result.validate ();
        
        return result;