1 19 package gcc.properties; 20 21 import gcc.util.*; 22 import java.util.*; 23 24 public abstract class PropertyType 25 { 26 protected static boolean _debug; 27 28 static 29 { 30 try 31 { 32 _debug = Boolean.getBoolean("gcc.debug:properties"); 33 } 34 catch (Exception ignore) { 36 _debug = false; 37 } 38 } 39 40 protected Class _componentClass; 41 42 protected String _propertyName; 43 44 protected String _displayName; 45 46 protected String _displayOnlyIfOther; 47 48 protected String _displayOnlyIfValue; 49 50 protected String _description; 51 52 protected String _consoleHelp; 53 54 protected int _sortOrder; 55 56 public PropertyType(Class componentClass, String propertyName) 57 { 58 _componentClass = componentClass; 59 _propertyName = propertyName; 60 } 61 62 public Class getComponentClass() 63 { 64 return _componentClass; 65 } 66 67 public PropertyMap getComponentProperties() 68 { 69 if (_componentClass == SystemProperties.class) 70 { 71 return SystemProperties.getInstance(); 72 } 73 else 74 { 75 return null; } 77 } 78 79 public String getPropertyName() 80 { 81 return _propertyName; 82 } 83 84 public String getDisplayName() 85 { 86 return _displayName; 87 } 88 89 public String getDisplayOnlyIfOther() 90 { 91 return _displayOnlyIfOther; 92 } 93 94 public String getDisplayOnlyIfValue() 95 { 96 return _displayOnlyIfValue; 97 } 98 99 public String getDescription() 100 { 101 return _description; 102 } 103 104 public String getConsoleHelp() 105 { 106 return _consoleHelp; 107 } 108 109 public int getSortOrder() 110 { 111 return _sortOrder; 112 } 113 114 public String getDefaultValueAsString() 115 { 116 return ""; 117 } 118 119 public boolean isList() 120 { 121 return false; 122 } 123 124 public boolean isReadOnly() 125 { 126 return false; 127 } 128 129 public void setDisplayName(String displayName) 130 { 131 _displayName = displayName; 132 } 133 134 public void setDisplayOnlyIf(PropertyType other, String value) 135 { 136 _displayOnlyIfOther = other.getPropertyName(); 137 _displayOnlyIfValue = value; 138 } 139 140 public void setDescription(String description) 141 { 142 _description = description; 143 } 144 145 public void setConsoleHelp(String consoleHelp) 146 { 147 _consoleHelp = consoleHelp; 148 } 149 150 public void setSortOrder(int sortOrder) 151 { 152 _sortOrder = sortOrder; 153 } 154 155 public void badPropertyValue(String instanceName, String value) 156 { 157 badPropertyValue(instanceName, value, (String)null); 158 } 159 160 public void badPropertyValue(String instanceName, String value, Exception ex) 161 { 162 badPropertyValue(instanceName, value, "exception: " + ExceptionUtil.getStackTrace(ex)); 163 } 164 165 public void badPropertyValue(String instanceName, String value, String reason) 166 { 167 175 Thread.dumpStack(); 176 } 177 178 public String expectedNumberInRange(long minimumValue, long maximumValue) 179 { 180 return "expected number in range [" + minimumValue + " .. " + maximumValue + "]"; 182 } 183 184 public String expectedNumberInRange(double minimumValue, double maximumValue) 185 { 186 return "expected number in range [" + minimumValue + " .. " + maximumValue + "]"; 188 } 189 190 public String expectedTrueOrFalse() 191 { 192 return "expected true or false"; 194 } 195 196 public String expectedValueInList(List legalValues) 197 { 198 return "expected value in list " + legalValues; 200 } 201 202 public void logPropertyValue(String instanceName, String value, boolean usingDefaultValue) 203 { 204 if (_propertyName.toLowerCase().endsWith("password")) 205 { 206 value = "******"; 207 } 208 if (_debug) { 210 if (usingDefaultValue) 211 { 212 if (_componentClass == SystemProperties.class) 213 { 214 SystemPropertyLog.getInstance(_propertyName).debugUsingDefaultValue(value); 215 } 216 else 217 { 218 getLog(instanceName).debugUsingDefaultValue(value); 219 } 220 } 221 else 222 { 223 if (_componentClass == SystemProperties.class) 224 { 225 SystemPropertyLog.getInstance(_propertyName).debugUsingValue(value); 226 } 227 else 228 { 229 getLog(instanceName).debugUsingValue(value); 230 } 231 } 232 } 233 } 234 235 public String getContext(String instanceName) 236 { 237 242 return "TODO: PropertyType.getContext()"; 243 } 244 245 public PropertyLog getLog(String instanceName) 246 { 247 return PropertyLog.getInstance(_propertyName + ", " + getContext(instanceName)); 248 } 249 } 250 | Popular Tags |