Class AbstractCollectionAttribute

java.lang.Object
org.graffiti.attributes.AbstractAttribute
org.graffiti.attributes.AbstractCollectionAttribute
All Implemented Interfaces:
Attribute, CollectionAttribute, DeepCopy, Displayable
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: 1.15 $
  • Constructor Details

    • 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 Details

    • 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
      Returns:
      the value of this attribute.
    • add

      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
      Overrides:
      toXMLString in class AbstractAttribute
      Returns:
      string holding an XML representation of this Displayable
      See Also:
      Displayable.toXMLString()