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

Package class diagram package AbstractConfigurationProperties
java.lang.Object
  extended by de.smartics.properties.spi.config.support.AbstractConfigurationProperties
All Implemented Interfaces:
ConfigurationProperties, ConfigurationPropertiesSpi
Direct Known Subclasses:
AbstractAdminModeConfigurationProperties, ConfigurationPropertiesManagementWithDefaults

@ThreadSafe
public abstract class AbstractConfigurationProperties
     
     
extends Object
implements ConfigurationProperties, ConfigurationPropertiesSpi

Abstract implementation of the ConfigurationProperties interface.


Constructor Summary
protected AbstractConfigurationProperties()
          Constructor for serializable subclasses.
protected AbstractConfigurationProperties(ConfigurationKey<?> key, PropertyDescriptorRegistry registry, PropertyValueSecurity decrypter)
          Default constructor.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds the given listener to track any property changes.
 void addPropertyChangeListener(PropertyKey name, PropertyChangeListener listener)
          Adds the given listener as a listener to the given property.
protected  void firePropertyChange(String name, String oldValue, String newValue)
          Fires the property change event.
 PropertiesContext getContext(Class<?> declaringType)
          Returns the properties context for the declaring type.
 PropertyContext getContext(PropertyDescriptor descriptor)
          Returns the properties context the property described by the given descriptor is part of.
 ConfigurationKey<?> getKey()
          Returns the key of the configuration.
<T> T
getProperties(Class<T> propertiesInterface)
          Returns a implementation of the given interface that has access to the property keys, the property descriptors and the properties itself, when they are declared in the given interface.
<T> T
getProperties(Class<T> propertiesInterface, SerializableConfigurationProperties configuration)
          Returns a implementation of the given interface that has access to the property keys, the property descriptors and the properties itself, when they are declared in the given interface.
 DescribedProperty getProperty(PropertyDescriptor descriptor)
          Returns the property for the given descriptor.
 DescribedProperty getProperty(PropertyKey key)
          Returns the property for the given key.
 DescribedProperty getProperty(String key)
          Returns the property for the given key.
 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.
protected  PropertyDescriptor getPropertyDescriptor(String key)
          Returns the property descriptor for a given key.
 Object getPropertyValue(PropertyDescriptor descriptor)
          Returns the property value for the given descriptor.
 Object getPropertyValue(PropertyDescriptor descriptor, Object defaultValue)
          Returns the property value for the given descriptor, allowing to transparently provide a default value to be returned in case the property has not been set.
 Object getPropertyValue(PropertyKey key)
          Returns the property value for the given key.
 Object getPropertyValue(String key)
          Returns the property value for the given key.
 Object getPropertyValue(String key, Object defaultValue)
          Returns the property value for the given key, allowing to transparently provide a default value to be returned in case the property has not been set.
 String getPropertyValueAsString(PropertyDescriptor descriptor)
          Returns the property string value for the given descriptor.
 String getPropertyValueAsString(PropertyDescriptor descriptor, Object defaultValue)
          Returns the property string value for the given descriptor.
 String getPropertyValueAsString(String key)
          Returns the property string value for the given key.
 String getPropertyValueAsString(String key, Object defaultValue)
          Returns the property string value for the given key.
 PropertyValueSecurity getPropertyValueSecurity()
          Returns the property value security helper to en- and decrypt property values.
 PropertyDescriptorRegistry getRegistry()
          Returns the registry to resolve property descriptors.
 ValidatedProperty getValidatedProperty(PropertyKey key, Object defaultValue)
          Returns the validated property for the given key, allowing to transparently provide a default value to be returned in case the property has not been set.
 ValidatedProperty getValidatedProperty(String key, Object defaultValue)
          Returns the validated property for the given key, allowing to transparently provide a default value to be returned in case the property has not been set.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes the given listener to stop tracking property changes.
 void removePropertyChangeListener(PropertyKey name, PropertyChangeListener listener)
          Removes the given listener as a listener to the given property.
protected  Object resolveAndConvert(PropertyDescriptor descriptor, Object value, Object defaultValue)
          Resolves and converts the given value.
