Class ConfigurationImpl

java.lang.Object
org.apache.felix.cm.impl.ConfigurationImpl

public class ConfigurationImpl extends Object
The ConfigurationImpl is the backend implementation of the Configuration Admin Service Specification Configuration object (section 104.4). Instances of this class are shared by multiple instances of the ConfigurationAdapter class, whose instances are actually returned to clients.
  • Field Details

    • CONFIGURATION_NEW

      private static final String CONFIGURATION_NEW
      The name of a synthetic property stored in the persisted configuration data to indicate that the configuration data is new, that is created but never updated (value is "_felix_.cm.newConfiguration").

      This special property is stored by the ConfigurationImpl(ConfigurationManager, PersistenceManager, String, String, String) constructor, when the configuration is first created and persisted and is interpreted by the ConfigurationImpl(ConfigurationManager, PersistenceManager, Dictionary) method when the configuration data is loaded in a new object.

      The goal of this property is to keep the information on whether configuration data is new (but persisted as per the spec) or has already been assigned with possible no data.

      See Also:
    • PROPERTY_LOCKED

      private static final String PROPERTY_LOCKED
      See Also:
    • PROPERTY_REVISION

      private static final String PROPERTY_REVISION
      See Also:
    • factoryPID

      private final TargetedPID factoryPID
      The factory PID of this configuration or null if this is not a factory configuration.
    • staticBundleLocation

      private volatile String staticBundleLocation
      The statically bound bundle location, which is set explicitly by calling the Configuration.setBundleLocation(String) method or when the configuration was created with the two-argument method.
    • dynamicBundleLocation

      private volatile String dynamicBundleLocation
      The bundle location from dynamic binding. This value is set as the configuration or factory is assigned to a ManagedService[Factory].
    • properties

      private volatile CaseInsensitiveDictionary properties
      The configuration data of this configuration instance. This is a private copy of the properties of which a copy is made when the
      invalid reference
      #getProperties()
      method is called. This field is null if the configuration has been created and never been updated with acutal configuration properties.
    • isDeleted

      private volatile boolean isDeleted
      Flag indicating that this configuration has been deleted.
      See Also:
    • revision

      private volatile long revision
      Configuration revision counter incremented each time the properties is set (in the constructor or the configure(Dictionary) method. This counter is persisted transparently so that
      invalid reference
      NotCachablePersistenceManager
      can provide a proper change count. The persistence is forward compatible such that previously persisted configurations are handled gracefully.
    • locked

      private volatile boolean locked
    • configurationManager

      private final ConfigurationManager configurationManager
      The configuration manager instance which caused this configuration object to be created.
    • persistenceManager

      private final PersistenceManager persistenceManager
    • baseId

      private final TargetedPID baseId
    • AUTO_PROPS

      private static final String[] AUTO_PROPS
  • Constructor Details

  • Method Details

    • isActive

      boolean isActive()
      Returns true if the ConfigurationManager of this configuration is still active.
    • storeSilently

      void storeSilently()
    • replaceProperty

      protected static void replaceProperty(Dictionary<String,Object> properties, String key, String value)
    • delete

      public void delete() throws IOException
      Throws:
      IOException
    • getPidString

      public String getPidString()
    • getPid

      public TargetedPID getPid()
    • getFactoryPidString

      public String getFactoryPidString()
    • getFactoryPid

      public TargetedPID getFactoryPid()
    • getBundleLocation

      String getBundleLocation()
      Returns the "official" bundle location as visible from the outside world of code calling into the Configuration.getBundleLocation() method.

      In other words: The getStaticBundleLocation() is returned if not null. Otherwise the getDynamicBundleLocation() is returned (which may also be null).

    • getDynamicBundleLocation

      String getDynamicBundleLocation()
    • getStaticBundleLocation

      String getStaticBundleLocation()
    • setStaticBundleLocation

      void setStaticBundleLocation(String bundleLocation)
    • setDynamicBundleLocation

      void setDynamicBundleLocation(String bundleLocation, boolean dispatchConfiguration)
    • tryBindLocation

      void tryBindLocation(String bundleLocation)
      Dynamically binds this configuration to the given location unless the configuration is already bound (statically or dynamically). In the case of this configuration to be dynamically bound a CM_LOCATION_CHANGED event is dispatched.
    • getProperties

      public Dictionary<String,Object> getProperties(boolean deepCopy)
      Returns an optionally deep copy of the properties of this configuration instance.

      This method returns a copy of the internal dictionary. If the deepCopy parameter is true array and collection values are copied into new arrays or collections. Otherwise just a new dictionary referring to the same objects is returned.

      Parameters:
      deepCopy - true if a deep copy is to be returned.
      Returns:
      the configuration properties
    • update

      public void update() throws IOException
      Throws:
      IOException
    • update

      public void update(Dictionary<String,?> properties) throws IOException
      Throws:
      IOException
      See Also:
      • Configuration.update(java.util.Dictionary)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • ensureFactoryConfigPersisted

      void ensureFactoryConfigPersisted() throws IOException
      Stores the configuration if it is a newly factory configuration which has not been persisted yet.

      This is used to ensure a configuration c as in

       Configuration cf = cm.createFactoryConfiguration(factoryPid);
       Configuration c = cm.getConfiguration(cf.getPid());
       
      is persisted after getConfiguration while createConfiguration alone does not persist yet.
      Throws:
      IOException
    • storeNewConfiguration

      private void storeNewConfiguration() throws IOException
      Persists a new (freshly created) configuration with a marker for it to be a new configuration.
      Throws:
      IOException - If an error occurrs storing the configuraiton
    • store

      void store() throws IOException
      Throws:
      IOException
    • getRevision

      public long getRevision()
      Returns the revision of this configuration object.

      When getting both the configuration properties and this revision counter, the two calls should be synchronized on this instance to ensure configuration values and revision counter match.

    • isNew

      boolean isNew()
      Returns false if this configuration contains configuration properties. Otherwise true is returned and this is a newly creted configuration object whose update(Dictionary) method has never been called.
    • isDeleted

      boolean isDeleted()
      Returns true if this configuration has already been deleted on the persistence.
    • configureFromPersistence

      private void configureFromPersistence(Dictionary<String,Object> properties)
    • configure

      private void configure(Dictionary<String,Object> properties)
    • setAutoProperties

      void setAutoProperties(Dictionary<String,Object> properties, boolean withBundleLocation)
    • setAutoProperties

      static void setAutoProperties(Dictionary<String,Object> properties, String pid, String factoryPid)
    • clearAutoProperties

      static void clearAutoProperties(Dictionary<String,Object> properties)
    • setLocked

      public void setLocked(boolean flag) throws IOException
      Throws:
      IOException
    • equals

      static boolean equals(Dictionary<String,Object> props1, Dictionary<String,Object> props2)
      Compare the two properties, ignoring auto properties
      Parameters:
      props1 - Set of properties
      props2 - Set of properties
      Returns:
      true if the set of properties is equal
    • convertToObjectArray

      private static Object[] convertToObjectArray(Object value)
      Convert the object to an array
      Parameters:
      value - The array
      Returns:
      an object array
    • isAutoProp

      static boolean isAutoProp(String name)
    • getCount

      static int getCount(Dictionary<String,Object> props)
    • isLocked

      public boolean isLocked()
    • getConfigurationManager

      final ConfigurationManager getConfigurationManager()