Package com.bc.ceres.binding
Class PropertyContainer
- java.lang.Object
-
- com.bc.ceres.binding.PropertyContainer
-
- All Implemented Interfaces:
PropertyChangeEmitter,PropertySet
- Direct Known Subclasses:
DefaultFigureStyle
public class PropertyContainer extends Object implements PropertySet
A convenience implementation of thePropertySetinterface.PropertyContaineris basically an implementation of the Property List design pattern.- Since:
- 0.6
-
-
Constructor Summary
Constructors Constructor Description PropertyContainer()Constructs a new, empty property container.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddProperties(Property... properties)Adds the given properties to this set.voidaddProperty(Property property)Adds a property to this set.voidaddPropertyChangeListener(PropertyChangeListener l)Adds a property change listener to this emitter.voidaddPropertyChangeListener(String name, PropertyChangeListener l)Adds a dedicated property change listener to this emitter.static PropertyContainercreateForFields(Class<?> type, PropertyDescriptorFactory descriptorFactory, PropertyAccessorFactory accessorFactory, boolean initValues)Creates a property container for the given template type.static PropertyContainercreateMapBacked(Map<String,Object> map)Creates a property container for a map backing the values.static PropertyContainercreateMapBacked(Map<String,Object> map, PropertySetDescriptor propertySetDescriptor)Creates a property container for a map backing the values.static PropertyContainercreateMapBacked(Map<String,Object> map, Class<?> templateType)Creates a property container for the given template type and map backing the values.static PropertyContainercreateMapBacked(Map<String,Object> map, Class<?> templateType, PropertyDescriptorFactory descriptorFactory)Creates a property container for the given template type and map backing the values.static PropertyContainercreateObjectBacked(Object object)Creates a property container for the given object.static PropertyContainercreateObjectBacked(Object object, PropertyDescriptorFactory descriptorFactory)Creates a property container for the given object.static PropertyContainercreateObjectBacked(Object object, PropertySetDescriptor propertySetDescriptor)static PropertyContainercreateValueBacked(Class<?> templateType)Creates a property container for the given template type.static PropertyContainercreateValueBacked(Class<?> templateType, PropertyDescriptorFactory descriptorFactory)Creates a property container for the given template type.PropertyDescriptorgetDescriptor(String name)Gets the descriptor for the named property.Property[]getProperties()Gets all properties currently contained in this set.PropertygetProperty(String name)Gets the named property.<T> TgetValue(String name)Gets the value of the named property.booleanisPropertyDefined(String name)Tests if the named property is defined in this set.voidremoveProperties(Property... properties)Removes the given properties from this set.voidremoveProperty(Property property)Removes a property from this set.voidremovePropertyChangeListener(PropertyChangeListener l)Removes a property change listener from this emitter.voidremovePropertyChangeListener(String name, PropertyChangeListener l)Removes a dedicated property change listener from this emitter.voidsetDefaultValues()Sets all properties to their default values.voidsetValue(String name, Object value)Sets the value of the named property.
-
-
-
Method Detail
-
createObjectBacked
public static PropertyContainer createObjectBacked(Object object)
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 createPropertyDescriptors of the fields of the object's type- Returns:
- The property container.
-
createObjectBacked
public static PropertyContainer createObjectBacked(Object object, PropertySetDescriptor propertySetDescriptor)
-
createMapBacked
public static PropertyContainer createMapBacked(Map<String,Object> map)
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
public static PropertyContainer createMapBacked(Map<String,Object> map, Class<?> templateType)
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 createPropertyDescriptors of the fields of the template type- Returns:
- The property container.
-
createValueBacked
public static PropertyContainer createValueBacked(Class<?> templateType)
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 createPropertyDescriptors 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 thedescriptorFactoryand theaccessorFactorywhich 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
public Property[] getProperties()
Description copied from interface:PropertySetGets all properties currently contained in this set.- Specified by:
getPropertiesin interfacePropertySet- Returns:
- The array of properties, which may be empty.
-
isPropertyDefined
public boolean isPropertyDefined(String name)
Description copied from interface:PropertySetTests if the named property is defined in this set. For undefined properties, the methodgetProperty(name)will always returnnull.- Specified by:
isPropertyDefinedin interfacePropertySet- Parameters:
name- The property name or the property's alias name (both case sensitive).- Returns:
trueif the property is defined.
-
getProperty
public Property getProperty(String name)
Description copied from interface:PropertySetGets the named property.- Specified by:
getPropertyin interfacePropertySet- Parameters:
name- The property name or the property's alias name (both case sensitive).- Returns:
- The property, or
nullif the property does not exist. - See Also:
PropertySet.isPropertyDefined(String),PropertyDescriptor.getAlias()
-
addProperty
public void addProperty(Property property)
Description copied from interface:PropertySetAdds a property to this set.- Specified by:
addPropertyin interfacePropertySet- Parameters:
property- The property.
-
addProperties
public void addProperties(Property... properties)
Description copied from interface:PropertySetAdds the given properties to this set.- Specified by:
addPropertiesin interfacePropertySet- Parameters:
properties- The properties to be added.
-
removeProperty
public void removeProperty(Property property)
Description copied from interface:PropertySetRemoves a property from this set.- Specified by:
removePropertyin interfacePropertySet- Parameters:
property- The property.
-
removeProperties
public void removeProperties(Property... properties)
Description copied from interface:PropertySetRemoves the given properties from this set.- Specified by:
removePropertiesin interfacePropertySet- Parameters:
properties- The properties to be removed.
-
getValue
public <T> T getValue(String name)
Description copied from interface:PropertySetGets the value of the named property.- Specified by:
getValuein interfacePropertySet- Parameters:
name- The property name.- Returns:
- The property value or
nullif a property with the given name does not exist.
-
setValue
public void setValue(String name, Object value) throws IllegalArgumentException
Description copied from interface:PropertySetSets the value of the named property.- Specified by:
setValuein 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
public PropertyDescriptor getDescriptor(String name)
Description copied from interface:PropertySetGets the descriptor for the named property.- Specified by:
getDescriptorin interfacePropertySet- Parameters:
name- The property name (case sensitive).- Returns:
- The descriptor, or
nullif the property is unknown.
-
setDefaultValues
public void setDefaultValues() throws IllegalStateExceptionDescription copied from interface:PropertySetSets all properties to their default values.- Specified by:
setDefaultValuesin interfacePropertySet- Throws:
IllegalStateException- If at least one of the default values is illegal. The cause will always be aValidationException.- See Also:
PropertyDescriptor.getDefaultValue()
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener l)
Description copied from interface:PropertyChangeEmitterAdds a property change listener to this emitter.- Specified by:
addPropertyChangeListenerin interfacePropertyChangeEmitter- Parameters:
l- The listener.
-
addPropertyChangeListener
public void addPropertyChangeListener(String name, PropertyChangeListener l)
Description copied from interface:PropertyChangeEmitterAdds a dedicated property change listener to this emitter.- Specified by:
addPropertyChangeListenerin interfacePropertyChangeEmitter- Parameters:
name- The property name.l- The listener.
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener l)
Description copied from interface:PropertyChangeEmitterRemoves a property change listener from this emitter.- Specified by:
removePropertyChangeListenerin interfacePropertyChangeEmitter- Parameters:
l- The listener.
-
removePropertyChangeListener
public void removePropertyChangeListener(String name, PropertyChangeListener l)
Description copied from interface:PropertyChangeEmitterRemoves a dedicated property change listener from this emitter.- Specified by:
removePropertyChangeListenerin interfacePropertyChangeEmitter- Parameters:
name- The property name.l- The listener.
-
-