protected  Object resolveAndConvertAndValidate(PropertyDescriptor descriptor, Object defaultValue, Object value)
          Resolves, converts and validates the given value.
 ConfigurationProperties toRepresentative()
          Creates an representative of this configuration.
 String toString()
          Returns the string representation of the object.
 void validate()
          Validates all properties in the given configuration in a non-lenient fashion.
 void validate(Class<?>... groups)
          Validates all properties in the given configuration and groups in a non-lenient fashion.
 void validate(PropertyDescriptor descriptor, Object value, Class<?>... ifInOneOfTheseGroups)
          Validates the given value for the given property.
 
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.ConfigurationProperties
getProperty, getPropertyAsType, getValidatedProperty, isInAdminMode, toSerializable, validate, validate, validate
 

Constructor Detail

AbstractConfigurationProperties

protected AbstractConfigurationProperties()
Constructor for serializable subclasses.


AbstractConfigurationProperties

protected AbstractConfigurationProperties(ConfigurationKey<?> key,
                                          PropertyDescriptorRegistry registry,
                                          PropertyValueSecurity decrypter)
                                   throws de.smartics.util.lang.NullArgumentException
Default constructor.

Parameters:
key - the key that identifies the configuration.
registry - the registry to resolve property descriptors.
decrypter - the helper to decrypt secured property values.
Throws:
de.smartics.util.lang.NullArgumentException - if key, registry or decrypter is null.
Method Detail

getKey

public final ConfigurationKey<?> getKey()
Description copied from interface: ConfigurationProperties
Returns the key of the configuration.

Specified by:
getKey in interface ConfigurationProperties
Returns:
the key of the configuration. Never null.

getContext

public final PropertyContext getContext(PropertyDescriptor descriptor)
                                 throws NullPointerException
Description copied from interface: ConfigurationProperties
Returns the properties context the property described by the given descriptor is part of.

Specified by:
getContext in interface ConfigurationProperties
Parameters:
descriptor - the descriptor of the property whose context is requested.
Returns:
the context of the property described by the descriptor.
Throws:
NullPointerException - if descriptor is null.

getContext

public final PropertiesContext getContext(Class<?> declaringType)
                                   throws NullPointerException
Description copied from interface: ConfigurationProperties
Returns the properties context for the declaring type. The declaring type is the interface type annotated with the PropertySet annotation. The context provides information about the properties of that set.

Specified by:
getContext in interface ConfigurationProperties
Parameters:
declaringType - the type that declares the properties whose context is requested.
Returns:
the context for the properties declared by the given type.
Throws:
NullPointerException - if declaringType is null.

getRegistry

public final PropertyDescriptorRegistry getRegistry()
Returns the registry to resolve property descriptors.

Returns:
the registry to resolve property descriptors.

getPropertyValueSecurity

public final PropertyValueSecurity getPropertyValueSecurity()
Returns the property value security helper to en- and decrypt property values.

Returns:
the property value security helper to en- and decrypt property values.

getProperty

public final DescribedProperty getProperty(String key)
                                    throws IllegalArgumentException,
                                           UnknownPropertyException
Description copied from interface: ConfigurationProperties
Returns the property for the given key.

Specified by:
getProperty in interface ConfigurationProperties
Parameters:
key - the unique key of the property.
Returns:
the requested property.
Throws:
IllegalArgumentException - if key is blank.
UnknownPropertyException - if key is not known.

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
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.

getProperty

public final DescribedProperty getProperty(PropertyKey key)
                                    throws IllegalArgumentException,
                                           UnknownPropertyException
Description copied from interface: ConfigurationProperties
Returns the property for the given key.

Specified by:
getProperty in interface ConfigurationProperties
Parameters:
key - the unique key of the property.
Returns:
the requested property.
Throws:
IllegalArgumentException - if key is blank.
UnknownPropertyException - if key is not known.

getProperty

public final DescribedProperty getProperty(PropertyDescriptor descriptor)
                                    throws IllegalArgumentException,
                                           UnknownPropertyException
Description copied from interface: ConfigurationProperties
Returns the property for the given descriptor.

