KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > common > config > ConfigParser


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

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 JavaDoc;
21 import java.io.FileInputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.util.*;
25
26 import com.versant.core.common.BindingSupportImpl;
27 import com.versant.core.common.Utils;
28
29 /**
30  * Parser for our property files. This will parse a file and return a Config
31  * instance.
32  */

33 public class ConfigParser {
34
35     public static final String JavaDoc VERSANT_JDO_META_DATA = "versant.jdoMetaData";
36
37     public static final String JavaDoc META_DATA_PRE_PROCESSOR = "versant.metadata.preprocessor";
38
39     public static final String JavaDoc PROJECT_DESCRIPTION = "versant.workbench.projectDescription";
40     public static final String JavaDoc PROPERTIES_FILE_MODE = "versant.workbench.propertiesFile";
41     public static final String JavaDoc PROPERTIES_SPLIT_FILE = "versant.workbench.splitPropertiesFiles";
42     public static final String JavaDoc SERVER = "versant.server";
43     public static final String JavaDoc REMOTE_ACCESS = "versant.remoteAccess";
44     public static final String JavaDoc ALLOW_REMOTE_PMS = "versant.remotePMs";
45     public static final String JavaDoc RMI_REGISTRY_PORT = "versant.rmiRegistryPort";
46     public static final String JavaDoc SERVER_PORT = "versant.serverPort";
47     public static final String JavaDoc RMI_CLIENT_SF = "versant.rmiClientSocketFactory";
48     public static final String JavaDoc RMI_CSF_IS_SSF = "versant.rmiClientSocketFactoryIsServerSF";
49     public static final String JavaDoc RMI_SERVER_SF = "versant.rmiServerSocketFactory";
50     public static final String JavaDoc ALLOW_PM_CLOSE_WITH_OPEN_TX = "versant.allowPmCloseWithOpenTx";
51     public static final String JavaDoc PRECOMPILE_NAMED_QUERIES = "versant.precompileNamedQueries";
52     public static final String JavaDoc CHECK_MODEL_CONSISTENCY_ON_COMMIT = "versant.checkModelConsistencyOnCommit";
53     public static final String JavaDoc INTERCEPT_DFG_FIELD_ACCESS = "versant.interceptDfgFieldAccess";
54     public static final String JavaDoc PM_CACHE_REF_TYPE = "versant.pmCacheRefType";
55
56     public static final String JavaDoc PMF_CLASS = "javax.jdo.PersistenceManagerFactoryClass";
57     public static final String JavaDoc OPTION_OPTIMISTIC = "javax.jdo.option.Optimistic";
58     public static final String JavaDoc OPTION_RETAINVALUES = "javax.jdo.option.RetainValues";
59     public static final String JavaDoc OPTION_RESTORE_VALUES = "javax.jdo.option.RestoreValues";
60     public static final String JavaDoc OPTION_NON_TRANSACTIONAL_READ = "javax.jdo.option.NontransactionalRead";
61     public static final String JavaDoc OPTION_NON_TRANSACTIONAL_WRITE = "javax.jdo.option.NontransactionalWrite";
62     public static final String JavaDoc OPTION_MULTITHREADED = "javax.jdo.option.Multithreaded";
63     public static final String JavaDoc OPTION_IGNORE_CACHE = "javax.jdo.option.IgnoreCache";
64     public static final String JavaDoc OPTION_CONNECTION_FACTORY_NAME = "javax.jdo.option.ConnectionFactoryName";
65     public static final String JavaDoc 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 JavaDoc HYPERDRIVE = "versant.hyperdrive";
104     public static final String JavaDoc HYPERDRIVE_SRC_DIR = "versant.hyperdriveSrcDir";
105     public static final String JavaDoc HYPERDRIVE_CLASS_DIR = "versant.hyperdriveClassDir";
106
107     public static final String JavaDoc PMPOOL_ENABLED = "versant.pmpoolEnabled";
108     public static final String JavaDoc PMPOOL_MAX_IDLE = "versant.pmpoolMaxIdle";
109
110     public static final int DEFAULT_PMPOOL_MAX_IDLE = 8;
111
112     public static final String JavaDoc REMOTE_PMPOOL_ENABLED = "versant.remotePmpoolEnabled";
113     public static final String JavaDoc REMOTE_PMPOOL_MAX_IDLE = "versant.remotePmpoolMaxIdle";
114     public static final String JavaDoc 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 JavaDoc FLUSH_THRESHOLD = "versant.flushThreshold";
120
121     public static final int DEFAULT_FLUSH_THRESHOLD = 0;
122
123     public static final String JavaDoc STORE_TYPE = "versant.type";
124     public static final String JavaDoc STORE_DB = "versant.db";
125     public static final String JavaDoc STORE_PROPERTIES = "versant.properties";
126     public static final String JavaDoc STORE_MAX_ACTIVE = "versant.maxActive";
127     public static final String JavaDoc STORE_MAX_IDLE = "versant.maxIdle";
128     public static final String JavaDoc STORE_MIN_IDLE = "versant.minIdle";
129     public static final String JavaDoc STORE_RESERVED = "versant.reserved";
130     public static final String JavaDoc STORE_EXT = "versant.ext.";
131     public static final int MAX_STORE_TYPE_MAPPING_COUNT = 100;
132     public static final String JavaDoc STORE_TYPE_MAPPING = "versant.jdbcType.";
133     public static final int MAX_STORE_JAVATYPE_MAPPING_COUNT = 100;
134     public static final String JavaDoc STORE_JAVATYPE_MAPPING = "versant.jdbcJavaType.";
135     public static final String JavaDoc STORE_NAMEGEN = "versant.jdbcNamegen";
136     public static final String JavaDoc STORE_MIGRATION_CONTROLS = "versant.jdbcMigration";
137     public static final String JavaDoc STORE_DISABLE_BATCHING = "versant.jdbcNobatching";
138     public static final String JavaDoc STORE_DISABLE_PS_CACHE = "versant.jdbcDisablePsCache";
139     public static final String JavaDoc STORE_PS_CACHE_MAX = "versant.psCacheMax";
140     public static final String JavaDoc STORE_VALIDATE_SQL = "versant.validateSql";
141     public static final String JavaDoc STORE_INIT_SQL = "versant.initSql";
142     public static final String JavaDoc STORE_WAIT_FOR_CON_ON_STARTUP = "versant.waitForConOnStartup";
143     public static final String JavaDoc STORE_TEST_ON_ALLOC = "versant.testOnAlloc";
144     public static final String JavaDoc STORE_TEST_ON_RELEASE = "versant.testOnRelease";
145     public static final String JavaDoc STORE_TEST_ON_EXCEPTION = "versant.testOnException";
146     public static final String JavaDoc STORE_TEST_WHEN_IDLE = "versant.testWhenIdle";
147     public static final String JavaDoc STORE_RETRY_INTERVAL_MS = "versant.retryIntervalMs";
148     public static final String JavaDoc STORE_RETRY_COUNT = "versant.retryCount";
149     public static final String JavaDoc STORE_VALIDATE_MAPPING_ON_STARTUP = "versant.validateMappingOnStartup";
150     public static final String JavaDoc STORE_CON_TIMEOUT = "versant.conTimeout";
151     public static final String JavaDoc STORE_TEST_INTERVAL = "versant.testInterval";
152     public static final String JavaDoc STORE_ISOLATION_LEVEL = "versant.isolationLevel";
153     public static final String JavaDoc STORE_BLOCK_WHEN_FULL = "versant.blockWhenFull";
154     public static final String JavaDoc STORE_MAX_CON_AGE = "versant.maxConAge";
155     public static final String JavaDoc STORE_MANAGED_ONE_TO_MANY = "versant.managedOneToMany";
156     public static final String JavaDoc STORE_MANAGED_MANY_TO_MANY = "versant.managedManyToMany";
157     public static final int MAX_STORE_SCO_FACTORY_COUNT = 100;
158     public static final String JavaDoc STORE_SCO_FACTORY_MAPPING = "versant.scoFactoryMapping.";
159     public static final String JavaDoc VDS_OID_BATCH_SIZE = "versant.vdsOidBatchSize";
160     public static final String JavaDoc VDS_SCHEMA_DEFINITION = "versant.vdsSchemaDefine";
161     public static final String JavaDoc VDS_SCHEMA_EVOLUTION = "versant.vdsSchemaEvolve";
162     public static final String JavaDoc VDS_NAMING_POLICY = "versant.vdsNamingPolicy";
163
164     // standard connection properties
165
public static final String JavaDoc STD_CON_DRIVER_NAME = "javax.jdo.option.ConnectionDriverName";
166     public static final String JavaDoc STD_CON_USER_NAME = "javax.jdo.option.ConnectionUserName";
167     public static final String JavaDoc STD_CON_PASSWORD = "javax.jdo.option.ConnectionPassword";
168     public static final String JavaDoc STD_CON_URL = "javax.jdo.option.ConnectionURL";
169     public static final String JavaDoc STD_CON_FACTORY_NAME = "javax.jdo.option.ConnectionFactoryName";
170     public static final String JavaDoc STD_CON2_FACTORY_NAME = "javax.jdo.option.ConnectionFactory2Name";
171
172     // 2de connection properties
173
public static final String JavaDoc CON2_DRIVER_NAME = "versant.Connection2DriverName";
174     public static final String JavaDoc CON2_USER_NAME = "versant.Connection2UserName";
175     public static final String JavaDoc CON2_PASSWORD = "versant.Connection2Password";
176     public static final String JavaDoc CON2_URL = "versant.Connection2URL";
177     public static final String JavaDoc CON2_PROPERTIES = "versant.properties2";
178
179     public static final int DEFAULT_MAX_CON_AGE = 1000;
180
181     public static final String JavaDoc ISOLATION_LEVEL_READ_UNCOMMITTED = "READ_UNCOMMITTED";
182     public static final String JavaDoc ISOLATION_LEVEL_READ_COMMITTED = "READ_COMMITTED";
183     public static final String JavaDoc ISOLATION_LEVEL_REPEATABLE_READ = "REPEATABLE_READ";
184     public static final String JavaDoc ISOLATION_LEVEL_SERIALIZABLE = "SERIALIZABLE";
185
186     public static final int MAX_JDO_FILE_COUNT = 1000;
187     public static final String JavaDoc JDO = "versant.metadata.";
188
189     public static final String JavaDoc EVENT_LOGGING = "versant.logging";
190
191     public static final String JavaDoc DATASTORE_TX_LOCKING = "versant.datastoreTxLocking";
192
193     public static final String JavaDoc DATASTORE_TX_LOCKING_NONE = "LOCKING_NONE";
194     public static final String JavaDoc DATASTORE_TX_LOCKING_FIRST = "LOCKING_FIRST";
195     public static final String JavaDoc DATASTORE_TX_LOCKING_ALL = "LOCKING_ALL";
196
197     public static final String JavaDoc RETAIN_CONNECTION_IN_OPT_TX = "versant.retainConnectionInOptTx";
198
199     public static final String JavaDoc CACHE_ENABLED = "versant.l2CacheEnabled";
200     public static final String JavaDoc CACHE_MAX_OBJECTS = "versant.l2CacheMaxObjects";
201     public static final String JavaDoc CACHE_LISTENER = "versant.l2CacheListener";
202     public static final String JavaDoc CACHE_CLUSTER_TRANSPORT = "versant.l2CacheClusterTransport";
203     public static final String JavaDoc CLUSTER_JGROUPS = "JGROUPS";
204     public static final String JavaDoc CLUSTER_TANGOSOL_COHERENCE = "TANGOSOL_COHERENCE";
205
206     public static final String JavaDoc QUERY_CACHE_ENABLED = "versant.l2QueryCacheEnabled";
207     public static final String JavaDoc QUERY_CACHE_MAX_QUERIES = "versant.l2QueryCacheMaxQueries";
208     public static final String JavaDoc 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 JavaDoc METRIC_USER = "versant.userMetric.";
217     public static final int MAX_METRIC_USER_COUNT = 100;
218
219     public static final String JavaDoc METRIC_SNAPSHOT_INTERVAL_MS = "versant.metricSnapshotIntervalMs";
220     public static final String JavaDoc METRIC_STORE_CAPACITY = "versant.metricStoreCapacity";
221
222     public static final String JavaDoc LOG_DOWNLOADER = "versant.logDownloader";
223     public static final String JavaDoc NAMING_POLICY_CLASS_NAME = "versant.namingPolicy";
224
225     // This is no longer used - the Workbench will automatically convert
226
// it to ext.jdbc-class-id instead on load
227
public static final String JavaDoc JDBC_INHERITANCE_NO_CLASSID =
228             "jdbc-inheritance-no-classid";
229
230     public static final String JavaDoc PM_CACHE_REF_TYPE_STRONG = "STRONG";
231     public static final String JavaDoc PM_CACHE_REF_TYPE_SOFT = "SOFT";
232     public static final String JavaDoc PM_CACHE_REF_TYPE_WEAK = "WEAK";
233
234     public static final int MAX_EXTERNALIZER_COUNT = 100;
235     public static final String JavaDoc EXTERNALIZER = "versant.externalizer.";
236
237     public static final String JavaDoc TESTING = "versant.testing";
238
239     // workbench specefic properties
240
public static final String JavaDoc MDEDIT_SRC_PATH = "versant.workbench.srcPath";
241     public static final int MAX_MDEDIT_CP_COUNT = 1000;
242     public static final String JavaDoc MDEDIT_CP = "versant.workbench.classpath.";
243
244     public static final String JavaDoc ANT_DISABLED = "versant.workbench.antDisabled";
245     public static final String JavaDoc ANT_BUILDFILE = "versant.workbench.antBuildfile";
246     public static final String JavaDoc ANT_RUN_TARGET = "versant.workbench.antRunTarget";
247     public static final String JavaDoc ANT_COMPILE = "versant.workbench.antCompile";
248     public static final String JavaDoc ANT_ARGS = "versant.workbench.antArgs";
249     public static final String JavaDoc ANT_SHOW_ALL_TARGETS = "versant.workbench.antShowAllTargets";
250
251     public static final String JavaDoc SCRIPT_DIR = "versant.workbench.scriptDir";
252
253     public static final String JavaDoc DIAGRAM = "versant.workbench.diagram";
254     public static final String JavaDoc DIAGRAM_COUNT = ".count";
255     public static final String JavaDoc DIAGRAM_CLASS = ".class";
256     public static final String JavaDoc DIAGRAM_NAME = ".name";
257     public static final String JavaDoc DIAGRAM_LEGEND = ".legend";
258
259     public static final String JavaDoc EXTERNALIZER_TYPE = ".type";
260     public static final String JavaDoc EXTERNALIZER_ENABLED = ".enabled";
261     public static final String JavaDoc EXTERNALIZER_CLASS = ".class";
262
263     public ConfigParser() {
264     }
265
266     /**
267      * Parse the supplied properties file and create a Config instance.
268      */

269     public ConfigInfo parse(String JavaDoc filename) {
270         try {
271             InputStream JavaDoc in = null;
272             try {
273                 in = new FileInputStream JavaDoc(filename);
274                 return parse(in);
275             } finally {
276                 if (in != null) in.close();
277             }
278         } catch (IOException JavaDoc e) {
279             handleException(e);
280             return null;
281         }
282     }
283
284     private void handleException(Throwable JavaDoc t) {
285         throw BindingSupportImpl.getInstance().runtime(
286                 t.getClass().getName() + ": " + t.getMessage(), t);
287     }
288
289     /**
290      * Parse the supplied properties resoutce and create a Config instance.
291      */

292     public ConfigInfo parseResource(String JavaDoc filename, ClassLoader JavaDoc cl) {
293         try {
294             InputStream JavaDoc 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 JavaDoc e) {
307             handleException(e);
308             return null;
309         }
310     }
311
312     public ConfigInfo parseResource(File JavaDoc file) {
313         try {
314             InputStream JavaDoc in = new FileInputStream JavaDoc(file);
315             try {
316                 return parse(in);
317             } finally {
318                 if (in != null) in.close();
319             }
320         } catch (IOException JavaDoc e) {
321             handleException(e);
322             return null;
323         }
324     }
325
326     /**
327      * Parse the supplied properties resoutce and create a Config instance.
328      */

329     public ConfigInfo parseResource(String JavaDoc filename) {
330         try {
331             InputStream JavaDoc 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 JavaDoc e) {
343             handleException(e);
344             return null;
345         }
346     }
347
348     /**
349      * Parse the supplied config stream and create a Config instance.
350      */

351     public ConfigInfo parse(InputStream JavaDoc in) {
352         Properties p = new Properties();
353         try {
354             p.load(in);
355         } catch (IOException JavaDoc e) {
356             throw BindingSupportImpl.getInstance().runtime(
357                     e.getClass() + ": " + e.getMessage(), e);
358         }
359         return parse(p);
360     }
361
362     /**
363      * Parse the supplied config properties and create a Config instance.
364      */

365     public ConfigInfo parse(Properties p) {
366         PropertyConverter.convert(p);
367         String JavaDoc 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         // datastore tx locking
422
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         // pm pool settings
448
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         // initialize the cache settings
464
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         // read externalizers
475
readExternalizers(p, c);
476
477         // read SCO factories
478
readSCOFactoryMappings(p, c.scoFactoryRegistryMappings);
479
480         // create store
481
String JavaDoc 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         // parse user defined base metrics
500
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         // find all .jdo and .jdoql files
515
int n = MAX_JDO_FILE_COUNT;
516         for (int i = 0; i < n; i++) {
517             String JavaDoc base = JDO + i;
518             String JavaDoc 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 JavaDoc 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 JavaDoc javaClassName = lp.nextString();
533                 String JavaDoc factoryName = lp.nextString();
534                 map.put(javaClassName, factoryName);
535             }
536         }
537     }
538
539     private void readExternalizers(Properties p, ConfigInfo c) {
540         String JavaDoc s;
541         String JavaDoc 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) { // we have an externalizer
546
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 JavaDoc extProps = ext + EXTERNALIZER_CLASS + ".";
552                 for (Iterator iter = all.iterator(); iter.hasNext();) {
553                     String JavaDoc key = (String JavaDoc)iter.next();
554                     if (key.startsWith(extProps)) {
555                         String JavaDoc 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 JavaDoc trim(String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc be, int ext) {
586         String JavaDoc 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 JavaDoc getReq(Properties p, String JavaDoc s, String JavaDoc alt) {
595         String JavaDoc 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 JavaDoc getReq(Properties p, String JavaDoc s) {
610         return getReq(p, s, null);
611     }
612
613     public static int getInt(Properties p, String JavaDoc s, int def) {
614         String JavaDoc 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 JavaDoc e) {
619             throw BindingSupportImpl.getInstance().runtime(
620                     "Expected int: " + s);
621         }
622     }
623
624     public static boolean getBoolean(Properties p, String JavaDoc s, boolean def) {
625         String JavaDoc v = p.getProperty(s);
626         if (v == null) return def;
627         return v.equals("true") || v.equals("on");
628     }
629
630     public static String JavaDoc getClassAndProps(Properties p, String JavaDoc key, Map map) {
631         Set all = p.keySet();
632         String JavaDoc nextKey = key + ".";
633         for (Iterator iter = all.iterator(); iter.hasNext();) {
634             String JavaDoc s = (String JavaDoc)iter.next();
635             if (s.startsWith(nextKey)) {
636                 String JavaDoc newKey = s.substring(nextKey.length());
637                 map.put(newKey, p.getProperty(s));
638             }
639         }
640         return p.getProperty(key);
641     }
642 }
643
Popular Tags