Clover coverage report - Ledge Components - SNAPSHOT
Coverage timestamp: Fri Nov 17 2006 05:13:20 CET
file stats: LOC: 341   Methods: 18
NCLOC: 163   Classes: 3
 
 Source file Conditionals Statements Methods TOTAL
DataSource.java 0% 0% 0% 0%
coverage
 1    //
 2    // Copyright (c) 2003-2005, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
 3    // All rights reserved.
 4    //
 5    // Redistribution and use in source and binary forms, with or without modification,
 6    // are permitted provided that the following conditions are met:
 7    //
 8    // * Redistributions of source code must retain the above copyright notice,
 9    // this list of conditions and the following disclaimer.
 10    // * Redistributions in binary form must reproduce the above copyright notice,
 11    // this list of conditions and the following disclaimer in the documentation
 12    // and/or other materials provided with the distribution.
 13    // * Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
 14    // nor the names of its contributors may be used to endorse or promote products
 15    // derived from this software without specific prior written permission.
 16    //
 17    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 18    // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 19    // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 20    // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 21    // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 22    // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 23    // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 24    // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 25    // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 26    // POSSIBILITY OF SUCH DAMAGE.
 27    //
 28    package org.objectledge.statistics;
 29   
 30    import java.math.BigDecimal;
 31   
 32    import org.jcontainer.dna.Configuration;
 33    import org.jcontainer.dna.ConfigurationException;
 34   
 35    /**
 36    * Describes a data source used for statistics computation, modeled after Munin tool.
 37    *
 38    * @author <a href="mailto:rafal@caltha.pl">Rafal Krzewski</a>
 39    * @version $Id: DataSource.java,v 1.7 2005/05/16 09:51:55 rafal Exp $
 40    */
 41    public class DataSource
 42    {
 43    private final String name;
 44   
 45    private final String label;
 46   
 47    private final String cdef;
 48   
 49    private final Type type;
 50   
 51    private final Graph graph;
 52   
 53    private final Number min;
 54   
 55    private final Number max;
 56   
 57    private final Number minWarning;
 58   
 59    private final Number maxWarning;
 60   
 61    private final Number minCritical;
 62   
 63    private final Number maxCritical;
 64   
 65    /**
 66    * Creates new ValueDescription instance.
 67    *
 68    * @param name the name of the data source.
 69    * @param label the data source label.
 70    * @param cdef the data transformation RPN expression.
 71    * @param type the data source type.
 72    * @param graph the graph type for the data source.
 73    * @param min minimal cutoff value (lesser values will be discarded), null to disable.
 74    * @param max maximal cutoff value (greater values will be discarded), null to disable.
 75    * @param minWarning the minimal warning value, null to disable.
 76    * @param maxWarning the maximal warning value, null to disable.
 77    * @param minCritical the minimal critical warning value, null to disable.
 78    * @param maxCritical the maximal critical warning value, null to disable.
 79    */
 80  0 public DataSource(String name, String label, String cdef, Type type, Graph graph,
 81    Number min, Number max, Number minWarning, Number maxWarning,
 82    Number minCritical, Number maxCritical)
 83    {
 84  0 this.name = name;
 85  0 this.label = label;
 86  0 this.cdef = cdef;
 87  0 this.type = type;
 88  0 this.graph = graph;
 89  0 this.min = min;
 90  0 this.max = max;
 91  0 this.minWarning = minWarning;
 92  0 this.maxWarning = maxWarning;
 93  0 this.minCritical = minCritical;
 94  0 this.maxCritical = maxCritical;
 95    }
 96   
 97    /**
 98    * Creates new DataSource instance.
 99    * @param name the name of the data source.
 100    * @param label the data source label.
 101    * @param type the data source type.
 102    * @param graph the graph type for the data source.
 103    */
 104  0 public DataSource(String name, String label, Type type, Graph graph)
 105    {
 106  0 this(name, label, null, type, graph, null, null, null, null, null, null);
 107    }
 108   
 109    /**
 110    * Creates new DataSource instance.
 111    *
 112    * @param config DNA configuration object.
 113    * @throws ConfigurationException if the configuraiton object contains invalid data.
 114    */
 115  0 public DataSource(Configuration config)
 116    throws ConfigurationException
 117    {
 118  0 this(
 119    config.getChild("name").getValue(),
 120    config.getChild("label").getValue(null),
 121    config.getChild("cdef").getValue(null),
 122    getType(config.getChild("type").getValue(null)),
 123    getGraph(config.getChild("graph").getValue(null)),
 124    getNumber(config.getChild("min").getValue(null)),
 125    getNumber(config.getChild("max").getValue(null)),
 126    getNumber(config.getChild("minWarning").getValue(null)),
 127    getNumber(config.getChild("maxWarning").getValue(null)),
 128    getNumber(config.getChild("minCritical").getValue(null)),
 129    getNumber(config.getChild("maxCritical").getValue(null))
 130    );
 131    }
 132   
 133    /**
 134    * Creates new DataSource instance.
 135    *
 136    * @param base base data source configuraiton.
 137    * @param override overriding data source configuration.
 138    */
 139  0 public DataSource(DataSource base, DataSource override)
 140    {
 141  0 this(
 142    base.getName(),
 143  0 override.getLabel() != null ? override.getLabel() : base.getLabel(),
 144  0 override.getCdef() != null ? override.getCdef() : base.getCdef(),
 145  0 override.getType() != null ? override.getType() : base.getType(),
 146  0 override.getGraph() != null ? override.getGraph() : base.getGraph(),
 147  0 override.getMin() != null ? override.getMin() : base.getMin(),
 148  0 override.getMax() != null ? override.getMax() : base.getMax(),
 149  0 override.getMinWarning() != null ? override.getMinWarning() : base.getMinWarning(),
 150  0 override.getMaxWarning() != null ? override.getMaxWarning() : base.getMaxWarning(),
 151  0 override.getMinCritical() != null ? override.getMinCritical() : base.getMinCritical(),
 152  0 override.getMaxCritical() != null ? override.getMaxCritical() : base.getMaxCritical()
 153    );
 154    }
 155   
 156    /**
 157    * Returns the name.
 158    *
 159    * @return the name.
 160    */
 161  0 public String getName()
 162    {
 163  0 return name;
 164    }
 165   
 166    /**
 167    * Returns the label.
 168    *
 169    * @return the label.
 170    */
 171  0 public String getLabel()
 172    {
 173  0 return label;
 174    }
 175   
 176    /**
 177    * Returns the cdef.
 178    *
 179    * @return the cdef.
 180    */
 181  0 public String getCdef()
 182    {
 183  0 return cdef;
 184    }
 185   
 186    /**
 187    * Returns the type.
 188    *
 189    * @return the type.
 190    */
 191  0 public Type getType()
 192    {
 193  0 return type;
 194    }
 195   
 196    /**
 197    * Returns the graph.
 198    *
 199    * @return the graph.
 200    */
 201  0 public Graph getGraph()
 202    {
 203  0 return graph;
 204    }
 205   
 206    /**
 207    * Returns the min.
 208    *
 209    * @return the min.
 210    */
 211  0 public Number getMin()
 212    {
 213  0 return min;
 214    }
 215   
 216    /**
 217    * Returns the max.
 218    *
 219    * @return the max.
 220    */
 221  0 public Number getMax()
 222    {
 223  0 return max;
 224    }
 225   
 226    /**
 227    * Returns the minWarning.
 228    *
 229    * @return the minWarning.
 230    */
 231  0 public Number getMinWarning()
 232    {
 233  0 return minWarning;
 234    }
 235   
 236    /**
 237    * Returns the maxWarning.
 238    *
 239    * @return the maxWarning.
 240    */
 241  0 public Number getMaxWarning()
 242    {
 243  0 return maxWarning;
 244    }
 245   
 246    /**
 247    * Returns the minCritical.
 248    *
 249    * @return the minCritical.
 250    */
 251  0 public Number getMinCritical()
 252    {
 253  0 return minCritical;
 254    }
 255   
 256    /**
 257    * Returns the maxCritical.
 258    *
 259    * @return the maxCritical.
 260    */
 261  0 public Number getMaxCritical()
 262    {
 263  0 return maxCritical;
 264    }
 265   
 266  0 private static Type getType(String type)
 267    {
 268  0 if(type == null)
 269    {
 270  0 return null;
 271    }
 272    else
 273    {
 274  0 return Type.valueOf(type);
 275    }
 276    }
 277   
 278  0 private static Graph getGraph(String graph)
 279    {
 280  0 if(graph == null)
 281    {
 282  0 return null;
 283    }
 284    else
 285    {
 286  0 return Graph.valueOf(graph);
 287    }
 288    }
 289   
 290  0 private static Number getNumber(String number)
 291    {
 292  0 if(number == null)
 293    {
 294  0 return null;
 295    }
 296    else
 297    {
 298  0 return new BigDecimal(number);
 299    }
 300    }
 301   
 302    /**
 303    * Types of data sources modeled after RRDTool.
 304    */
 305    public enum Type
 306    {
 307    /** A nondecreasing conter value, suitable for computing rate over time. */
 308    COUNTER,
 309   
 310    /** A a floating value, suitable for computing average over time. */
 311    GAUGE,
 312   
 313    /** Like COUNTER, but value is reset to 0 after each read. */
 314    ABSOLUTE,
 315   
 316    /** Like COUNTER, but may increase and decrease - thus no wraparound protection
 317    * is available.*/
 318    DERIVE
 319    }
 320   
 321    /**
 322    * Graph types modeled after RRDTool.
 323    */
 324    public enum Graph
 325    {
 326    /** Hidden graph. */
 327    HIDDEN,
 328   
 329    /** Line graph 1. */
 330    LINE1,
 331   
 332    /** Line graph 2. */
 333    LINE2,
 334   
 335    /** Line graph 3. */
 336    LINE3,
 337   
 338    /** Area graph. */
 339    AREA
 340    }
 341    }