JzrLib API


JzrLib should consist of many layers. Each of these layers will do its own job, thus targetting different users.

The highest-level layer is meant to be used by GUI developers. It should be very simple to use, and probably consist of JPanels with one additional method intended to execute Bazaar command.

For example, for the Bazaar command init there should be a class named (probably) InitPanel. This panel should implement all the GUI functionality, allowing its user to set all the options and needed values. Let's say that the "exec" method of this class would be responsible for executing the Bazaar init command.

All those classes would make use of the middle-level layer, which would be responsible for constructing Bazaar commands. This layer could be a single class (probably a singleton), with methods for all the Bazaar commands. Alternatively only a few methods could be used to execute all the Bazaar commands, if such generalization is possible.

For example, the mentioned init command could be implemented as the "init" method, with arguments for this command options and parameters. Lists seem to be the best type for arguments. Such a method would be responsible for constructing ready-to-use system command.

It is possible that there will be some methods for constructing lists of arguments for the methods mentioned above. These method will belong to the middle-level layer as well.

Finally, the lowest-level layer will consist of problably a small number of classes, used to execute system commands.

The middle-level API

1. There is only one class (singleton) which is the Bazaar wrapper for JVM. This class consists of methods used to communicate with Bazaar and run all the supported Bazaar commands.

2. Bazaar commands have various arguments. I think that the simplest way to pass them into some method is to put them in some map. The keys in this map would be the arguments' names. It would lead to a really simple convention.

Let's consider a simple example: the init command. According to Bazaar, this commands can have parameters like —create-prefix and —knit. Let's assume that we'd like to call the init command in the following form:

$ bzr init --create-prefix --knit /path/to/repo

This call can be "translated" into the JzrLib API as follows:
Map<String, Object> map = bzrObject.getEmptyArgs();
map.put( "--create-prefix", null );
map.put( "--knit", null );
bzrObject.init( map, "/path/to/repo" );
bzrObject.releaseArgs( map );

In the code above, the getEmptyArgs() methods returns an empty map, which can be used to set parameters. The map can be "released" later, with the releaseArgs() method. The bzrObject object is responsible for maintaining a poll of such maps for JzrLib user's convenience.

Setting the parameters is very easy: it's done with the standard put method. The key is the string representing the argument's name, and the value is the vaule of this argument. The value can be null - in such cases it's assumed that no value should be used for this particular argument.

Such API should be easy to implement and easy to learn.