KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.StringListParser;
15 import com.versant.core.metadata.parser.JdoExtensionKeys;
16 import com.versant.core.metadata.parser.JdoExtension;
17
18 import java.util.*;
19 import java.io.*;
20
21 /**
22  * This class is used to convert old jdogenie properties
23  * to new versant properties,
24  */

25 public class PropertyConverter {
26
27     public static final HashMap oldToNew = new HashMap();
28
29     static {
30         String JavaDoc PROJECT_DESCRIPTION = "project.description";
31         oldToNew.put(PROJECT_DESCRIPTION, ConfigParser.PROJECT_DESCRIPTION);
32         String JavaDoc SERVER = "server";
33         oldToNew.put(SERVER, ConfigParser.SERVER);
34         String JavaDoc HOST = "host";
35         oldToNew.put(HOST, "versant.host");
36         String JavaDoc ALLOW_REMOTE_ACCESS = "remote.access";
37         oldToNew.put(ALLOW_REMOTE_ACCESS, ConfigParser.REMOTE_ACCESS);
38         String JavaDoc ALLOW_REMOTE_PMS = "remote.pm";
39         oldToNew.put(ALLOW_REMOTE_PMS, ConfigParser.ALLOW_REMOTE_PMS);
40         String JavaDoc REMOTE_USERNAME = "remote.username";
41         oldToNew.put(REMOTE_USERNAME, "versant.remoteUsername");
42         String JavaDoc REMOTE_PASSWORD = "remote.password";
43         oldToNew.put(REMOTE_PASSWORD, "versant.remotePassword");
44         String JavaDoc RMI_REGISTRY_PORT = "rmi.registry.port";
45         oldToNew.put(RMI_REGISTRY_PORT, ConfigParser.RMI_REGISTRY_PORT);
46         String JavaDoc SERVER_PORT = "server.port";
47         oldToNew.put(SERVER_PORT, ConfigParser.SERVER_PORT);
48         String JavaDoc RMI_CLIENT_SF = "rmi.client.sf";
49         oldToNew.put(RMI_CLIENT_SF, ConfigParser.RMI_CLIENT_SF);
50         String JavaDoc RMI_CSF_IS_SSF = "rmi.csf.is.ssf";
51         oldToNew.put(RMI_CSF_IS_SSF, ConfigParser.RMI_CSF_IS_SSF);
52         String JavaDoc RMI_SERVER_SF = "rmi.server.sf";
53         oldToNew.put(RMI_SERVER_SF, ConfigParser.RMI_SERVER_SF);
54         String JavaDoc ALLOW_PM_CLOSE_WITH_OPEN_TX = "allow.pm.close.with.open.tx";
55         oldToNew.put(ALLOW_PM_CLOSE_WITH_OPEN_TX,
56                 ConfigParser.ALLOW_PM_CLOSE_WITH_OPEN_TX);
57         String JavaDoc PRECOMPILE_NAMED_QUERIES = "precompile.named.queries";
58         oldToNew.put(PRECOMPILE_NAMED_QUERIES,
59                 ConfigParser.PRECOMPILE_NAMED_QUERIES);
60         String JavaDoc CHECK_MODEL_CONSISTENCY_ON_COMMIT = "check.model.consistency.on.commit";
61         oldToNew.put(CHECK_MODEL_CONSISTENCY_ON_COMMIT,
62                 ConfigParser.CHECK_MODEL_CONSISTENCY_ON_COMMIT);
63         String JavaDoc INTERCEPT_DFG_FIELD_ACCESS = "intercept.dfg.field.access";
64         oldToNew.put(INTERCEPT_DFG_FIELD_ACCESS,
65                 ConfigParser.INTERCEPT_DFG_FIELD_ACCESS);
66         String JavaDoc PM_CACHE_REF_TYPE = "pm.cache.ref.type";
67         oldToNew.put(PM_CACHE_REF_TYPE, ConfigParser.PM_CACHE_REF_TYPE);
68
69         String JavaDoc HYPERDRIVE = "hyperdrive";
70         oldToNew.put(HYPERDRIVE, ConfigParser.HYPERDRIVE);
71
72         String JavaDoc PMPOOL_ENABLED = "pmpool.enabled";
73         oldToNew.put(PMPOOL_ENABLED, ConfigParser.PMPOOL_ENABLED);
74         String JavaDoc PMPOOL_MAX_IDLE = "pmpool.maxIdle";
75         oldToNew.put(PMPOOL_MAX_IDLE, ConfigParser.PMPOOL_MAX_IDLE);
76
77         String JavaDoc REMOTE_PMPOOL_ENABLED = "remote.pmpool.enabled";
78         oldToNew.put(REMOTE_PMPOOL_ENABLED, ConfigParser.REMOTE_PMPOOL_ENABLED);
79         String JavaDoc REMOTE_PMPOOL_MAX_IDLE = "remote.pmpool.maxIdle";
80         oldToNew.put(REMOTE_PMPOOL_MAX_IDLE,
81                 ConfigParser.REMOTE_PMPOOL_MAX_IDLE);
82         String JavaDoc REMOTE_PMPOOL_MAX_ACTIVE = "remote.pmpool.maxActive";
83         oldToNew.put(REMOTE_PMPOOL_MAX_ACTIVE,
84                 ConfigParser.REMOTE_PMPOOL_MAX_ACTIVE);
85
86         String JavaDoc FLUSH_THRESHOLD = "flush.threshold";
87         oldToNew.put(FLUSH_THRESHOLD, ConfigParser.FLUSH_THRESHOLD);
88
89         String JavaDoc STORE_COUNT = "storeCount";
90         oldToNew.put(STORE_COUNT, null);
91         String JavaDoc STORE = "store";
92         oldToNew.put(STORE, null);
93         String JavaDoc STORE_NAME = "store0.name";
94         oldToNew.put(STORE_NAME, null);
95         String JavaDoc STORE_TYPE = "store0.type";
96         oldToNew.put(STORE_TYPE, ConfigParser.STORE_TYPE);
97         String JavaDoc STORE_DB = "store0.db";
98         oldToNew.put(STORE_DB, ConfigParser.STORE_DB);
99         String JavaDoc STORE_URL = "store0.url";
100         oldToNew.put(STORE_URL, ConfigParser.STD_CON_URL);
101         String JavaDoc STORE_DRIVER = "store0.driver";
102         oldToNew.put(STORE_DRIVER, ConfigParser.STD_CON_DRIVER_NAME);
103         String JavaDoc STORE_USER = "store0.user";
104         oldToNew.put(STORE_USER, ConfigParser.STD_CON_USER_NAME);
105         String JavaDoc STORE_PASSWORD = "store0.password";
106         oldToNew.put(STORE_PASSWORD, ConfigParser.STD_CON_PASSWORD);
107         String JavaDoc STORE_PROPERTIES = "store0.properties";
108         oldToNew.put(STORE_PROPERTIES, ConfigParser.STORE_PROPERTIES);
109         String JavaDoc STORE_MAX_ACTIVE = "store0.maxActive";
110         oldToNew.put(STORE_MAX_ACTIVE, ConfigParser.STORE_MAX_ACTIVE);
111         String JavaDoc STORE_MAX_IDLE = "store0.maxIdle";
112         oldToNew.put(STORE_MAX_IDLE, ConfigParser.STORE_MAX_IDLE);
113         String JavaDoc STORE_MIN_IDLE = "store0.minIdle";
114         oldToNew.put(STORE_MIN_IDLE, ConfigParser.STORE_MIN_IDLE);
115         String JavaDoc STORE_RESERVED = "store0.reserved";
116         oldToNew.put(STORE_RESERVED, ConfigParser.STORE_RESERVED);
117         String JavaDoc STORE_TYPE_MAPPING_COUNT = "store0.jdbc.type.count";
118         oldToNew.put(STORE_TYPE_MAPPING_COUNT, null);
119         String JavaDoc STORE_JAVATYPE_MAPPING_COUNT = "store0.jdbc.javatype.count";
120         oldToNew.put(STORE_JAVATYPE_MAPPING_COUNT, null);
121         String JavaDoc STORE_NAMEGEN = "store0.jdbc.namegen";
122         oldToNew.put(STORE_NAMEGEN, ConfigParser.STORE_NAMEGEN);
123         String JavaDoc STORE_MIGRATION_CONTROLS = "store0.jdbc.migration";
124         oldToNew.put(STORE_MIGRATION_CONTROLS,
125                 ConfigParser.STORE_MIGRATION_CONTROLS);
126         String JavaDoc STORE_DISABLE_BATCHING = "store0.jdbc.nobatching";
127         oldToNew.put(STORE_DISABLE_BATCHING,
128                 ConfigParser.STORE_DISABLE_BATCHING);
129         String JavaDoc STORE_DISABLE_PS_CACHE = "store0.jdbc.disable.pscache";
130         oldToNew.put(STORE_DISABLE_PS_CACHE,
131                 ConfigParser.STORE_DISABLE_PS_CACHE);
132         String JavaDoc STORE_PS_CACHE_MAX = "store0.pscache.max";
133         oldToNew.put(STORE_PS_CACHE_MAX, ConfigParser.STORE_PS_CACHE_MAX);
134         String JavaDoc STORE_VALIDATE_SQL = "store0.validate.sql";
135         oldToNew.put(STORE_VALIDATE_SQL, ConfigParser.STORE_VALIDATE_SQL);
136         String JavaDoc STORE_INIT_SQL = "store0.init.sql";
137         oldToNew.put(STORE_INIT_SQL, ConfigParser.STORE_INIT_SQL);
138         String JavaDoc STORE_WAIT_FOR_CON_ON_STARTUP = "store0.wait.for.con.on.startup";
139         oldToNew.put(STORE_WAIT_FOR_CON_ON_STARTUP,
140                 ConfigParser.STORE_WAIT_FOR_CON_ON_STARTUP);
141         String JavaDoc STORE_TEST_ON_ALLOC = "store0.test.on.alloc";
142         oldToNew.put(STORE_TEST_ON_ALLOC, ConfigParser.STORE_TEST_ON_ALLOC);
143         String JavaDoc STORE_TEST_ON_RELEASE = "store0.test.on.release";
144         oldToNew.put(STORE_TEST_ON_RELEASE, ConfigParser.STORE_TEST_ON_RELEASE);
145         String JavaDoc STORE_TEST_ON_EXCEPTION = "store0.test.on.exception";
146         oldToNew.put(STORE_TEST_ON_EXCEPTION,
147                 ConfigParser.STORE_TEST_ON_EXCEPTION);
148         String JavaDoc STORE_TEST_WHEN_IDLE = "store0.test.when.idle";
149         oldToNew.put(STORE_TEST_WHEN_IDLE, ConfigParser.STORE_TEST_WHEN_IDLE);
150         String JavaDoc STORE_RETRY_INTERVAL_MS = "store0.retry.interval.ms";
151         oldToNew.put(STORE_RETRY_INTERVAL_MS,
152                 ConfigParser.STORE_RETRY_INTERVAL_MS);
153         String JavaDoc STORE_RETRY_COUNT = "store0.retry.count";
154         oldToNew.put(STORE_RETRY_COUNT, ConfigParser.STORE_RETRY_COUNT);
155         String JavaDoc STORE_VALIDATE_MAPPING_ON_STARTUP = "store0.validate.mapping.on.startup";
156         oldToNew.put(STORE_VALIDATE_MAPPING_ON_STARTUP,
157                 ConfigParser.STORE_VALIDATE_MAPPING_ON_STARTUP);
158         String JavaDoc STORE_CON_TIMEOUT = "store0.con.timeout";
159         oldToNew.put(STORE_CON_TIMEOUT, ConfigParser.STORE_CON_TIMEOUT);
160         String JavaDoc STORE_TEST_INTERVAL = "store0.test.interval";
161         oldToNew.put(STORE_TEST_INTERVAL, ConfigParser.STORE_TEST_INTERVAL);
162         String JavaDoc STORE_ISOLATION_LEVEL = "store0.isolation.level";
163         oldToNew.put(STORE_ISOLATION_LEVEL, ConfigParser.STORE_ISOLATION_LEVEL);
164         String JavaDoc STORE_BLOCK_WHEN_FULL = "store0.block.when.full";
165         oldToNew.put(STORE_BLOCK_WHEN_FULL, ConfigParser.STORE_BLOCK_WHEN_FULL);
166         String JavaDoc STORE_MAX_CON_AGE = "store0.max.con.age";
167         oldToNew.put(STORE_MAX_CON_AGE, ConfigParser.STORE_MAX_CON_AGE);
168         String JavaDoc STORE_MANAGED_ONE_TO_MANY = "store0.managed.one.to.many";
169         oldToNew.put(STORE_MANAGED_ONE_TO_MANY,
170                 ConfigParser.STORE_MANAGED_ONE_TO_MANY);
171         String JavaDoc STORE_MANAGED_MANY_TO_MANY = "store0.managed.many.to.many";
172         oldToNew.put(STORE_MANAGED_MANY_TO_MANY,
173                 ConfigParser.STORE_MANAGED_MANY_TO_MANY);
174         String JavaDoc STORE_SCO_FACTORY_COUNT = "store0.sco.factory.count";
175         oldToNew.put(STORE_SCO_FACTORY_COUNT, null);
176         String JavaDoc STORE_OID_BATCH_SIZE = "store0.OID.batch.size";
177         oldToNew.put(STORE_OID_BATCH_SIZE, ConfigParser.VDS_OID_BATCH_SIZE);
178         String JavaDoc STORE_SCHEMA_DEFINITION = "store0.schema.define";
179         oldToNew.put(STORE_SCHEMA_DEFINITION,
180                 ConfigParser.VDS_SCHEMA_DEFINITION);
181         String JavaDoc STORE_SCHEMA_EVOLUTION = "store0.schema.evolve";
182         oldToNew.put(STORE_SCHEMA_EVOLUTION, ConfigParser.VDS_SCHEMA_EVOLUTION);
183
184         String JavaDoc MDEDIT_SRC_PATH = "mdedit.srcPath";
185         oldToNew.put(MDEDIT_SRC_PATH, ConfigParser.MDEDIT_SRC_PATH);
186         String JavaDoc MDEDIT_CP_COUNT = "mdedit.classPathCount";
187         oldToNew.put(MDEDIT_CP_COUNT, null);
188
189         String JavaDoc JDO_FILE_COUNT = "jdoFileCount";
190         oldToNew.put(JDO_FILE_COUNT, null);
191
192         String JavaDoc EVENT_LOGGING = "event.logging";
193         oldToNew.put(EVENT_LOGGING, ConfigParser.EVENT_LOGGING);
194
195         String JavaDoc DATASTORE_TX_LOCKING = "datastore.tx.locking";
196         oldToNew.put(DATASTORE_TX_LOCKING, ConfigParser.DATASTORE_TX_LOCKING);
197
198         String JavaDoc CACHE_ENABLED = "cache.enabled";
199         oldToNew.put(CACHE_ENABLED, ConfigParser.CACHE_ENABLED);
200         String JavaDoc CACHE_MAX_OBJECTS = "cache.maxobjects";
201         oldToNew.put(CACHE_MAX_OBJECTS, ConfigParser.CACHE_MAX_OBJECTS);
202         String JavaDoc CACHE_LISTENER = "cache.listener";
203         oldToNew.put(CACHE_LISTENER, ConfigParser.CACHE_LISTENER);
204         String JavaDoc CACHE_CLUSTER_TRANSPORT = "cache.cluster.transport";
205         oldToNew.put(CACHE_CLUSTER_TRANSPORT,
206                 ConfigParser.CACHE_CLUSTER_TRANSPORT);
207
208         String JavaDoc QUERY_CACHE_ENABLED = "query.cache.enabled";
209         oldToNew.put(QUERY_CACHE_ENABLED, ConfigParser.QUERY_CACHE_ENABLED);
210         String JavaDoc QUERY_CACHE_MAX_QUERIES = "query.cache.max.queries";
211         oldToNew.put(QUERY_CACHE_MAX_QUERIES,
212                 ConfigParser.QUERY_CACHE_MAX_QUERIES);
213
214         String JavaDoc ANT_DISABLED = "ant.disabled";
215         oldToNew.put(ANT_DISABLED, ConfigParser.ANT_DISABLED);
216         String JavaDoc ANT_BUILDFILE = "ant.buildfile";
217         oldToNew.put(ANT_BUILDFILE, ConfigParser.ANT_BUILDFILE);
218         String JavaDoc ANT_RUN_TARGET = "ant.run.target";
219         oldToNew.put(ANT_RUN_TARGET, ConfigParser.ANT_RUN_TARGET);
220         String JavaDoc ANT_COMPILE = "ant.compile";
221         oldToNew.put(ANT_COMPILE, ConfigParser.ANT_COMPILE);
222         String JavaDoc ANT_ARGS = "ant.args";
223         oldToNew.put(ANT_ARGS, ConfigParser.ANT_ARGS);
224         String JavaDoc ANT_SHOW_ALL_TARGETS = "ant.show.all.targets";
225         oldToNew.put(ANT_SHOW_ALL_TARGETS, ConfigParser.ANT_SHOW_ALL_TARGETS);
226
227         String JavaDoc SCRIPT_DIR = "script.dir";
228         oldToNew.put(SCRIPT_DIR, ConfigParser.SCRIPT_DIR);
229
230         String JavaDoc METRIC_SNAPSHOT_INTERVAL_MS = "metric.snapshot.interval.ms";
231         oldToNew.put(METRIC_SNAPSHOT_INTERVAL_MS,
232                 ConfigParser.METRIC_SNAPSHOT_INTERVAL_MS);
233         String JavaDoc METRIC_STORE_CAPACITY = "metric.store.capacity";
234         oldToNew.put(METRIC_STORE_CAPACITY, ConfigParser.METRIC_STORE_CAPACITY);
235
236         String JavaDoc LOG_DOWNLOADER = "log.downloader";
237         oldToNew.put(LOG_DOWNLOADER, ConfigParser.LOG_DOWNLOADER);
238
239         String JavaDoc EXTERNALIZER_COUNT = "externalizer.count";
240         oldToNew.put(EXTERNALIZER_COUNT, null);
241
242         String JavaDoc TESTING = "testing";
243         oldToNew.put(TESTING, ConfigParser.TESTING);
244
245     }
246
247     
248     public static void main(String JavaDoc[] args) {
249         String JavaDoc src = null;
250         String JavaDoc dest = null;
251         for (int i = 0; i < args.length; i++) {
252             if (i == 0) src = args[i];
253             if (i == 1) dest = args[i];
254         }
255         if (src == null) {
256             printHelp();
257         }
258         File srcFile = new File(src);
259         if (!srcFile.exists()) {
260             System.out.println("Input file " + src + " does not exist.");
261             printHelp();
262             System.exit(-1);
263         }
264         File destFile = null;
265         if (dest == null) {
266             int last = src.lastIndexOf('.');
267             dest = src.substring(0, last) + ".properties";
268             destFile = new File(dest);
269             if (destFile.exists()) {
270                 System.out.println(
271                         "File " + dest + " will be created by this tool,");
272                 System.out.println(
273                         "but it already exists. (we do not want to overide existing files) ");
274                 System.exit(-1);
275
276             }
277         }
278         if (dest != null) {
279             destFile = new File(dest);
280             if (!destFile.exists()) {
281                 try {
282                     destFile.createNewFile();
283                 } catch (IOException e) {
284                     System.out.println("Could not create file " + dest);
285                     System.exit(-1);
286                 }
287             }
288         }
289         Properties p = new Properties();
290         try {
291             InputStream in = null;
292             try {
293                 in = new FileInputStream(src);
294
295                 try {
296                     p.load(in);
297                 } catch (IOException e) {
298                     e.printStackTrace();
299                 }
300             } finally {
301                 if (in != null) in.close();
302             }
303         } catch (IOException e) {
304             e.printStackTrace();
305         }
306
307         try {
308             ArrayList lines = new ArrayList();
309             BufferedReader reader = null;
310             BufferedWriter writer = null;
311             try {
312                 reader = new BufferedReader(new FileReader(srcFile));
313                 String JavaDoc[] newLines = null;
314                 // Read file
315
while (true) {
316                     String JavaDoc line = reader.readLine();
317                     if (line == null) {
318                         break;
319                     }
320                     newLines = getConvertedLine(line);
321                     for (int i = 0; i < newLines.length; i++) {
322                         lines.add(newLines[i]);
323                     }
324                 }
325             } finally {
326                 try {
327                     reader.close();
328                 } catch (IOException ex) {
329                 }
330             }
331             try {
332                 writer = new BufferedWriter(new FileWriter(destFile, false));
333                 // Write file
334
Iterator iter = lines.iterator();
335                 while (iter.hasNext()) {
336                     writer.write((String JavaDoc)iter.next());
337                     writer.newLine();
338                 }
339             } finally {
340                 try {
341                     writer.close();
342                 } catch (IOException ex) {
343                     //hide
344
}
345             }
346         } catch (IOException e) {
347             e.printStackTrace();
348         }
349     }
350     
351
352     private static String JavaDoc[] getConvertedLine(String JavaDoc line) {
353         if (line.trim().equals("")) {
354             return new String JavaDoc[]{line};
355         } else if (line.trim().startsWith("#")) {
356             return new String JavaDoc[]{line};
357         } else {
358             return getPropLines(line);
359         }
360     }
361
362     private static String JavaDoc[] getPropLines(String JavaDoc line) {
363         int first = line.indexOf('=');
364         Properties p = new Properties();
365         p.setProperty(line.substring(0, first),
366                 line.substring(first + 1, line.length()));
367         convert(p, true);
368         Set set = p.keySet();
369         String JavaDoc[] props = new String JavaDoc[set.size()];
370         StringBuffer JavaDoc newLine = null;
371         int i = 0;
372         for (Iterator iter = set.iterator(); iter.hasNext();) {
373             String JavaDoc s = (String JavaDoc)iter.next();
374             newLine = new StringBuffer JavaDoc();
375             newLine.append(s);
376             newLine.append("=");
377             newLine.append(p.getProperty(s));
378             props[i++] = newLine.toString();
379         }
380         return props;
381     }
382
383     private static void printHelp() {
384         System.out.println(
385                 "usage: com.versant.core.common.config.PropertyConverter <inputFile> [<outputFile>]");
386         System.out.println(
387                 " <inputFile> The old *.jdogenie file to be converted.");
388         System.out.println(
389                 " If output file is not specified then the output");
390         System.out.println(
391                 " file will be <inputFile>.properties");
392         System.out.println(" <outputFile> The new file .properties file.");
393         System.exit(-1);
394     }
395
396     /**
397      * Converts the old jdogenie properties to the new versant properties.
398      *
399      * @param original
400      * @return the new versant properties
401      */

402     public static boolean convert(Properties original) {
403         return convert(original, false);
404     }
405
406     /**
407      * Converts the old jdogenie properties to the new versant properties.
408      *
409      * @param original
410      * @return the new versant properties
411      */

412     private static boolean convert(Properties original, boolean converted) {
413         Properties oldProps = (Properties)original.clone();
414         Properties newProps = new Properties();
415         ArrayList list = new ArrayList(oldProps.keySet());
416         Collections.sort(list);
417         for (Iterator iter = list.iterator(); iter.hasNext();) {
418             String JavaDoc key = (String JavaDoc)iter.next();
419             if (oldToNew.containsKey(key)) {
420                 if (oldToNew.get(key) != null) {
421                     newProps.setProperty((String JavaDoc)oldToNew.get(key),
422                             oldProps.getProperty(key));
423                 }
424                 // ignore prop if oldToNew is null
425
converted = true;
426             } else {
427                 String JavaDoc STORE_EXT = "store0.ext.";
428                 String JavaDoc STORE_TYPE_MAPPING = "store0.jdbc.type.";
429                 String JavaDoc STORE_JAVATYPE_MAPPING = "store0.jdbc.javatype.";
430                 String JavaDoc STORE_SCO_FACTORY_MAPPING = "store0.sco.factory.mapping";
431                 String JavaDoc JDO = "jdo";
432                 String JavaDoc METRIC_USER = "metric.user.";
433                 String JavaDoc EXTERNALIZER = "externalizer.";
434                 String JavaDoc DIAGRAM = "diagram";
435                 String JavaDoc MDEDIT_CP = "mdedit.cp";
436                 if (key.startsWith(STORE_EXT)) {
437                     String JavaDoc newKey = ConfigParser.STORE_EXT +
438                             key.substring(STORE_EXT.length(), key.length());
439                     newProps.setProperty(newKey, oldProps.getProperty(key));
440                     converted = true;
441                 } else if (key.startsWith(STORE_TYPE_MAPPING)) {
442                     String JavaDoc newKey = ConfigParser.STORE_TYPE_MAPPING +
443                             key.substring(STORE_TYPE_MAPPING.length(),
444                                     key.length());
445                     newProps.setProperty(newKey, oldProps.getProperty(key));
446                     converted = true;
447                 } else if (key.startsWith(STORE_JAVATYPE_MAPPING)) {
448                     String JavaDoc newKey = ConfigParser.STORE_JAVATYPE_MAPPING +
449                             key.substring(STORE_JAVATYPE_MAPPING.length(),
450                                     key.length());
451                     newProps.setProperty(newKey, oldProps.getProperty(key));
452                     converted = true;
453                 } else if (key.startsWith(STORE_SCO_FACTORY_MAPPING)) {
454                     String JavaDoc newKey = ConfigParser.STORE_SCO_FACTORY_MAPPING +
455                             key.substring(STORE_SCO_FACTORY_MAPPING.length(),
456                                     key.length());
457                     newProps.setProperty(newKey, oldProps.getProperty(key));
458                 } else if (key.startsWith(JDO)) {
459                     String JavaDoc newKey = ConfigParser.JDO +
460                             key.substring(JDO.length(),
461                                     key.length());
462                     newProps.setProperty(newKey, oldProps.getProperty(key));
463                     converted = true;
464                 } else if (key.startsWith(METRIC_USER)) {
465                     String JavaDoc newKey = ConfigParser.METRIC_USER +
466                             key.substring(METRIC_USER.length(),
467                                     key.length());
468                     newProps.setProperty(newKey, oldProps.getProperty(key));
469                     converted = true;
470                 } else if (key.startsWith(EXTERNALIZER)) {
471                     String JavaDoc newKey = ConfigParser.EXTERNALIZER +
472                             key.substring(EXTERNALIZER.length(),
473                                     key.length());
474                     newProps.setProperty(newKey, oldProps.getProperty(key));
475                     converted = true;
476                 } else if (key.startsWith(DIAGRAM)) {
477                     String JavaDoc newKey = ConfigParser.DIAGRAM +
478                             key.substring(DIAGRAM.length(),
479                                     key.length());
480                     newProps.setProperty(newKey, oldProps.getProperty(key));
481                     converted = true;
482                 } else if (key.startsWith(MDEDIT_CP)) {
483                     String JavaDoc newKey = ConfigParser.MDEDIT_CP +
484                             key.substring(MDEDIT_CP.length(),
485                                     key.length());
486                     newProps.setProperty(newKey, oldProps.getProperty(key));
487                     converted = true;
488                 } else {
489
490                     newProps.put(key, oldProps.get(key));
491                     //newProps.setProperty(key, oldProps.getProperty(key));
492
}
493             }
494         }
495         if (converted) {
496             fillAsProps(newProps, ConfigParser.EVENT_LOGGING); //
497
fillAsProps(newProps, ConfigParser.RMI_CLIENT_SF); //
498
fillAsProps(newProps, ConfigParser.RMI_SERVER_SF); //
499
fillAsProps(newProps, ConfigParser.CACHE_CLUSTER_TRANSPORT); //
500
fillAsProps(newProps, ConfigParser.CACHE_LISTENER);
501             fillAsProps(newProps, ConfigParser.STORE_NAMEGEN); //
502
fillAsProps(newProps, ConfigParser.STORE_MIGRATION_CONTROLS); //
503
fillAsProps(newProps,
504                     ConfigParser.STORE_EXT +
505                     JdoExtension.toKeyString(
506                             JdoExtensionKeys.JDBC_KEY_GENERATOR)); //
507
fillAsProps(newProps, ConfigParser.LOG_DOWNLOADER); //
508
fillExternalizer(newProps);
509         }
510
511         original.clear();
512         original.putAll(newProps);
513         if ("za.co.hemtech.jdo.client.BootstrapPMF".equals(original.getProperty(
514                 ConfigParser.PMF_CLASS))) {
515             original.setProperty(ConfigParser.PMF_CLASS,
516                     "com.versant.core.jdo.BootstrapPMF");
517         }
518         return converted;
519     }
520
521     /**
522      * Fill all the given properties into newProps.
523      *
524      * @param newProps
525      */

526     private static void fillAsProps(Properties newProps, String JavaDoc lookup) {
527         String JavaDoc s = newProps.getProperty(lookup);
528         if (s != null) {
529             HashMap logging = new HashMap(17);
530             StringListParser lp = new StringListParser(s);
531             String JavaDoc name = null; // skip unused class name
532
try {
533                 name = lp.nextQuotedString(); // skip unused class name
534
} catch (IllegalStateException JavaDoc e) {
535                 return;
536             }
537             lp.nextProperties(logging);
538             Set names = logging.keySet();
539             for (Iterator iter = names.iterator(); iter.hasNext();) {
540                 String JavaDoc key = (String JavaDoc)iter.next();
541                 newProps.setProperty(lookup + "." + key,
542                         (String JavaDoc)logging.get(key));
543             }
544             newProps.remove(lookup);
545             if (name != null) {
546                 newProps.setProperty(lookup, name);
547             }
548         }
549     }
550
551     /**
552      * Fill all the externalizer properties into newProps.
553      *
554      * @param newProps
555      */

556     private static void fillExternalizer(Properties newProps) {
557         String JavaDoc s;
558         for (int i = 0; i < ConfigParser.MAX_EXTERNALIZER_COUNT; i++) {
559             String JavaDoc key = ConfigParser.EXTERNALIZER + i;
560             s = newProps.getProperty(key);
561             if (s != null) {
562                 StringListParser lp = new StringListParser(s);
563                 Object JavaDoc o = newProps.setProperty(key + ConfigParser.EXTERNALIZER_TYPE,
564                         lp.nextString());
565                 if (o != null) {
566                     newProps.setProperty(key + ConfigParser.EXTERNALIZER_TYPE,
567                             (String JavaDoc)o);
568                     continue;
569                 }
570                 boolean enabled = lp.nextBoolean();
571                 newProps.setProperty(key + ConfigParser.EXTERNALIZER_ENABLED,
572                         (enabled ? "true" : "false"));
573                 String JavaDoc externalizerName = lp.nextQuotedString();
574                 if (externalizerName != null) {
575                     newProps.setProperty(key + ConfigParser.EXTERNALIZER_CLASS,
576                             externalizerName);
577                 }
578
579                 HashMap typeKeys = new HashMap(17);
580                 lp.nextProperties(typeKeys);
581                 Set names = typeKeys.keySet();
582                 for (Iterator iter = names.iterator(); iter.hasNext();) {
583                     String JavaDoc typeKey = (String JavaDoc)iter.next();
584                     newProps.setProperty(key +
585                             ConfigParser.EXTERNALIZER_CLASS + "." + typeKey,
586                             (String JavaDoc)typeKeys.get(typeKey));
587                 }
588                 newProps.remove(key);
589             }
590         }
591     }
592
593 }
594
595
Popular Tags