public abstract class ConfigurationManager
extends java.lang.Object
Configurations belong to one of three different, separate "scopes", which determine which preferences to use as the backing store for the configuration properties.
Configuration.SCOPE_SYSTEM
means the configuration is stored in the system preferences.Configuration.SCOPE_USER
means the configuration is stored in the user preferences.Configuration.SCOPE_TEMP
means the configuration is not stored permanently at all, but only used for the
current session.Preferences
,
Configuration
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
COMMAND_LINE_CONFIG_PROPERTY
-Dclearreports.config=USER/myConfig
|
static boolean |
ISINIT |
static java.lang.String |
NAME_DEFAULT
The name to use for USER or SYSTEM configurations which are to be used by default.
|
static java.lang.String |
NAME_TEMP_DEFAULT
The name to use for TEMP configurations which are to be used by default.
|
Constructor and Description |
---|
ConfigurationManager() |
Modifier and Type | Method and Description |
---|---|
abstract void |
addConfigurationChangeListener(ConfigurationChangeListener listener)
Adds a listener for a ConfigurationChangeEvent.
|
abstract void |
addConfigurationMigrator(ConfigurationMigrator migrator)
Add a migrator for the configurations.
|
abstract void |
copy(int srcScope,
java.lang.String srcName,
int destScope,
java.lang.String destName)
Creates a copy of the specified source configuration at the specified destination with the given name.
|
abstract Configuration |
create(int scope,
java.lang.String name)
Creates a new, empty configuration with the given name and context and stores it in the appropriate Preferences.
|
abstract void |
delete(Configuration config)
Irreversible removes the specified configuration from storage.
|
abstract void |
delete(int scope,
java.lang.String name)
Irreversible removes the specified configuration from storage.
|
abstract void |
exportToStream(int srcScope,
java.lang.String srcName,
java.io.OutputStream out)
Writes the properties in the configuration specified to the output stream in a format suitable for loading it
back using the importFromStream method.
|
Configuration |
get(java.lang.String fullName)
Fetches the configuration specified by the name and the scope.
|
abstract Configuration |
get(int scope,
java.lang.String name)
Fetches the configuration specified by the name and the scope.
|
abstract Configuration[] |
getAll(int scope)
Returns all configurations in the given scope.
|
abstract java.net.InetAddress[] |
getAvailableIPAddresses()
Returns all available IP addresses on the current system as a InetAddress array, each IP address as an individual
InetAddress.
|
abstract Configuration |
getCurrent()
Returns the current Configuration.
|
static ConfigurationManager |
getInstance()
Returns the singleton instance of the ConfigurationManager.
|
static java.lang.String |
getRecoveryConfiguration()
The preferred configuration of the recovery mode.
|
abstract void |
importFromStream(int destScope,
java.lang.String destName,
java.io.InputStream in)
Imports all of the preferences represented by the properties stored in the stream.
|
static boolean |
isHelpCenterMode()
If the application run in help center mode.
|
static boolean |
isReadable(int scope)
Checks if the scope is readable by the current user.
|
static boolean |
isRecoveryMode()
If the application run in recovery mode.
|
static boolean |
isWriteable(int scope)
Checks if the scope is writeable by the current user.
|
abstract void |
put(int scope,
java.lang.String name,
Configuration source)
Stores the configuration at the position specified.
|
abstract void |
removeConfigurationChangeListener(ConfigurationChangeListener listener)
Removes the given ConfigurationChangeListener.
|
abstract void |
removeConfigurationMigrator(ConfigurationMigrator migrator)
Remove the given migrator from the list.
|
abstract void |
rename(int srcScope,
java.lang.String srcName,
int destScope,
java.lang.String destName)
Renames and/or moves a configuration.
|
abstract void |
setCurrent(Configuration config)
Sets the given configuration as the one currently being used by the application instead of the default
configuration as specified in
getCurrent() . |
abstract Configuration |
setTemporaryProperties(java.util.Properties props)
Creates and returns a new temporary configuration called "<temp copy>", imports the given properties and
sets the created configuration as the current configuration.
|
abstract Configuration |
setTemporaryPropertiesFromURL(java.net.URL propsURL)
Creates and returns a new temporary configuration called "<temp copy>", imports the given properties and
sets the created configuration as the current configuration.
|
public static java.lang.String NAME_DEFAULT
getCurrent()
for
more information on the order of where the default configuration is searched for.public static final java.lang.String NAME_TEMP_DEFAULT
getCurrent()
for more
information on the order of where the default configuration is searched for.public static final java.lang.String COMMAND_LINE_CONFIG_PROPERTY
public static boolean ISINIT
public static ConfigurationManager getInstance()
public abstract void copy(int srcScope, java.lang.String srcName, int destScope, java.lang.String destName) throws java.lang.SecurityException
srcName
- name of configuration to copysrcScope
- scope of configuration to copydestName
- name of new, copied configuration. The name must be unique for the given scope.destScope
- scope to store the new, copied configuration in - SCOPE_SYSTEM, SCOPE_USER, SCOPE_TEMPjava.lang.SecurityException
- if you do not have permission to create a new configuration in the scope specified or
if you do not have permission to read from the source configuration.java.lang.IllegalArgumentException
- if there is no configuration at the given source or destinationConfiguration.SCOPE_SYSTEM
,
Configuration.SCOPE_USER
,
Configuration.SCOPE_TEMP
@Nonnull public abstract Configuration create(int scope, java.lang.String name) throws java.lang.SecurityException
name
- name the new configuration should have. This name must be unique for the given scope and may not be
null, empty, or contain a slash ('/') characterscope
- scope to store the new configuration in - SCOPE_SYSTEM, SCOPE_USER, or SCOPE_TEMPjava.lang.SecurityException
- if you do not have permission to store a configuration in the scope specified.java.lang.IllegalArgumentException
- if the given name already exists as a configuration or if it is null, empty, or
contains a slash characterConfiguration.SCOPE_SYSTEM
,
Configuration.SCOPE_USER
,
Configuration.SCOPE_TEMP
public abstract void delete(Configuration config) throws java.lang.SecurityException
getCurrent()
is being removed, this will
additionally call setCurrent(null)
.config
- Configuration to remove from storagejava.lang.SecurityException
- if you do not have permission to remove the configuration from storage, i.e. if the
configuration is in a scope for which you do not have write permission.public abstract void delete(int scope, java.lang.String name) throws java.lang.SecurityException
getCurrent()
is being removed, this will additionally call
setCurrent(null)
.name
- name of the configuration to deletescope
- scope of the configuration to delete, scope has to be exactly one of the defined scopesjava.lang.SecurityException
- if you do not have permission to delete the configuration in the scope specified.java.lang.IllegalArgumentException
- if you try to delete a non-existent configurationConfiguration.SCOPE_SYSTEM
,
Configuration.SCOPE_USER
,
Configuration.SCOPE_TEMP
public abstract void exportToStream(int srcScope, java.lang.String srcName, java.io.OutputStream out) throws java.lang.SecurityException, java.io.IOException
After the stream is written to, it is flushed, but remains open after this method returns.
srcName
- name of the configuration to exportsrcScope
- scope of the configuration to exportout
- the output stream on which to emit the configuration's propertiesjava.lang.SecurityException
- if you do not have permission to read from the scope specifiedjava.io.IOException
- if writing to the specified output stream results in an IOExceptionProperties.store(OutputStream, String)
,
Configuration.SCOPE_SYSTEM
,
Configuration.SCOPE_USER
,
Configuration.SCOPE_TEMP
@Nullable public Configuration get(java.lang.String fullName) throws java.lang.SecurityException
fullName
- the configuration name in the format scope/namejava.lang.SecurityException
- if it is not possible to read from the scope's root because of security reasonsjava.lang.IllegalArgumentException
- if the name is in the wrong format@Nullable public abstract Configuration get(int scope, java.lang.String name) throws java.lang.SecurityException
scope
- scope of configuration to fetchname
- name of configuration to fetchjava.lang.SecurityException
- if it is not possible to read from the scope's root because of security reasonsConfiguration.SCOPE_SYSTEM
,
Configuration.SCOPE_USER
,
Configuration.SCOPE_TEMP
public abstract Configuration[] getAll(int scope)
Configuration.SCOPE_SYSTEM
- The system preferencesConfiguration.SCOPE_USER
- The user preferencesConfiguration.SCOPE_TEMP
- Preferences held temporarily without a backing storeSCOPE_SYSTEM | SCOPE_USERwould fetch all configurations in the system and user preferences, for example.
scope
- Scope to fetch the configurations fromjava.lang.IllegalArgumentException
- if you provide a scope which is neither one of the scopes nor put together by a
bit-wise "OR" operation of more than one scope.Configuration.SCOPE_SYSTEM
,
Configuration.SCOPE_USER
,
Configuration.SCOPE_TEMP
public abstract java.net.InetAddress[] getAvailableIPAddresses()
public abstract void setCurrent(Configuration config)
getCurrent()
. Note that you can set null here, this will cause the default
configuration to be used instead. Note also that this setting is not persistent, in other words it applies only
for this session.config
- Configuration to set as the "current" configuration for this session only.@Nonnull public abstract Configuration getCurrent()
setCurrent(Configuration)
for this session, this configuration
is returned. If it has changed since the setCurrent call, a new instance is created with refreshed content.Configuration.SCOPE_TEMP
public abstract void importFromStream(int destScope, java.lang.String destName, java.io.InputStream in) throws java.lang.SecurityException, java.io.IOException
If a configuration specified by the name and scope already exists, properties will be replaced by the properties in the stream if they exist there. If a configuration does not exist, one will be created at the position given.
destName
- name of the configuration to import the preferences into. If no such configuration exists, one
will be created.destScope
- sScope of the configuration to import the preferences into.in
- the input stream from which to read the propertiesjava.lang.SecurityException
- if you do not have permission to write to the configuration specifiedjava.io.IOException
- If reading from the specified input stream results in an IOExceptionProperties.load(InputStream)
,
exportToStream(int, String, OutputStream)
,
Configuration.SCOPE_SYSTEM
,
Configuration.SCOPE_USER
,
Configuration.SCOPE_TEMP
public abstract void put(int scope, java.lang.String name, Configuration source) throws java.lang.SecurityException
scope
- scope the configuration is to be stored inname
- name the configuration is to havesource
- Configuration to store - if null is set, this will be the equivalent to
delete(int, String)
.java.lang.SecurityException
- if you do not have permission to write to the given scopeConfiguration.SCOPE_SYSTEM
,
Configuration.SCOPE_USER
,
Configuration.SCOPE_TEMP
public abstract void rename(int srcScope, java.lang.String srcName, int destScope, java.lang.String destName) throws java.lang.SecurityException
copy(int, String, int, String)
with the given parameters, and then calling
delete(Configuration)
on the old configuration. The new name does not need to be different from the old
name, however it must not be empty nor null and must be unique for the scope given.srcScope
- Scope of the configuration to rename or movesrcName
- Name of the configuration to rename or movedestScope
- New scope to give the configurationdestName
- New name to give the configurationjava.lang.SecurityException
- if you do not have permission to read, write, or delete a configuration in its given
scope.Configuration.SCOPE_SYSTEM
,
Configuration.SCOPE_USER
,
Configuration.SCOPE_TEMP
public abstract Configuration setTemporaryProperties(java.util.Properties props)
props
- properties to pass the new configurationcreate(int, String)
,
Configuration.putAll(java.util.Map)
,
setCurrent(Configuration)
public abstract Configuration setTemporaryPropertiesFromURL(java.net.URL propsURL) throws java.io.IOException
propsURL
- URL to a property filejava.io.IOException
- if any I/O Error occurcreate(int, String)
,
Configuration.putAll(java.util.Map)
,
setCurrent(Configuration)
public static boolean isReadable(int scope)
scope
- Possible values:
java.lang.IllegalArgumentException
- if scope if not Configuration.SCOPE_SYSTEM
,
Configuration.SCOPE_USER
or Configuration.SCOPE_TEMP
.public static boolean isWriteable(int scope)
scope
- Possible values:
java.lang.IllegalArgumentException
- if scope if not Configuration.SCOPE_SYSTEM
,
Configuration.SCOPE_USER
or Configuration.SCOPE_TEMP
.public abstract void addConfigurationChangeListener(ConfigurationChangeListener listener)
Configuration
has changed through Configuration.put(String, String)
or
Configuration.putAll(java.util.Map)
.getCurrent()
)listener
- ConfigurationChangeListener, may not be nulljava.lang.IllegalArgumentException
- if listener is nullConfigurationChangeListener
,
ConfigurationChangeEvent
public abstract void removeConfigurationChangeListener(ConfigurationChangeListener listener)
listener
- listener to remove, may not be nulljava.lang.IllegalArgumentException
- if null is passed inpublic abstract void addConfigurationMigrator(ConfigurationMigrator migrator)
migrator
- the migratorpublic abstract void removeConfigurationMigrator(ConfigurationMigrator migrator)
migrator
- the migrator to remove.public static boolean isRecoveryMode()
public static boolean isHelpCenterMode()
@Nullable public static java.lang.String getRecoveryConfiguration()
Copyright © 1999-2020 by i-net software GmbH