Interface Configuration
-
@ProviderType public interface ConfigurationThe configuration information for aManagedServiceorManagedServiceFactoryobject. The Configuration Admin service uses this interface to represent the configuration information for aManagedServiceor for a service instance of aManagedServiceFactory.A
Configurationobject contains a configuration dictionary and allows the properties to be updated via this object. Bundles wishing to receive configuration dictionaries do not need to use this class - they register aManagedServiceorManagedServiceFactory. Only administrative bundles, and bundles wishing to update their own configurations need to use this class.The properties handled in this configuration have case insensitive
Stringobjects as keys. However, case must be preserved from the last set key/value.A configuration can be bound to a specific bundle or to a region of bundles using the location. In its simplest form the location is the location of the target bundle that registered a Managed Service or a Managed Service Factory. However, if the location starts with
?then the location indicates multiple delivery. In such a case the configuration must be delivered to all targets. If security is on, the Configuration Permission can be used to restrict the targets that receive updates. The Configuration Admin must only update a target when the configuration location matches the location of the target's bundle or the target bundle has a Configuration Permission with the actionConfigurationPermission.TARGETand a name that matches the configuration location. The name in the permission may contain wildcards ('*') to match the location using the same substring matching rules asFilter. Bundles can always create, manipulate, and be updated from configurations that have a location that matches their bundle location.If a configuration's location is
null, it is not yet bound to a location. It will become bound to the location of the first bundle that registers aManagedServiceorManagedServiceFactoryobject with the corresponding PID.The same
Configurationobject is used for configuring both a Managed Service Factory and a Managed Service. When it is important to differentiate between these two the term "factory configuration" is used.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classConfiguration.ConfigurationAttributeConfiguration Attributes.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddAttributes(Configuration.ConfigurationAttribute... attrs)Add attributes to the configuration.voiddelete()Delete thisConfigurationobject.booleanequals(java.lang.Object other)Equality is defined to have equal PIDs Two Configuration objects are equal when their PIDs are equal.java.util.Set<Configuration.ConfigurationAttribute>getAttributes()Get the attributes of this configuration.java.lang.StringgetBundleLocation()Get the bundle location.longgetChangeCount()Get the change count.java.lang.StringgetFactoryPid()For a factory configuration return the PID of the corresponding Managed Service Factory, else returnnull.java.lang.StringgetPid()Get the PID for thisConfigurationobject.java.util.Dictionary<java.lang.String,java.lang.Object>getProcessedProperties(org.osgi.framework.ServiceReference<?> reference)Return the processed properties of thisConfigurationobject.java.util.Dictionary<java.lang.String,java.lang.Object>getProperties()Return the properties of thisConfigurationobject.inthashCode()Hash code is based on PID.voidremoveAttributes(Configuration.ConfigurationAttribute... attrs)Remove attributes from this configuration.voidsetBundleLocation(java.lang.String location)Bind thisConfigurationobject to the specified location.voidupdate()Update theConfigurationobject with the current properties.voidupdate(java.util.Dictionary<java.lang.String,?> properties)Update the properties of thisConfigurationobject.booleanupdateIfDifferent(java.util.Dictionary<java.lang.String,?> properties)Update the properties of thisConfigurationobject if the provided properties are different than the currently stored set.
-
-
-
Method Detail
-
getPid
java.lang.String getPid()
Get the PID for thisConfigurationobject.- Returns:
- the PID for this
Configurationobject. - Throws:
java.lang.IllegalStateException- if this configuration has been deleted
-
getProperties
java.util.Dictionary<java.lang.String,java.lang.Object> getProperties()
Return the properties of thisConfigurationobject. TheDictionaryobject returned is a private copy for the caller and may be changed without influencing the stored configuration. The keys in the returned dictionary are case insensitive and are always of typeString.If called just after the configuration is created and before update has been called, this method returns
null.- Returns:
- A private copy of the properties for the caller or
null. These properties must not contain the "service.bundleLocation" property. The value of this property may be obtained from thegetBundleLocation()method. - Throws:
java.lang.IllegalStateException- If this configuration has been deleted.
-
getProcessedProperties
java.util.Dictionary<java.lang.String,java.lang.Object> getProcessedProperties(org.osgi.framework.ServiceReference<?> reference)
Return the processed properties of thisConfigurationobject.The
Dictionaryobject returned is a private copy for the caller and may be changed without influencing the stored configuration. The keys in the returned dictionary are case insensitive and are always of typeString.Before the properties are returned they are processed by all the registered
ConfigurationPlugins handling this configuration.If called just after the configuration is created and before update has been called, this method returns
null.- Parameters:
reference- The reference to the Managed Service or Managed Service Factory to pass to the registeredConfigurationPlugins handling this configuration. Must not benull.- Returns:
- A private copy of the processed properties for the caller or
null. These properties must not contain the "service.bundleLocation" property. The value of this property may be obtained from thegetBundleLocation()method. - Throws:
java.lang.IllegalStateException- If this configuration has been deleted.- Since:
- 1.6
-
update
void update(java.util.Dictionary<java.lang.String,?> properties) throws java.io.IOExceptionUpdate the properties of thisConfigurationobject.Stores the properties in persistent storage after adding or overwriting the following properties:
- "service.pid" : is set to be the PID of this configuration.
- "service.factoryPid" : if this is a factory configuration it is set to the factory PID else it is not set.
String.If the corresponding Managed Service/Managed Service Factory is registered, its updated method must be called asynchronously. Else, this callback is delayed until aforementioned registration occurs.
Also notifies all Configuration Listeners with a
ConfigurationEvent.CM_UPDATEDevent.- Parameters:
properties- the new set of properties for this configuration- Throws:
ReadOnlyConfigurationException- If the configuration isread only.java.io.IOException- if update cannot be made persistentjava.lang.IllegalArgumentException- if theDictionaryobject contains invalid configuration types or contains case variants of the same key name.java.lang.IllegalStateException- If this configuration has been deleted.
-
delete
void delete() throws java.io.IOExceptionDelete thisConfigurationobject.Removes this configuration object from the persistent store. Notify asynchronously the corresponding Managed Service or Managed Service Factory. A
ManagedServiceobject is notified by a call to itsupdatedmethod with anullproperties argument. AManagedServiceFactoryobject is notified by a call to itsdeletedmethod.Also notifies all Configuration Listeners with a
ConfigurationEvent.CM_DELETEDevent.- Throws:
ReadOnlyConfigurationException- If the configuration isread only.java.io.IOException- If delete fails.java.lang.IllegalStateException- If this configuration has been deleted.
-
getFactoryPid
java.lang.String getFactoryPid()
For a factory configuration return the PID of the corresponding Managed Service Factory, else returnnull.- Returns:
- factory PID or
null - Throws:
java.lang.IllegalStateException- If this configuration has been deleted.
-
update
void update() throws java.io.IOExceptionUpdate theConfigurationobject with the current properties. Initiate theupdatedcallback to the Managed Service or Managed Service Factory with the current properties asynchronously.This is the only way for a bundle that uses a Configuration Plugin service to initiate a callback. For example, when that bundle detects a change that requires an update of the Managed Service or Managed Service Factory via its
ConfigurationPluginobject.- Throws:
java.io.IOException- if update cannot access the properties in persistent storagejava.lang.IllegalStateException- If this configuration has been deleted.- See Also:
ConfigurationPlugin
-
updateIfDifferent
boolean updateIfDifferent(java.util.Dictionary<java.lang.String,?> properties) throws java.io.IOExceptionUpdate the properties of thisConfigurationobject if the provided properties are different than the currently stored set. Properties are compared as follows.- Scalars are compared using
equals - Arrays are compared using
Arrays.equals - Collections are compared using
equals
update(Dictionary)method.- Parameters:
properties- The new set of properties for this configuration.- Returns:
- If the properties are different and the configuration is updated
trueis returned. If the properties are the same,falseis returned. - Throws:
ReadOnlyConfigurationException- If the configuration isread only.java.io.IOException- If update cannot be made persistent.java.lang.IllegalArgumentException- If theDictionaryobject contains invalid configuration types or contains case variants of the same key name.java.lang.IllegalStateException- If this configuration has been deleted.- Since:
- 1.6
- Scalars are compared using
-
setBundleLocation
void setBundleLocation(java.lang.String location)
Bind thisConfigurationobject to the specified location. If the location parameter isnullthen theConfigurationobject will not be bound to a location/region. It will be set to the bundle's location before the first time a Managed Service/Managed Service Factory receives thisConfigurationobject via the updated method and before any plugins are called. The bundle location or region will be set persistently.If the location starts with
?then all targets registered with the given PID must be updated.If the location is changed then existing targets must be informed. If they can no longer see this configuration, the configuration must be deleted or updated with
null. If this configuration becomes visible then they must be updated with this configuration.Also notifies all Configuration Listeners with a
ConfigurationEvent.CM_LOCATION_CHANGEDevent.- Parameters:
location- a location, region, ornull- Throws:
java.lang.IllegalStateException- If this configuration has been deleted.java.lang.SecurityException- when the required permissions are not available
-
getBundleLocation
java.lang.String getBundleLocation()
Get the bundle location. Returns the bundle location or region to which this configuration is bound, ornullif it is not yet bound to a bundle location or region. If the location starts with?then the configuration is delivered to all targets and not restricted to a single bundle.- Returns:
- location to which this configuration is bound, or
null. - Throws:
java.lang.IllegalStateException- If this configuration has been deleted.java.lang.SecurityException- when the required permissions are not available
-
getChangeCount
long getChangeCount()
Get the change count. Each Configuration must maintain a change counter that is incremented with a positive value every time the configuration is updated and its properties are stored. The counter must be incremented before the targets are updated and events are sent out.- Returns:
- A monotonically increasing value reflecting changes in this Configuration.
- Throws:
java.lang.IllegalStateException- If this configuration has been deleted.- Since:
- 1.5
-
addAttributes
void addAttributes(Configuration.ConfigurationAttribute... attrs) throws java.io.IOException
Add attributes to the configuration.- Parameters:
attrs- The attributes to add.- Throws:
java.io.IOException- If the new state cannot be persisted.java.lang.IllegalStateException- If this configuration has been deleted.java.lang.SecurityException- when the required permissions are not available- Since:
- 1.6
-
getAttributes
java.util.Set<Configuration.ConfigurationAttribute> getAttributes()
Get the attributes of this configuration.- Returns:
- The set of attributes.
- Throws:
java.lang.IllegalStateException- If this configuration has been deleted.- Since:
- 1.6
-
removeAttributes
void removeAttributes(Configuration.ConfigurationAttribute... attrs) throws java.io.IOException
Remove attributes from this configuration.- Parameters:
attrs- The attributes to remove.- Throws:
java.io.IOException- If the new state cannot be persisted.java.lang.IllegalStateException- If this configuration has been deleted.java.lang.SecurityException- when the required permissions are not available- Since:
- 1.6
-
equals
boolean equals(java.lang.Object other)
Equality is defined to have equal PIDs Two Configuration objects are equal when their PIDs are equal.- Overrides:
equalsin classjava.lang.Object- Parameters:
other-Configurationobject to compare against- Returns:
trueif equal,falseif not aConfigurationobject or one with a different PID.
-
hashCode
int hashCode()
Hash code is based on PID. The hash code for two Configuration objects must be the same when the Configuration PID's are the same.- Overrides:
hashCodein classjava.lang.Object- Returns:
- hash code for this Configuration object
-
-