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

Package class diagram package ConfigurationPropertiesManagementWithDefaults
java.lang.Object
  extended by de.smartics.properties.spi.config.support.AbstractConfigurationProperties
      extended by de.smartics.properties.spi.config.support.ConfigurationPropertiesManagementWithDefaults
All Implemented Interfaces:
ConfigurationProperties, ConfigurationPropertiesManagement, SerializableConfigurationProperties, SerializableConfigurationPropertiesManagement, ConfigurationPropertiesSpi, Serializable

public final class ConfigurationPropertiesManagementWithDefaults
     
     
extends AbstractConfigurationProperties
implements SerializableConfigurationPropertiesManagement

A configuration properties instance that contains the main configuration properties, which matches the key, and all the defaults that have a partial representation of the key.

This implementation is thread-safe as long as the passed in instances of ConfigurationPropertiesManagement are thread-safe.

See Also:
Serialized Form

Constructor Summary
ConfigurationPropertiesManagementWithDefaults(List<ConfigurationPropertiesManagement> configurationProperties)
          Default constructor.
 
Method Summary
 ConfigurationPropertiesManagement addDefinitions(PropertyProvider properties)
          Adds the given definitions to this configuration.
 void addDescriptors(Class<?> declaringType)
          Adds all property descriptors declared in the given type.
 void flush()
          Signal to flush properties changed in memory to be written to a secondary storage.
 PropertyDescriptor getDescriptor(PropertyKey key)
          Returns the descriptor for the given key.
 PropertyDescriptor getDescriptor(String key)
          Returns the descriptor for the given key.
 List<PropertyDescriptor> getMandatoryPropertyDescriptors()
          Returns the list of mandatory properties.
 DescribedProperty getProperty(PropertyDescriptor descriptor, Object defaultValue)
          Returns the property for the given descriptor, allowing to transparently provide a default value to be returned in case the property has not been set.
 DescribedProperty getProperty(String key, Object defaultValue)
          Returns the property for the given key, allowing to transparently provide a default value to be returned in case the property has not been set.
 Object getPropertyAsType(PropertyDescriptor descriptor)
          Returns the yet not validated property for the given descriptor's key.
 PropertyStoreAccessor getPropertyStoreAccessor()
          Provides direct access to the properties in the underlying store.
 ValidatedProperty getValidatedProperty(PropertyDescriptor descriptor, Object defaultValue)
          Returns the validated property for the given descriptor's key, allowing to transparently provide a default value to be returned in case the property has not been set.
 boolean isInAdminMode()
          Checks whether or not this configuration is in administration mode.
 Property setProperty(PropertyKey key, String value)
          Sets the property value for the given key.
 void setToAdminMode(boolean newMode)
          Sets the administration mode for this configuration.
 ConfigurationPropertiesManagement toRepresentative()
          Creates an representative of this configuration.
 SerializableConfigurationPropertiesManagement toSerializable()
          Creates a serializable variant of this implementation.
 String toString()
          Returns the string representation of the object.
 Property unsetProperty(PropertyKey key)
          Unsets the property value for the given key.
 void validate(boolean lenient, Class<?>... groups)
          Validates all properties in the given configuration.
 void validate(PropertyDescriptor descriptor, Class<?>... groups)
          Validates the given property in the given configuration.
 void validate(PropertyDescriptor descriptor, String value, Class<?>... groups)
          Validates the given property in the given configuration.
 
Methods inherited from class de.smartics.properties.spi.config.support.AbstractConfigurationProperties
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, getContext, getContext, getKey, getProperties, getProperties, getProperty, getProperty, getProperty, getPropertyDescriptor, getPropertyValue, getPropertyValue, getPropertyValue, getPropertyValue, getPropertyValue, getPropertyValueAsString, getPropertyValueAsString, getPropertyValueAsString, getPropertyValueAsString, getPropertyValueSecurity, getRegistry, getValidatedProperty, getValidatedProperty, removePropertyChangeListener, removePropertyChangeListener, resolveAndConvert, resolveAndConvertAndValidate, validate, validate, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.smartics.properties.api.config.domain.ConfigurationPropertiesManagement
getPropertyValueSecurity, getRegistry
 
