1 18 package org.apache.geronimo.interop.properties; 19 20 import java.util.List ; 21 22 import org.apache.geronimo.interop.util.ExceptionUtil; 23 24 public abstract class PropertyType { 25 protected static boolean debug; 26 27 static { 28 try { 29 debug = Boolean.getBoolean("org.apache.geronimo.interop.debug:properties"); 30 } catch (Exception ignore) { 32 debug = false; 33 } 34 } 35 36 private Class componentClass; 37 private String propertyName; 38 private String displayName; 39 private String displayOnlyIfOther; 40 private String displayOnlyIfValue; 41 private String description; 42 private String consoleHelp; 43 private int sortOrder; 44 45 public PropertyType(Class componentClass, String propertyName) { 46 this.componentClass = componentClass; 47 this.propertyName = propertyName; 48 } 49 50 public Class getComponentClass() { 51 return componentClass; 52 } 53 54 public PropertyMap getComponentProperties() { 55 if (componentClass == SystemProperties.class) { 56 return SystemProperties.getInstance(); 57 } else { 58 return null; } 60 } 61 62 public String getPropertyName() { 63 return propertyName; 64 } 65 66 public String getDisplayName() { 67 return displayName; 68 } 69 70 public String getDisplayOnlyIfOther() { 71 return displayOnlyIfOther; 72 } 73 74 public String getDisplayOnlyIfValue() { 75 return displayOnlyIfValue; 76 } 77 78 public String getDescription() { 79 return description; 80 } 81 82 public String getConsoleHelp() { 83 return consoleHelp; 84 } 85 86 public int getSortOrder() { 87 return sortOrder; 88 } 89 90 public String getDefaultValueAsString() { 91 return ""; 92 } 93 94 public boolean isList() { 95 return false; 96 } 97 98 public boolean isReadOnly() { 99 return false; 100 } 101 102 public void setDisplayName(String displayName) { 103 this.displayName = displayName; 104 } 105 106 public void setDisplayOnlyIf(PropertyType other, String value) { 107 displayOnlyIfOther = other.getPropertyName(); 108 displayOnlyIfValue = value; 109 } 110 111 public void setDescription(String description) { 112 this.description = description; 113 } 114 115 public void setConsoleHelp(String consoleHelp) { 116 this.consoleHelp = consoleHelp; 117 } 118 119 public void setSortOrder(int sortOrder) { 120 this.sortOrder = sortOrder; 121 } 122 123 public void badPropertyValue(String instanceName, String value) { 124 badPropertyValue(instanceName, value, (String ) null); 125 } 126 127 public void badPropertyValue(String instanceName, String value, Exception ex) { 128 badPropertyValue(instanceName, value, "exception: " + ExceptionUtil.getStackTrace(ex)); 129 } 130 131 public void badPropertyValue(String instanceName, String value, String reason) { 132 140 Thread.dumpStack(); 141 } 142 143 public String expectedNumberInRange(long minimumValue, long maximumValue) { 144 return "expected number in range [" + minimumValue + " .. " + maximumValue + "]"; 146 } 147 148 public String expectedNumberInRange(double minimumValue, double maximumValue) { 149 return "expected number in range [" + minimumValue + " .. " + maximumValue + "]"; 151 } 152 153 public String expectedTrueOrFalse() { 154 return "expected true or false"; 156 } 157 158 public String expectedValueInList(List legalValues) { 159 return "expected value in list " + legalValues; 161 } 162 163 public void logPropertyValue(String instanceName, String value, boolean usingDefaultValue) { 164 if (propertyName.toLowerCase().endsWith("password")) { 165 value = "******"; 166 } 167 if (debug) { 169 if (usingDefaultValue) { 170 if (componentClass == SystemProperties.class) { 171 SystemPropertyLog.getInstance(propertyName).debugUsingDefaultValue(value); 172 } else { 173 getLog(instanceName).debugUsingDefaultValue(value); 174 } 175 } else { 176 if (componentClass == SystemProperties.class) { 177 SystemPropertyLog.getInstance(propertyName).debugUsingValue(value); 178 } else { 179 getLog(instanceName).debugUsingValue(value); 180 } 181 } 182 } 183 } 184 185 public String getContext(String instanceName) { 186 191 return "TODO: PropertyType.getContext()"; 192 } 193 194 public PropertyLog getLog(String instanceName) { 195 return PropertyLog.getInstance(propertyName + ", " + getContext(instanceName)); 196 } 197 } 198 | Popular Tags |