Specified by:
getProperty in interface ConfigurationProperties
Parameters:
descriptor - the descriptor containing the unique key of the property.
Returns:
the requested property.
Throws:
UnknownPropertyException - if the key of the descriptor is not known.
IllegalArgumentException

getProperties

public final <T> T getProperties(Class<T> propertiesInterface)
Description copied from interface: ConfigurationProperties
Returns a implementation of the given interface that has access to the property keys, the property descriptors and the properties itself, when they are declared in the given interface. The interface must be annotated with an PropertySet annotation.

Specified by:
getProperties in interface ConfigurationProperties
Type Parameters:
T - type variable to enable a type save return value.
Parameters:
propertiesInterface - a PropertySet annotated interface for which a implementation to access the property keys, descriptors and values is requested.
Returns:
a implementation of the given interface to access property information.

getProperties

public final <T> T getProperties(Class<T> propertiesInterface,
                                 SerializableConfigurationProperties configuration)
Description copied from interface: ConfigurationPropertiesSpi
Returns a implementation of the given interface that has access to the property keys, the property descriptors and the properties itself, when they are declared in the given interface. The interface must be annotated with an PropertySet annotation.

Allows to pass in a configuration to consult.

Specified by:
getProperties in interface ConfigurationPropertiesSpi
Type Parameters:
T - type variable to enable a type save return value.
Parameters:
propertiesInterface - a PropertySet annotated interface for which a implementation to access the property keys, descriptors and values is requested.
configuration - the access to the properties. Must not be null.
Returns:
a implementation of the given interface to access property information.

getPropertyValue

public final Object getPropertyValue(String key)
                              throws IllegalArgumentException,
                                     UnknownPropertyException,
                                     PropertyValidationException
Description copied from interface: ConfigurationProperties
Returns the property value for the given key.

Specified by:
getPropertyValue in interface ConfigurationProperties
Parameters:
key - the key to the property.
Returns:
the value to the property. A value of null is returned in cause of an optional property being not set.
Throws:
IllegalArgumentException - if key is blank.
UnknownPropertyException - if key is not known.
PropertyValidationException - if the property is invalid according to its constraints.

getPropertyValue

public final Object getPropertyValue(PropertyKey key)
                              throws IllegalArgumentException,
                                     UnknownPropertyException,
                                     PropertyValidationException
Description copied from interface: ConfigurationProperties
Returns the property value for the given key.

Specified by:
getPropertyValue in interface ConfigurationProperties
Parameters:
key - the key to the property.
Returns:
the value to the property. A value of null is returned in cause of an optional property being not set.
Throws:
IllegalArgumentException - if key is blank.
UnknownPropertyException - if key is not known.
PropertyValidationException - if the property is invalid according to its constraints.

getPropertyValue

public final Object getPropertyValue(String key,
                                     Object defaultValue)
                              throws de.smartics.util.lang.NullArgumentException,
                                     PropertyValidationException
Description copied from interface: ConfigurationProperties
Returns the property value for the given key, allowing to transparently provide a default value to be returned in case the property has not been set.

Specified by:
getPropertyValue in interface ConfigurationProperties
Parameters:
key - the key to the property.
defaultValue - the default value to use in case no value has been specified.
Returns:
the value to the property. A value of null is returned in cause of an optional property being not set.
Throws:
PropertyValidationException - if the property is invalid according to its constraints.
de.smartics.util.lang.NullArgumentException

getPropertyValueAsString

public final String getPropertyValueAsString(String key)
                                      throws de.smartics.util.lang.NullArgumentException,
                                             PropertyValidationException
Description copied from interface: ConfigurationProperties
Returns the property string value for the given key. If the property type is not String, the Object.toString() method is called to create the string representation of the value. null is always returned as null (not as the String "null").

Specified by:
getPropertyValueAsString in interface ConfigurationProperties
Parameters:
key - the key to the property.
Returns:
the value to the property. A value of null is returned in cause of an optional property being not set.
Throws:
PropertyValidationException - if the property is invalid according to its constraints.
de.smartics.util.lang.NullArgumentException

getPropertyValue

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