Methods inherited from interface de.smartics.properties.api.config.domain.ConfigurationProperties
addPropertyChangeListener, addPropertyChangeListener, getContext, getContext, getKey, getProperties, getProperty, getProperty, getProperty, getPropertyValue, getPropertyValue, getPropertyValue, getPropertyValue, getPropertyValue, getPropertyValueAsString, getPropertyValueAsString, getPropertyValueAsString, getPropertyValueAsString, getValidatedProperty, getValidatedProperty, removePropertyChangeListener, removePropertyChangeListener, validate, validate
 

Constructor Detail

ConfigurationPropertiesManagementWithDefaults

public ConfigurationPropertiesManagementWithDefaults(List<ConfigurationPropertiesManagement> configurationProperties)
                                              throws IllegalArgumentException
Default constructor.

Parameters:
configurationProperties - the list of configuration properties to consult on requests.
Throws:
IllegalArgumentException - if configurationProperties is null or empty.
Method Detail

isInAdminMode

public boolean isInAdminMode()
Description copied from interface: ConfigurationProperties
Checks whether or not this configuration is in administration mode. In this mode the configuration is less strict with certain validations. Especially it allows to edit otherwise read-only properties.

Specified by:
isInAdminMode in interface ConfigurationProperties
Returns:
true if the configuration is in administration mode, false otherwise.

setToAdminMode

public void setToAdminMode(boolean newMode)
Description copied from interface: ConfigurationPropertiesManagement
Sets the administration mode for this configuration.

Specified by:
setToAdminMode in interface ConfigurationPropertiesManagement
Parameters:
newMode - the new value of the mode true if the configuration is to be set in administration mode, false if not.
See Also:
ConfigurationProperties.isInAdminMode()

getPropertyStoreAccessor

public PropertyStoreAccessor getPropertyStoreAccessor()
Description copied from interface: ConfigurationPropertiesManagement
Provides direct access to the properties in the underlying store.

Specified by:
getPropertyStoreAccessor in interface ConfigurationPropertiesManagement
Returns:
direct access to the properties in the underlying store.

getProperty

public DescribedProperty getProperty(PropertyDescriptor descriptor,
                                     Object defaultValue)
                              throws IllegalArgumentException,
                                     UnknownPropertyException
Description copied from interface: ConfigurationProperties
Returns the property for the given descriptor, allowing to transparently provide a default value to be returned in case the property has not been set.

Specified by:
getProperty in interface ConfigurationProperties
Parameters:
descriptor - the descriptor containing the unique key of the property.
defaultValue - the default value to use in case no value has been specified.
Returns:
the requested property.
Throws:
UnknownPropertyException - if the key of the descriptor is not known.
IllegalArgumentException

getProperty

public DescribedProperty getProperty(String key,
                                     Object defaultValue)
                              throws IllegalArgumentException,
                                     UnknownPropertyException
Description copied from interface: ConfigurationProperties
Returns the property for the given key, allowing to transparently provide a default value to be returned in case the property has not been set.

Specified by:
getProperty in interface ConfigurationProperties
Overrides:
getProperty in class AbstractConfigurationProperties
Parameters:
key - the unique key of the property.
defaultValue - the default value to use in case no value has been specified.
Returns:
the requested property.
Throws:
IllegalArgumentException - if key is blank.
UnknownPropertyException - if key is not known.

getPropertyAsType

public Object getPropertyAsType(PropertyDescriptor descriptor)
                         throws IllegalArgumentException,
                                UnknownPropertyException,
                                PropertyValueConversionException,
                                SecurityException,
                                PropertyRootException
Description copied from interface: ConfigurationProperties
Returns the yet not validated property for the given descriptor's key. This is useful to access the resolved and converted value to apply validation only under certain conditions.

