00001 package SctData;
00002
00003 import Sct.*;
00004 import java.util.*;
00005 import java.io.InputStream;
00006 import java.lang.reflect.*;
00007
00008
00032 public abstract class ConfigurationVariable implements Streamable {
00033
00034 ConfigurationVariable(String variableName, String description) {
00035 this.repVal = ConfigurationVariableMap.getRep(getClass().getName());
00036 this.variableName = variableName;
00037 this.description = description;
00038 }
00039
00040 public boolean equals(Object o) {
00041 if (o instanceof ConfigurationVariable) {
00042 return repVal == ((ConfigurationVariable)o).repVal;
00043 }
00044 return false;
00045 }
00046
00047 public String getVariableName() {
00048 return variableName;
00049 }
00050
00051 public String getStrategyDescription() {
00052 return description;
00053 }
00054
00055 public String getClassName() {
00056 return "SctData.ConfigurationVariable";
00057 }
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 public static ConfigurationVariable read(IStream in, ObjectManager o) throws java.io.IOException {
00092 short rep = in.readShort("ScanVariable");
00093 try {
00094 return ConfigurationVariableMap.get(rep);
00095 } catch (ClassNotFoundException e) {
00096 java.io.IOException ioe = new java.io.IOException();
00097 ioe.initCause(e);
00098 throw ioe;
00099 }
00100 }
00101
00102 public void write(OStream s, ObjectManager o) throws java.io.IOException {
00103 s.writeShort("ScanVariable", repVal, false);
00104 }
00105
00106 private String variableName;
00107 private String description;
00108 protected short repVal;
00109
00110
00111 private static class ConfigurationVariableMap {
00112
00113 static ConfigurationVariable get(short rep) throws java.lang.ClassNotFoundException {
00114 String className = (String)map.hashMap1.get(new Short(rep));
00115 if (className == null)
00116 return new DefaultVariable(rep);
00117 try {
00118 Class cfClass = ConfigurationVariableMap.class.getClassLoader().loadClass(className);
00119 return (ConfigurationVariable)cfClass.newInstance();
00120 } catch (InstantiationException e) {
00121 return new DefaultVariable(rep);
00122 } catch (IllegalAccessException e) {
00123 return new DefaultVariable(rep);
00124 } catch (ClassNotFoundException e) {
00125 e.printStackTrace();
00126 return new DefaultVariable(rep);
00127 } catch (Exception e) {
00128 e.printStackTrace();
00129 return new DefaultVariable(rep);
00130 }
00131 }
00132
00133 static short getRep(String className) throws MissingResourceException {
00134 Short s = (Short)map.hashMap2.get(className);
00135 if (s==null) return 0;
00136 return s.shortValue();
00137 }
00138
00142 ConfigurationVariableMap() {
00143 try {
00144 InputStream is = ConfigurationVariableMap.class.getClassLoader().getResourceAsStream("ConfigurationVariables.properties");
00145 if (is == null) throw new java.io.FileNotFoundException("ConfigurationVariableMap is uninitialized as properties file can't be found");
00146
00147 Properties p = new Properties();
00148 p.load(is);
00149
00150
00151 Iterator it = p.entrySet().iterator();
00152 while (it.hasNext()) {
00153 Map.Entry entry = (Map.Entry)it.next();
00154 Field f = Scans.class.getField((String)entry.getKey());
00155 add((Short)f.get(null), (String)entry.getValue());
00156 }
00157 } catch (Exception e) {
00158 e.printStackTrace();
00159 System.err.println("Error setting up ConfigurationVariableMap. Likely problems with streaming");
00160 }
00161 }
00162
00163 private void add(Short rep, String var) {
00164 if (!hashMap1.containsKey(rep)) {
00165 hashMap1.put(rep, var);
00166 hashMap2.put(var, rep);
00167 }
00168 }
00169
00170
00171 private static ConfigurationVariableMap map = new ConfigurationVariableMap();
00172 private HashMap hashMap1 = new HashMap();
00173 private HashMap hashMap2 = new HashMap();
00174 }
00175
00176
00177 }