Source Code Cross Referenced for PropertyConverter.java in  » Testing » PolePosition-0.20 » com » versant » core » common » config » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » PolePosition 0.20 » com.versant.core.common.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1998 - 2005 Versant Corporation
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         * Versant Corporation - initial API and implementation
010:         */
011:        package com.versant.core.common.config;
012:
013:        import com.versant.core.util.StringListParser;
014:        import com.versant.core.metadata.parser.JdoExtensionKeys;
015:        import com.versant.core.metadata.parser.JdoExtension;
016:
017:        import java.util.*;
018:        import java.io.*;
019:
020:        /**
021:         * This class is used to convert old jdogenie properties
022:         * to new versant properties,
023:         */
024:        public class PropertyConverter {
025:
026:            public static final HashMap oldToNew = new HashMap();
027:
028:            static {
029:                String PROJECT_DESCRIPTION = "project.description";
030:                oldToNew.put(PROJECT_DESCRIPTION,
031:                        ConfigParser.PROJECT_DESCRIPTION);
032:                String SERVER = "server";
033:                oldToNew.put(SERVER, ConfigParser.SERVER);
034:                String HOST = "host";
035:                oldToNew.put(HOST, "versant.host");
036:                String ALLOW_REMOTE_ACCESS = "remote.access";
037:                oldToNew.put(ALLOW_REMOTE_ACCESS, ConfigParser.REMOTE_ACCESS);
038:                String ALLOW_REMOTE_PMS = "remote.pm";
039:                oldToNew.put(ALLOW_REMOTE_PMS, ConfigParser.ALLOW_REMOTE_PMS);
040:                String REMOTE_USERNAME = "remote.username";
041:                oldToNew.put(REMOTE_USERNAME, "versant.remoteUsername");
042:                String REMOTE_PASSWORD = "remote.password";
043:                oldToNew.put(REMOTE_PASSWORD, "versant.remotePassword");
044:                String RMI_REGISTRY_PORT = "rmi.registry.port";
045:                oldToNew.put(RMI_REGISTRY_PORT, ConfigParser.RMI_REGISTRY_PORT);
046:                String SERVER_PORT = "server.port";
047:                oldToNew.put(SERVER_PORT, ConfigParser.SERVER_PORT);
048:                String RMI_CLIENT_SF = "rmi.client.sf";
049:                oldToNew.put(RMI_CLIENT_SF, ConfigParser.RMI_CLIENT_SF);
050:                String RMI_CSF_IS_SSF = "rmi.csf.is.ssf";
051:                oldToNew.put(RMI_CSF_IS_SSF, ConfigParser.RMI_CSF_IS_SSF);
052:                String RMI_SERVER_SF = "rmi.server.sf";
053:                oldToNew.put(RMI_SERVER_SF, ConfigParser.RMI_SERVER_SF);
054:                String ALLOW_PM_CLOSE_WITH_OPEN_TX = "allow.pm.close.with.open.tx";
055:                oldToNew.put(ALLOW_PM_CLOSE_WITH_OPEN_TX,
056:                        ConfigParser.ALLOW_PM_CLOSE_WITH_OPEN_TX);
057:                String PRECOMPILE_NAMED_QUERIES = "precompile.named.queries";
058:                oldToNew.put(PRECOMPILE_NAMED_QUERIES,
059:                        ConfigParser.PRECOMPILE_NAMED_QUERIES);
060:                String CHECK_MODEL_CONSISTENCY_ON_COMMIT = "check.model.consistency.on.commit";
061:                oldToNew.put(CHECK_MODEL_CONSISTENCY_ON_COMMIT,
062:                        ConfigParser.CHECK_MODEL_CONSISTENCY_ON_COMMIT);
063:                String INTERCEPT_DFG_FIELD_ACCESS = "intercept.dfg.field.access";
064:                oldToNew.put(INTERCEPT_DFG_FIELD_ACCESS,
065:                        ConfigParser.INTERCEPT_DFG_FIELD_ACCESS);
066:                String PM_CACHE_REF_TYPE = "pm.cache.ref.type";
067:                oldToNew.put(PM_CACHE_REF_TYPE, ConfigParser.PM_CACHE_REF_TYPE);
068:
069:                String HYPERDRIVE = "hyperdrive";
070:                oldToNew.put(HYPERDRIVE, ConfigParser.HYPERDRIVE);
071:
072:                String PMPOOL_ENABLED = "pmpool.enabled";
073:                oldToNew.put(PMPOOL_ENABLED, ConfigParser.PMPOOL_ENABLED);
074:                String PMPOOL_MAX_IDLE = "pmpool.maxIdle";
075:                oldToNew.put(PMPOOL_MAX_IDLE, ConfigParser.PMPOOL_MAX_IDLE);
076:
077:                String REMOTE_PMPOOL_ENABLED = "remote.pmpool.enabled";
078:                oldToNew.put(REMOTE_PMPOOL_ENABLED,
079:                        ConfigParser.REMOTE_PMPOOL_ENABLED);
080:                String REMOTE_PMPOOL_MAX_IDLE = "remote.pmpool.maxIdle";
081:                oldToNew.put(REMOTE_PMPOOL_MAX_IDLE,
082:                        ConfigParser.REMOTE_PMPOOL_MAX_IDLE);
083:                String REMOTE_PMPOOL_MAX_ACTIVE = "remote.pmpool.maxActive";
084:                oldToNew.put(REMOTE_PMPOOL_MAX_ACTIVE,
085:                        ConfigParser.REMOTE_PMPOOL_MAX_ACTIVE);
086:
087:                String FLUSH_THRESHOLD = "flush.threshold";
088:                oldToNew.put(FLUSH_THRESHOLD, ConfigParser.FLUSH_THRESHOLD);
089:
090:                String STORE_COUNT = "storeCount";
091:                oldToNew.put(STORE_COUNT, null);
092:                String STORE = "store";
093:                oldToNew.put(STORE, null);
094:                String STORE_NAME = "store0.name";
095:                oldToNew.put(STORE_NAME, null);
096:                String STORE_TYPE = "store0.type";
097:                oldToNew.put(STORE_TYPE, ConfigParser.STORE_TYPE);
098:                String STORE_DB = "store0.db";
099:                oldToNew.put(STORE_DB, ConfigParser.STORE_DB);
100:                String STORE_URL = "store0.url";
101:                oldToNew.put(STORE_URL, ConfigParser.STD_CON_URL);
102:                String STORE_DRIVER = "store0.driver";
103:                oldToNew.put(STORE_DRIVER, ConfigParser.STD_CON_DRIVER_NAME);
104:                String STORE_USER = "store0.user";
105:                oldToNew.put(STORE_USER, ConfigParser.STD_CON_USER_NAME);
106:                String STORE_PASSWORD = "store0.password";
107:                oldToNew.put(STORE_PASSWORD, ConfigParser.STD_CON_PASSWORD);
108:                String STORE_PROPERTIES = "store0.properties";
109:                oldToNew.put(STORE_PROPERTIES, ConfigParser.STORE_PROPERTIES);
110:                String STORE_MAX_ACTIVE = "store0.maxActive";
111:                oldToNew.put(STORE_MAX_ACTIVE, ConfigParser.STORE_MAX_ACTIVE);
112:                String STORE_MAX_IDLE = "store0.maxIdle";
113:                oldToNew.put(STORE_MAX_IDLE, ConfigParser.STORE_MAX_IDLE);
114:                String STORE_MIN_IDLE = "store0.minIdle";
115:                oldToNew.put(STORE_MIN_IDLE, ConfigParser.STORE_MIN_IDLE);
116:                String STORE_RESERVED = "store0.reserved";
117:                oldToNew.put(STORE_RESERVED, ConfigParser.STORE_RESERVED);
118:                String STORE_TYPE_MAPPING_COUNT = "store0.jdbc.type.count";
119:                oldToNew.put(STORE_TYPE_MAPPING_COUNT, null);
120:                String STORE_JAVATYPE_MAPPING_COUNT = "store0.jdbc.javatype.count";
121:                oldToNew.put(STORE_JAVATYPE_MAPPING_COUNT, null);
122:                String STORE_NAMEGEN = "store0.jdbc.namegen";
123:                oldToNew.put(STORE_NAMEGEN, ConfigParser.STORE_NAMEGEN);
124:                String STORE_MIGRATION_CONTROLS = "store0.jdbc.migration";
125:                oldToNew.put(STORE_MIGRATION_CONTROLS,
126:                        ConfigParser.STORE_MIGRATION_CONTROLS);
127:                String STORE_DISABLE_BATCHING = "store0.jdbc.nobatching";
128:                oldToNew.put(STORE_DISABLE_BATCHING,
129:                        ConfigParser.STORE_DISABLE_BATCHING);
130:                String STORE_DISABLE_PS_CACHE = "store0.jdbc.disable.pscache";
131:                oldToNew.put(STORE_DISABLE_PS_CACHE,
132:                        ConfigParser.STORE_DISABLE_PS_CACHE);
133:                String STORE_PS_CACHE_MAX = "store0.pscache.max";
134:                oldToNew.put(STORE_PS_CACHE_MAX,
135:                        ConfigParser.STORE_PS_CACHE_MAX);
136:                String STORE_VALIDATE_SQL = "store0.validate.sql";
137:                oldToNew.put(STORE_VALIDATE_SQL,
138:                        ConfigParser.STORE_VALIDATE_SQL);
139:                String STORE_INIT_SQL = "store0.init.sql";
140:                oldToNew.put(STORE_INIT_SQL, ConfigParser.STORE_INIT_SQL);
141:                String STORE_WAIT_FOR_CON_ON_STARTUP = "store0.wait.for.con.on.startup";
142:                oldToNew.put(STORE_WAIT_FOR_CON_ON_STARTUP,
143:                        ConfigParser.STORE_WAIT_FOR_CON_ON_STARTUP);
144:                String STORE_TEST_ON_ALLOC = "store0.test.on.alloc";
145:                oldToNew.put(STORE_TEST_ON_ALLOC,
146:                        ConfigParser.STORE_TEST_ON_ALLOC);
147:                String STORE_TEST_ON_RELEASE = "store0.test.on.release";
148:                oldToNew.put(STORE_TEST_ON_RELEASE,
149:                        ConfigParser.STORE_TEST_ON_RELEASE);
150:                String STORE_TEST_ON_EXCEPTION = "store0.test.on.exception";
151:                oldToNew.put(STORE_TEST_ON_EXCEPTION,
152:                        ConfigParser.STORE_TEST_ON_EXCEPTION);
153:                String STORE_TEST_WHEN_IDLE = "store0.test.when.idle";
154:                oldToNew.put(STORE_TEST_WHEN_IDLE,
155:                        ConfigParser.STORE_TEST_WHEN_IDLE);
156:                String STORE_RETRY_INTERVAL_MS = "store0.retry.interval.ms";
157:                oldToNew.put(STORE_RETRY_INTERVAL_MS,
158:                        ConfigParser.STORE_RETRY_INTERVAL_MS);
159:                String STORE_RETRY_COUNT = "store0.retry.count";
160:                oldToNew.put(STORE_RETRY_COUNT, ConfigParser.STORE_RETRY_COUNT);
161:                String STORE_VALIDATE_MAPPING_ON_STARTUP = "store0.validate.mapping.on.startup";
162:                oldToNew.put(STORE_VALIDATE_MAPPING_ON_STARTUP,
163:                        ConfigParser.STORE_VALIDATE_MAPPING_ON_STARTUP);
164:                String STORE_CON_TIMEOUT = "store0.con.timeout";
165:                oldToNew.put(STORE_CON_TIMEOUT, ConfigParser.STORE_CON_TIMEOUT);
166:                String STORE_TEST_INTERVAL = "store0.test.interval";
167:                oldToNew.put(STORE_TEST_INTERVAL,
168:                        ConfigParser.STORE_TEST_INTERVAL);
169:                String STORE_ISOLATION_LEVEL = "store0.isolation.level";
170:                oldToNew.put(STORE_ISOLATION_LEVEL,
171:                        ConfigParser.STORE_ISOLATION_LEVEL);
172:                String STORE_BLOCK_WHEN_FULL = "store0.block.when.full";
173:                oldToNew.put(STORE_BLOCK_WHEN_FULL,
174:                        ConfigParser.STORE_BLOCK_WHEN_FULL);
175:                String STORE_MAX_CON_AGE = "store0.max.con.age";
176:                oldToNew.put(STORE_MAX_CON_AGE, ConfigParser.STORE_MAX_CON_AGE);
177:                String STORE_MANAGED_ONE_TO_MANY = "store0.managed.one.to.many";
178:                oldToNew.put(STORE_MANAGED_ONE_TO_MANY,
179:                        ConfigParser.STORE_MANAGED_ONE_TO_MANY);
180:                String STORE_MANAGED_MANY_TO_MANY = "store0.managed.many.to.many";
181:                oldToNew.put(STORE_MANAGED_MANY_TO_MANY,
182:                        ConfigParser.STORE_MANAGED_MANY_TO_MANY);
183:                String STORE_SCO_FACTORY_COUNT = "store0.sco.factory.count";
184:                oldToNew.put(STORE_SCO_FACTORY_COUNT, null);
185:                String STORE_OID_BATCH_SIZE = "store0.OID.batch.size";
186:                oldToNew.put(STORE_OID_BATCH_SIZE,
187:                        ConfigParser.VDS_OID_BATCH_SIZE);
188:                String STORE_SCHEMA_DEFINITION = "store0.schema.define";
189:                oldToNew.put(STORE_SCHEMA_DEFINITION,
190:                        ConfigParser.VDS_SCHEMA_DEFINITION);
191:                String STORE_SCHEMA_EVOLUTION = "store0.schema.evolve";
192:                oldToNew.put(STORE_SCHEMA_EVOLUTION,
193:                        ConfigParser.VDS_SCHEMA_EVOLUTION);
194:
195:                String MDEDIT_SRC_PATH = "mdedit.srcPath";
196:                oldToNew.put(MDEDIT_SRC_PATH, ConfigParser.MDEDIT_SRC_PATH);
197:                String MDEDIT_CP_COUNT = "mdedit.classPathCount";
198:                oldToNew.put(MDEDIT_CP_COUNT, null);
199:
200:                String JDO_FILE_COUNT = "jdoFileCount";
201:                oldToNew.put(JDO_FILE_COUNT, null);
202:
203:                String EVENT_LOGGING = "event.logging";
204:                oldToNew.put(EVENT_LOGGING, ConfigParser.EVENT_LOGGING);
205:
206:                String DATASTORE_TX_LOCKING = "datastore.tx.locking";
207:                oldToNew.put(DATASTORE_TX_LOCKING,
208:                        ConfigParser.DATASTORE_TX_LOCKING);
209:
210:                String CACHE_ENABLED = "cache.enabled";
211:                oldToNew.put(CACHE_ENABLED, ConfigParser.CACHE_ENABLED);
212:                String CACHE_MAX_OBJECTS = "cache.maxobjects";
213:                oldToNew.put(CACHE_MAX_OBJECTS, ConfigParser.CACHE_MAX_OBJECTS);
214:                String CACHE_LISTENER = "cache.listener";
215:                oldToNew.put(CACHE_LISTENER, ConfigParser.CACHE_LISTENER);
216:                String CACHE_CLUSTER_TRANSPORT = "cache.cluster.transport";
217:                oldToNew.put(CACHE_CLUSTER_TRANSPORT,
218:                        ConfigParser.CACHE_CLUSTER_TRANSPORT);
219:
220:                String QUERY_CACHE_ENABLED = "query.cache.enabled";
221:                oldToNew.put(QUERY_CACHE_ENABLED,
222:                        ConfigParser.QUERY_CACHE_ENABLED);
223:                String QUERY_CACHE_MAX_QUERIES = "query.cache.max.queries";
224:                oldToNew.put(QUERY_CACHE_MAX_QUERIES,
225:                        ConfigParser.QUERY_CACHE_MAX_QUERIES);
226:
227:                String ANT_DISABLED = "ant.disabled";
228:                oldToNew.put(ANT_DISABLED, ConfigParser.ANT_DISABLED);
229:                String ANT_BUILDFILE = "ant.buildfile";
230:                oldToNew.put(ANT_BUILDFILE, ConfigParser.ANT_BUILDFILE);
231:                String ANT_RUN_TARGET = "ant.run.target";
232:                oldToNew.put(ANT_RUN_TARGET, ConfigParser.ANT_RUN_TARGET);
233:                String ANT_COMPILE = "ant.compile";
234:                oldToNew.put(ANT_COMPILE, ConfigParser.ANT_COMPILE);
235:                String ANT_ARGS = "ant.args";
236:                oldToNew.put(ANT_ARGS, ConfigParser.ANT_ARGS);
237:                String ANT_SHOW_ALL_TARGETS = "ant.show.all.targets";
238:                oldToNew.put(ANT_SHOW_ALL_TARGETS,
239:                        ConfigParser.ANT_SHOW_ALL_TARGETS);
240:
241:                String SCRIPT_DIR = "script.dir";
242:                oldToNew.put(SCRIPT_DIR, ConfigParser.SCRIPT_DIR);
243:
244:                String METRIC_SNAPSHOT_INTERVAL_MS = "metric.snapshot.interval.ms";
245:                oldToNew.put(METRIC_SNAPSHOT_INTERVAL_MS,
246:                        ConfigParser.METRIC_SNAPSHOT_INTERVAL_MS);
247:                String METRIC_STORE_CAPACITY = "metric.store.capacity";
248:                oldToNew.put(METRIC_STORE_CAPACITY,
249:                        ConfigParser.METRIC_STORE_CAPACITY);
250:
251:                String LOG_DOWNLOADER = "log.downloader";
252:                oldToNew.put(LOG_DOWNLOADER, ConfigParser.LOG_DOWNLOADER);
253:
254:                String EXTERNALIZER_COUNT = "externalizer.count";
255:                oldToNew.put(EXTERNALIZER_COUNT, null);
256:
257:                String TESTING = "testing";
258:                oldToNew.put(TESTING, ConfigParser.TESTING);
259:
260:            }
261:
262:            public static void main(String[] args) {
263:                String src = null;
264:                String dest = null;
265:                for (int i = 0; i < args.length; i++) {
266:                    if (i == 0)
267:                        src = args[i];
268:                    if (i == 1)
269:                        dest = args[i];
270:                }
271:                if (src == null) {
272:                    printHelp();
273:                }
274:                File srcFile = new File(src);
275:                if (!srcFile.exists()) {
276:                    System.out
277:                            .println("Input file " + src + " does not exist.");
278:                    printHelp();
279:                    System.exit(-1);
280:                }
281:                File destFile = null;
282:                if (dest == null) {
283:                    int last = src.lastIndexOf('.');
284:                    dest = src.substring(0, last) + ".properties";
285:                    destFile = new File(dest);
286:                    if (destFile.exists()) {
287:                        System.out.println("File " + dest
288:                                + " will be created by this tool,");
289:                        System.out
290:                                .println("but it already exists. (we do not want to overide existing files) ");
291:                        System.exit(-1);
292:
293:                    }
294:                }
295:                if (dest != null) {
296:                    destFile = new File(dest);
297:                    if (!destFile.exists()) {
298:                        try {
299:                            destFile.createNewFile();
300:                        } catch (IOException e) {
301:                            System.out.println("Could not create file " + dest);
302:                            System.exit(-1);
303:                        }
304:                    }
305:                }
306:                Properties p = new Properties();
307:                try {
308:                    InputStream in = null;
309:                    try {
310:                        in = new FileInputStream(src);
311:
312:                        try {
313:                            p.load(in);
314:                        } catch (IOException e) {
315:                            e.printStackTrace();
316:                        }
317:                    } finally {
318:                        if (in != null)
319:                            in.close();
320:                    }
321:                } catch (IOException e) {
322:                    e.printStackTrace();
323:                }
324:
325:                try {
326:                    ArrayList lines = new ArrayList();
327:                    BufferedReader reader = null;
328:                    BufferedWriter writer = null;
329:                    try {
330:                        reader = new BufferedReader(new FileReader(srcFile));
331:                        String[] newLines = null;
332:                        // Read file
333:                        while (true) {
334:                            String line = reader.readLine();
335:                            if (line == null) {
336:                                break;
337:                            }
338:                            newLines = getConvertedLine(line);
339:                            for (int i = 0; i < newLines.length; i++) {
340:                                lines.add(newLines[i]);
341:                            }
342:                        }
343:                    } finally {
344:                        try {
345:                            reader.close();
346:                        } catch (IOException ex) {
347:                        }
348:                    }
349:                    try {
350:                        writer = new BufferedWriter(new FileWriter(destFile,
351:                                false));
352:                        // Write file
353:                        Iterator iter = lines.iterator();
354:                        while (iter.hasNext()) {
355:                            writer.write((String) iter.next());
356:                            writer.newLine();
357:                        }
358:                    } finally {
359:                        try {
360:                            writer.close();
361:                        } catch (IOException ex) {
362:                            //hide
363:                        }
364:                    }
365:                } catch (IOException e) {
366:                    e.printStackTrace();
367:                }
368:            }
369:
370:            private static String[] getConvertedLine(String line) {
371:                if (line.trim().equals("")) {
372:                    return new String[] { line };
373:                } else if (line.trim().startsWith("#")) {
374:                    return new String[] { line };
375:                } else {
376:                    return getPropLines(line);
377:                }
378:            }
379:
380:            private static String[] getPropLines(String line) {
381:                int first = line.indexOf('=');
382:                Properties p = new Properties();
383:                p.setProperty(line.substring(0, first), line.substring(
384:                        first + 1, line.length()));
385:                convert(p, true);
386:                Set set = p.keySet();
387:                String[] props = new String[set.size()];
388:                StringBuffer newLine = null;
389:                int i = 0;
390:                for (Iterator iter = set.iterator(); iter.hasNext();) {
391:                    String s = (String) iter.next();
392:                    newLine = new StringBuffer();
393:                    newLine.append(s);
394:                    newLine.append("=");
395:                    newLine.append(p.getProperty(s));
396:                    props[i++] = newLine.toString();
397:                }
398:                return props;
399:            }
400:
401:            private static void printHelp() {
402:                System.out
403:                        .println("usage: com.versant.core.common.config.PropertyConverter <inputFile> [<outputFile>]");
404:                System.out
405:                        .println("  <inputFile>    The old *.jdogenie file to be converted.");
406:                System.out
407:                        .println("                 If output file is not specified then the output");
408:                System.out
409:                        .println("                 file will be <inputFile>.properties");
410:                System.out
411:                        .println("  <outputFile>   The new file .properties file.");
412:                System.exit(-1);
413:            }
414:
415:            /**
416:             * Converts the old jdogenie properties to the new versant properties.
417:             *
418:             * @param original
419:             * @return the new versant properties
420:             */
421:            public static boolean convert(Properties original) {
422:                return convert(original, false);
423:            }
424:
425:            /**
426:             * Converts the old jdogenie properties to the new versant properties.
427:             *
428:             * @param original
429:             * @return the new versant properties
430:             */
431:            private static boolean convert(Properties original,
432:                    boolean converted) {
433:                Properties oldProps = (Properties) original.clone();
434:                Properties newProps = new Properties();
435:                ArrayList list = new ArrayList(oldProps.keySet());
436:                Collections.sort(list);
437:                for (Iterator iter = list.iterator(); iter.hasNext();) {
438:                    String key = (String) iter.next();
439:                    if (oldToNew.containsKey(key)) {
440:                        if (oldToNew.get(key) != null) {
441:                            newProps.setProperty((String) oldToNew.get(key),
442:                                    oldProps.getProperty(key));
443:                        }
444:                        // ignore prop if oldToNew is null
445:                        converted = true;
446:                    } else {
447:                        String STORE_EXT = "store0.ext.";
448:                        String STORE_TYPE_MAPPING = "store0.jdbc.type.";
449:                        String STORE_JAVATYPE_MAPPING = "store0.jdbc.javatype.";
450:                        String STORE_SCO_FACTORY_MAPPING = "store0.sco.factory.mapping";
451:                        String JDO = "jdo";
452:                        String METRIC_USER = "metric.user.";
453:                        String EXTERNALIZER = "externalizer.";
454:                        String DIAGRAM = "diagram";
455:                        String MDEDIT_CP = "mdedit.cp";
456:                        if (key.startsWith(STORE_EXT)) {
457:                            String newKey = ConfigParser.STORE_EXT
458:                                    + key.substring(STORE_EXT.length(), key
459:                                            .length());
460:                            newProps.setProperty(newKey, oldProps
461:                                    .getProperty(key));
462:                            converted = true;
463:                        } else if (key.startsWith(STORE_TYPE_MAPPING)) {
464:                            String newKey = ConfigParser.STORE_TYPE_MAPPING
465:                                    + key.substring(
466:                                            STORE_TYPE_MAPPING.length(), key
467:                                                    .length());
468:                            newProps.setProperty(newKey, oldProps
469:                                    .getProperty(key));
470:                            converted = true;
471:                        } else if (key.startsWith(STORE_JAVATYPE_MAPPING)) {
472:                            String newKey = ConfigParser.STORE_JAVATYPE_MAPPING
473:                                    + key.substring(STORE_JAVATYPE_MAPPING
474:                                            .length(), key.length());
475:                            newProps.setProperty(newKey, oldProps
476:                                    .getProperty(key));
477:                            converted = true;
478:                        } else if (key.startsWith(STORE_SCO_FACTORY_MAPPING)) {
479:                            String newKey = ConfigParser.STORE_SCO_FACTORY_MAPPING
480:                                    + key.substring(STORE_SCO_FACTORY_MAPPING
481:                                            .length(), key.length());
482:                            newProps.setProperty(newKey, oldProps
483:                                    .getProperty(key));
484:                        } else if (key.startsWith(JDO)) {
485:                            String newKey = ConfigParser.JDO
486:                                    + key.substring(JDO.length(), key.length());
487:                            newProps.setProperty(newKey, oldProps
488:                                    .getProperty(key));
489:                            converted = true;
490:                        } else if (key.startsWith(METRIC_USER)) {
491:                            String newKey = ConfigParser.METRIC_USER
492:                                    + key.substring(METRIC_USER.length(), key
493:                                            .length());
494:                            newProps.setProperty(newKey, oldProps
495:                                    .getProperty(key));
496:                            converted = true;
497:                        } else if (key.startsWith(EXTERNALIZER)) {
498:                            String newKey = ConfigParser.EXTERNALIZER
499:                                    + key.substring(EXTERNALIZER.length(), key
500:                                            .length());
501:                            newProps.setProperty(newKey, oldProps
502:                                    .getProperty(key));
503:                            converted = true;
504:                        } else if (key.startsWith(DIAGRAM)) {
505:                            String newKey = ConfigParser.DIAGRAM
506:                                    + key.substring(DIAGRAM.length(), key
507:                                            .length());
508:                            newProps.setProperty(newKey, oldProps
509:                                    .getProperty(key));
510:                            converted = true;
511:                        } else if (key.startsWith(MDEDIT_CP)) {
512:                            String newKey = ConfigParser.MDEDIT_CP
513:                                    + key.substring(MDEDIT_CP.length(), key
514:                                            .length());
515:                            newProps.setProperty(newKey, oldProps
516:                                    .getProperty(key));
517:                            converted = true;
518:                        } else {
519:
520:                            newProps.put(key, oldProps.get(key));
521:                            //newProps.setProperty(key, oldProps.getProperty(key));
522:                        }
523:                    }
524:                }
525:                if (converted) {
526:                    fillAsProps(newProps, ConfigParser.EVENT_LOGGING); //
527:                    fillAsProps(newProps, ConfigParser.RMI_CLIENT_SF); //
528:                    fillAsProps(newProps, ConfigParser.RMI_SERVER_SF); //
529:                    fillAsProps(newProps, ConfigParser.CACHE_CLUSTER_TRANSPORT); //
530:                    fillAsProps(newProps, ConfigParser.CACHE_LISTENER);
531:                    fillAsProps(newProps, ConfigParser.STORE_NAMEGEN); //
532:                    fillAsProps(newProps, ConfigParser.STORE_MIGRATION_CONTROLS); //
533:                    fillAsProps(
534:                            newProps,
535:                            ConfigParser.STORE_EXT
536:                                    + JdoExtension
537:                                            .toKeyString(JdoExtensionKeys.JDBC_KEY_GENERATOR)); //
538:                    fillAsProps(newProps, ConfigParser.LOG_DOWNLOADER); //
539:                    fillExternalizer(newProps);
540:                }
541:
542:                original.clear();
543:                original.putAll(newProps);
544:                if ("za.co.hemtech.jdo.client.BootstrapPMF".equals(original
545:                        .getProperty(ConfigParser.PMF_CLASS))) {
546:                    original.setProperty(ConfigParser.PMF_CLASS,
547:                            "com.versant.core.jdo.BootstrapPMF");
548:                }
549:                return converted;
550:            }
551:
552:            /**
553:             * Fill all the given properties into newProps.
554:             *
555:             * @param newProps
556:             */
557:            private static void fillAsProps(Properties newProps, String lookup) {
558:                String s = newProps.getProperty(lookup);
559:                if (s != null) {
560:                    HashMap logging = new HashMap(17);
561:                    StringListParser lp = new StringListParser(s);
562:                    String name = null; // skip unused class name
563:                    try {
564:                        name = lp.nextQuotedString(); // skip unused class name
565:                    } catch (IllegalStateException e) {
566:                        return;
567:                    }
568:                    lp.nextProperties(logging);
569:                    Set names = logging.keySet();
570:                    for (Iterator iter = names.iterator(); iter.hasNext();) {
571:                        String key = (String) iter.next();
572:                        newProps.setProperty(lookup + "." + key,
573:                                (String) logging.get(key));
574:                    }
575:                    newProps.remove(lookup);
576:                    if (name != null) {
577:                        newProps.setProperty(lookup, name);
578:                    }
579:                }
580:            }
581:
582:            /**
583:             * Fill all the externalizer properties into newProps.
584:             *
585:             * @param newProps
586:             */
587:            private static void fillExternalizer(Properties newProps) {
588:                String s;
589:                for (int i = 0; i < ConfigParser.MAX_EXTERNALIZER_COUNT; i++) {
590:                    String key = ConfigParser.EXTERNALIZER + i;
591:                    s = newProps.getProperty(key);
592:                    if (s != null) {
593:                        StringListParser lp = new StringListParser(s);
594:                        Object o = newProps.setProperty(key
595:                                + ConfigParser.EXTERNALIZER_TYPE, lp
596:                                .nextString());
597:                        if (o != null) {
598:                            newProps.setProperty(key
599:                                    + ConfigParser.EXTERNALIZER_TYPE,
600:                                    (String) o);
601:                            continue;
602:                        }
603:                        boolean enabled = lp.nextBoolean();
604:                        newProps.setProperty(key
605:                                + ConfigParser.EXTERNALIZER_ENABLED,
606:                                (enabled ? "true" : "false"));
607:                        String externalizerName = lp.nextQuotedString();
608:                        if (externalizerName != null) {
609:                            newProps.setProperty(key
610:                                    + ConfigParser.EXTERNALIZER_CLASS,
611:                                    externalizerName);
612:                        }
613:
614:                        HashMap typeKeys = new HashMap(17);
615:                        lp.nextProperties(typeKeys);
616:                        Set names = typeKeys.keySet();
617:                        for (Iterator iter = names.iterator(); iter.hasNext();) {
618:                            String typeKey = (String) iter.next();
619:                            newProps.setProperty(key
620:                                    + ConfigParser.EXTERNALIZER_CLASS + "."
621:                                    + typeKey, (String) typeKeys.get(typeKey));
622:                        }
623:                        newProps.remove(key);
624:                    }
625:                }
626:            }
627:
628:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.