org.graffiti.attributes
Class AbstractCollectionAttribute

java.lang.Object
  extended by org.graffiti.attributes.AbstractAttribute
      extended by org.graffiti.attributes.AbstractCollectionAttribute
All Implemented Interfaces:
Attribute, CollectionAttribute, DeepCopy, Displayable<Object>
Direct Known Subclasses:
HashMapAttribute, LinkedHashMapAttribute

public abstract class AbstractCollectionAttribute
extends AbstractAttribute
implements CollectionAttribute

Provides common functionality for CollectionAttribute instances. Calls the ListenerManager and delegates the functionality to the implementing class.

Version:
$Revision: 5779 $

Field Summary
 
Fields inherited from interface org.graffiti.attributes.Attribute
SEPARATOR
 
Constructor Summary
AbstractCollectionAttribute(String id)
          Constructor for setting the id of an AbstractCollectionAttribute.
 
Method Summary
 void add(Attribute a)
          Adds a given attribute to the collection.
 void add(Attribute a, boolean inform)
          Adds a given attribute to the collection.
 boolean containsAttribute(String path)
          Returns if the given path contains an Attribute of any kind.
 Attributable getAttributable()
          Returns the Attribute's Attributable.
 Attribute getAttribute(String path)
          Returns the attribute located at path.
 Object getValue()
          Returns the value of this attribute, i.e.
 boolean isEmpty()
          Returns true if the HashMapAttribute is empty.
 void remove(Attribute attr)
          Removes the given attribute from the collection by calling remove(String id) with the attribute's id as parameter.
 void remove(String attrId)
          Removes the attribute with the given id from the collection.
 void setAttributable(Attributable att)
          Sets the Attribute's Attributable.
 String toString(int n)
          Returns a string representation prepended by n spaces of this attribute.
 String toXMLString()
          Returns a well-formed XML string representing the Displayable.
 
Methods inherited from class org.graffiti.attributes.AbstractAttribute
getDescription, getId, getName, getParent, getPath, setDescription, setParent, setValue, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.graffiti.attributes.CollectionAttribute
getCollection, setCollection
 
Methods inherited from interface org.graffiti.attributes.Attribute
getId, getParent, getPath, setDefaultValue, setParent, setValue
 
Methods inherited from interface org.graffiti.plugin.Displayable
getDescription, getName, setDescription
 
Methods inherited from interface org.graffiti.core.DeepCopy
copy
 

Constructor Detail

AbstractCollectionAttribute

public AbstractCollectionAttribute(String id)
                            throws IllegalIdException
Constructor for setting the id of an AbstractCollectionAttribute.

Parameters:
id - the id of the Attribute.
Throws:
IllegalIdException - if the given id contains a seperator. This is checked for in the constructor of the superclass AbstractAttribute.
Method Detail

setAttributable

public void setAttributable(Attributable att)
                     throws FieldAlreadySetException
Sets the Attribute's Attributable.

Implementation Notes: This method should only be called once and only by an addAttribute() method call! The attributable property may only be set on the root Attribute of a hierarchy

Specified by:
setAttributable in interface CollectionAttribute
Parameters:
att - the new Attributable of the Attribute.
Throws:
FieldAlreadySetException - DOCUMENT ME!

getAttributable

public Attributable getAttributable()
Returns the Attribute's Attributable.

Specified by:
getAttributable in interface Attribute
Overrides:
getAttributable in class AbstractAttribute
Returns:
the Attribute's Attributable.

getAttribute

public Attribute getAttribute(String path)
                       throws AttributeNotFoundException
Returns the attribute located at path.

Specified by:
getAttribute in interface CollectionAttribute
Parameters:
path - the relative path to the attribute from this.
Returns:
the attribute found at path.
Throws:
AttributeNotFoundException - if there is no attribute located at path.

isEmpty

public boolean isEmpty()
Returns true if the HashMapAttribute is empty. The same as getCollection().isEmpty() would yield, but this method should be faster since the map is not copied.

Specified by:
isEmpty in interface CollectionAttribute
Returns:
true if the HashMapAttribute is empty.

getValue

public Object getValue()
Returns the value of this attribute, i.e. map between contained attributes' ids and these attributes. The behaviour of this method depends on implementation of method getCollection() in concret classes which inherit this one. See documentation of concret classes for more information.

Specified by:
getValue in interface Attribute
Specified by:
getValue in interface Displayable<Object>
Returns:
the value of this attribute.

add

public void add(Attribute a)
         throws AttributeExistsException,
                FieldAlreadySetException
Adds a given attribute to the collection. Informs the ListenerManager about the addition.

Specified by:
add in interface CollectionAttribute
Parameters:
a - the new attribute to add to the list.
Throws:
AttributeExistsException - if there is already an attribute with the id of a.
FieldAlreadySetException - thrown if Attribute a already has a parent or attributable associated with it.

add

public void add(Attribute a,
                boolean inform)
         throws AttributeExistsException,
                FieldAlreadySetException
Adds a given attribute to the collection. Only informs the ListenerManager about the addition when inform is set to true.

Specified by:
add in interface CollectionAttribute
Parameters:
a - the new attribute to add to the list.
inform - when true, ListenerManager gets informed otherwise not
Throws:
AttributeExistsException - if there is already an attribute with the id of a.
FieldAlreadySetException - thrown if Attribute a already has a parent or attributable associated with it.

remove

public void remove(String attrId)
            throws AttributeNotFoundException
Removes the attribute with the given id from the collection. Notifies ListenerManager with an AttributeRemoved event when the attribute hierarchy is attached to an Attributable.

Specified by:
remove in interface CollectionAttribute
Parameters:
attrId - the id of the attribute.
Throws:
AttributeNotFoundException - if there is no attribute with the given id.
IllegalIdException - DOCUMENT ME!

remove

public void remove(Attribute attr)
            throws AttributeNotFoundException
Removes the given attribute from the collection by calling remove(String id) with the attribute's id as parameter. Notifies ListenerManager with an AttributeRemoved event when the attribute hierarchy is attached to an Attributable.

Specified by:
remove in interface CollectionAttribute
Parameters:
attr - the attribute to be removed.
Throws:
AttributeNotFoundException - if the given attribute is not in the HashMap.

toString

public String toString(int n)
Description copied from interface: Attribute
Returns a string representation prepended by n spaces of this attribute.

Specified by:
toString in interface Attribute
Overrides:
toString in class AbstractAttribute
Returns:
DOCUMENT ME!
See Also:
Attribute.toString(int)

toXMLString

public String toXMLString()
Description copied from interface: Displayable
Returns a well-formed XML string representing the Displayable. The Displayable should be reconstructable via this representation. Therefore it must at least include the type of Displayable (classname) and a representation of its value. PROBABLE FUTURE DESIGN: The Displayables themselves will provide a method to reconstruct their value from the XML representation they provided.

Specified by:
toXMLString in interface Displayable<Object>
Overrides:
toXMLString in class AbstractAttribute
Returns:
string holding an XML representation of this Displayable
See Also:
Displayable.toXMLString()

containsAttribute

public boolean containsAttribute(String path)
Returns if the given path contains an Attribute of any kind.

Specified by:
containsAttribute in interface CollectionAttribute
Parameters:
path - The path of the Attribute to be tested.
Returns:
true, if an Attribute is saved in the given path, false otherwise.


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