Previous Up Next

Chapter 2  Migrating from Another File Format

2.1  Introduction: Description of Problem

Consider the following scenario. Your company has been selling an application for the past five years and, up until now, that application has used, say, an XML file to store its configuration information. You are designing an updated version of the application, and you would like to switch from using XML to Config4* for its configuration file. There is just one problem: you need to find a way for users to be able to automatically convert their existing XML-based configuration data into Config4* format. How can you achieve this goal?

2.2  Solution

An easy way to help users migrate from, say, an XML file format to Config4* is to write a program that does the following:

  1. Call Configuration.create() to create an empty configuration object.
  2. Parse an input XML file and store the result in a DOM tree.
  3. Traverse the DOM tree and, for each name-value pair you encounter, call cfg.insertString() or cfg.insertList() to add the name-value pair into the configuration object.
  4. When you have finished traversing the DOM tree, call cfg.dump() to get a textual representation of all the configuration information, and write this to a configuration file.

That’s all that is required.

Previous Up Next