com.tensegrity.generic.attribute
Interface Attribute

All Superinterfaces:
java.lang.Cloneable, Restrictable
All Known Subinterfaces:
CustomAttribute
All Known Implementing Classes:
DirectoryLocationAttribute, FormatAttribute, HRefAttribute, ItemListAttribute, MetricAttribute

public interface Attribute
extends Restrictable, java.lang.Cloneable

An Attribute encapsulates a name-value pair and provides type information for that value at runtime. Furthermore, this interface is responsible for accepting and applying a Constraint object which can restrict its value and value type.

In its simplest form, an Attribute consists of:

  1. A Name of type java.lang.String.
  2. A Value of type java.lang.Object.

Constructing an Attribute and related objects is done by means of a AttributeFactory, which will hide the particular implementation classes from client code.

The procedure for constructing an Attribute requires client code to initially obtain a reference to a factory instance). Constructing a new Attribute object is then done by calling the newAttribute method on that factory instance.

An Attribute instance supports two mutally-exclusive states called mutable and immutable. An immutable Attribute must guarantee that both its name and value can never be changed after instantiation. There are many scenarios where immutable attributes provide additional safety during program development. In case the name or the value needs to be changed, however, you have to use a mutable Attribute. The state of an Attribute can be changed from mutable to immutable and back by calling the #setMutable() method.

Attribute objects that are dereferenced will be garbage collected.

Version:
$Id: Attribute.java,v 1.36 2005/03/11 18:13:16 AndreasEbbert Exp $
Author:
M. Kegel, S. Rutz

Method Summary
 java.lang.Object clone()
          Clones this attribute.
 java.lang.Object cloneValue()
          Clones this attribute's value.
 java.lang.String getName()
          Returns the Attribute name.
 AttributeType getType()
          Returns the current value's type.
 java.lang.Object getValue()
          Returns the Attribute value.
 boolean isMutable()
          Returns the mutable flag that indicates whether the attribute is mutable or immutable.
 void setMutable(boolean mutable)
          Sets the mutable flag that indicates whether the attribute is mutable or immutable.
 void setValue(java.lang.Object value)
          Sets the Attribute value.
 
Methods inherited from interface com.tensegrity.generic.constraint.Restrictable
getConstraint, setConstraint
 

Method Detail

getType

public AttributeType getType()
Returns the current value's type.

Returns:
the type of the current value.

Find more information in the class documentation


getName

public java.lang.String getName()
Returns the Attribute name.

Returns:
the name of the attribute.

Find more information in the class documentation


getValue

public java.lang.Object getValue()
Returns the Attribute value.

Returns:
the value of this attribute.

Find more information in the class documentation


setValue

public void setValue(java.lang.Object value)
              throws IllegalValueException,
                     ConstraintViolationException
Sets the Attribute value.

Parameters:
value - the new value of the attribute.
Throws:
IllegalValueException - if the attribute value is invalid.
ConstraintViolationException - thrown if the constraint of this attribute does not permit setting the new value.

Find more information in the class documentation


clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones this attribute. The name of the attribute is not deep-copied, as String instances are immutable. The value of the attribute is copied by means of the clone method of Object.

Returns:
a deep copy of this attribute.
Throws:
java.lang.CloneNotSupportedException - if invoking this method on the object is not allowed or supported.

Find more information in the class documentation


cloneValue

public java.lang.Object cloneValue()
                            throws java.lang.CloneNotSupportedException
Clones this attribute's value. Usually a deep copy is returned. The value object itself can decide what is to be considered a deep-copy. Sometimes in case of (nested) references to immutable objects a deep-copy may be the same as a shallow-copy.

Returns:
a deep copy of this attribute's value.
Throws:
java.lang.CloneNotSupportedException - may be thrown if invoking this method on the value is not allowed or supported.

Find more information in the class documentation


isMutable

public boolean isMutable()
Returns the mutable flag that indicates whether the attribute is mutable or immutable.

Returns:
true, if it is mutable; false, if it is immutable.

setMutable

public void setMutable(boolean mutable)
Sets the mutable flag that indicates whether the attribute is mutable or immutable.

Parameters:
mutable - the new value of the mutable flag.


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.