Best way to detect file versions


I have developed an internal file format that did not support yet any
versioning. I want to support file versions in my next release, as I
have breaking changes in that release.

In the first version I have a main 'configuration' file that the
application will create. In there is a dynamic structure that I can
use to stor any parameter.

Also I have a file per application (I can store different application
layouts - prototyping information). In that I do not yet have any
dynamic container that I can use for storing version information for
that file.

The application relies on a UML model that the system imports and the
file contains the representation of the UML model. Thus the
application file. Details are not related to the versioning problem .

What is the best and easiest way to get a solution?

A new file extension would be the easiest solution, but I need to add
code to check for exsistence of old or new files.

Pro: It is simply detected by an existence of files with given
extension and switch to the corresponding function
that handles that version.

Con: It can only be used for detecting the beginning of a versioned
file, not the versions in that file at future.

Using my visitor pattern based function to check for a specific
element in the file as a version prefix would be
possible as I have implemented a delegation mechanism using a
namespace string from the visitor function to
the real storage function. The namespace is used to select an
implementaton by a plugin mechanism. This way
I am able to select a version2 plugin if I find a corresponding
version information in the file.

In my second version I generate the plugin code that stores or loads
the application data. Thus the big work is

Pro: The version is optionally possible and if not, version 1 is
assumed. The implementation will support multible
versions by a namespace means (document format version). Finally a
second version can be used to support
breaking changes at modelling level (UML => XML => XSLT => Internal
format). This second version is the
document version.

Con: I need to open scan the file for a specific version information
before reading the document with a proper
implementation. Thus I need to seek back to position 0.

At the end of writing I found that I also could place the full
namespace into the file. In that way I do not need to
add code except reading the namespace to select a proper plugin to
read the document.

The implementation must run in Linux, Windows, Mac OS X and Solaris. I
may prefer document version information carried within the file.

What do you mean?

Are there other ways to solve the problem?



More information about my project can be found at my website: