org.graffiti.attributes
Class HashMapAttribute

java.lang.Object
  extended by org.graffiti.attributes.AbstractAttribute
      extended by org.graffiti.attributes.AbstractCollectionAttribute
          extended by org.graffiti.attributes.HashMapAttribute
All Implemented Interfaces:
Attribute, CollectionAttribute, DeepCopy, Displayable<Object>
Direct Known Subclasses:
ColorAttribute, DimensionAttribute, DockingAttribute, GraphElementGraphicAttribute, GraphGraphicAttribute, ImageAttribute, LabelAttribute, PortAttribute, PortsAttribute

public class HashMapAttribute
extends AbstractCollectionAttribute
implements CollectionAttribute

Maps a given id to an attribute. (e.g. if this Attribute contains 2 other attributes, one StringAttribute with id "Name" and another CollectionAttribute with id "Color" which contains three IntegerAttributes ('red', 'green' and 'blue'). The map then contains only the two key-value pairs 'Name'-StringAttribute and 'Color'-CollectionAttribute. The subattributes 'red', 'green' and 'blue' are not mapped in this Attribute!

Version:
$Revision: 5767 $
See Also:
CollectionAttribute, CompositeAttribute

Field Summary
 
Fields inherited from class org.graffiti.attributes.AbstractCollectionAttribute
attributes
 
Fields inherited from class org.graffiti.attributes.AbstractAttribute
id
 
Fields inherited from interface org.graffiti.attributes.Attribute
SEPARATOR
 
Constructor Summary
HashMapAttribute(String id)
          Construct a new instance of a HashMapAttribute.
 
Method Summary
 Object copy()
          Copies this CollectionAttribute and returns the copy.
protected  void doSetValue(Object o)
          Sets the value of the attribute by calling method setCollection(Map attrs).
 Map<String,Attribute> getCollection()
          Returns a cloned map (shallow copy of map: i.e.
 void setCollection(Map<String,Attribute> attrs)
          Sets the collection of attributes contained within this CollectionAttribute For each entry in the map, pre- and post- AttributeAdded events are generated since method add(Attribute a) is called for each attribute in the map.
 void setDefaultValue()
          Already done in constructor for this attribute type.
 
Methods inherited from class org.graffiti.attributes.AbstractCollectionAttribute
add, add, containsAttribute, getAttributable, getAttribute, getValue, isEmpty, remove, remove, setAttributable, toString, toXMLString
 
Methods inherited from class org.graffiti.attributes.AbstractAttribute
callPostAttributeAdded, callPostAttributeChanged, callPostAttributeRemoved, callPreAttributeAdded, callPreAttributeChanged, callPreAttributeRemoved, getDescription, getId, getName, getParent, getPath, getSpaces, getStandardXML, setDescription, setParent, setValue, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.graffiti.attributes.CollectionAttribute
add, add, containsAttribute, getAttribute, isEmpty, remove, remove, setAttributable
 
Methods inherited from interface org.graffiti.attributes.Attribute
getAttributable, getId, getParent, getPath, getValue, setParent, setValue, toString
 
Methods inherited from interface org.graffiti.plugin.Displayable
getDescription, getName, setDescription, toXMLString
 

Constructor Detail

HashMapAttribute

public HashMapAttribute(String id)
Construct a new instance of a HashMapAttribute. The internal HashMap is initialized empty.

Parameters:
id - the id of the attribute.
Method Detail

setCollection

public void setCollection(Map<String,Attribute> attrs)
Sets the collection of attributes contained within this CollectionAttribute For each entry in the map, pre- and post- AttributeAdded events are generated since method add(Attribute a) is called for each attribute in the map.

Specified by:
setCollection in interface CollectionAttribute
Parameters:
attrs - the Map that contains all attributes.

getCollection

public Map<String,Attribute> getCollection()
Returns a cloned map (shallow copy of map: i.e. this.map.equals(getCollection())but not this.map == getCollection()) between attributes' ids and attributes contained in this attribute.

Specified by:
getCollection in interface CollectionAttribute
Returns:
a clone of the list of attributes in this attribute.

setDefaultValue

public void setDefaultValue()
Already done in constructor for this attribute type.

Specified by:
setDefaultValue in interface Attribute
See Also:
Attribute.setDefaultValue()

copy

public Object copy()
Copies this CollectionAttribute and returns the copy. All sub-attributes will be copied, too, i.e. a deep-copy is returned.

Specified by:
copy in interface DeepCopy
Returns:
a copy of the CollectionAttribute.

doSetValue

protected void doSetValue(Object o)
                   throws IllegalArgumentException
Sets the value of the attribute by calling method setCollection(Map attrs). The "value" is the Collection of attributes. For each entry in the map, pre- and post- AttributeAdded events are generated.

Specified by:
doSetValue in class AbstractAttribute
Parameters:
o - the new value of the attribute.
Throws:
IllegalArgumentException - if the parameter has not the appropriate class for this attribute.


Generated at 2012-05-30 11:00:36 PM CEST