Specified by:
getPropertyAsType in interface ConfigurationProperties
Parameters:
descriptor - descriptor key to the property.
Returns:
the resolved property. May be null if the property's value is actually unset.
Throws:
IllegalArgumentException - if descriptor is blank.
UnknownPropertyException - if descriptor is not known.
PropertyValueConversionException - if the property cannot be converted to its value.
SecurityException - on any problem decrypting an encrypted value.
PropertyRootException - on any problem.

getValidatedProperty

public ValidatedProperty getValidatedProperty(PropertyDescriptor descriptor,
                                              Object defaultValue)
                                       throws IllegalArgumentException,
                                              UnknownPropertyException,
                                              PropertyValidationException,
                                              SecurityException
Description copied from interface: ConfigurationProperties
Returns the validated property for the given descriptor's key, allowing to transparently provide a default value to be returned in case the property has not been set.

Specified by:
getValidatedProperty in interface ConfigurationProperties
Parameters:
descriptor - descriptor key to the property.
defaultValue - the default value to use in case no value has been specified.
Returns:
the validated property. Never null, although the value / validated value of the returned property may be null.
Throws:
IllegalArgumentException - if descriptor is blank.
UnknownPropertyException - if descriptor is not known.
PropertyValidationException - if the property is invalid according to its constraints.
SecurityException - on any problem decrypting an encrypted value.

validate

public void validate(boolean lenient,
                     Class<?>... groups)
              throws ConfigurationValidationException
Description copied from interface: ConfigurationProperties
Validates all properties in the given configuration.

Specified by:
validate in interface ConfigurationProperties
Parameters:
lenient - the lenient flag that tells the validation process to handle unknown properties gracefully if set to true. If the value is false unknown properties are reported as validation failures.
groups - the validation groups to consider in the validation process. The groups will be validated in the given order. As soon as a validation group fails, the validation process is aborted without checking the not yet processed groups.
Throws:
ConfigurationValidationException - if the configuration contains properties that do not meet the required constraints.

validate

public void validate(PropertyDescriptor descriptor,
                     Class<?>... groups)
              throws ConfigurationValidationException
Description copied from interface: ConfigurationProperties
Validates the given property in the given configuration.

Specified by:
validate in interface ConfigurationProperties
Parameters:
descriptor - the descriptor whose value is to be validated.
groups - the validation only takes place if this constraint is part of any of the specified groups or the argument is empty or null.
Throws:
ConfigurationValidationException - if property does not meet the required constraints.

validate

public void validate(PropertyDescriptor descriptor,
                     String value,
                     Class<?>... groups)
              throws ConfigurationValidationException
Description copied from interface: ConfigurationProperties
Validates the given property in the given configuration.

Specified by:
validate in interface ConfigurationProperties
Parameters:
descriptor - the descriptor whose value is to be validated.
value - the property value to be validated.
groups - the validation only takes place if this constraint is part of any of the specified groups or the argument is empty or null.
Throws:
ConfigurationValidationException - if property does not meet the required constraints.

flush

public void flush()
Description copied from interface: ConfigurationPropertiesManagement
Signal to flush properties changed in memory to be written to a secondary storage.

Implementations are not required to only write on a flush. They have to make sure that after the flush is called, all data is transfered to the secondary storage.

Specified by:
flush in interface ConfigurationPropertiesManagement

toRepresentative

public ConfigurationPropertiesManagement toRepresentative()
Description copied from interface: ConfigurationProperties
Creates an representative of this configuration. If the configuration serves for a specific configuration key, this instance will be returned. If the configuration servers for multiple configuration keys, the representative is returned. The representative is usually the configuration that is associated with the full key.

Specified by:
toRepresentative in interface ConfigurationProperties
Specified by:
toRepresentative in interface ConfigurationPropertiesManagement
Overrides:
toRepresentative in class AbstractConfigurationProperties
Returns:
the representative (may be this).

toSerializable

