1 64 65 package com.jcorporate.expresso.kernel; 66 67 import java.util.Collections ; 68 import java.util.HashMap ; 69 import java.util.Map ; 70 71 100 101 public class InstallationOptions { 102 103 106 protected Map installValues = new HashMap (); 107 108 111 protected Map nameMetadataMap = new HashMap (); 112 113 114 public InstallationOptions() { 115 116 } 117 118 123 public InstallationMetadata createNewMetadata(String name, Object defaultValue) { 124 InstallationMetadata metadata = new InstallationMetadata(); 125 metadata.setName(name); 126 metadata.setDefaultValue(defaultValue); 127 metadata.setDescription(name); 128 return metadata; 129 } 130 131 137 public void addMetaData(InstallationMetadata metadata) { 138 installValues.put(metadata, null); 139 nameMetadataMap.put(metadata.getName(), metadata); 140 } 141 142 148 public void setInstallOption(String name, Object newValue) { 149 InstallationMetadata metadata = (InstallationMetadata) nameMetadataMap.get(name); 150 if (metadata == null) { 151 throw new IllegalArgumentException ("Invalid Install Option Name: " + name); 152 } 153 154 installValues.put(metadata, newValue); 155 } 156 157 164 public Object getInstallOption(String name) { 165 InstallationMetadata metadata = (InstallationMetadata) nameMetadataMap.get(name); 166 if (metadata == null) { 167 throw new IllegalArgumentException ("Invalid Install Option Name: " + name); 168 } 169 170 Object returnValue = installValues.get(metadata); 171 172 if (returnValue == null) { 173 returnValue = metadata.getDefaultValue(); 174 } 175 176 return returnValue; 177 } 178 179 public Map getAllInstallValues() { 180 return Collections.unmodifiableMap(installValues); 181 } 182 183 public java.util.Set getAllInstallNames() { 184 return nameMetadataMap.keySet(); 185 } 186 187 188 191 public class InstallationMetadata { 192 193 public InstallationMetadata() { 194 195 } 196 197 200 private Object defaultValue; 201 202 205 private String description; 206 207 210 private String type = null; 211 212 215 private String name; 216 217 public Object getDefaultValue() { 218 return defaultValue; 219 } 220 221 public void setDefaultValue(Object newValue) { 222 defaultValue = newValue; 223 224 if (type == null) { 228 type = newValue.getClass().getName(); 229 } 230 } 231 232 public void setDescription(String newValue) { 233 description = newValue; 234 } 235 236 public String getDescription() { 237 return description; 238 } 239 240 public void setType(String newValue) { 241 type = newValue; 242 } 243 244 public String getType() { 245 return type; 246 } 247 248 public void setName(String newValue) { 249 name = newValue; 250 } 251 252 public String getName() { 253 return name; 254 } 255 256 262 public int hashCode() { 263 return name.hashCode(); 264 } 265 } 266 } | Popular Tags |