Specified by:
getPropertyValue in interface ConfigurationProperties
Parameters:
descriptor - the key to the property.
defaultValue - the default value to use in case no value has been specified.
Returns:
the value to the property. A value of null is returned in cause of an optional property being not set.
Throws:
NullPointerException - if descriptor is null.
PropertyValueConversionException - if conversion fails.
PropertyValidationException - if the property is invalid according to its constraints.
UnknownPropertyException - if the requested property is not known to the system.

getPropertyValueAsString

public final String getPropertyValueAsString(String key,
                                             Object defaultValue)
                                      throws de.smartics.util.lang.NullArgumentException,
                                             PropertyValidationException
Description copied from interface: ConfigurationProperties
Returns the property string value for the given key. If the property type is not String, the Object.toString() method is called to create the string representation of the value. null is always returned as null (not as the String "null").

Specified by:
getPropertyValueAsString in interface ConfigurationProperties
Parameters:
key - the key to the property.
defaultValue - the default value to use in case no value has been specified.
Returns:
the value to the property. A value of null is returned in cause of an optional property being not set.
Throws:
PropertyValidationException - if the property is invalid according to its constraints.
de.smartics.util.lang.NullArgumentException

getPropertyValue

public final Object getPropertyValue(PropertyDescriptor descriptor)
                              throws de.smartics.util.lang.NullArgumentException,
                                     PropertyValidationException
Description copied from interface: ConfigurationProperties
Returns the property value for the given descriptor.

Specified by:
getPropertyValue in interface ConfigurationProperties
Parameters:
descriptor - the key to the property.
Returns:
the value to the property. A value of null is returned in cause of an optional property being not set.
Throws:
PropertyValidationException - if the property is invalid according to its constraints.
de.smartics.util.lang.NullArgumentException

getPropertyValueAsString

public final String getPropertyValueAsString(PropertyDescriptor descriptor)
                                      throws de.smartics.util.lang.NullArgumentException,
                                             PropertyValidationException
Description copied from interface: ConfigurationProperties
Returns the property string value for the given descriptor. If the property type is not String, the Object.toString() method is called to create the string representation of the value. null is always returned as null (not as the String "null").

Specified by:
getPropertyValueAsString in interface ConfigurationProperties
Parameters:
descriptor - the key to the property.
Returns:
the value to the property. A value of null is returned in cause of an optional property being not set.
Throws:
PropertyValidationException - if the property is invalid according to its constraints.
de.smartics.util.lang.NullArgumentException

getPropertyValueAsString

public final String getPropertyValueAsString(PropertyDescriptor descriptor,
                                             Object defaultValue)
                                      throws de.smartics.util.lang.NullArgumentException,
                                             PropertyValidationException
Description copied from interface: ConfigurationProperties
Returns the property string value for the given descriptor. If the property type is not String, the Object.toString() method is called to create the string representation of the value. null is always returned as null (not as the String "null").

Specified by:
getPropertyValueAsString in interface ConfigurationProperties
Parameters:
descriptor - the key to the property.
defaultValue - the default value to use in case no value has been specified.
Returns:
the value to the property. A value of null is returned in cause of an optional property being not set.
Throws:
PropertyValidationException - if the property is invalid according to its constraints.
de.smartics.util.lang.NullArgumentException

getValidatedProperty

public final ValidatedProperty getValidatedProperty(PropertyKey key,
                                                    Object defaultValue)
                                             throws IllegalArgumentException,
                                                    UnknownPropertyException,
                                                    PropertyValidationException,
                                                    SecurityException
Description copied from interface: ConfigurationProperties
Returns the validated 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:
getValidatedProperty in interface ConfigurationProperties
Parameters:
key - the 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 key is blank.
UnknownPropertyException - if key is not known.
PropertyValidationException - if the property is invalid according to its constraints.
SecurityException - on any problem decrypting an encrypted value.

getValidatedProperty

public final ValidatedProperty getValidatedProperty(String key,
                                                    Object defaultValue)
                                             throws IllegalArgumentException,
                                                    UnknownPropertyException,
                                                    PropertyValidationException,
                                                    SecurityException
