de.smartics.properties.spi.config.support
Class InMemoryPropertiesManager

Package class diagram package InMemoryPropertiesManager
java.lang.Object
  extended by de.smartics.properties.spi.config.support.InMemoryPropertiesManager
All Implemented Interfaces:
PropertyManager, PropertyProvider, PropertySource, Serializable

@ThreadSafe
public final class InMemoryPropertiesManager
     
     
extends Object
implements PropertyManager

Helper implementation to deal with property management. This is a pure String key and value implementation of a properties map.

See Also:
Serialized Form

Constructor Summary
InMemoryPropertiesManager(ConfigurationKey<?> configurationKey)
          Convenience constructor creating a UUID as source.
InMemoryPropertiesManager(ConfigurationKey<?> configurationKey, PropertyLocation sourceId)
          Default constructor.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds the given listener to track any property changes.
 void addPropertyChangeListener(String name, PropertyChangeListener listener)
          Adds the given listener as a listener to the given property.
 boolean containsKey(String name)
          Checks if a given property is provided by the property provider.
 ConfigurationKey<?> getConfigurationKey()
          Returns the key of the configuration whose properties are managed.
 PropertyCollection getProperties()
          Returns the collection of all property values known to the system.
 Property getProperty(String name)
          Returns the property with the given name.
 PropertyLocation getSourceId()
          Returns the unique identifier of the property source.
 boolean isLazy()
          Providers that do not have to fetch their property definitions eagerly return true here.
 Property removeProperty(String name)
          Removes a property making it unknown to the system.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes the given listener to stop tracking property changes.
 void removePropertyChangeListener(String name, PropertyChangeListener listener)
          Removes the given listener as a listener to the given property.
 Property setProperty(Property property)
          Sets the property with the given name to the given value.
 String toString()
          Returns the string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InMemoryPropertiesManager

public InMemoryPropertiesManager(ConfigurationKey<?> configurationKey,
                                 PropertyLocation sourceId)
                          throws NullPointerException
Default constructor.

Parameters:
configurationKey - the key of the configuration whose properties are managed.
sourceId - the unique identifier of the property source.
Throws:
NullPointerException - if configurationKey or sourceId is null.

InMemoryPropertiesManager

public InMemoryPropertiesManager(ConfigurationKey<?> configurationKey)
                          throws NullPointerException
Convenience constructor creating a UUID as source.

Usually the default constructor should be used, since it provides proper information on the physical resource of the properties that is of invaluable help if someone tries to track down a configuration problem with a property.

Parameters:
configurationKey - the key of the configuration whose properties are managed.
Throws:
NullPointerException - if configurationKey is null.
Method Detail

getConfigurationKey

public ConfigurationKey<?> getConfigurationKey()
Returns the key of the configuration whose properties are managed.

Specified by:
getConfigurationKey in interface PropertyProvider
Returns:
the key of the configuration whose properties are managed.

getSourceId

public PropertyLocation getSourceId()
Description copied from interface: PropertyProvider
Returns the unique identifier of the property source. This value is used to identify the source when reporting about a property.

Specified by:
getSourceId in interface PropertyProvider
Returns:
the unique identifier of the property source.

isLazy

public boolean isLazy()
Description copied from interface: PropertyProvider
Providers that do not have to fetch their property definitions eagerly return true here. All others return false. Usually providers that fetch properties from a backend store are lazy, while properties on a class path are eager.

Generally: If the provider cannot fetch individual properties easily, then they should fetch them eagerly and hold them in memory. Otherwise they will fetch properties on demand (aka lazily).

Specified by:
isLazy in interface PropertyProvider
Returns:
true if the property provider is lazy, false if it is eager.

setProperty

@CheckForNull
public Property setProperty(Property property)
                     throws NullPointerException
Description copied from interface: PropertySource
Sets the property with the given name to the given value.

Specified by:
setProperty in interface PropertySource
Parameters:
property - the property to be set.
Returns:
the old property or null if it either was not set or had the value null.
Throws:
NullPointerException - if property is null.

getProperty

@CheckForNull
public Property getProperty(String name)
                     throws NullPointerException,
                            IllegalArgumentException
Description copied from interface: PropertyProvider
Returns the property with the given name.

Specified by:
getProperty in interface PropertyProvider
Parameters:
name - the name of the property to fetch.
Returns:
the value to the property.
Throws:
NullPointerException - if name is null.
IllegalArgumentException - if the property is not known. A property is not known if its key has not been registered. A property that is registered with the null value is known.

containsKey

public boolean containsKey(String name)
                    throws NullPointerException
Description copied from interface: PropertyProvider
Checks if a given property is provided by the property provider.

Specified by:
containsKey in interface PropertyProvider
Parameters:
name - the property name to check.
Returns:
true if the provider provides a property for the name, false otherwise.
Throws:
NullPointerException - if name is null.

removeProperty

@CheckForNull
public Property removeProperty(String name)
                        throws NullPointerException
Description copied from interface: PropertySource
Removes a property making it unknown to the system. If only the value should be set to null use PropertySource.setProperty(Property).

Specified by:
removeProperty in interface PropertySource
Parameters:
name - the name of the property to be removed.
Returns:
the old value of the property.
Throws:
NullPointerException - if name is null.

getProperties

public PropertyCollection getProperties()
Description copied from interface: PropertyProvider
Returns the collection of all property values known to the system.

Specified by:
getProperties in interface PropertyProvider
Returns:
the collection of all property values known to the system. May be empty, but is never null.

addPropertyChangeListener

public void addPropertyChangeListener(String name,
                                      PropertyChangeListener listener)
                               throws NullPointerException
Description copied from interface: PropertyManager
Adds the given listener as a listener to the given property.

Specified by:
addPropertyChangeListener in interface PropertyManager
Parameters:
name - the name of the property to track changes.
listener - the listener to add.
Throws:
NullPointerException - if name or listener is null.

removePropertyChangeListener

public void removePropertyChangeListener(String name,
                                         PropertyChangeListener listener)
                                  throws NullPointerException
Description copied from interface: PropertyManager
Removes the given listener as a listener to the given property.

Specified by:
removePropertyChangeListener in interface PropertyManager
Parameters:
name - the name of the property to stop tracking changes.
listener - the listener to remove.
Throws:
NullPointerException - if name or listener is null.

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
                               throws NullPointerException
Description copied from interface: PropertyManager
Adds the given listener to track any property changes.

Specified by:
addPropertyChangeListener in interface PropertyManager
Parameters:
listener - the listener to add.
Throws:
NullPointerException - if listener is null.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
                                  throws NullPointerException
Description copied from interface: PropertyManager
Removes the given listener to stop tracking property changes.

Specified by:
removePropertyChangeListener in interface PropertyManager
Parameters:
listener - the listener to remove.
Throws:
NullPointerException - if listener is null.

toString

public String toString()
Returns the string representation of the object.

Overrides:
toString in class Object
Returns:
the string representation of the object.


Copyright © 2012-2013 Kronseder & Reiner GmbH - smartics. All Rights Reserved.