com.waveset.object
Class ResultItem

java.lang.Object
  extended bycom.waveset.util.AbstractXmlObject
      extended bycom.waveset.object.ResultItem
All Implemented Interfaces:
javax.naming.Referenceable, XmlObject

public class ResultItem
extends AbstractXmlObject

Represents a single result which may be aggregated in a WavesetResult object.

There are two "classes" of items, one that represents a named value, and the other that represents a status/warning/error message. We might want to have actual subclasses for these, but that felt like overkill at the time.

The first thing you examine in a ResultItem is the "type" field which must be interpreted by the application in the context of the method that returned it. One common value for the type field is the string "message" which indicates that this is a message of some kind. I wanted to avoid a fixed set of static enumeration objects for these because we don't know what all of the types will be and they'll be extended all the time.

For "message" types, the object will always be a com.waveset.util.Message object.

Might want to have more than a success/failure boolean, possibly some constants?


Nested Class Summary
static class ResultItem.Status
          Used for values of the _status field in both WavesetResult and ResultItem.
 
Field Summary
static java.lang.String code_id
           
static java.lang.String DATA
          Type used to indicate the item is a name/value pair.
static java.lang.String ELEMENT
          Our XML element name.
static java.lang.String ERROR
          Built-in item type for ResultError objects.
static java.lang.String MESSAGE
          Built-in item type for messages.
static java.lang.String REPORT
          Built-in item type for Report objects.
static java.lang.String TABLE
          Built-in item type for ResultTable objects.
 
Fields inherited from class com.waveset.util.AbstractXmlObject
_trace
 
Constructor Summary
ResultItem()
           
ResultItem(org.w3c.dom.Element e)
           
 
Method Summary
 java.lang.String getElementName()
          Get the XML element name, required by XmlObject.
 Message getMessage()
          Convenience method to access the Message object for message items.
 Message getMessage(java.util.Locale locale)
           
 java.lang.String getMessageText()
          Convenience method to access the text of a message (or error) item.
 java.lang.String getMessageText(java.util.Locale locale)
          Convenience method to access the text of a message (or error) item with a locale (if passed).
 java.lang.String getName()
           
 ResultItem.Status getStatus()
          Get the item status.
 java.lang.String getString()
          Get the item value as a string.
 java.lang.String getType()
          Get the item type.
 java.lang.Object getValue()
          Get the item value.
 boolean isError()
          Convenience method that tests to see if the item represents an error.
 boolean isMessage()
          Convenience method that tests to see if this is a message item.
 boolean isReport()
          Convenience method that tests to see if this is a report item.
 void parseXml(org.w3c.dom.Element e)
          Build a result item by parsing its DOM representation and setting the corresponding fields.
 void setName(java.lang.String s)
           
 void setStatus(ResultItem.Status status)
          Set the item status.
 void setType(java.lang.String s)
          Set the item type.
 void setValue(java.lang.Object o)
          Set the item value.
 void toXml(java.lang.StringBuffer b, int indent)
          Serialize the item to an XML buffer.
 
Methods inherited from class com.waveset.util.AbstractXmlObject
addXmlHeader, cloneObject, dump, dumpFile, getReference, println, setTrace, toIdentityString, toVerboseString, toVerboseString, toXml, toXml, toXml
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

ELEMENT

public static final java.lang.String ELEMENT
Our XML element name.

See Also:
Constant Field Values

MESSAGE

public static final java.lang.String MESSAGE
Built-in item type for messages.

See Also:
Constant Field Values

ERROR

public static final java.lang.String ERROR
Built-in item type for ResultError objects.

See Also:
Constant Field Values

REPORT

public static final java.lang.String REPORT
Built-in item type for Report objects. Formerly these were always String objects, but now they may also be com.waveset.util.Report objects. My preference is that they always be, but that will need to migrate over time. Only need this if you want to store a String report.

See Also:
Constant Field Values

TABLE

public static final java.lang.String TABLE
Built-in item type for ResultTable objects. !! Don't need this, use instanceof

See Also:
Constant Field Values

DATA

public static final java.lang.String DATA
Type used to indicate the item is a name/value pair. These may be used to convey information to applications, but are generally not visible when the result is displayed.

See Also:
Constant Field Values
Constructor Detail

ResultItem

public ResultItem()

ResultItem

public ResultItem(org.w3c.dom.Element e)
           throws WavesetException
Method Detail

getElementName

public java.lang.String getElementName()
Get the XML element name, required by XmlObject.

Specified by:
getElementName in interface XmlObject
Specified by:
getElementName in class AbstractXmlObject

getName

public java.lang.String getName()

setName

public void setName(java.lang.String s)

getType

public java.lang.String getType()
Get the item type. This is a string that may be one of a few predefined types, or some arbitrary application defined type.


setType

public void setType(java.lang.String s)
Set the item type. This is normally called only by WavesetResult as it builds it's item list.


getValue

public java.lang.Object getValue()
Get the item value.

For items of type ResultItem.MESSAGE, the value is normally a java.lang.String or com.waveset.msgcat.Message object. We try to use Message objects where possible, so the message can be reformatted for different locals at the time it must be presented, rather than the time it is captured in the result object.


getString

public java.lang.String getString()
Get the item value as a string.


setValue

public void setValue(java.lang.Object o)
Set the item value.


isError

public boolean isError()
Convenience method that tests to see if the item represents an error.


isMessage

public boolean isMessage()
Convenience method that tests to see if this is a message item. Note that this will return true for error messages as well as informational messages.


isReport

public boolean isReport()
Convenience method that tests to see if this is a report item.


getMessage

public Message getMessage()
Convenience method to access the Message object for message items. The item may be an normal message or an error message. If an error message, it may be any type of error container.

If the item was created with a String rather than a Message, we'll fake up a Message object containing the string, just so we can have a consistent return.

NOTE: This is called in several places that expect a non-null Message to be returned, so always return something. The original code did however return null if _value was null. Need to examine the callers!!


getMessage

public Message getMessage(java.util.Locale locale)

getMessageText

public java.lang.String getMessageText()
Convenience method to access the text of a message (or error) item.


getMessageText

public java.lang.String getMessageText(java.util.Locale locale)
Convenience method to access the text of a message (or error) item with a locale (if passed).


getStatus

public ResultItem.Status getStatus()
Get the item status. Status is represented using a "enumeration" of objects. It is usually Status.OK. Status will be Status.ERROR for error or exception messages.


setStatus

public void setStatus(ResultItem.Status status)
Set the item status.


toXml

public void toXml(java.lang.StringBuffer b,
                  int indent)
Serialize the item to an XML buffer.

Specified by:
toXml in interface XmlObject
Specified by:
toXml in class AbstractXmlObject

parseXml

public void parseXml(org.w3c.dom.Element e)
              throws WavesetException
Build a result item by parsing its DOM representation and setting the corresponding fields.

Normally values are XmlObjects, but the agent still uses elements, and we use the above in toXml if the object is a PersistentObject.

Throws:
WavesetException