1 24 package org.objectweb.jalisto.se.impl.client; 25 26 import org.objectweb.jalisto.se.api.JalistoProperties; 27 import org.objectweb.jalisto.se.api.internal.Constants; 28 import org.objectweb.jalisto.se.exception.JalistoException; 29 30 import java.io.File ; 31 import java.io.FileInputStream ; 32 import java.io.InputStream ; 33 import java.net.URL ; 34 import java.util.*; 35 36 public class JalistoPropertiesClientImpl implements JalistoProperties { 37 38 private static final String NAME = "jalisto"; 39 private static final String SERVER_PROPERTIES_PATH = "jalisto.properties"; 40 private static final String CACHE_IMPLEMENTATION = "org.objectweb.jalisto.se.impl.cache.GenericCache"; 41 private static final String OBJECT_CACHE_SIZE = "500"; 42 private static final String CACHE_CLEAR_POURCENT = "20"; 43 private static final String ALLOWS_SPECIAL_FUNCTIONNALITIES = "no"; 44 public static final String COMMUNICATION_FACTORY_CLASS = 45 "org.objectweb.jalisto.se.impl.remote.socket.CommunicationFactorySocketImpl"; 46 public static final String HOST = "localhost"; 47 public static final String PORT = "7777"; 48 private static final String QUERY_MANAGER_CLASS = Constants.QUERY_MANAGER; 49 private static final String TRACE = ""; 50 51 52 public static final String SERVER_PROPERTIES_PATH_KEY = "serverPropertiesFile"; 53 public static final String HOST_KEY = "host"; 54 public static final String PORT_KEY = "port"; 55 56 57 private File parent; 58 private Properties prop; 59 private String propertiesPath; 60 private JalistoProperties remoteProperties; 61 62 63 static final long serialVersionUID = -7589477064771161459L; 64 65 public JalistoPropertiesClientImpl(String databasePropertiesFilePath) { 66 this.propertiesPath = databasePropertiesFilePath; 67 68 try { 69 prop = new Properties(); 70 prop.put(NAME_KEY, NAME); 71 prop.put(SERVER_PROPERTIES_PATH_KEY, SERVER_PROPERTIES_PATH); 72 prop.put(CACHE_IMPLEMENTATION_KEY, CACHE_IMPLEMENTATION); 73 prop.put(OBJECT_CACHE_SIZE_KEY, OBJECT_CACHE_SIZE); 74 prop.put(CACHE_CLEAR_POURCENT_KEY, CACHE_CLEAR_POURCENT); 75 prop.put(ALLOWS_SPECIAL_FUNCTIONNALITIES_KEY, ALLOWS_SPECIAL_FUNCTIONNALITIES); 76 prop.put(COMMUNICATION_FACTORY_CLASS_KEY, COMMUNICATION_FACTORY_CLASS); 77 prop.put(HOST_KEY, HOST); 78 prop.put(PORT_KEY, PORT); 79 prop.put(QUERY_MANAGER_CLASS_KEY, QUERY_MANAGER_CLASS); 80 prop.put(TRACE_KEY, TRACE); 81 82 boolean isLoaded = false; 83 if (!databasePropertiesFilePath.equalsIgnoreCase("")) { 84 File propfile = new File (databasePropertiesFilePath); 85 if (propfile.exists() && (!propfile.isDirectory())) { 86 parent = propfile.getAbsoluteFile().getParentFile(); 87 FileInputStream fis = new FileInputStream (propfile); 88 prop.load(fis); 89 isLoaded = true; 90 } 91 if (!isLoaded) { 92 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 93 InputStream testIS = classLoader.getResourceAsStream(databasePropertiesFilePath); 94 URL url = classLoader.getResource(databasePropertiesFilePath); 95 propfile = new File (url.getFile()); 96 parent = propfile.getAbsoluteFile().getParentFile(); 97 prop.load(testIS); 98 isLoaded = true; 99 } 100 } else { 101 parent = new File (System.getProperty("user.dir")); 102 System.out.println("Use default properties values with execution path : " + parent.getAbsolutePath()); 103 isLoaded = true; 104 } 105 106 if (!isLoaded) { 107 parent = new File (System.getProperty("user.dir")); 108 System.out.println("Exception during reading of Jalisto properties use only default values"); 109 System.out.println("Work in system user.dir directory : " + String.valueOf(parent)); 110 } 111 112 truncateProperties(); 113 } catch (Exception e) { 114 throw new JalistoException( 115 "Error during initialisation of JalistoProperties, using " + databasePropertiesFilePath, e); 116 } 117 } 118 119 public void setRemoteProperties(JalistoProperties remoteProperties) { 120 this.remoteProperties = remoteProperties; 121 } 122 123 public String getName() { 124 return getProperty(NAME_KEY); 125 } 126 127 public String getServerPropertiesPath() { 128 return getProperty(SERVER_PROPERTIES_PATH_KEY); 129 } 130 131 public int getObjectCacheSize() { 132 return Integer.parseInt(getProperty(OBJECT_CACHE_SIZE_KEY)); 133 } 134 135 public double getCacheClearPourcent() { 136 return Double.parseDouble("0." + getProperty(CACHE_CLEAR_POURCENT_KEY)); 137 } 138 139 public String getCommunicationFactoryClassName() { 140 return getProperty(COMMUNICATION_FACTORY_CLASS_KEY); 141 } 142 143 public String getHost() { 144 return getProperty(HOST_KEY); 145 } 146 147 public int getPort() { 148 return Integer.parseInt(getProperty(PORT_KEY)); 149 } 150 151 public Collection getKeys() { 152 return prop.keySet(); 153 } 154 155 public String getProperty(String key) { 156 return prop.getProperty(key); 157 } 158 159 public void setProperty(String key, String property) { 160 prop.setProperty(key, property); 161 } 162 163 public Collection getTraceModuleNames() { 164 return getStrings(TRACE_KEY, ","); 165 } 166 167 public boolean isTraceEnable() { 168 String modules = getProperty(TRACE_KEY); 169 return ((modules != null) && (!modules.equals(""))); 170 } 171 172 private Collection getStrings(Object key, String separator) { 173 String value = prop.getProperty((String ) key); 174 List result = new ArrayList(); 175 if (value != null) { 176 StringTokenizer tokenizer = new StringTokenizer(value, separator); 177 while (tokenizer.hasMoreTokens()) { 178 result.add(tokenizer.nextToken().trim()); 179 } 180 } 181 return result; 182 } 183 184 public String toString() { 185 StringBuffer sb = new StringBuffer (); 186 sb.append("JalistoClientProperties["); 187 Iterator keys = prop.keySet().iterator(); 188 while (keys.hasNext()) { 189 String key = (String ) keys.next(); 190 sb.append(key).append("=").append(prop.getProperty(key)); 191 if (keys.hasNext()) { 192 sb.append(","); 193 } 194 } 195 sb.append("]"); 196 return sb.toString(); 197 } 198 199 public JalistoProperties getClone() { 200 return new JalistoPropertiesClientImpl(propertiesPath); 201 } 202 203 private void truncateProperties() { 204 Iterator keys = prop.keySet().iterator(); 205 while (keys.hasNext()) { 206 String key = (String ) keys.next(); 207 String value = prop.getProperty(key); 208 while (value.endsWith(" ") || value.endsWith("\t")) { 209 value = value.substring(0, value.length() - 1); 210 } 211 prop.setProperty(key, value); 212 } 213 } 214 215 public String getPropertiesPath() { 216 return propertiesPath; 217 } 218 219 222 223 public void checkProperty(JalistoProperties oldProps, String property) { 224 throw new UnsupportedOperationException (); 225 } 226 227 public void compareProperties(JalistoProperties oldProps) { 228 throw new UnsupportedOperationException (); 229 } 230 231 public int getAdditionalSpace() { 232 return remoteProperties.getAdditionalSpace(); 233 } 234 235 public short getClassPageSize() { 236 return remoteProperties.getClassPageSize(); 237 } 238 239 public String getDbFileFullName() { 240 return remoteProperties.getDbFileFullName(); 241 } 242 243 public String getImplementation() { 244 return remoteProperties.getImplementation(); 245 } 246 247 public int getInitialSize() { 248 return remoteProperties.getInitialSize(); 249 } 250 251 public int getInstanceDbFileNumber() { 252 return remoteProperties.getInstanceDbFileNumber(); 253 } 254 255 public String getInstanceDbFilePathAt(int index) { 256 return remoteProperties.getInstanceDbFilePathAt(index); 257 } 258 259 public short getInstancePageSize() { 260 return remoteProperties.getInstancePageSize(); 261 } 262 263 public int getKeyLength() { 264 return remoteProperties.getKeyLength(); 265 } 266 267 public String getLogFileName() { 268 return remoteProperties.getLogFileName(); 269 } 270 271 public int getMBeanJmxPort() { 272 return remoteProperties.getMBeanJmxPort(); 273 } 274 275 public String getOidDbFilePath() { 276 return remoteProperties.getOidDbFilePath(); 277 } 278 279 public int getOidPageSize() { 280 return remoteProperties.getOidPageSize(); 281 } 282 283 public int getOidTableSize() { 284 return remoteProperties.getOidTableSize(); 285 } 286 287 public int getPageCacheSize() { 288 return remoteProperties.getPageCacheSize(); 289 } 290 291 public String [] getPathes() { 292 return remoteProperties.getPathes(); 293 } 294 295 public String getSystemDbFilePath() { 296 return remoteProperties.getSystemDbFilePath(); 297 } 298 299 public short getSystemPageSize() { 300 return remoteProperties.getSystemPageSize(); 301 } 302 303 public boolean isCleanLog() { 304 return remoteProperties.isCleanLog(); 305 } 306 307 public boolean allowsSpecialFunctionnalities() { 308 return getProperty(ALLOWS_SPECIAL_FUNCTIONNALITIES_KEY).equalsIgnoreCase("yes"); 309 } 310 311 public boolean isKeepingInMemory() { 312 return remoteProperties.isKeepingInMemory(); 313 } 314 315 public boolean isMonoImplementation() { 316 return remoteProperties.isMonoImplementation(); 317 } 318 319 public boolean isMultiImplementation() { 320 return remoteProperties.isMultiImplementation(); 321 } 322 323 public boolean isReadOnlyImplementation() { 324 return remoteProperties.isReadOnlyImplementation(); 325 } 326 327 public String getInternalFactoryClass() { 328 return remoteProperties.getInternalFactoryClass(); 329 } 330 } 331 | Popular Tags |