Package org.graffiti.attributes
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 $
-
Field Summary
-
Constructor Summary
Constructors Constructor Description AbstractCollectionAttribute(String id)
Constructor for setting the id of anAbstractCollectionAttribute
. -
Method Summary
Modifier and Type Method Description void
add(Attribute a)
Adds a given attribute to the collection.void
add(Attribute a, boolean inform)
Adds a given attribute to the collection.Attributable
getAttributable()
Returns theAttribute
'sAttributable
.Attribute
getAttribute(String path)
Returns the attribute located atpath
.Object
getValue()
Returns the value of this attribute, i.e.boolean
isEmpty()
Returnstrue
if the HashMapAttribute is empty.void
remove(String attrId)
Removes the attribute with the given id from the collection.void
remove(Attribute attr)
Removes the given attribute from the collection by callingremove(String id)
with the attribute's id as parameter.void
setAttributable(Attributable att)
Sets theAttribute
'sAttributable
.String
toString(int n)
Returns a string representation prepended byn
spaces of this attribute.String
toXMLString()
Returns a well-formed XML string representing the Displayable.Methods inherited from class org.graffiti.attributes.AbstractAttribute
addEdgeAttributeType, addNodeAttributeType, getDescription, getIcon, getId, getName, getParent, getPath, getTypedAttribute, isDeleted, isTypedAttributeFromID, setDeleted, setDescription, setId, 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.Attribute
getId, getParent, getPath, isDeleted, setDefaultValue, setDeleted, setId, setParent, setValue
Methods inherited from interface org.graffiti.attributes.CollectionAttribute
getCollection, setCollection, size
Methods inherited from interface org.graffiti.plugin.Displayable
getDescription, getIcon, getName, setDescription
-
Constructor Details
-
AbstractCollectionAttribute
Constructor for setting the id of anAbstractCollectionAttribute
.- Parameters:
id
- the id of theAttribute
.- Throws:
IllegalIdException
- if the given id contains a seperator. This is checked for in the constructor of the superclassAbstractAttribute
.
-
-
Method Details
-
setAttributable
Sets theAttribute
'sAttributable
.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 rootAttribute
of a hierarchy- Specified by:
setAttributable
in interfaceCollectionAttribute
- Parameters:
att
- the newAttributable
of theAttribute
.- Throws:
FieldAlreadySetException
- DOCUMENT ME!
-
getAttributable
Returns theAttribute
'sAttributable
.- Specified by:
getAttributable
in interfaceAttribute
- Overrides:
getAttributable
in classAbstractAttribute
- Returns:
- the
Attribute
'sAttributable
.
-
getAttribute
Returns the attribute located atpath
.- Specified by:
getAttribute
in interfaceCollectionAttribute
- Parameters:
path
- the relative path to the attribute fromthis
.- Returns:
- the attribute found at
path
. - Throws:
AttributeNotFoundException
- if there is no attribute located at path.
-
isEmpty
public boolean isEmpty()Returnstrue
if the HashMapAttribute is empty. The same asgetCollection().isEmpty()
would yield, but this method should be faster since the map is not copied.- Specified by:
isEmpty
in interfaceCollectionAttribute
- Returns:
true
if the HashMapAttribute is empty.
-
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 methodgetCollection()
in concret classes which inherit this one. See documentation of concret classes for more information.- Specified by:
getValue
in interfaceAttribute
- Specified by:
getValue
in interfaceDisplayable
- Returns:
- the value of this attribute.
-
add
Adds a given attribute to the collection. Informs theListenerManager
about the addition.- Specified by:
add
in interfaceCollectionAttribute
- 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, FieldAlreadySetExceptionAdds a given attribute to the collection. Only informs theListenerManager
about the addition wheninform
is set to true.- Specified by:
add
in interfaceCollectionAttribute
- 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
Removes the attribute with the given id from the collection. NotifiesListenerManager
with an AttributeRemoved event when the attribute hierarchy is attached to anAttributable
.- Specified by:
remove
in interfaceCollectionAttribute
- Parameters:
attrId
- the id of the attribute.- Throws:
AttributeNotFoundException
- if there is no attribute with the given id.IllegalIdException
- DOCUMENT ME!
-
remove
Removes the given attribute from the collection by callingremove(String id)
with the attribute's id as parameter. NotifiesListenerManager
with an AttributeRemoved event when the attribute hierarchy is attached to anAttributable
.- Specified by:
remove
in interfaceCollectionAttribute
- Parameters:
attr
- the attribute to be removed.- Throws:
AttributeNotFoundException
- if the given attribute is not in the HashMap.
-
toString
Description copied from interface:Attribute
Returns a string representation prepended byn
spaces of this attribute.- Specified by:
toString
in interfaceAttribute
- Overrides:
toString
in classAbstractAttribute
- Returns:
- DOCUMENT ME!
- See Also:
Attribute.toString(int)
-
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 interfaceDisplayable
- Overrides:
toXMLString
in classAbstractAttribute
- Returns:
- string holding an XML representation of this Displayable
- See Also:
Displayable.toXMLString()
-