|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.waveset.util.AbstractXmlObject
com.waveset.object.WavesetResult
public class WavesetResult
An object used to encapsulate a complex set of results. Originally developed to capture status from background workflow tasks, now also being used by provisioning operations that may affect more than one resource.
A result is a list of items, defined by the ResultItem
class.
Each item has a value which may be any XmlObject. Items may
have an optional name and an optional type.
Some item values are self describing and need no type qualifier. Others may use the type to indicate the semantics of the value. For example the value of an item containing a message may be a simple String object. To indicate that this is a displayable message the item type ResultItem.TYPE_MESSAGE is used.
NOTE: This has evolved several times. We originally supported the notion of a "status" on each item which was an indication of error severity: ok, warning, and error. This was confusing since not all items have a severity level. The new ErrorMessage object is a better way to express this. // *
// * I thought about eliminating the ResultItem object and instead just // * maintaining a list of things, but this would require a different // * kind of wrapper object for simple items like messages to distinguish // * them from non-displayable data values. So we either get rid of // * ResultItem and introduce ResultMessage and ResultData, or keep // * ResultItem and live with a sometimes unnecessary level of indirection. // * Having ResultItem also allows us to give items names, which comes // * in handy with workflow, where we may wish to modify previously // * added results. // *
ResultItem
Field Summary | |
---|---|
static java.lang.String |
code_id
|
static java.lang.String |
ELEMENT
The name of our XML element. |
static java.lang.String |
ITEM_TYPE
Value for the ResultItem type of a nested result object. |
static java.lang.String |
PROVISION_STATUS
ResultItem name commonly added to result indicating the status of the provisioning operation when workflow is involved. |
Constructor Summary | |
---|---|
WavesetResult()
Construct an empty result |
|
WavesetResult(org.w3c.dom.Element e)
Construct a result object from its DOM representation. |
|
WavesetResult(java.lang.String xml)
Create a result object by parsing its XML representation. |
Method Summary | |
---|---|
ResultItem |
add(java.lang.Object object)
Add an object to the result. |
void |
addError(com.waveset.msgcat.ErrorMessage msg)
|
void |
addError(ResultError err)
Add a ResultError object. |
void |
addException(java.lang.Throwable t)
Add an exception to the result. |
ResultItem |
addMessage(com.waveset.msgcat.Message msg)
|
ResultItem |
addMessage(java.lang.String msg)
Add an pre-formatted ordinary message to the result. |
ResultItem |
addNamedResult(java.lang.String name,
java.lang.Object value)
Add a named data object to the result. |
ResultItem |
addNamedResult(java.lang.String name,
java.lang.String type,
java.lang.Object value)
Add a named object to the result. |
void |
addResult(ResultItem item)
Add a new item to the result object. |
ResultItem |
addResult(java.lang.String type,
java.lang.Object value)
Add a typed string result. |
void |
addWarning(com.waveset.msgcat.Message msg)
Add an warning message to the result. |
void |
assimilate(WavesetResult res)
Appends the items in one result with this one. |
void |
assimilateMessages(WavesetResult src)
Append the messages or errors from another result. |
GenericObject |
findAsynchInfo()
Get the optional GenericObject object containing the asynchronous info on this or any contained WavesetResult. |
GenericObject |
getAsynchInfo()
Get the optional GenericObject object containing the asynchronous info. |
java.lang.String |
getElementName()
Return the name of our XML element, required by XmlObject. |
com.waveset.msgcat.Message |
getErrorMessage()
Convenience method to return the first error message in the result. |
java.util.List<com.waveset.msgcat.Message> |
getErrorMessages()
Convenience method to return a list of all error messages found in this result. |
java.util.List<com.waveset.msgcat.Message> |
getErrorMessages(int maxMessages)
Convenience method to return up to the specified number of error messages from this result. |
java.util.List |
getErrors()
Convenience method to extract a flat list of String objects for each error item in the result, formatted according to the current locale. |
void |
getErrors(java.util.List errors)
Convenience method to extract a flat list of String objects for each error item in the result, formatted according to the current locale. |
void |
getErrors(java.util.List errors,
java.util.Locale locale)
Convenience method to extract a flat list of String objects for each error item in the result, formatted according to the given locale. |
java.util.List |
getErrors(java.util.Locale locale)
Convenience method to extract a flat list of String objects for each error item in the result, formatted according to the given locale. |
java.util.List |
getMessages()
Convenience method to extract a flat list of String objects for each non-error message in the result, formatted according to the current locale. |
void |
getMessages(java.util.List messages)
Convenience method to extract a flat list of String objects for each non-error message in the result, formatted according to the current locale. |
void |
getMessages(java.util.List messages,
java.util.Locale locale)
Convenience method to extract a flat list of String objects for each non-error message in the result, formatted according to the given locale. |
java.util.List |
getMessages(java.util.Locale locale)
Convenience method to extract a flat list of String objects for each non-error message in the result, formatted according to the given locale. |
java.lang.String |
getName()
Get the result name. |
java.lang.Object |
getNamedResultValue(java.lang.String name)
Convenience method to return the value of the first item that has a given name. |
WavesetResult |
getNestedResult(java.lang.String name)
Recursively search for a nested WavesetResult with the given name. |
com.waveset.object.ResourceResult |
getResourceResult(java.lang.String name)
Return a specific resource result. |
java.lang.Object |
getResult(java.lang.String type)
Convenience method to return the value of the first item that has a given type. |
ResultItem |
getResultByClass(java.lang.Class c)
Search for a result value by class. |
ResultItem |
getResultByName(java.lang.String name)
Return the first ResultItem with the given name. |
ResultItem |
getResultByType(java.lang.String type)
Return the first ResultItem with the given type. |
ResultItem |
getResultItem(java.lang.String type)
Return the first ResultItem with the given type. |
java.util.List |
getResultItemList(java.lang.String type)
Return a list of ResultItems with the given type. |
java.util.ArrayList<ResultItem> |
getResults()
Return the list of results. |
java.util.List |
getResultsByClass(java.lang.Class c)
Return the list of ResultItems with the given class. |
com.waveset.object.ResultTable |
getResultTable()
Return the first ResultTable in the result item list. |
com.waveset.msgcat.Message |
getTitle()
Get the optional Message object containing the result title. |
boolean |
hasError()
Originally we tried to maintain the _status field as an indication of whether there were any error in this result. |
boolean |
hasWarning()
Originally we tried to maintain the _status field as an indication of whether there were any error in this result. |
boolean |
isAsynchronous()
Indicates whether or not this is the result of an asynchronous result. |
boolean |
isEmpty()
|
boolean |
isError()
The first version of the class defined this method which checked a field we tried to keep up to date. |
void |
parseXml(org.w3c.dom.Element e)
Parse the DOM representation of a result, and set the corresponding fields. |
void |
removeResult(ResultItem item)
Remove a result item. |
void |
removeResultByName(java.lang.String name)
Remove a result item with the given name. |
void |
removeResultByType(java.lang.String type)
Remove a result item with the given type. |
void |
setAsynchInfo(GenericObject asynchInfo)
Set the asynchronous info. |
void |
setAsynchronous(boolean async)
Indicates that this is the result of an asynchronous task. |
void |
setName(java.lang.String name)
Set the result name. |
ResultItem |
setNamedResult(java.lang.String name,
java.lang.String type,
java.lang.Object value)
Add or update a result item. |
ResultItem |
setResult(java.lang.String type,
java.lang.Object value)
Assing a result by type, overwriting any current result with that type. |
void |
setTitle(com.waveset.msgcat.Message msg)
Set the title message. |
void |
toXml(java.lang.StringBuffer b,
int indent)
Serialize the result to an XML buffer. |
Methods inherited from class com.waveset.util.AbstractXmlObject |
---|
addXmlHeader, cloneObject, dump, dumpFile, getReference, setTrace, toIdentityString, toVerboseString, toVerboseString, toXml, toXml, toXml |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String code_id
public static final java.lang.String ELEMENT
public static final java.lang.String ITEM_TYPE
public static final java.lang.String PROVISION_STATUS
Constructor Detail |
---|
public WavesetResult()
public WavesetResult(org.w3c.dom.Element e) throws com.waveset.util.WavesetException
com.waveset.util.WavesetException
public WavesetResult(java.lang.String xml) throws com.waveset.util.WavesetException
com.waveset.util.WavesetException
Method Detail |
---|
public ResultItem add(java.lang.Object object)
public void addError(com.waveset.msgcat.ErrorMessage msg)
public void addError(ResultError err)
public void addException(java.lang.Throwable t)
This gets converted into a MESSAGE item, with a status of ERROR, and whose value is the text of the message.
Note that we store the com.waveset.msgcat.Message object if the exception has one since we may want to reformat the message for a different locale when it is eventually rendered. If the exception has no Message, we just store the message text.
We might have to store more here, possibly the class name of the exception, that would potentially allow us to recreate the exception object when the item is deserialized.
public ResultItem addMessage(com.waveset.msgcat.Message msg)
public ResultItem addMessage(java.lang.String msg)
You should be using Message objects, but this is supported to ease the transition to message catalogs, or for emergency "can't happen" messages.
public ResultItem addNamedResult(java.lang.String name, java.lang.Object value)
public ResultItem addNamedResult(java.lang.String name, java.lang.String type, java.lang.Object value)
public void addResult(ResultItem item)
The global status will be updated if the item status is more severe than the current global status.
public ResultItem addResult(java.lang.String type, java.lang.Object value)
You would call this if you wanted your own item type, beyond the build-in types for messages and errors.
public void addWarning(com.waveset.msgcat.Message msg)
public void assimilate(WavesetResult res)
This may be used in places where a "master" result is being maintained and sub-operations produce result objects of their own that need to be assimilated into the master result.
public void assimilateMessages(WavesetResult src)
public GenericObject findAsynchInfo()
public GenericObject getAsynchInfo()
public java.lang.String getElementName()
getElementName
in interface XmlObject
getElementName
in class AbstractXmlObject
public com.waveset.msgcat.Message getErrorMessage()
Similar to hasError, but we look specifically for Message objects whereas hasError will stop on the first item with an error status.
public java.util.List<com.waveset.msgcat.Message> getErrorMessages()
error messages
found in this result.
public java.util.List<com.waveset.msgcat.Message> getErrorMessages(int maxMessages)
error messages
from this result.
public java.util.List getErrors()
public void getErrors(java.util.List errors)
public void getErrors(java.util.List errors, java.util.Locale locale)
public java.util.List getErrors(java.util.Locale locale)
public java.util.List getMessages()
public void getMessages(java.util.List messages)
public void getMessages(java.util.List messages, java.util.Locale locale)
public java.util.List getMessages(java.util.Locale locale)
public java.lang.String getName()
public java.lang.Object getNamedResultValue(java.lang.String name)
public WavesetResult getNestedResult(java.lang.String name)
public com.waveset.object.ResourceResult getResourceResult(java.lang.String name)
public java.lang.Object getResult(java.lang.String type)
This should only be used if you know from context that there will only be one item of this type in the result. It should not be used for displaying messages, since there can be more than one message in the result.
public ResultItem getResultByClass(java.lang.Class c)
public ResultItem getResultByName(java.lang.String name)
public ResultItem getResultByType(java.lang.String type)
public ResultItem getResultItem(java.lang.String type)
This should only be used if you know from context that there will only be one item of this type in the result. It should not be used for displaying messages, since there can be more than one message in the result. !! Would like to change the behavior to search by name only
public java.util.List getResultItemList(java.lang.String type)
This should only be used if you know from context that there will only be one item of this type in the result. It should not be used for displaying messages, since there can be more than one message in the result. !! Would like to change the behavior to search by name only
public java.util.ArrayList<ResultItem> getResults()
ResultItem
objects.
public java.util.List getResultsByClass(java.lang.Class c)
public com.waveset.object.ResultTable getResultTable()
public com.waveset.msgcat.Message getTitle()
public boolean hasError()
public boolean hasWarning()
public boolean isAsynchronous()
public boolean isEmpty()
public boolean isError()
public void parseXml(org.w3c.dom.Element e) throws com.waveset.util.WavesetException
com.waveset.util.WavesetException
public void removeResult(ResultItem item)
public void removeResultByName(java.lang.String name)
public void removeResultByType(java.lang.String type)
public void setAsynchInfo(GenericObject asynchInfo)
public void setAsynchronous(boolean async)
setAsynchInfo
.
async
- boolean where true indicates that this is the result
of an asynchronous task.public void setName(java.lang.String name)
public ResultItem setNamedResult(java.lang.String name, java.lang.String type, java.lang.Object value)
You would call this if for result items that can be changed after having been added. If the value is null, the existing item will be removed.
public ResultItem setResult(java.lang.String type, java.lang.Object value)
public void setTitle(com.waveset.msgcat.Message msg)
public void toXml(java.lang.StringBuffer b, int indent)
toXml
in interface XmlObject
toXml
in class AbstractXmlObject
b
- StringBuffer in which to write the generated xmlindent
- Number of spaces to indent the generated xml block
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |