com.telelogic.cs.api
Class Attribute

java.lang.Object
  extended by com.telelogic.cs.api.Attribute
All Implemented Interfaces:
java.io.Serializable

public final class Attribute
extends java.lang.Object
implements java.io.Serializable

The value of an attribute. Pairs up the name of an attribute with it's value. Used when creating and modify attributes as well as when looking up attribute values.

Attributes are all based on three basic types: string, date, and boolean. All attributes store their values in one of these types. Note that the webtype is different than this raw type. For example, ccm_listboxes and ccm_strings see different, but they both store their values as strings. When an attribute is returned from the API it will have exactly one value stored as one of these basic types. You must know which type to expect to to be able to read the correct value. Either assume the type if the lifecycle is well know, or inspect the Attribute object to see which value is set.

It is also possible to create an empty attribute object. These are attributes that have no value; essentially they're just a name. These can be used as an alternative way to delete attributes: when an empty attribute is set on a change request, the attribute is deleted. Note that API methods will will not generally return empty attributes, instead they would return a "null" value or simply skip the the attribute, as appropriate. The exception is collectAttributes, which does return empty attributes for any missing attributes.

Often trigger scripts can gloss over the the actual type of attributes since the toString method of attributes will always return a logical representation of the value. For strings it is the string value; for dates it is a string representation of the date and time for the current locale; and for booleans it is either the string true or false. In some contexts (e.g., string concatenation in Rhino/JavaScript) toString will be implicitly called for you and should do the right thing. Just be aware of the specific accessor methods when more precision is needed, e.g., to format a date in a specific way.

Since:
4.7 06
See Also:
Serialized Form

Nested Class Summary
static class Attribute.Type
          Constants for the different possible types of attributes.
 
Constructor Summary
Attribute(java.lang.String name)
          Creates an empty attribute, that is one without a value.
Attribute(java.lang.String name, java.lang.Boolean booleanValue)
          Constructs a new boolean attribute.
Attribute(java.lang.String name, java.util.Date dateValue)
          Constructs a new date attribute.
Attribute(java.lang.String name, java.lang.String stringValue)
          Constructs a new string attribute.
 
Method Summary
 boolean equals(java.lang.Object that)
           
 java.lang.Boolean getBooleanValue()
          Gets the boolean value of this attribute if appropriate.
 java.util.Date getDateValue()
          Gets the date value of this attribute is appropriate.
 java.lang.String getName()
          Gets the name of this attribute.
 java.lang.String getStringValue()
          Gets the string value of this attribute is appropriate.
 Attribute.Type getType()
          Gets the type of this attribute.
 int hashCode()
           
 boolean isEmpty()
          Checks is this attribute has a value or not.
 java.lang.String toString()
          Formats this attribute's value as a string, no matter what type it is.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Attribute

public Attribute(java.lang.String name,
                 java.lang.String stringValue)
Constructs a new string attribute. Object only exists in memory; it must be explicitly set on a CR before the attribute is persisted in the database.

Parameters:
name - the name of the attribute
stringValue - the string value to give the attribute.

Attribute

public Attribute(java.lang.String name)
Creates an empty attribute, that is one without a value. Setting this on a CR effectively deletes the attribute.

Parameters:
name - name of the attribute to delete.

Attribute

public Attribute(java.lang.String name,
                 java.util.Date dateValue)
Constructs a new date attribute. Object only exists in memory; it must be explicitly set on a CR before the attribute is persisted in the database.

Parameters:
name - the name of the attribute
dateValue - the date value to give the attribute.

Attribute

public Attribute(java.lang.String name,
                 java.lang.Boolean booleanValue)
Constructs a new boolean attribute. Object only exists in memory; it must be explicitly set on a CR before the attribute is persisted in the database.

Parameters:
name - the name of the attribute
booleanValue - the boolean value to give the attribute.
Method Detail

getName

public java.lang.String getName()
Gets the name of this attribute. This is the raw name; not its label that end user see on forms.

Returns:
the name of this attribute.

getBooleanValue

public java.lang.Boolean getBooleanValue()
Gets the boolean value of this attribute if appropriate.

Returns:
the boolean value of this attribute.
Throws:
java.lang.IllegalStateException - if this is attribute is not a boolean attribute.

getDateValue

public java.util.Date getDateValue()
Gets the date value of this attribute is appropriate.

Returns:
the date value of this attribute, or null if it is not a date attribute.

getStringValue

public java.lang.String getStringValue()
Gets the string value of this attribute is appropriate.

Returns:
the string value of this attribute, or null if it is not a string attribute.

isEmpty

public boolean isEmpty()
Checks is this attribute has a value or not. If it is empty, setting it on a CR or task will effectively delete the attribute. See the main Attribute description for details.

Returns:
true if this attribute is empty. false if it has a string, date, or boolean value.

getType

public Attribute.Type getType()
Gets the type of this attribute. May be used to know which value method to call.

Note that this is the in-memory type of this attribute, which may not necessarily correspond to the type of the attribute defined in the current CR process. Values returned from Change will reflect the actual type of the attribute, but Attribute objects created in your scripts will reflect the type they were constructed with, which is not restricted by the CR process. If you actually try and set a CR attribute to something that does not match the CR process, you will get an error.

Returns:
the type of this attribute.

toString

public java.lang.String toString()
Formats this attribute's value as a string, no matter what type it is. See the class description for details..

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object that)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object


© Copyright IBM Corporation 2000, 2009
US Government Users Restricted Rights--Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
Notices