class JndiRepositoryFactory implements ObjectFactory {

    @Override
    public Object getObjectInstance( Object obj,
                                     final Name name,
                                     final Context nameCtx,
                                     Hashtable<?, ?> environment )
        throws IOException, SAXException, RepositoryException, NamingException {
        if (!(obj instanceof Reference)) return null;
        Reference ref = (Reference)obj;

        // Get the name of the repository
        RefAddr repositoryName = ref.get(REPOSITORY_NAME);
        String repoName = repositoryName != null ? repositoryName.getContent().toString() : null;

        // Get the configuration file
        RefAddr configFileRef = ref.get(CONFIG_FILE);
        String configFile = configFileRef != null ? configFileRef.getContent().toString() : null;

        RefAddr configFilesRef = ref.get(CONFIG_FILES);
        Set<String> configFiles = configFilesRef != null ? parseStrings(configFilesRef.getContent().toString()) : null;

        if (!StringUtil.isBlank(repoName) && !StringUtil.isBlank(configFile)) {
            // Start the named repository ...
            return getRepository(configFile, repoName, nameCtx, name);
        }
        else if (configFiles != null) {
            // Start the configured repositories ...
            for (String file : configFiles) {
                getRepository(file, null, nameCtx, name);
            }
            return ENGINE;
        }
        return null;
    }

}