public SerializableConfigurationPropertiesManagement toSerializable()
Description copied from interface: ConfigurationProperties
Creates a serializable variant of this implementation.

Specified by:
toSerializable in interface ConfigurationProperties
Specified by:
toSerializable in interface ConfigurationPropertiesManagement
Returns:
a serializable variant of this implementation.
See Also:
ConfigurationPropertiesProxy, ConfigurationPropertiesManagementProxy

addDefinitions

public ConfigurationPropertiesManagement addDefinitions(PropertyProvider properties)
                                                 throws NullPointerException
Description copied from interface: ConfigurationPropertiesManagement
Adds the given definitions to this configuration.

Specified by:
addDefinitions in interface ConfigurationPropertiesManagement
Parameters:
properties - the property definitions to add.
Returns:
a reference to this configuration for chaining.
Throws:
NullPointerException - if properties is null.

setProperty

public Property setProperty(PropertyKey key,
                            String value)
                     throws NullPointerException,
                            PropertyValidationException,
                            ReadOnlyPropertyException
Sets the property value for the given key.

This method sets the property in the most defining representative. If the client wants to change a value in a specific defaulting representation by its configuration key, the client has to access this particular instance and set it manually.

Specified by:
setProperty in interface ConfigurationPropertiesManagement
Parameters:
key - the key to the property.
value - the value to the property.
Returns:
the old value to the property. A value of null is returned if the property had no value prior to this call.
Throws:
NullPointerException - if key is null.
PropertyValidationException - if the property value is invalid according to its constraints.
ReadOnlyPropertyException - if the property to update is read-only.

unsetProperty

public Property unsetProperty(PropertyKey key)
                       throws NullPointerException,
                              ReadOnlyPropertyException
Unsets the property value for the given key.

This method unsets the property in the most defining representative. If the client wants to change a value in a specific defaulting representation by its configuration key, the client has to access this particular instance and unset it manually.

Specified by:
unsetProperty in interface ConfigurationPropertiesManagement
Parameters:
key - the key to the property.
Returns:
the old value to the property. A value of null is returned if the property had no value prior to this call.
Throws:
NullPointerException - if key is null.
ReadOnlyPropertyException - if the property to update is read-only.

addDescriptors

public void addDescriptors(Class<?> declaringType)
                    throws DuplicatePropertyDeclarationsException
Description copied from interface: ConfigurationPropertiesManagement
Adds all property descriptors declared in the given type.

Specified by:
addDescriptors in interface ConfigurationPropertiesManagement
Parameters:
declaringType - the type that declares the descriptors.
Throws:
DuplicatePropertyDeclarationsException - if any of the descriptors declare the same property.

getDescriptor

public PropertyDescriptor getDescriptor(String key)
                                 throws UnknownPropertyException
Description copied from interface: ConfigurationPropertiesManagement
Returns the descriptor for the given key.

Specified by:
getDescriptor in interface ConfigurationPropertiesManagement
Parameters:
key - the of the requested descriptor.
Returns:
the descriptor whose key matches the given key.
Throws:
UnknownPropertyException - if the property is not known.

getDescriptor

public PropertyDescriptor getDescriptor(PropertyKey key)
                                 throws UnknownPropertyException
Description copied from interface: ConfigurationPropertiesManagement
Returns the descriptor for the given key.

Specified by:
getDescriptor in interface ConfigurationPropertiesManagement
Parameters:
key - the of the requested descriptor.
Returns:
the descriptor whose key matches the given key.
Throws:
UnknownPropertyException - if the property is not known.

getMandatoryPropertyDescriptors

public List<PropertyDescriptor> getMandatoryPropertyDescriptors()
Description copied from interface: ConfigurationPropertiesManagement
Returns the list of mandatory properties.

Returns a copy that can be edited.

Specified by:
getMandatoryPropertyDescriptors in interface ConfigurationPropertiesManagement
Returns:
the list of mandatory properties.

toString

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

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


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