Loading a Registry

This example shows how to load a registry. On a load method, the class reads the configuration file (adapters.txt) and dynamically instantiates the repository given within the repository-config tag. In this case, the adapters.txt file is a flat properties file, so we can use the standard PropertyRepository class. Sample config file:

To access the PropertyRepository, merely requires:
    RepositoryRegistry repositoryRegistry = RepositoryRegistry.Factory.create();
    PropertyRepository repository = (PropertyRepository) repositoryRegistry.find("adapter"); `

You may invoke the loadFromFile method multiple times with different registry-config.xml files and the RepositoryRegistry instance will cumulatively load the repositories. As of version 1.2.0, each RepositoryRegistry is no longer a singleton, so you can also create and load multiple RepositoryRegistry instances, each containing a different set of repositories.

Keep in mind that if you have loaded other repositories into the registry and need to access them through the find method, you need to cast to the appropriate type.

Loading Repositories Programmatically

You don't need a registry-config file to load repositories. Consider the following example. Create a PropertyRepository , load it and add to the RepositoryRegistry

    PropertyRepository repo = new ProperyRepository();
    FileInputStream fileInputStream = new FileInputStream("myprops.txt");
    repo.load(fileInputStream, null);
    repositoryRegistry.addRepository("my-props", repo);