public final class Attribute
extends java.lang.Object
implements java.io.Serializable
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.
Modifier and Type | Class and Description |
---|---|
static class |
Attribute.Type
Constants for the different possible types of attributes.
|
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public Attribute(java.lang.String name, java.lang.String stringValue)
name
- the name of the attributestringValue
- the string value to give the attribute.public Attribute(java.lang.String name)
name
- name of the attribute to delete.public Attribute(java.lang.String name, java.util.Date dateValue)
name
- the name of the attributedateValue
- the date value to give the attribute.public Attribute(java.lang.String name, java.lang.Boolean booleanValue)
name
- the name of the attributebooleanValue
- the boolean value to give the attribute.public java.lang.String getName()
public java.lang.Boolean getBooleanValue()
java.lang.IllegalStateException
- if this is attribute is not a boolean attribute.public java.util.Date getDateValue()
null
if it is not a date attribute.public java.lang.String getStringValue()
null
if it is not a string attribute.public boolean isEmpty()
Attribute
description
for details.true
if this attribute is empty. false
if
it has a string, date, or boolean value.public Attribute.Type getType()
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.
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object that)
equals
in class java.lang.Object
public int hashCode()
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