KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > metrics > MeasurementDescriptor


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.metrics;
34
35 import java.lang.reflect.*;
36
37 public class MeasurementDescriptor {
38     private static final Class JavaDoc constructorSignature[] = {MeasurementDescriptor.class, Metrics.class, String JavaDoc.class};
39
40     private String JavaDoc shortName;
41     private String JavaDoc longName;
42     private Class JavaDoc classFor;
43     private String JavaDoc initText;
44     private Comparable JavaDoc lowerThreshold;
45     private Comparable JavaDoc upperThreshold;
46     private boolean visible = true;
47     private boolean cached = true;
48
49     public String JavaDoc getShortName() {
50         return shortName;
51     }
52
53     public void setShortName(String JavaDoc shortName) {
54         this.shortName = shortName;
55     }
56     
57     public String JavaDoc getLongName() {
58         return longName;
59     }
60
61     public void setLongName(String JavaDoc longName) {
62         this.longName = longName;
63     }
64     
65     public Class JavaDoc getClassFor() {
66         return classFor;
67     }
68
69     public void setClassFor(Class JavaDoc classFor) {
70         if (classFor != null) {
71             this.classFor = classFor;
72         } else {
73             throw new IllegalArgumentException JavaDoc("class cannot be null");
74         }
75     }
76
77     public void getClassForByName(String JavaDoc className) throws ClassNotFoundException JavaDoc {
78         this.classFor = Class.forName(className);
79     }
80
81     public String JavaDoc getInitText() {
82         return initText;
83     }
84
85     public void setInitText(String JavaDoc initText) {
86         this.initText = initText;
87     }
88
89     public Comparable JavaDoc getLowerThreshold() {
90         return lowerThreshold;
91     }
92
93     public void setLowerThreshold(Comparable JavaDoc lowerThreshold) {
94         this.lowerThreshold = lowerThreshold;
95     }
96
97     public Comparable JavaDoc getUpperThreshold() {
98         return upperThreshold;
99     }
100
101     public void setUpperThreshold(Comparable JavaDoc upperThreshold) {
102         this.upperThreshold = upperThreshold;
103     }
104
105     public boolean isVisible() {
106         return visible;
107     }
108
109     public void setVisible(boolean visible) {
110         this.visible = visible;
111     }
112     
113     public boolean isCached() {
114         return cached;
115     }
116
117     public void setCached(boolean cached) {
118         this.cached = cached;
119     }
120
121     public Measurement createMeasurement() throws InstantiationException JavaDoc, IllegalAccessException JavaDoc, NoSuchMethodException JavaDoc, InvocationTargetException {
122         return createMeasurement(null);
123     }
124     
125     public Measurement createMeasurement(Metrics context) throws InstantiationException JavaDoc, IllegalAccessException JavaDoc, NoSuchMethodException JavaDoc, InvocationTargetException {
126         Measurement result = null;
127
128         Constructor constructor = getClassFor().getConstructor(constructorSignature);
129         Object JavaDoc params[] = new Object JavaDoc[3];
130         params[0] = this;
131         params[1] = context;
132         params[2] = getInitText();
133         result = (Measurement) constructor.newInstance(params);
134
135         return result;
136     }
137
138     public String JavaDoc getRangeAsString() {
139         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
140
141         result.append("[");
142         result.append((getLowerThreshold() != null) ? getLowerThreshold().toString() : "*");
143         result.append(", ");
144         result.append((getUpperThreshold() != null) ? getUpperThreshold().toString() : "*");
145         result.append("]");
146
147         return result.toString();
148     }
149 }
150
Popular Tags