SystemProperties.java revision f7958cde6d0dd7640c8212ea2a93dbbbfca0234f
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. 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
* at opensso/legal/CDDLv1.0.txt.
* 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]"
*
* $Id: SystemProperties.java,v 1.21 2009/10/12 17:55:06 alanchu Exp $
*
* Portions Copyrighted 2010-2014 ForgeRock AS.
*/
/**
* This class provides functionality that allows single-point-of-access to all
* related system properties.
* <p>
* The system properties can be set in couple of ways: programmatically by
* calling the <code>initializeProperties</code> method, or can be statically
* loaded at startup from a file named:
* <code>AMConfig.[class,properties]</code>.
* Setting the properties through the API takes precedence and will replace the
* properties loaded via file. For statically loading the properties via a file,
* this class tries to first find a class, <code>AMConfig.class</code>, and
* then a file, <code>AMConfig.properties</code> in the CLASSPATH accessible
* to this code. The <code>AMConfig.class</code> takes precedence over the
* flat file <code>AMConfig.properties</code>.
* <p>
* If multiple servers are running, each may have their own configuration file.
* The naming convention for such scenarios is
* <code>AMConfig-<serverName></code>.
* @supported.all.api
*/
public class SystemProperties {
private static String instanceName;
private static ReentrantReadWriteLock rwLock = new
private static boolean sitemonitorDisabled = false;
static {
}
private static void initAttributeMapping() {
try {
}
// No Resource Bundle Found, Continue.
// Could be in Test Mode.
}
}
private static Properties props;
private static long lastModified;
private static String initSecondaryError;
/**
* Runtime flag to be set, in order to override the path of the
* configuration file.
*/
/**
* Default name of the configuration file.
*/
/**
* New configuration file extension
*/
private static Map tagswapValues;
/**
* Initialization to load the properties file for config information before
* anything else starts.
*/
static {
try {
// Initialize properties
props = new Properties();
// Load properties from file
if (serverName != null) {
} else {
fname = configName;
}
// Get the location of the new configuration file in case
// of single war deployment
try {
if ((newConfigFileLoc != null) &&
) {
.toLowerCase();
try {
} catch (IOException ioe) {
try {
} catch (IOException ioexp) {
}
} finally {
}
}
}
}
} catch (MissingResourceException e) {
// Can't print the message to debug due to dependency
// Save it as a String and provide when requested.
try {
} catch (IOException ioe) {
// Should not happend, ignore the exception
}
}
}
/**
* Helper function to handle associated exceptions during initialization of
* properties using external properties file in a single war deployment.
*/
// Save it as a String and provide when requested.
try {
} catch (IOException ioe) {
// Should not happend, ignore the exception
}
}
/**
* This method lets you query for a system property whose value is same as
* <code>String</code> key. The method first tries to read the property
* from java.lang.System followed by a lookup in the config file.
*
* @param key
* type <code>String</code>, the key whose value one is
* looking for.
* @return the value if the key exists; otherwise returns <code>null</code>
*/
try {
// look up values in SMS services only if in server mode.
if (isServerMode() || sitemonitorDisabled) {
}
}
if (k.equals("%SERVER_URI%")) {
val);
} else {
}
}
} else {
}
}
}
}
}
return (answer);
} finally {
}
}
}
}
return answer;
}
/**
* This method lets you query for a system property whose value is same as
* <code>String</code> key.
*
* @param key the key whose value one is looking for.
* @param def the default value if the key does not exist.
* @return the value if the key exists; otherwise returns default value.
*/
}
/**
* Returns the property value as a boolean
*
* @param key the key whose value one is looking for.
* @return the boolean value if the key exists; otherwise returns false
*/
return false;
}
/**
* Returns the property value as a boolean
*
* @param key
* @param defaultValue value if key is not found.
* @return the boolean value if the key exists; otherwise the default value
*/
{ return defaultValue; }
}
/**
* @param key The System Property key to lookup.
* @param defaultValue If the property was not set, or could not be parsed to an int.
* @return Either the defaultValue, or the numeric value assigned to the System Property.
*/
return defaultValue;
}
try {
} catch (NumberFormatException e) {
return defaultValue;
}
}
/**
* Returns all the properties defined and their values.
*
* @return Properties object with all the key value pairs.
*/
public static Properties getProperties() {
try {
return properties;
} finally {
}
}
/**
* This method lets you get all the properties defined and their values. The
* method first tries to load the properties from java.lang.System followed
* by a lookup in the config file.
*
* @return Properties object with all the key value pairs.
*
*/
public static Properties getAll() {
try {
// Iterate over the System Properties & add them in result obj
}
}
return properties;
} finally {
}
}
/**
* This method lets you query for all the platform properties defined and
* their values. Returns a Properties object with all the key value pairs.
*
* @deprecated use <code>getAll()</code>
*
* @return the platform properties
*/
public static Properties getPlatform() {
return getAll();
}
tagswapValues = new HashMap();
}
}
}
/**
* Initializes properties bundle from the <code>file<code>
* passed.
*
* @param file type <code>String</code>, file name for the resource bundle
* @exception MissingResourceException
*/
throws MissingResourceException {
try {
// Copy the properties to props
while (e.hasMoreElements()) {
}
// Reset the last modified time
} finally {
}
}
initializeProperties(properties, false);
}
/**
* Initializes the properties to be used by OpenSSO. Ideally this
* must be called first before any other method is called within OpenSSO
* Enterprise. This method provides a programmatic way to set the
* properties, and will override similar properties if loaded for a
* properties file.
*
* @param properties properties for OpenSSO
* @param reset <code>true</code> to reset existing properties.
*/
public static void initializeProperties(
boolean reset)
{
}
/**
* Initializes the properties to be used by OpenSSO. Ideally this
* must be called first before any other method is called within OpenSSO
* Enterprise. This method provides a programmatic way to set the
* properties, and will override similar properties if loaded for a
* properties file.
*
* @param properties properties for OpenSSO.
* @param reset <code>true</code> to reset existing properties.
* @param withDefaults <code>true</code> to include default properties.
*/
public static void initializeProperties(
boolean reset,
boolean withDefaults) {
if (withDefaults) {
}
try {
if (defaultProp != null) {
}
if (!reset) {
}
} finally {
}
}
/**
* Initializes the property to be used by OpenSSO. Ideally this
* must be called first before any other method is called within OpenSSO
* Enterprise.
* This method provides a programmatic way to set a specific property, and
* will override similar property if loaded for a properties file.
*
* @param propertyName property name.
* @param propertyValue property value.
*/
public static void initializeProperties(
) {
try {
} finally {
}
}
/**
* Returns a counter for last modification. The counter is incremented if
* the properties are changed by calling the following method
* <code>initializeProperties</code>. This is a convenience methods for
* applications to track changes to OpenSSO properties.
*
* @return counter of the last modification
*/
public static long lastModified() {
return (lastModified);
}
/**
* Returns error messages during initialization, else <code>null</code>.
*
* @return error messages during initialization
*/
public static String getInitializationError() {
return (initError);
}
/**
* Returns error messages during initialization using the single war
* deployment, else <code>null</code>.
*
* @return error messages during initialization of AM as single war
*/
public static String getSecondaryInitializationError() {
return (initSecondaryError);
}
/**
* Sets the server instance name of which properties are retrieved
* to initialized this object.
*
* @param name Server instance name.
*/
instanceName = name;
}
/**
* Returns the server instance name of which properties are retrieved
* to initialized this object.
*
* @return Server instance name.
*/
public static String getServerInstanceName() {
return instanceName;
}
/**
* Returns <code>true</code> if instance is running in server mode.
*
* @return <code>true</code> if instance is running in server mode.
*/
public static boolean isServerMode() {
// use getProp and not get method to avoid infinite loop
}
/**
* Returns the property name to service attribute schema name mapping.
*
* @return Property name to service attribute schema name mapping.
*/
public static Map getAttributeMap() {
try {
return attributeMap;
} finally {
}
}
}