Config Stores

Configuration files are stored in entities called Stores.

The methods that need to be implemented on a store are:

- {@link oaj.config.store.ConfigStore}
  - {@link oaj.config.store.ConfigStore#read(String) read(String)} - Read a config file.
  - {@link oaj.config.store.ConfigStore#write(String,String,String) write(String,String,String)} - Write a config file.
  - {@link oaj.config.store.ConfigStore#update(String,String) update(String,String)} - Update the contents of a config file.

Read is self-explanatory:

public String read(String name) { // Return the contents of the specified configuration. }

Write is slightly trickier:

public String write(String name, String oldContents, String newContents) { // If the old contents match the current stored contents, the new contents will get stored, // and the method returns null indicating success. // If the old contents DO NOT match the current stored contents (i.e. it was modified in some way), // the new contents are NOT stored, and the method returns the current stored contents. // If the old contents are null, then just always write the new contents. }

The update method is called whenever the stored file gets modified externally:

public String update(String name, String newContents) { // Do something with the updated contents. }

Two configuration stores are provided by default:

- {@link oaj.config.store.ConfigFileStore} - File-system storage.
- {@link oaj.config.store.ConfigMemoryStore} - In-memory storage.

The store is defined on the `Config` object via the following setting:

- {@link oaj.config.Config#CONFIG_store}

##### Example:

// Create a config with in-memory storage. Config c = Config. create("MyConfig.cfg").store(ConfigMemoryStore. DEFAULT).build();

The default store used is {@link oaj.config.store.ConfigFileStore#DEFAULT} which defines the execution directory as the file system directory to store and retrieve files.