Description copied from interface: ConfigurationProperties
Returns the validated 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:
getValidatedProperty in interface ConfigurationProperties
Parameters:
key - the 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 key is blank.
UnknownPropertyException - if key is not known.
PropertyValidationException - if the property is invalid according to its constraints.
SecurityException - on any problem decrypting an encrypted value.

getPropertyDescriptor

protected final PropertyDescriptor getPropertyDescriptor(String key)
                                                  throws de.smartics.util.lang.BlankArgumentException,
                                                         PropertyValidationException
Returns the property descriptor for a given key.

Parameters:
key - the key for which the property descriptor is needed.
Returns:
the property descriptor for the given key.
Throws:
de.smartics.util.lang.BlankArgumentException - when the key is blank.
PropertyValidationException - when the configuration is invalid.

resolveAndConvertAndValidate

protected final Object resolveAndConvertAndValidate(PropertyDescriptor descriptor,
                                                    Object defaultValue,
                                                    Object value)
                                             throws PropertyValueConversionException,
                                                    PropertyValidationException,
                                                    SecurityException
Resolves, converts and validates the given value.

Parameters:
descriptor - the property descriptor.
defaultValue - the default value to use if value is null and there is no default expression.
value - the value to resolve, convert and validate.
Returns:
the resolved, converted and validated value.
Throws:
PropertyValueConversionException - if the value cannot be converted from String to the target type. If the configuration is set to admin mode, the unresolved value will be returned. In this case the type is not of the target type as described by the descriptor.
PropertyValidationException - if at least on constraint is not met.
SecurityException - on any problem decrypting an encrypted value.

validate

public void validate(PropertyDescriptor descriptor,
                     Object value,
                     Class<?>... ifInOneOfTheseGroups)
Validates the given value for the given property.

Parameters:
descriptor - the descriptor to the property to use for validation.
value - the property value to validate.
ifInOneOfTheseGroups - 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.

resolveAndConvert

protected final Object resolveAndConvert(PropertyDescriptor descriptor,
                                         Object value,
                                         Object defaultValue)
                                  throws PropertyValueResolveException,
                                         PropertyValueConversionException,
                                         SecurityException
Resolves and converts the given value.

Parameters:
descriptor - the property descriptor.
value - the value to resolve and convert.
defaultValue - the default value to use if value is null and there is no default expression.
Returns:
the resolved and converted value.
Throws:
PropertyValueResolveException - if the value cannot be resolved.
PropertyValueConversionException - if the value cannot be converted from String to the target type.
SecurityException - on any problem decrypting an encrypted value.

validate

public final void validate()
                    throws ConfigurationValidationException
Description copied from interface: ConfigurationProperties
Validates all properties in the given configuration in a non-lenient fashion.

Specified by:
validate in interface ConfigurationProperties
Throws:
ConfigurationValidationException - if the configuration contains properties that do not meet the required constraints.

validate

public final void validate(Class<?>... groups)
                    throws ConfigurationValidationException
Description copied from interface: ConfigurationProperties
Validates all properties in the given configuration and groups in a non-lenient fashion.

Specified by:
validate in interface ConfigurationProperties
Parameters:
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.

addPropertyChangeListener

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

Specified by:
addPropertyChangeListener in interface ConfigurationProperties
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 final void removePropertyChangeListener(PropertyKey name,
                                               PropertyChangeListener listener)
                                        throws NullPointerException
Description copied from interface: ConfigurationProperties
Removes the given listener as a listener to the given property.

Specified by:
removePropertyChangeListener in interface ConfigurationProperties
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 final void addPropertyChangeListener(PropertyChangeListener listener)
                                     throws NullPointerException
Description copied from interface: ConfigurationProperties
Adds the given listener to track any property changes.

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

removePropertyChangeListener

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

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

firePropertyChange

protected final void firePropertyChange(String name,
                                        String oldValue,
                                        String newValue)
Fires the property change event.

Parameters:
name - the name of the property.
oldValue - the old value of the property that has been changed.
newValue - the new and current value of the property.

toRepresentative

public ConfigurationProperties 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
Returns:
the representative (may be this).

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.