ConfigBootstrapHelper.java revision 613bebac604c632625f09ce743b38cba4265b107
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright © 2011 ForgeRock AS. All rights reserved.
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*/
/**
* Helper class for bootstrapping the configuration, and in turn the system
*
* The boostrapping mechanism works in the following order:
* 1. Repository bundle activators register a bootstrap repository that knows how to access configuration.
* The basic info to bootstrap comes from system properties or configuration files
* 2. A repo persistence plug-in for the configuration admin is registered for configuration to get loaded/stored in the repository
* 3. When the OSGi configuration administration service comes up, proceed with handling configuration in files (if enabled)
* via the felix file install mechanism
*
* @author aegloff
*/
public class ConfigBootstrapHelper {
// Properties to set bootstrapping behavior
// Properties to set configuration file handling behavior
public static final String OPENIDM_FILEINSTALL_BUNDLES_NEW_START = "openidm.fileinstall.bundles.new.start";
// Filename prefix for repository configuration
// Default prefix for OpenIDM OSGi services
static boolean warnMissingConfig = true;
/**
* Get the configured bootstrap information for a repository
*
* Currently only one bootstrap repository is selected.
*
* Bootstrap information in system properties takes precedence over configuration files
*
* Configuration keys returned are lower case, whether they originate from system properties or
* configuration files.
*
* @param repoType the type of the boostrap repository,
* equivalent to the last part of its PID
* @return The relevant bootstrap configuration if this repository should be bootstraped, null if not
*/
// System properties take precedence over configuration files
}
}
return result;
}
// If bootstrap info not found in system properties, check for configuration files
File unqualified = new File(confDir, REPO_FILE_PREFIX + repoType.toLowerCase() + JSON_CONFIG_FILE_EXT);
File qualified = new File(confDir, ConfigBootstrapHelper.DEFAULT_SERVICE_RDN_PREFIX + REPO_FILE_PREFIX
try {
if (unqualified.exists()) {
} else {
// Check at least one configuration exists
warnMissingConfig = false;
}
return null;
}
}
throw new RuntimeException("Failed to load configuration file to boostrap repository "
}
return result;
}
// A list of repository configuration files
}
};
}
/**
* Get the directory for configuration file view
*
* @return config dir
*/
public static String getConfigFileInstallDir() {
// Default the configuration directory if not declared
return dir;
}
/**
* Configure to process all JSON configuration files (if enabled)
*
* @param configAdmin the OSGi configuration admin service
* @throws java.io.IOException
*/
}
// Apply the latest configuration changes from file
} else {
}
}
/**
* Prefixes unqualified PIDs with the default RDN qualifier
* I.e. file names can be unqualified and will be prefixed
* with the default.
* Configuring services with PIDs that are not qualified
* by org. or com. is currently not supported.
* @param fileNamePid
* @return
*/
// Prefix unqualified pid names with the default.
}
return qualifiedPid;
}
/**
* Removes the default RDN prefix if this is a qualified name
* int the default namespace. IF not, it STAYS qualified.
*
* Configuring services with PIDs that are not qualified
* by org. or com. is currently not supported.
* @param qualifiedPid
* @return
*/
} else {
return qualifiedPid;
}
}
}