public class SystemProperties extends Object
The system properties can be set in couple of ways: programmatically by
calling the initializeProperties
method, or can be statically
loaded at startup from a file named:
AMConfig.[class,properties]
.
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, AMConfig.class
, and
then a file, AMConfig.properties
in the CLASSPATH accessible
to this code. The AMConfig.class
takes precedence over the
flat file AMConfig.properties
.
If multiple servers are running, each may have their own configuration file.
The naming convention for such scenarios is
AMConfig-<serverName>
.
Constructor and Description |
---|
SystemProperties() |
Modifier and Type | Method and Description |
---|---|
static String |
get(String key)
This method lets you query for a system property whose value is same as
String key. |
static String |
get(String key,
String def)
This method lets you query for a system property whose value is same as
String key. |
static Properties |
getAll()
This method lets you get all the properties defined and their values.
|
static boolean |
getAsBoolean(String key)
Returns the property value as a boolean
|
static boolean |
getAsBoolean(String key,
boolean defaultValue)
Returns the property value as a boolean
|
static int |
getAsInt(String key,
int defaultValue) |
static long |
getAsLong(String key,
long defaultValue) |
static Set<String> |
getAsSet(String key)
Parses a system property as a set of strings by splitting the value on white space characters.
|
static Set<String> |
getAsSet(String key,
String delimiterRegex)
Parses a system property as a set of strings by splitting the value on the given delimiter expression.
|
static Set<String> |
getAsSet(String key,
String delimiterRegex,
Set<String> defaultValue)
Parses a system property as a set of strings by splitting the value on the given delimiter expression.
|
static Map<String,AttributeStruct> |
getAttributeMap()
Returns the property name to service attribute schema name mapping.
|
static Properties |
getPlatform()
Deprecated.
use
getAll() |
static Properties |
getProperties()
Returns all the properties defined and their values.
|
static String |
getServerInstanceName()
Returns the server instance name of which properties are retrieved
to initialized this object.
|
static void |
initializeProperties(Properties properties) |
static void |
initializeProperties(Properties properties,
boolean reset)
Initializes the properties to be used by OpenAM.
|
static void |
initializeProperties(Properties properties,
boolean reset,
boolean withDefaults)
Initializes the properties to be used by OpenAM.
|
static void |
initializeProperties(String file)
Initializes properties bundle from the
file passed. |
static void |
initializeProperties(String propertyName,
String propertyValue)
Initializes a property to be used by OpenAM.
|
static boolean |
isServerMode()
Returns
true if instance is running in server mode. |
static long |
lastModified()
Returns a counter for last modification.
|
static void |
observe(ConfigurationListener listener,
String... properties)
Listen for runtime changes to a system property value.
|
static String |
replaceServerUriPlaceholder(String line,
String value)
Deal with the special case where OpenAM is deployed at the ROOT context so that lines containing the %SERVER_URI%
placeholder are properly handled.
|
static void |
setServerInstanceName(String name)
Sets the server instance name of which properties are retrieved
to initialized this object.
|
public static String get(String key)
String
key. The method first tries to read the property
from java.lang.System followed by a lookup in the config file.key
- type String
, the key whose value one is
looking for.null
public static String replaceServerUriPlaceholder(String line, String value)
line
- String the line to replace occurrences of the %SERVER_URI% placeholder.value
- String the value to use in place of the %SERVER_URI% placeholder.public static String get(String key, String def)
String
key.key
- the key whose value one is looking for.def
- the default value if the key does not exist.public static boolean getAsBoolean(String key)
key
- the key whose value one is looking for.public static boolean getAsBoolean(String key, boolean defaultValue)
key
- the property name.defaultValue
- value if key is not found.public static int getAsInt(String key, int defaultValue)
key
- The System Property key to lookup.defaultValue
- If the property was not set, or could not be parsed to an int.public static long getAsLong(String key, long defaultValue)
key
- The System Property key to lookup.defaultValue
- If the property was not set, or could not be parsed to a long.public static Set<String> getAsSet(String key, String delimiterRegex, Set<String> defaultValue)
key
- The System Property key to lookup.delimiterRegex
- The regular expression to use to split the value into elements in the set.defaultValue
- The default set to return if the property does not exist.public static Set<String> getAsSet(String key, String delimiterRegex)
key
- The System Property key to lookup.delimiterRegex
- The regular expression to use to split the value into elements in the set.public static Set<String> getAsSet(String key)
key
- The System Property key to lookup.public static Properties getProperties()
public static Properties getAll()
public static Properties getPlatform()
getAll()
public static void initializeProperties(String file) throws MissingResourceException
file
passed.file
- type String
, file name for the resource bundleMissingResourceException
- If the resource bundle cannot be found.public static void initializeProperties(Properties properties)
public static void initializeProperties(Properties properties, boolean reset)
properties
- properties for OpenAMreset
- true
to reset existing properties.public static void initializeProperties(Properties properties, boolean reset, boolean withDefaults)
properties
- properties for OpenAM.reset
- true
to reset existing properties.withDefaults
- true
to include default properties.public static void initializeProperties(String propertyName, String propertyValue)
propertyName
- property name.propertyValue
- property value.public static long lastModified()
initializeProperties
. This is a convenience method for
applications to track changes to OpenAM properties.public static void setServerInstanceName(String name)
name
- Server instance name.public static String getServerInstanceName()
public static boolean isServerMode()
true
if instance is running in server mode.true
if instance is running in server mode.public static Map<String,AttributeStruct> getAttributeMap()
public static void observe(ConfigurationListener listener, String... properties)
serverdefaults.properties
, amPlatform.xml
and
serverAttributeMap.properties
.listener
- The listener to call when one of the provided properties has changed.properties
- The list of properties that should be observed. A change in any one of these properties
will cause the listener to be notified.Copyright © 2010-2020, ForgeRock All Rights Reserved.