001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.metrics;
034:
035: import java.lang.reflect.*;
036:
037: public class MeasurementDescriptor {
038: private static final Class constructorSignature[] = {
039: MeasurementDescriptor.class, Metrics.class, String.class };
040:
041: private String shortName;
042: private String longName;
043: private Class classFor;
044: private String initText;
045: private Comparable lowerThreshold;
046: private Comparable upperThreshold;
047: private boolean visible = true;
048: private boolean cached = true;
049:
050: public String getShortName() {
051: return shortName;
052: }
053:
054: public void setShortName(String shortName) {
055: this .shortName = shortName;
056: }
057:
058: public String getLongName() {
059: return longName;
060: }
061:
062: public void setLongName(String longName) {
063: this .longName = longName;
064: }
065:
066: public Class getClassFor() {
067: return classFor;
068: }
069:
070: public void setClassFor(Class classFor) {
071: if (classFor != null) {
072: this .classFor = classFor;
073: } else {
074: throw new IllegalArgumentException("class cannot be null");
075: }
076: }
077:
078: public void getClassForByName(String className)
079: throws ClassNotFoundException {
080: this .classFor = Class.forName(className);
081: }
082:
083: public String getInitText() {
084: return initText;
085: }
086:
087: public void setInitText(String initText) {
088: this .initText = initText;
089: }
090:
091: public Comparable getLowerThreshold() {
092: return lowerThreshold;
093: }
094:
095: public void setLowerThreshold(Comparable lowerThreshold) {
096: this .lowerThreshold = lowerThreshold;
097: }
098:
099: public Comparable getUpperThreshold() {
100: return upperThreshold;
101: }
102:
103: public void setUpperThreshold(Comparable upperThreshold) {
104: this .upperThreshold = upperThreshold;
105: }
106:
107: public boolean isVisible() {
108: return visible;
109: }
110:
111: public void setVisible(boolean visible) {
112: this .visible = visible;
113: }
114:
115: public boolean isCached() {
116: return cached;
117: }
118:
119: public void setCached(boolean cached) {
120: this .cached = cached;
121: }
122:
123: public Measurement createMeasurement()
124: throws InstantiationException, IllegalAccessException,
125: NoSuchMethodException, InvocationTargetException {
126: return createMeasurement(null);
127: }
128:
129: public Measurement createMeasurement(Metrics context)
130: throws InstantiationException, IllegalAccessException,
131: NoSuchMethodException, InvocationTargetException {
132: Measurement result = null;
133:
134: Constructor constructor = getClassFor().getConstructor(
135: constructorSignature);
136: Object params[] = new Object[3];
137: params[0] = this ;
138: params[1] = context;
139: params[2] = getInitText();
140: result = (Measurement) constructor.newInstance(params);
141:
142: return result;
143: }
144:
145: public String getRangeAsString() {
146: StringBuffer result = new StringBuffer();
147:
148: result.append("[");
149: result
150: .append((getLowerThreshold() != null) ? getLowerThreshold()
151: .toString()
152: : "*");
153: result.append(", ");
154: result
155: .append((getUpperThreshold() != null) ? getUpperThreshold()
156: .toString()
157: : "*");
158: result.append("]");
159:
160: return result.toString();
161: }
162: }
|