pl.edu.agh.cast.data.model.property
Class PropertyContainer

java.lang.Object
  extended by pl.edu.agh.cast.data.model.property.PropertyContainer
All Implemented Interfaces:
Serializable, Observer, IDisposable, IValidatable, IPropertyContainer
Direct Known Subclasses:
AbstractDataSet, AbstractElement

public class PropertyContainer
extends Object
implements IPropertyContainer, Observer, IDisposable

Default implementation of IPropertyContainer. It should be either sub-classed or aggregated by other classes that implement this interface.

Author:
AGH CAST Team
See Also:
Serialized Form

Constructor Summary
protected PropertyContainer()
          Default constructor.
  PropertyContainer(MetaPropertyManager mpm)
          Constructor.
 
Method Summary
 void addProperty(Property<? extends MetaProperty> property)
          Adds property to this container.
protected  void afterSetMetaPropertyManager()
          Called right after setting the MPM.
protected  Property<? extends MetaProperty> createProperty(MetaProperty metaProperty)
           
 void dispose()
          Disposes this instance of PropertyContainer.
 Collection<CustomProperty> getCustomProperties()
          Returns all custom properties.
 MetaPropertyManager getMetaPropertyManager()
          Returns MetaPropertyManager of this container's properties.
 Collection<PermanentProperty> getPermanentProperties()
          Returns all permanent properties.
 Collection<Property<? extends MetaProperty>> getProperties()
          Returns all properties.
 Property<? extends MetaProperty> getProperty(String name)
          Returns property with given name.
 Collection<TransientProperty> getTransientProperties()
          Returns all transient properties.
protected  void initializeProperties()
           
 boolean isValid()
          Checks if the state of implementing object is valid.
 boolean matches(IPropertyContainer other)
          Checks if this property container matches the property container argument.
 Property<? extends MetaProperty> removeProperty(String name)
          Removes property with given name.
 void setMetaPropertyManager(MetaPropertyManager mpm)
          Sets the MetaPropertyManager of this container's properties.
 Property<? extends MetaProperty> setProperty(String name, Object value)
          Modifies property value.
 void update(Observable sender, Object event)
          Notifies the container about change of the observed MetaPropertyManager ( getMetaPropertyManager()).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyContainer

protected PropertyContainer()
Default constructor.

Usage of this constructor is discouraged, since it does not provide any integrity control. If, however, this constructor is used, the isValid() method should be called in order to check the integrity.


PropertyContainer

public PropertyContainer(MetaPropertyManager mpm)
Constructor.

Parameters:
mpm - MetaPropertyManager which manages container's meta-properties
Method Detail

addProperty

public void addProperty(Property<? extends MetaProperty> property)
Adds property to this container.

Specified by:
addProperty in interface IPropertyContainer
Parameters:
property - property to add
See Also:
#addProperty(pl.edu.agh.cast.data.model.property.Property)

getCustomProperties

public Collection<CustomProperty> getCustomProperties()
Returns all custom properties.

Specified by:
getCustomProperties in interface IPropertyContainer
Returns:
unmodifiable collection of custom properties
See Also:
IPropertyContainer.getCustomProperties()

getPermanentProperties

public Collection<PermanentProperty> getPermanentProperties()
Returns all permanent properties.

Specified by:
getPermanentProperties in interface IPropertyContainer
Returns:
unmodifiable collection of permanent properties
See Also:
IPropertyContainer.getPermanentProperties()

getTransientProperties

public Collection<TransientProperty> getTransientProperties()
Returns all transient properties.

Specified by:
getTransientProperties in interface IPropertyContainer
Returns:
unmodifiable collection of transient properties
See Also:
IPropertyContainer.getTransientProperties()

getProperties

public Collection<Property<? extends MetaProperty>> getProperties()
Returns all properties.

Specified by:
getProperties in interface IPropertyContainer
Returns:
unmodifiable collection of all properties
See Also:
IPropertyContainer.getProperties()

getProperty

public Property<? extends MetaProperty> getProperty(String name)
Returns property with given name.

If a property was not yet created but a meta-property with given name is defined in meta-property manager then a new instance is added to the container and returned.

Specified by:
getProperty in interface IPropertyContainer
Parameters:
name - name of the property
Returns:
property with give name, or null if property with given name is not defined
See Also:
IPropertyContainer.getProperty(java.lang.String)

removeProperty

public Property<? extends MetaProperty> removeProperty(String name)
Removes property with given name.

Specified by:
removeProperty in interface IPropertyContainer
Parameters:
name - name of the property
Returns:
the removed property
See Also:
IPropertyContainer.removeProperty(java.lang.String)

setProperty

public Property<? extends MetaProperty> setProperty(String name,
                                                    Object value)
Modifies property value.

Specified by:
setProperty in interface IPropertyContainer
Parameters:
name - name of the property
value - new value of the property
Returns:
modified property
See Also:
IPropertyContainer.setProperty(java.lang.String, java.lang.Object)

initializeProperties

protected final void initializeProperties()

getMetaPropertyManager

public MetaPropertyManager getMetaPropertyManager()
Returns MetaPropertyManager of this container's properties.

Specified by:
getMetaPropertyManager in interface IPropertyContainer
Returns:
the meta property manager
See Also:
IPropertyContainer.getMetaPropertyManager()

setMetaPropertyManager

public final void setMetaPropertyManager(MetaPropertyManager mpm)
Sets the MetaPropertyManager of this container's properties.

Parameters:
mpm - the meta property manager

afterSetMetaPropertyManager

protected void afterSetMetaPropertyManager()
Called right after setting the MPM. May be overridden.


update

public final void update(Observable sender,
                         Object event)
Notifies the container about change of the observed MetaPropertyManager ( getMetaPropertyManager()).

Specified by:
update in interface Observer
Parameters:
sender - the sender object - must be equal to this container's MetaPropertyManager
event - the event object - must be an instance of MetaPropertyEvent
Throws:
IllegalArgumentException - if any of the arguments is null or if sender != this.getMetaPropertyManager() or event is not of type MetaPropertyEvent
See Also:
Observer.update(java.util.Observable, java.lang.Object)

dispose

public void dispose()
Disposes this instance of PropertyContainer. This method has to be called before disposing the container. Not doing so will result in the instance not being garbage-collected (thus memory leakage).

Specified by:
dispose in interface IDisposable
See Also:
IDisposable.dispose()

matches

public boolean matches(IPropertyContainer other)
Checks if this property container matches the property container argument. This method should be used to compare domain semantic of two objects, as it compares values of chosen (set as matchable) properties.

One container matches the second one if:

Specified by:
matches in interface IPropertyContainer
Parameters:
other - the reference property container with which to compare
Returns:
true if this container is matchable to the container argument.
See Also:
matches(pl.edu.agh.cast.data.model.property.IPropertyContainer)

isValid

public boolean isValid()
Checks if the state of implementing object is valid.

Specified by:
isValid in interface IValidatable
Returns:
true if object's state is valid, false otherwise
See Also:
IValidatable.isValid()

createProperty

protected Property<? extends MetaProperty> createProperty(MetaProperty metaProperty)


Copyright © 2007-2009 IISG AGH-UST Krakow, Poland. All Rights Reserved.