1 2 12 package com.versant.core.common.config; 13 14 import com.versant.core.jdo.VersantPersistenceManager; 15 import com.versant.core.metadata.MDStatics; 16 import com.versant.core.metadata.parser.JdoExtension; 17 import com.versant.core.metadata.parser.JdoRoot; 18 import com.versant.core.util.StringListParser; 19 20 import java.io.File ; 21 import java.io.FileInputStream ; 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.util.*; 25 26 import com.versant.core.common.BindingSupportImpl; 27 import com.versant.core.common.Utils; 28 29 33 public class ConfigParser { 34 35 public static final String VERSANT_JDO_META_DATA = "versant.jdoMetaData"; 36 37 public static final String META_DATA_PRE_PROCESSOR = "versant.metadata.preprocessor"; 38 39 public static final String PROJECT_DESCRIPTION = "versant.workbench.projectDescription"; 40 public static final String PROPERTIES_FILE_MODE = "versant.workbench.propertiesFile"; 41 public static final String PROPERTIES_SPLIT_FILE = "versant.workbench.splitPropertiesFiles"; 42 public static final String SERVER = "versant.server"; 43 public static final String REMOTE_ACCESS = "versant.remoteAccess"; 44 public static final String ALLOW_REMOTE_PMS = "versant.remotePMs"; 45 public static final String RMI_REGISTRY_PORT = "versant.rmiRegistryPort"; 46 public static final String SERVER_PORT = "versant.serverPort"; 47 public static final String RMI_CLIENT_SF = "versant.rmiClientSocketFactory"; 48 public static final String RMI_CSF_IS_SSF = "versant.rmiClientSocketFactoryIsServerSF"; 49 public static final String RMI_SERVER_SF = "versant.rmiServerSocketFactory"; 50 public static final String ALLOW_PM_CLOSE_WITH_OPEN_TX = "versant.allowPmCloseWithOpenTx"; 51 public static final String PRECOMPILE_NAMED_QUERIES = "versant.precompileNamedQueries"; 52 public static final String CHECK_MODEL_CONSISTENCY_ON_COMMIT = "versant.checkModelConsistencyOnCommit"; 53 public static final String INTERCEPT_DFG_FIELD_ACCESS = "versant.interceptDfgFieldAccess"; 54 public static final String PM_CACHE_REF_TYPE = "versant.pmCacheRefType"; 55 56 public static final String PMF_CLASS = "javax.jdo.PersistenceManagerFactoryClass"; 57 public static final String OPTION_OPTIMISTIC = "javax.jdo.option.Optimistic"; 58 public static final String OPTION_RETAINVALUES = "javax.jdo.option.RetainValues"; 59 public static final String OPTION_RESTORE_VALUES = "javax.jdo.option.RestoreValues"; 60 public static final String OPTION_NON_TRANSACTIONAL_READ = "javax.jdo.option.NontransactionalRead"; 61 public static final String OPTION_NON_TRANSACTIONAL_WRITE = "javax.jdo.option.NontransactionalWrite"; 62 public static final String OPTION_MULTITHREADED = "javax.jdo.option.Multithreaded"; 63 public static final String OPTION_IGNORE_CACHE = "javax.jdo.option.IgnoreCache"; 64 public static final String OPTION_CONNECTION_FACTORY_NAME = "javax.jdo.option.ConnectionFactoryName"; 65 public static final String OPTION_CONNECTION_FACTORY2_NAME = "javax.jdo.option.ConnectionFactory2Name"; 66 67 public static final boolean PARALLEL_COLLECTION_FETCH_DEFAULT = true; 68 public static final boolean DEFAULT_ALLOW_PM_CLOSE_WITH_OPEN_TX = false; 69 public static final boolean DEFAULT_ALLOW_REMOTE_ACCESS = true; 70 public static final boolean DEFAULT_ALLOW_REMOTE_PMS = true; 71 public static final boolean DEFAULT_RMI_CSF_IS_SSF = false; 72 public static final boolean DEFAULT_HYPERDRIVE = true; 73 public static final boolean DEFAULT_PMPOOL_ENABLED = true; 74 public static final boolean DEFAULT_REMOTE_PMPOOL_ENABLED = true; 75 public static final boolean DEFAULT_PRECOMPILE_NAMED_QUERIES = true; 76 public static final boolean DEFAULT_CHECK_MODEL_CONSISTENCY_ON_COMMIT = false; 77 public static final boolean DEFAULT_ANT_DISABLED = false; 78 public static final boolean DEFAULT_OPTION_OPTIMISTIC = true; 79 public static final boolean DEFAULT_OPTION_RETAINVALUES = false; 80 public static final boolean DEFAULT_OPTION_RESTORE_VALUES = false; 81 public static final boolean DEFAULT_OPTION_IGNORE_CACHE = false; 82 public static final boolean DEFAULT_OPTION_NON_TRANSACTIONAL_READ = false; 83 public static final boolean DEFAULT_OPTION_NON_TRANSACTIONAL_WRITE = false; 84 public static final boolean DEFAULT_OPTION_MULTITHREADED = false; 85 public static final boolean DEFAULT_CACHE_ENABLED = true; 86 public static final boolean DEFAULT_QUERY_CACHE_ENABLED = true; 87 public static final boolean DEFAULT_ANT_SHOW_ALL_TARGETS = false; 88 public static final int DEFAULT_STORE_MAX_ACTIVE = 10; 89 public static final int DEFAULT_STORE_MAX_IDLE = 10; 90 public static final int DEFAULT_STORE_MIN_IDLE = 2; 91 public static final int DEFAULT_STORE_RESERVED = 1; 92 public static final boolean DEFAULT_STORE_WAIT_FOR_CON_ON_STARTUP = false; 93 public static final boolean DEFAULT_STORE_TEST_ON_ALLOC = false; 94 public static final boolean DEFAULT_STORE_TEST_ON_RELEASE = false; 95 public static final boolean DEFAULT_STORE_TEST_ON_EXCEPTION = true; 96 public static final int DEFAULT_STORE_RETRY_INTERVAL_MS = 1000; 97 public static final int DEFAULT_STORE_RETRY_COUNT = 30; 98 public static final boolean DEFAULT_STORE_MANAGED_ONE_TO_MANY = false; 99 public static final boolean DEFAULT_STORE_MANAGED_MANY_TO_MANY = false; 100 101 public static final int DEFAULT_RMI_REGISTRY_PORT = 2388; 102 103 public static final String HYPERDRIVE = "versant.hyperdrive"; 104 public static final String HYPERDRIVE_SRC_DIR = "versant.hyperdriveSrcDir"; 105 public static final String HYPERDRIVE_CLASS_DIR = "versant.hyperdriveClassDir"; 106 107 public static final String PMPOOL_ENABLED = "versant.pmpoolEnabled"; 108 public static final String PMPOOL_MAX_IDLE = "versant.pmpoolMaxIdle"; 109 110 public static final int DEFAULT_PMPOOL_MAX_IDLE = 8; 111 112 public static final String REMOTE_PMPOOL_ENABLED = "versant.remotePmpoolEnabled"; 113 public static final String REMOTE_PMPOOL_MAX_IDLE = "versant.remotePmpoolMaxIdle"; 114 public static final String REMOTE_PMPOOL_MAX_ACTIVE = "versant.remotePmpoolMaxActive"; 115 116 public static final int DEFAULT_REMOTE_PMPOOL_MAX_IDLE = 2; 117 public static final int DEFAULT_REMOTE_PMPOOL_MAX_ACTIVE = 5; 118 119 public static final String FLUSH_THRESHOLD = "versant.flushThreshold"; 120 121 public static final int DEFAULT_FLUSH_THRESHOLD = 0; 122 123 public static final String STORE_TYPE = "versant.type"; 124 public static final String STORE_DB = "versant.db"; 125 public static final String STORE_PROPERTIES = "versant.properties"; 126 public static final String STORE_MAX_ACTIVE = "versant.maxActive"; 127 public static final String STORE_MAX_IDLE = "versant.maxIdle"; 128 public static final String STORE_MIN_IDLE = "versant.minIdle"; 129 public static final String STORE_RESERVED = "versant.reserved"; 130 public static final String STORE_EXT = "versant.ext."; 131 public static final int MAX_STORE_TYPE_MAPPING_COUNT = 100; 132 public static final String STORE_TYPE_MAPPING = "versant.jdbcType."; 133 public static final int MAX_STORE_JAVATYPE_MAPPING_COUNT = 100; 134 public static final String STORE_JAVATYPE_MAPPING = "versant.jdbcJavaType."; 135 public static final String STORE_NAMEGEN = "versant.jdbcNamegen"; 136 public static final String STORE_MIGRATION_CONTROLS = "versant.jdbcMigration"; 137 public static final String STORE_DISABLE_BATCHING = "versant.jdbcNobatching"; 138 public static final String STORE_DISABLE_PS_CACHE = "versant.jdbcDisablePsCache"; 139 public static final String STORE_PS_CACHE_MAX = "versant.psCacheMax"; 140 public static final String STORE_VALIDATE_SQL = "versant.validateSql"; 141 public static final String STORE_INIT_SQL = "versant.initSql"; 142 public static final String STORE_WAIT_FOR_CON_ON_STARTUP = "versant.waitForConOnStartup"; 143 public static final String STORE_TEST_ON_ALLOC = "versant.testOnAlloc"; 144 public static final String STORE_TEST_ON_RELEASE = "versant.testOnRelease"; 145 public static final String STORE_TEST_ON_EXCEPTION = "versant.testOnException"; 146 public static final String STORE_TEST_WHEN_IDLE = "versant.testWhenIdle"; 147 public static final String STORE_RETRY_INTERVAL_MS = "versant.retryIntervalMs"; 148 public static final String STORE_RETRY_COUNT = "versant.retryCount"; 149 public static final String STORE_VALIDATE_MAPPING_ON_STARTUP = "versant.validateMappingOnStartup"; 150 public static final String STORE_CON_TIMEOUT = "versant.conTimeout"; 151 public static final String STORE_TEST_INTERVAL = "versant.testInterval"; 152 public static final String STORE_ISOLATION_LEVEL = "versant.isolationLevel"; 153 public static final String STORE_BLOCK_WHEN_FULL = "versant.blockWhenFull"; 154 public static final String STORE_MAX_CON_AGE = "versant.maxConAge"; 155 public static final String STORE_MANAGED_ONE_TO_MANY = "versant.managedOneToMany"; 156 public static final String STORE_MANAGED_MANY_TO_MANY = "versant.managedManyToMany"; 157 public static final int MAX_STORE_SCO_FACTORY_COUNT = 100; 158 public static final String STORE_SCO_FACTORY_MAPPING = "versant.scoFactoryMapping."; 159 public static final String VDS_OID_BATCH_SIZE = "versant.vdsOidBatchSize"; 160 public static final String VDS_SCHEMA_DEFINITION = "versant.vdsSchemaDefine"; 161 public static final String VDS_SCHEMA_EVOLUTION = "versant.vdsSchemaEvolve"; 162 public static final String VDS_NAMING_POLICY = "versant.vdsNamingPolicy"; 163 164 public static final String STD_CON_DRIVER_NAME = "javax.jdo.option.ConnectionDriverName"; 166 public static final String STD_CON_USER_NAME = "javax.jdo.option.ConnectionUserName"; 167 public static final String STD_CON_PASSWORD = "javax.jdo.option.ConnectionPassword"; 168 public static final String STD_CON_URL = "javax.jdo.option.ConnectionURL"; 169 public static final String STD_CON_FACTORY_NAME = "javax.jdo.option.ConnectionFactoryName"; 170 public static final String STD_CON2_FACTORY_NAME = "javax.jdo.option.ConnectionFactory2Name"; 171 172 public static final String CON2_DRIVER_NAME = "versant.Connection2DriverName"; 174 public static final String CON2_USER_NAME = "versant.Connection2UserName"; 175 public static final String CON2_PASSWORD = "versant.Connection2Password"; 176 public static final String CON2_URL = "versant.Connection2URL"; 177 public static final String CON2_PROPERTIES = "versant.properties2"; 178 179 public static final int DEFAULT_MAX_CON_AGE = 1000; 180 181 public static final String ISOLATION_LEVEL_READ_UNCOMMITTED = "READ_UNCOMMITTED"; 182 public static final String ISOLATION_LEVEL_READ_COMMITTED = "READ_COMMITTED"; 183 public static final String ISOLATION_LEVEL_REPEATABLE_READ = "REPEATABLE_READ"; 184 public static final String ISOLATION_LEVEL_SERIALIZABLE = "SERIALIZABLE"; 185 186 public static final int MAX_JDO_FILE_COUNT = 1000; 187 public static final String JDO = "versant.metadata."; 188 189 public static final String EVENT_LOGGING = "versant.logging"; 190 191 public static final String DATASTORE_TX_LOCKING = "versant.datastoreTxLocking"; 192 193 public static final String DATASTORE_TX_LOCKING_NONE = "LOCKING_NONE"; 194 public static final String DATASTORE_TX_LOCKING_FIRST = "LOCKING_FIRST"; 195 public static final String DATASTORE_TX_LOCKING_ALL = "LOCKING_ALL"; 196 197 public static final String RETAIN_CONNECTION_IN_OPT_TX = "versant.retainConnectionInOptTx"; 198 199 public static final String CACHE_ENABLED = "versant.l2CacheEnabled"; 200 public static final String CACHE_MAX_OBJECTS = "versant.l2CacheMaxObjects"; 201 public static final String CACHE_LISTENER = "versant.l2CacheListener"; 202 public static final String CACHE_CLUSTER_TRANSPORT = "versant.l2CacheClusterTransport"; 203 public static final String CLUSTER_JGROUPS = "JGROUPS"; 204 public static final String CLUSTER_TANGOSOL_COHERENCE = "TANGOSOL_COHERENCE"; 205 206 public static final String QUERY_CACHE_ENABLED = "versant.l2QueryCacheEnabled"; 207 public static final String QUERY_CACHE_MAX_QUERIES = "versant.l2QueryCacheMaxQueries"; 208 public static final String COMPILED_QUERY_CACHE_SIZE = "versant.compiledQueryCacheSize"; 209 210 public static final int DEFAULT_CACHE_MAX_OBJECTS = 10000; 211 public static final int DEFAULT_CACHE_MAX_QUERIES = 1000; 212 213 public static final int DEFAULT_METRIC_SNAPSHOT_INTERVAL_MS = 1000; 214 public static final int DEFAULT_METRIC_STORE_CAPACITY = 60 * 60; 215 216 public static final String METRIC_USER = "versant.userMetric."; 217 public static final int MAX_METRIC_USER_COUNT = 100; 218 219 public static final String METRIC_SNAPSHOT_INTERVAL_MS = "versant.metricSnapshotIntervalMs"; 220 public static final String METRIC_STORE_CAPACITY = "versant.metricStoreCapacity"; 221 222 public static final String LOG_DOWNLOADER = "versant.logDownloader"; 223 public static final String NAMING_POLICY_CLASS_NAME = "versant.namingPolicy"; 224 225 public static final String JDBC_INHERITANCE_NO_CLASSID = 228 "jdbc-inheritance-no-classid"; 229 230 public static final String PM_CACHE_REF_TYPE_STRONG = "STRONG"; 231 public static final String PM_CACHE_REF_TYPE_SOFT = "SOFT"; 232 public static final String PM_CACHE_REF_TYPE_WEAK = "WEAK"; 233 234 public static final int MAX_EXTERNALIZER_COUNT = 100; 235 public static final String EXTERNALIZER = "versant.externalizer."; 236 237 public static final String TESTING = "versant.testing"; 238 239 public static final String MDEDIT_SRC_PATH = "versant.workbench.srcPath"; 241 public static final int MAX_MDEDIT_CP_COUNT = 1000; 242 public static final String MDEDIT_CP = "versant.workbench.classpath."; 243 244 public static final String ANT_DISABLED = "versant.workbench.antDisabled"; 245 public static final String ANT_BUILDFILE = "versant.workbench.antBuildfile"; 246 public static final String ANT_RUN_TARGET = "versant.workbench.antRunTarget"; 247 public static final String ANT_COMPILE = "versant.workbench.antCompile"; 248 public static final String ANT_ARGS = "versant.workbench.antArgs"; 249 public static final String ANT_SHOW_ALL_TARGETS = "versant.workbench.antShowAllTargets"; 250 251 public static final String SCRIPT_DIR = "versant.workbench.scriptDir"; 252 253 public static final String DIAGRAM = "versant.workbench.diagram"; 254 public static final String DIAGRAM_COUNT = ".count"; 255 public static final String DIAGRAM_CLASS = ".class"; 256 public static final String DIAGRAM_NAME = ".name"; 257 public static final String DIAGRAM_LEGEND = ".legend"; 258 259 public static final String EXTERNALIZER_TYPE = ".type"; 260 public static final String EXTERNALIZER_ENABLED = ".enabled"; 261 public static final String EXTERNALIZER_CLASS = ".class"; 262 263 public ConfigParser() { 264 } 265 266 269 public ConfigInfo parse(String filename) { 270 try { 271 InputStream in = null; 272 try { 273 in = new FileInputStream (filename); 274 return parse(in); 275 } finally { 276 if (in != null) in.close(); 277 } 278 } catch (IOException e) { 279 handleException(e); 280 return null; 281 } 282 } 283 284 private void handleException(Throwable t) { 285 throw BindingSupportImpl.getInstance().runtime( 286 t.getClass().getName() + ": " + t.getMessage(), t); 287 } 288 289 292 public ConfigInfo parseResource(String filename, ClassLoader cl) { 293 try { 294 InputStream in = null; 295 try { 296 if (filename.startsWith("/")) filename = filename.substring(1); 297 in = cl.getResourceAsStream(filename); 298 if (in == null) { 299 throw BindingSupportImpl.getInstance().runtime( 300 "Resource not found: " + filename); 301 } 302 return parse(in); 303 } finally { 304 if (in != null) in.close(); 305 } 306 } catch (IOException e) { 307 handleException(e); 308 return null; 309 } 310 } 311 312 public ConfigInfo parseResource(File file) { 313 try { 314 InputStream in = new FileInputStream (file); 315 try { 316 return parse(in); 317 } finally { 318 if (in != null) in.close(); 319 } 320 } catch (IOException e) { 321 handleException(e); 322 return null; 323 } 324 } 325 326 329 public ConfigInfo parseResource(String filename) { 330 try { 331 InputStream in = null; 332 try { 333 in = getClass().getResourceAsStream(filename); 334 if (in == null) { 335 throw BindingSupportImpl.getInstance().runtime( 336 "Resource not found: " + filename); 337 } 338 return parse(in); 339 } finally { 340 if (in != null) in.close(); 341 } 342 } catch (IOException e) { 343 handleException(e); 344 return null; 345 } 346 } 347 348 351 public ConfigInfo parse(InputStream in) { 352 Properties p = new Properties(); 353 try { 354 p.load(in); 355 } catch (IOException e) { 356 throw BindingSupportImpl.getInstance().runtime( 357 e.getClass() + ": " + e.getMessage(), e); 358 } 359 return parse(p); 360 } 361 362 365 public ConfigInfo parse(Properties p) { 366 PropertyConverter.convert(p); 367 String s; 368 ConfigInfo c = new ConfigInfo(); 369 c.metaDataPreProcessor = p.getProperty(META_DATA_PRE_PROCESSOR); 370 c.props = p; 371 c.jdoMetaData = (JdoRoot[])p.get(VERSANT_JDO_META_DATA); 372 c.serverName = p.getProperty(SERVER, "versant"); 373 c.hyperdrive = getBoolean(p, HYPERDRIVE, DEFAULT_HYPERDRIVE); 374 c.hyperdriveSrcDir = p.getProperty(HYPERDRIVE_SRC_DIR); 375 c.hyperdriveClassDir = p.getProperty(HYPERDRIVE_CLASS_DIR); 376 c.flushThreshold = getInt(p, FLUSH_THRESHOLD, DEFAULT_FLUSH_THRESHOLD); 377 c.allowPmCloseWithOpenTx = getBoolean(p, ALLOW_PM_CLOSE_WITH_OPEN_TX, 378 DEFAULT_ALLOW_PM_CLOSE_WITH_OPEN_TX); 379 c.precompileNamedQueries = getBoolean(p, PRECOMPILE_NAMED_QUERIES, 380 DEFAULT_PRECOMPILE_NAMED_QUERIES); 381 c.checkModelConsistencyOnCommit = getBoolean(p, 382 CHECK_MODEL_CONSISTENCY_ON_COMMIT, 383 DEFAULT_CHECK_MODEL_CONSISTENCY_ON_COMMIT); 384 c.interceptDfgFieldAccess = getBoolean(p, INTERCEPT_DFG_FIELD_ACCESS, 385 false); 386 c.testing = getBoolean(p, TESTING, false); 387 c.remoteAccess = p.getProperty(REMOTE_ACCESS); 388 389 s = p.getProperty(PM_CACHE_REF_TYPE, PM_CACHE_REF_TYPE_SOFT); 390 if (s.equals(PM_CACHE_REF_TYPE_SOFT)) { 391 c.pmCacheRefType = VersantPersistenceManager.PM_CACHE_REF_TYPE_SOFT; 392 } else if (s.equals(PM_CACHE_REF_TYPE_WEAK)) { 393 c.pmCacheRefType = VersantPersistenceManager.PM_CACHE_REF_TYPE_WEAK; 394 } else if (s.equals(PM_CACHE_REF_TYPE_STRONG)) { 395 c.pmCacheRefType = VersantPersistenceManager.PM_CACHE_REF_TYPE_STRONG; 396 } else { 397 throw BindingSupportImpl.getInstance().runtime("Invalid " + PM_CACHE_REF_TYPE + 398 ": '" + s + "', expected " + PM_CACHE_REF_TYPE_SOFT + ", " + 399 PM_CACHE_REF_TYPE_WEAK + " or " + 400 PM_CACHE_REF_TYPE_STRONG); 401 } 402 403 c.retainValues = getBoolean(p, OPTION_RETAINVALUES, 404 DEFAULT_OPTION_RETAINVALUES); 405 c.restoreValues = getBoolean(p, OPTION_RESTORE_VALUES, 406 DEFAULT_OPTION_RESTORE_VALUES); 407 c.optimistic = getBoolean(p, OPTION_OPTIMISTIC, 408 DEFAULT_OPTION_OPTIMISTIC); 409 c.nontransactionalRead = getBoolean(p, OPTION_NON_TRANSACTIONAL_READ, 410 DEFAULT_OPTION_NON_TRANSACTIONAL_READ); 411 c.nontransactionalWrite = getBoolean(p, OPTION_NON_TRANSACTIONAL_WRITE, 412 DEFAULT_OPTION_NON_TRANSACTIONAL_WRITE); 413 c.ignoreCache = getBoolean(p, OPTION_IGNORE_CACHE, 414 DEFAULT_OPTION_IGNORE_CACHE); 415 c.multithreaded = getBoolean(p, OPTION_MULTITHREADED, 416 DEFAULT_OPTION_MULTITHREADED); 417 c.connectionFactoryName = p.getProperty(OPTION_CONNECTION_FACTORY_NAME); 418 c.connectionFactory2Name = p.getProperty( 419 OPTION_CONNECTION_FACTORY2_NAME); 420 421 s = p.getProperty(DATASTORE_TX_LOCKING); 423 if (s == null) { 424 c.datastoreTxLocking = VersantPersistenceManager.LOCKING_FIRST; 425 } else { 426 if (s.equals(DATASTORE_TX_LOCKING_ALL)) { 427 c.datastoreTxLocking = VersantPersistenceManager.LOCKING_ALL; 428 } else if (s.equals(DATASTORE_TX_LOCKING_FIRST)) { 429 c.datastoreTxLocking = VersantPersistenceManager.LOCKING_FIRST; 430 } else if (s.equals(DATASTORE_TX_LOCKING_NONE)) { 431 c.datastoreTxLocking = VersantPersistenceManager.LOCKING_NONE; 432 } else { 433 throw BindingSupportImpl.getInstance().runtime("Invalid datastore.tx.locking: '" + 434 s + "', expected none, first or all."); 435 } 436 } 437 438 s = p.getProperty(RETAIN_CONNECTION_IN_OPT_TX); 439 if ("true".equals(s)) { 440 c.retainConnectionInOptTx = MDStatics.TRUE; 441 } else if ("false".equals(s)) { 442 c.retainConnectionInOptTx = MDStatics.FALSE; 443 } else { 444 c.retainConnectionInOptTx = MDStatics.NOT_SET; 445 } 446 447 c.pmpoolEnabled = getBoolean(p, PMPOOL_ENABLED, DEFAULT_PMPOOL_ENABLED); 449 c.pmpoolMaxIdle = getInt(p, PMPOOL_MAX_IDLE, DEFAULT_PMPOOL_MAX_IDLE); 450 c.remotePmpoolEnabled = getBoolean(p, REMOTE_PMPOOL_ENABLED, 451 DEFAULT_REMOTE_PMPOOL_ENABLED); 452 c.remotePmpoolMaxIdle = getInt(p, REMOTE_PMPOOL_MAX_IDLE, 453 DEFAULT_REMOTE_PMPOOL_MAX_IDLE); 454 c.remotePmpoolMaxActive = getInt(p, REMOTE_PMPOOL_MAX_ACTIVE, 455 DEFAULT_REMOTE_PMPOOL_MAX_ACTIVE); 456 457 c.queryCacheEnabled = getBoolean(p, QUERY_CACHE_ENABLED, 458 DEFAULT_QUERY_CACHE_ENABLED); 459 c.maxQueriesToCache = getInt(p, QUERY_CACHE_MAX_QUERIES, 460 DEFAULT_CACHE_MAX_QUERIES); 461 c.compiledQueryCacheSize = getInt(p, COMPILED_QUERY_CACHE_SIZE, 0); 462 463 c.useCache = getBoolean(p, CACHE_ENABLED, DEFAULT_CACHE_ENABLED); 465 c.cacheMaxObjects = getInt(p, CACHE_MAX_OBJECTS, DEFAULT_CACHE_MAX_OBJECTS); 466 467 c.cacheListenerClass = getClassAndProps(p, CACHE_CLUSTER_TRANSPORT, 468 c.cacheListenerProps = new HashMap()); 469 if (c.cacheListenerClass == null && c.cacheListenerProps == null) { 470 c.cacheListenerClass = getClassAndProps(p, CACHE_LISTENER, 471 c.cacheListenerProps = new HashMap()); 472 } 473 474 readExternalizers(p, c); 476 477 readSCOFactoryMappings(p, c.scoFactoryRegistryMappings); 479 480 String db = p.getProperty(STORE_DB); 482 if (Utils.isVersantDatabaseType(db)) { 483 db = "versant"; 484 p.put(STORE_DB, db); 485 } 486 c.db = p.getProperty(STORE_DB); 487 c.url = p.getProperty(STD_CON_URL); 488 489 getClassAndProps(p, EVENT_LOGGING, c.perfProps = new HashMap()); 490 491 c.logDownloaderClass = getClassAndProps(p, LOG_DOWNLOADER, 492 c.logDownloaderProps = new HashMap()); 493 494 c.metricStoreCapacity = getInt(p, METRIC_STORE_CAPACITY, 495 DEFAULT_METRIC_STORE_CAPACITY); 496 c.metricSnapshotIntervalMs = getInt(p, METRIC_SNAPSHOT_INTERVAL_MS, 497 DEFAULT_METRIC_SNAPSHOT_INTERVAL_MS); 498 499 for (int i = 0; i < MAX_METRIC_USER_COUNT; i++) { 501 s = p.getProperty(METRIC_USER + i); 502 if (s == null) continue; 503 StringListParser lp = new StringListParser(s); 504 ConfigInfo.UserBaseMetric u = new ConfigInfo.UserBaseMetric(); 505 u.name = lp.nextString(); 506 u.displayName = lp.nextQuotedString(); 507 u.category = lp.nextQuotedString(); 508 u.description = lp.nextQuotedString(); 509 u.defaultCalc = lp.nextInt(); 510 u.decimals = lp.nextInt(); 511 c.userBaseMetrics.add(u); 512 } 513 514 int n = MAX_JDO_FILE_COUNT; 516 for (int i = 0; i < n; i++) { 517 String base = JDO + i; 518 String f = p.getProperty(base); 519 if (f == null) continue; 520 c.jdoResources.add(f); 521 } 522 523 return c; 524 } 525 526 private void readSCOFactoryMappings(Properties p, Map map) { 527 String s; 528 for (int x = 0; x < MAX_STORE_SCO_FACTORY_COUNT; x++) { 529 s = p.getProperty(STORE_SCO_FACTORY_MAPPING + x); 530 if (s != null) { 531 StringListParser lp = new StringListParser(s); 532 String javaClassName = lp.nextString(); 533 String factoryName = lp.nextString(); 534 map.put(javaClassName, factoryName); 535 } 536 } 537 } 538 539 private void readExternalizers(Properties p, ConfigInfo c) { 540 String s; 541 String ext = null; 542 for (int i = 0; i < MAX_EXTERNALIZER_COUNT; i++) { 543 ext = EXTERNALIZER + i; 544 s = p.getProperty(ext + EXTERNALIZER_TYPE); 545 if (s != null) { ConfigInfo.ExternalizerInfo ei = new ConfigInfo.ExternalizerInfo(); 547 ei.typeName = s; 548 ei.enabled = getBoolean(p, ext + EXTERNALIZER_ENABLED, false); 549 ei.externalizerName = p.getProperty(ext + EXTERNALIZER_CLASS); 550 Set all = p.keySet(); 551 String extProps = ext + EXTERNALIZER_CLASS + "."; 552 for (Iterator iter = all.iterator(); iter.hasNext();) { 553 String key = (String )iter.next(); 554 if (key.startsWith(extProps)) { 555 String newKey = key.substring(extProps.length() + 1); 556 ei.args.put(newKey, p.getProperty(key)); 557 } 558 } 559 c.externalizers.add(ei); 560 } 561 } 562 } 563 564 public static String trim(String s) { 565 if (s == null) return s; 566 s = s.trim(); 567 if (s.length() == 0) return null; 568 return s; 569 } 570 571 public static int getExtEnum(Properties p, String be, int ext, 572 Map map, int def) { 573 JdoExtension e = getExt(p, be, ext); 574 if (e == null) return def; 575 return e.getEnum(map); 576 } 577 578 public static boolean getExtBoolean(Properties p, String be, int ext, 579 boolean def) { 580 JdoExtension e = getExt(p, be, ext); 581 if (e == null) return def; 582 return e.getBoolean(); 583 } 584 585 public static JdoExtension getExt(Properties p, String be, int ext) { 586 String s = p.getProperty(be + JdoExtension.toKeyString(ext)); 587 if (s == null) return null; 588 JdoExtension e = new JdoExtension(); 589 e.key = ext; 590 e.value = s; 591 return e; 592 } 593 594 public static String getReq(Properties p, String s, String alt) { 595 String v = p.getProperty(s); 596 if (v == null && alt != null) v = p.getProperty(alt); 597 if (v == null) { 598 if (alt == null) { 599 throw BindingSupportImpl.getInstance().runtime("Expected property: '" + s + 600 "'"); 601 } else { 602 throw BindingSupportImpl.getInstance().runtime("Expected property: '" + s + 603 "' or '" + alt + "'"); 604 } 605 } 606 return v; 607 } 608 609 public static String getReq(Properties p, String s) { 610 return getReq(p, s, null); 611 } 612 613 public static int getInt(Properties p, String s, int def) { 614 String v = p.getProperty(s); 615 if (v == null || v.equals("null") || v.length() == 0) return def; 616 try { 617 return Integer.parseInt(v); 618 } catch (NumberFormatException e) { 619 throw BindingSupportImpl.getInstance().runtime( 620 "Expected int: " + s); 621 } 622 } 623 624 public static boolean getBoolean(Properties p, String s, boolean def) { 625 String v = p.getProperty(s); 626 if (v == null) return def; 627 return v.equals("true") || v.equals("on"); 628 } 629 630 public static String getClassAndProps(Properties p, String key, Map map) { 631 Set all = p.keySet(); 632 String nextKey = key + "."; 633 for (Iterator iter = all.iterator(); iter.hasNext();) { 634 String s = (String )iter.next(); 635 if (s.startsWith(nextKey)) { 636 String newKey = s.substring(nextKey.length()); 637 map.put(newKey, p.getProperty(s)); 638 } 639 } 640 return p.getProperty(key); 641 } 642 } 643 | Popular Tags |