1 32 33 package com.jeantessier.metrics; 34 35 import java.lang.reflect.*; 36 37 public class MeasurementDescriptor { 38 private static final Class constructorSignature[] = {MeasurementDescriptor.class, Metrics.class, String .class}; 39 40 private String shortName; 41 private String longName; 42 private Class classFor; 43 private String initText; 44 private Comparable lowerThreshold; 45 private Comparable upperThreshold; 46 private boolean visible = true; 47 private boolean cached = true; 48 49 public String getShortName() { 50 return shortName; 51 } 52 53 public void setShortName(String shortName) { 54 this.shortName = shortName; 55 } 56 57 public String getLongName() { 58 return longName; 59 } 60 61 public void setLongName(String longName) { 62 this.longName = longName; 63 } 64 65 public Class getClassFor() { 66 return classFor; 67 } 68 69 public void setClassFor(Class classFor) { 70 if (classFor != null) { 71 this.classFor = classFor; 72 } else { 73 throw new IllegalArgumentException ("class cannot be null"); 74 } 75 } 76 77 public void getClassForByName(String className) throws ClassNotFoundException { 78 this.classFor = Class.forName(className); 79 } 80 81 public String getInitText() { 82 return initText; 83 } 84 85 public void setInitText(String initText) { 86 this.initText = initText; 87 } 88 89 public Comparable getLowerThreshold() { 90 return lowerThreshold; 91 } 92 93 public void setLowerThreshold(Comparable lowerThreshold) { 94 this.lowerThreshold = lowerThreshold; 95 } 96 97 public Comparable getUpperThreshold() { 98 return upperThreshold; 99 } 100 101 public void setUpperThreshold(Comparable 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 , IllegalAccessException , NoSuchMethodException , InvocationTargetException { 122 return createMeasurement(null); 123 } 124 125 public Measurement createMeasurement(Metrics context) throws InstantiationException , IllegalAccessException , NoSuchMethodException , InvocationTargetException { 126 Measurement result = null; 127 128 Constructor constructor = getClassFor().getConstructor(constructorSignature); 129 Object params[] = new Object [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 getRangeAsString() { 139 StringBuffer result = new StringBuffer (); 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 |