Package com.bc.ceres.binding
Class PropertyContainer
java.lang.Object
com.bc.ceres.binding.PropertyContainer
- All Implemented Interfaces:
PropertyChangeEmitter
,PropertySet
- Direct Known Subclasses:
DefaultFigureStyle
A convenience implementation of the
PropertySet
interface.
PropertyContainer
is basically an implementation of the Property List design pattern.- Since:
- 0.6
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addProperties
(Property... properties) Adds the given properties to this set.void
addProperty
(Property property) Adds a property to this set.void
Adds a property change listener to this emitter.void
Adds a dedicated property change listener to this emitter.static PropertyContainer
createForFields
(Class<?> type, PropertyDescriptorFactory descriptorFactory, PropertyAccessorFactory accessorFactory, boolean initValues) Creates a property container for the given template type.static PropertyContainer
createMapBacked
(Map<String, Object> map) Creates a property container for a map backing the values.static PropertyContainer
createMapBacked
(Map<String, Object> map, PropertySetDescriptor propertySetDescriptor) Creates a property container for a map backing the values.static PropertyContainer
createMapBacked
(Map<String, Object> map, Class<?> templateType) Creates a property container for the given template type and map backing the values.static PropertyContainer
createMapBacked
(Map<String, Object> map, Class<?> templateType, PropertyDescriptorFactory descriptorFactory) Creates a property container for the given template type and map backing the values.static PropertyContainer
createObjectBacked
(Object object) Creates a property container for the given object.static PropertyContainer
createObjectBacked
(Object object, PropertyDescriptorFactory descriptorFactory) Creates a property container for the given object.static PropertyContainer
createObjectBacked
(Object object, PropertySetDescriptor propertySetDescriptor) static PropertyContainer
createValueBacked
(Class<?> templateType) Creates a property container for the given template type.static PropertyContainer
createValueBacked
(Class<?> templateType, PropertyDescriptorFactory descriptorFactory) Creates a property container for the given template type.getDescriptor
(String name) Gets the descriptor for the named property.Property[]
Gets all properties currently contained in this set.getProperty
(String name) Gets the named property.<T> T
Gets the value of the named property.boolean
isPropertyDefined
(String name) Tests if the named property is defined in this set.void
removeProperties
(Property... properties) Removes the given properties from this set.void
removeProperty
(Property property) Removes a property from this set.void
Removes a property change listener from this emitter.void
Removes a dedicated property change listener from this emitter.void
Sets all properties to their default values.void
Sets the value of the named property.
-
Constructor Details
-
PropertyContainer
public PropertyContainer()Constructs a new, empty property container.
-
-
Method Details
-
createObjectBacked
Creates a property container for the given object. The factory method will not modify the object, thus not setting any default values.- Parameters:
object
- the backing object- Returns:
- The property container.
-
createObjectBacked
public static PropertyContainer createObjectBacked(Object object, PropertyDescriptorFactory descriptorFactory) Creates a property container for the given object. The factory method will not modify the object, thus not setting any default values.- Parameters:
object
- the backing objectdescriptorFactory
- a factory used to createPropertyDescriptor
s of the fields of the object's type- Returns:
- The property container.
-
createObjectBacked
public static PropertyContainer createObjectBacked(Object object, PropertySetDescriptor propertySetDescriptor) -
createMapBacked
Creates a property container for a map backing the values. The properties are derived from the current map entries.- Parameters:
map
- the map which backs the values- Returns:
- The property container.
-
createMapBacked
public static PropertyContainer createMapBacked(Map<String, Object> map, PropertySetDescriptor propertySetDescriptor) Creates a property container for a map backing the values. The factory method will not modify the given map, thus not setting any default values.- Parameters:
map
- the map which backs the valuespropertySetDescriptor
- A descriptor the property set to be created.- Returns:
- The property container.
-
createMapBacked
Creates a property container for the given template type and map backing the values. The factory method will not modify the given map, thus not setting any default values.- Parameters:
map
- the map which backs the valuestemplateType
- the template type- Returns:
- The property container.
-
createMapBacked
public static PropertyContainer createMapBacked(Map<String, Object> map, Class<?> templateType, PropertyDescriptorFactory descriptorFactory) Creates a property container for the given template type and map backing the values. The factory method will not modify the given map, thus not setting any default values.- Parameters:
map
- the map which backs the valuestemplateType
- the template typedescriptorFactory
- a factory used to createPropertyDescriptor
s of the fields of the template type- Returns:
- The property container.
-
createValueBacked
Creates a property container for the given template type. All properties will have their values set to default values (if specified).- Parameters:
templateType
- the template type- Returns:
- The property container.
-
createValueBacked
public static PropertyContainer createValueBacked(Class<?> templateType, PropertyDescriptorFactory descriptorFactory) Creates a property container for the given template type. All properties will have their values set to default values (if specified).- Parameters:
templateType
- the template class used to derive the descriptors fromdescriptorFactory
- a factory used to createPropertyDescriptor
s of the fields of the template type- Returns:
- The property container.
-
createForFields
public static PropertyContainer createForFields(Class<?> type, PropertyDescriptorFactory descriptorFactory, PropertyAccessorFactory accessorFactory, boolean initValues) Creates a property container for the given template type. Properties are generated using thedescriptorFactory
and theaccessorFactory
which are called for each non-static and non-transient class field.- Parameters:
type
- The type that provides the fields.descriptorFactory
- The property descriptor factory.accessorFactory
- The property accessor factory.initValues
- Iftrue
, properties are initialised by their default values, if specified.- Returns:
- The property container.
-
getProperties
Description copied from interface:PropertySet
Gets all properties currently contained in this set.- Specified by:
getProperties
in interfacePropertySet
- Returns:
- The array of properties, which may be empty.
-
isPropertyDefined
Description copied from interface:PropertySet
Tests if the named property is defined in this set. For undefined properties, the methodgetProperty(name)
will always returnnull
.- Specified by:
isPropertyDefined
in interfacePropertySet
- Parameters:
name
- The property name or the property's alias name (both case sensitive).- Returns:
true
if the property is defined.
-
getProperty
Description copied from interface:PropertySet
Gets the named property.- Specified by:
getProperty
in interfacePropertySet
- Parameters:
name
- The property name or the property's alias name (both case sensitive).- Returns:
- The property, or
null
if the property does not exist. - See Also:
-
addProperty
Description copied from interface:PropertySet
Adds a property to this set.- Specified by:
addProperty
in interfacePropertySet
- Parameters:
property
- The property.
-
addProperties
Description copied from interface:PropertySet
Adds the given properties to this set.- Specified by:
addProperties
in interfacePropertySet
- Parameters:
properties
- The properties to be added.
-
removeProperty
Description copied from interface:PropertySet
Removes a property from this set.- Specified by:
removeProperty
in interfacePropertySet
- Parameters:
property
- The property.
-
removeProperties
Description copied from interface:PropertySet
Removes the given properties from this set.- Specified by:
removeProperties
in interfacePropertySet
- Parameters:
properties
- The properties to be removed.
-
getValue
Description copied from interface:PropertySet
Gets the value of the named property.- Specified by:
getValue
in interfacePropertySet
- Parameters:
name
- The property name.- Returns:
- The property value or
null
if a property with the given name does not exist.
-
setValue
Description copied from interface:PropertySet
Sets the value of the named property.- Specified by:
setValue
in interfacePropertySet
- Parameters:
name
- The property name.value
- The new property value.- Throws:
IllegalArgumentException
- If the value is illegal. The cause will always be aValidationException
.
-
getDescriptor
Description copied from interface:PropertySet
Gets the descriptor for the named property.- Specified by:
getDescriptor
in interfacePropertySet
- Parameters:
name
- The property name (case sensitive).- Returns:
- The descriptor, or
null
if the property is unknown.
-
setDefaultValues
Description copied from interface:PropertySet
Sets all properties to their default values.- Specified by:
setDefaultValues
in interfacePropertySet
- Throws:
IllegalStateException
- If at least one of the default values is illegal. The cause will always be aValidationException
.- See Also:
-
addPropertyChangeListener
Description copied from interface:PropertyChangeEmitter
Adds a property change listener to this emitter.- Specified by:
addPropertyChangeListener
in interfacePropertyChangeEmitter
- Parameters:
l
- The listener.
-
addPropertyChangeListener
Description copied from interface:PropertyChangeEmitter
Adds a dedicated property change listener to this emitter.- Specified by:
addPropertyChangeListener
in interfacePropertyChangeEmitter
- Parameters:
name
- The property name.l
- The listener.
-
removePropertyChangeListener
Description copied from interface:PropertyChangeEmitter
Removes a property change listener from this emitter.- Specified by:
removePropertyChangeListener
in interfacePropertyChangeEmitter
- Parameters:
l
- The listener.
-
removePropertyChangeListener
Description copied from interface:PropertyChangeEmitter
Removes a dedicated property change listener from this emitter.- Specified by:
removePropertyChangeListener
in interfacePropertyChangeEmitter
- Parameters:
name
- The property name.l
- The listener.
-