Class Outcome
java.lang.Object
org.cristalise.kernel.persistency.outcome.Outcome
- All Implemented Interfaces:
C2KLocalObject
A C2KLocalObject encapsulating management of XML data. It has methods to manipulate and validate the XML,
and with a valid ID it can be stored in ClusterStore.
It contains lot of utility code to read and set data in the Outcome (xml).
-
Constructor Summary
ConstructorsConstructorDescriptionUse this constructor to manipulate, validate and store this outcomeVery basic constructor to set all membersUse this constructor for XML manipulation only.The constructor derives all the meta data (ID and Schema) from the pathUse this constructor for XML manipulation and validation.The constructor derives all the meta data (ID and Schema) from the path -
Method Summary
Modifier and TypeMethodDescriptionappendXmlFragment(String xpath, String xmlFragment) Append the new Node created from xmlFragment as a child of the Node selected by the XPathevaluateXpath(String xpathExpr, QName returnType) Evaluates the given XPath expression thread-safely and efficiently.evaluateXpath(Node startNode, String xpathExpr, QName returnType) Evaluates the given XPath expression thread-safely and efficientlygetAllRecords(String xpath) Reads all Attributes and child Elements of the list of Node selected by the xpathgetAllRecords(String xpath, List<String> names) Reads list of list of values of the Attributes and child Elements of the list of Elements selected by the xpath.getAttribute(String name) Retrieves an Attribute value by name of the root Element.getAttribute(Element element, String name) Retrieves an Attribute value by name of the given Element.getAttributeOfField(String field, String attribute) Retrieves an Attribute value by name from the named Element.Each C2KLocalObject is stored with a path identifier starting with the ClusterType: DomainPath: /Path/Domain/Name ItemPath: /Path/Item AgentPath: /Path/Agent RolePath: /Path/Role/Name Properties: /Property/Name Workflow: /LifeCycle/workflow Collections: /Collection/Name/Version (default Name='last') Outcomes: /Outcome/SchemaName/SchemaVersion/EventID Viewpoints: /ViewPoint/SchemaName/Name (default Name='last') Events: /AuditTrail/EventID Jobs: /Job/JobIDReturnsClusterType.OUTCOMEgetData()Returns the serialised DOM as a string without pretty printing-getData(boolean prettyPrint) Returns the serialised DOM as a string -Retrieves the textNode value of the named Element of the root Element.Retrieves the textNode value of the named Element of the given Element.getFieldByXPath(String xpath) Retrieves the text, CDATA or attribute value of the Node selected by the XPathgetName()Gets the name of the C2KLocalObjectgetNodeByXPath(String xpathExpr) Gets a List selected by the xpathgetNodesByXPath(String xpathExpr) Gets a NodeList selected by the xpathgetNodeValue(Node node) Gets the value of the given TEXT, CDATA, ATTRIBUTE or ELEMENT NodeReads the all Attributes and child Elements of the root ElementReads the all Attributes and child Elements of the Node selected by the xpathReads list of values of the Attributes and child Elements of the Element selected by the xpath.Reads list of values of the Attributes and child Elements of the root Element.getRecordOfElement(Element element, List<String> names) Reads list of values of the Attributes and child Elements of the given Element.getRecordOfNode(Node node) Reads the all Attributes and child Elements of the given Node.Gets the Schema object associated with the OutcomegetSchema(TransactionKey transactionKey) Gets the Schema object associated with the OutcomeGets the name or UUID of the Schema item associated with the OutcomeDeprecated.intGets the version of the Schema item associated with the OutcomebooleanbooleanbooleanisIdentical(Outcome other) Checks if the Outcome is identical with the given inputstatic booleanisIdentical(Document origDocument, Document otherDocument) Utility method to comare 2 XML Documentsstatic Documentstatic DocumentParses the xml string into a DOM treestatic Documentparse(InputSource xml) Parses the input source into a DOM tree.removeNodeByXPath(String xpathExpr) Removes the node selected by the xpathstatic StringSerialize the given DocumentvoidsetAttribute(String name, String data) Sets an Attribute value by name of the root Element.voidsetAttribute(String name, String data, boolean remove) Sets the value of an attribute in the root Element.voidsetAttribute(Element element, String name, String data) Sets an Attribute value by name of the given Element.voidsetAttribute(Element element, String name, String data, boolean remove) Sets an Attribute value by name of the given Element.voidsetAttributeOfField(String field, String name, String data) Sets the value of an attribute in a given Field, i.e.voidsetAttributeOfField(String field, String name, String data, boolean remove) Sets the value of an attribute in a given Field, i.e.voidvoidSets the textNode value of the named Element of the root Element.voidSets the textNode value of the named Element of the root Element.voidSets the textNode value of the named Element of the given Element.voidSets the textNode value of the named Element of the given Element.voidsetFieldByXPath(String xpath, String data) Sets the text, CDATA or attribute value of the Node selected by the XPath.voidsetFieldByXPath(String xpath, String data, boolean remove) Sets the text, CDATA or attribute value of the Node selected by the XPath.protected voidsetMetaDataFromPath(String path) Retrieves the SchemaName, Version, EevetnId triplet from the path.voidSets the name of the C2KLocalObjectvoidsetNodeValue(Node node, String value) Sets the value of the given TEXT, CDATA, ATTRIBUTE or ELEMENT NodevoidsetNodeValue(Node node, String value, boolean useCdata) Sets the value of the given TEXT, CDATA, ATTRIBUTE or ELEMENT NodevoidSets the values of Attributes and child Element of the Element selected by xpath.voidSets the values of Attributes and child Element of the root Element.voidSets the values of Attributes and child Element of given Element.toString()static voidtraverseChildElements(Node node, Consumer<Node> action) validate()Validates the actual XML Document against the provided SchemavoidValidates the actual XML Document against the provided Schema
-
Constructor Details
-
Outcome
Use this constructor for XML manipulation only. This Outcome cannot be validate nor it can be stored in ClusterStore.- Parameters:
xml- the XML string to be manipulated- Throws:
InvalidDataException- there was an error parsing the XML
-
Outcome
Use this constructor for XML manipulation and validation. This Outcome cannot be stored in ClusterStore.- Parameters:
xml- the XML string to be manipulatedschema- the Schema of the XML- Throws:
InvalidDataException- there was an error parsing the XML
-
Outcome
public Outcome(int id, String xml, String schemaName, Integer schemaVersion) throws InvalidDataException - Throws:
InvalidDataException
-
Outcome
Use this constructor to manipulate, validate and store this outcome- Parameters:
id- eventIDxml- the XML string to be manipulatedschema- the Schema of the XML- Throws:
InvalidDataException- there was an error parsing the XML
-
Outcome
Very basic constructor to set all members- Parameters:
id- eventIDdom- parsed XML Documentschema- the Schema instance
-
Outcome
The constructor derives all the meta data (ID and Schema) from the path- Parameters:
path- the actuals path used by the ClusterStoragexml- the XML string to parse- Throws:
PersistencyException- there was DB errorInvalidDataException- Version or EventID was an invalid number
-
Outcome
The constructor derives all the meta data (ID and Schema) from the path- Parameters:
path- the actuals path used by the ClusterStoragedata- the parsed xml Document- Throws:
PersistencyException- there was DB errorInvalidDataException- Version or EventID was an invalid number
-
-
Method Details
-
getSchema
Gets the Schema object associated with the Outcome- Returns:
- the Schema object associated with the Outcome
-
getSchema
Gets the Schema object associated with the Outcome- Parameters:
transactionKey- the key of the transaction- Returns:
- the Schema object associated with the Outcome
-
setMetaDataFromPath
Retrieves the SchemaName, Version, EevetnId triplet from the path. Check getClusterPath() implementation- Parameters:
path- the ClusterPath to work with- Throws:
PersistencyException- path was incorrectInvalidDataException- Schema was not found or the Path has incorrect data
-
evaluateXpath
Evaluates the given XPath expression thread-safely and efficiently. It starts fromt he root Node.- Parameters:
xpathExpr- the XPath expression- Returns:
- the result of the evaluated expression
- Throws:
XPathExpressionException- If expression cannot be compiled.
-
evaluateXpath
public Object evaluateXpath(Node startNode, String xpathExpr, QName returnType) throws XPathExpressionException Evaluates the given XPath expression thread-safely and efficiently- Parameters:
startNode- the starting NodexpathExpr- the XPath expression- Returns:
- the result of the evaluated expression
- Throws:
XPathExpressionException- If expression cannot be compiled.
-
validate
Validates the actual XML Document against the provided Schema- Returns:
- the errors found
- Throws:
InvalidDataException- Schema was null
-
validateAndCheck
Validates the actual XML Document against the provided Schema- Throws:
InvalidDataException- XML document is not valid instance of the Schema
-
setName
Description copied from interface:C2KLocalObjectSets the name of the C2KLocalObject- Specified by:
setNamein interfaceC2KLocalObject- Parameters:
name- Name of the C2KLocalObject
-
getName
Description copied from interface:C2KLocalObjectGets the name of the C2KLocalObject- Specified by:
getNamein interfaceC2KLocalObject- Returns:
- name of the C2KLocalObject
-
setData
- Throws:
SAXExceptionIOException
-
getNodeValue
Gets the value of the given TEXT, CDATA, ATTRIBUTE or ELEMENT Node- Parameters:
node- the Node to work on- Returns:
- the value of the node
- Throws:
InvalidDataException- the Node is not a proper type
-
setNodeValue
Sets the value of the given TEXT, CDATA, ATTRIBUTE or ELEMENT Node- Parameters:
node- the Node to work onvalue- the value to set- Throws:
InvalidDataException- the Node is not a proper type
-
setNodeValue
Sets the value of the given TEXT, CDATA, ATTRIBUTE or ELEMENT Node- Parameters:
node- the Node to work onvalue- the value to setuseCdata- force to use CDATA- Throws:
InvalidDataException- the Node is not a proper type
-
getFieldByXPath
Retrieves the text, CDATA or attribute value of the Node selected by the XPath- Parameters:
xpath- The path to access the selected Node- Returns:
- the value of the selected Node
- Throws:
XPathExpressionException- xpath was not valid (e.g. there is no such node)InvalidDataException- xpath result is not text, CDATA or attribute
-
setAttribute
public void setAttribute(Element element, String name, String data, boolean remove) throws InvalidDataException Sets an Attribute value by name of the given Element. It only updates existing Attributes. If data is null, Element exists and the remove flag is true the node is removed.- Parameters:
element- the Element to searchname- the name of the Attributedata- the value to setremove- flag to remove existing node when data is null- Throws:
InvalidDataException- the attribute was not found
-
setAttribute
Sets an Attribute value by name of the given Element. It only updates existing Attributes.- Parameters:
element- the Element to searchname- the name of the Attributedata- the value to set- Throws:
InvalidDataException- the Attribute was not found
-
setAttribute
Sets the value of an attribute in the root Element. It can only update existing attributes.- Parameters:
name- the name of the Attributedata- the value to be setremove- flag to remove the element if the data is null- Throws:
InvalidDataException- attribute was not found
-
setAttribute
Sets an Attribute value by name of the root Element.- Parameters:
name- the name of the Attributedata- the value to set- Throws:
InvalidDataException- the name was not found
-
setAttributeOfField
public void setAttributeOfField(String field, String name, String data, boolean remove) throws InvalidDataException Sets the value of an attribute in a given Field, i.e. named Element. It can only update existing attributes.- Parameters:
field- the named Element in the root Elementname- the name of the Attributedata- the value to be setremove- flag to remove the element if the data is null- Throws:
InvalidDataException- Element or attribute was not found
-
setAttributeOfField
Sets the value of an attribute in a given Field, i.e. named Element. It can only update existing attributes.- Parameters:
field- the named Element in the root Elementname- the name of the Attributedata- the value to be set- Throws:
InvalidDataException- Element or attribute was not found
-
setField
public void setField(Element element, String name, String data, boolean remove) throws InvalidDataException Sets the textNode value of the named Element of the given Element. It only updates existing Element.- Parameters:
element- Element to usename- the name of the Elementdata- the data to be setremove- flag to remove the element if the data is null- Throws:
InvalidDataException- the name was not found or there were more Elements with the given name
-
setField
Sets the textNode value of the named Element of the given Element. It only updates existing Element.- Parameters:
element- Element to usename- the name of the Elementdata- the data to be set- Throws:
InvalidDataException- the name was not found or there were more Elements with the given name
-
setField
Sets the textNode value of the named Element of the root Element. It only updates existing Element.- Parameters:
name- the name of the Elementdata- the data to be setremove- flag to remove the element if the data is null- Throws:
InvalidDataException- the name was not found or there were more Elements with the given name
-
setField
Sets the textNode value of the named Element of the root Element. It only updates existing Element.- Parameters:
name- the name of the Elementdata- the data to be set- Throws:
InvalidDataException- the name was not found or there were more Elements with the given name
-
setFieldByXPath
public void setFieldByXPath(String xpath, String data) throws XPathExpressionException, InvalidDataException Sets the text, CDATA or attribute value of the Node selected by the XPath. It only updates existing Nodes.- Parameters:
xpath- the selected Node to be updateddata- string containing the data- Throws:
XPathExpressionException- xpath is invalidInvalidDataException- xpath result is not text, CDATA or attribute
-
setFieldByXPath
public void setFieldByXPath(String xpath, String data, boolean remove) throws XPathExpressionException, InvalidDataException Sets the text, CDATA or attribute value of the Node selected by the XPath. It only updates existing Nodes. If data is null and the node exists, the node is removed- Parameters:
xpath- the selected Node to be updateddata- string containing the data, it can be nullremove- flag to remove existing node when data is null- Throws:
XPathExpressionException- xpath is invalidInvalidDataException- xpath result is not text, CDATA or attribute
-
appendXmlFragment
Append the new Node created from xmlFragment as a child of the Node selected by the XPath- Parameters:
xpath- the selected parent nodexmlFragment- string containing the xml fragment- Returns:
- the Node just added
- Throws:
InvalidDataException
-
getData
Returns the serialised DOM as a string without pretty printing-- Returns:
- the xml string
-
getData
Returns the serialised DOM as a string -- Parameters:
prettyPrint- is the string should be pretty printed or not- Returns:
- the xml string
-
getSchemaName
Gets the name or UUID of the Schema item associated with the Outcome- Returns:
- the name or UUID of the Schema item associated with the Outcome
-
getSchemaType
Deprecated.usegetSchemaName()instead- Returns:
-
getSchemaVersion
public int getSchemaVersion()Gets the version of the Schema item associated with the Outcome- Returns:
- the version of the Schema item associated with the Outcome
-
getClusterType
ReturnsClusterType.OUTCOME- Specified by:
getClusterTypein interfaceC2KLocalObject- Returns:
- string id of the type
-
getClusterPath
Description copied from interface:C2KLocalObjectEach C2KLocalObject is stored with a path identifier starting with the ClusterType:- DomainPath: /Path/Domain/Name
- ItemPath: /Path/Item
- AgentPath: /Path/Agent
- RolePath: /Path/Role/Name
- Properties: /Property/Name
- Workflow: /LifeCycle/workflow
- Collections: /Collection/Name/Version (default Name='last')
- Outcomes: /Outcome/SchemaName/SchemaVersion/EventID
- Viewpoints: /ViewPoint/SchemaName/Name (default Name='last')
- Events: /AuditTrail/EventID
- Jobs: /Job/JobID
- Specified by:
getClusterPathin interfaceC2KLocalObject- Returns:
- The path identifier (i.e. primary key) of the object
-
newDocument
- Throws:
SAXExceptionIOException
-
parse
Parses the xml string into a DOM tree- Parameters:
xml- string to be parsed, can be null. When xml is null it creates empty Document.- Returns:
- the parsed Document
- Throws:
SAXException- error parsing documentIOException- any IO errors occur
-
parse
Parses the input source into a DOM tree. When input source is null it creates empty Document.- Parameters:
xml- string to be parsed, can be null.- Returns:
- the parsed Document
- Throws:
SAXException- error parsing documentIOException- any IO errors occur
-
getAttribute
Retrieves an Attribute value by name of the given Element.- Parameters:
element- the Element to queryname- The name of the attribute to retrieve.- Returns:
- The value as a string, or null if that attribute does not have a specified or default value.
-
getAttribute
Retrieves an Attribute value by name of the root Element.- Parameters:
name- The name of the attribute to retrieve.- Returns:
- The value as a string, or null if that attribute does not have a specified or default value.
-
getAttributeOfField
Retrieves an Attribute value by name from the named Element.- Parameters:
field- The name of the field.attribute- The name of the attribute to retrieve.- Returns:
- The value as a string, or null if that attribute does not have a specified or default value.
-
getField
Retrieves the textNode value of the named Element of the given Element.- Parameters:
element- the Element to queryname- The name of the Element- Returns:
- The value as a string, or null if that field does not exists
-
getField
Retrieves the textNode value of the named Element of the root Element.- Parameters:
name- The name of the Element- Returns:
- The value as a string, or null if that field does not exists
-
getNodesByXPath
Gets a NodeList selected by the xpath- Parameters:
xpathExpr- the xpath to select the list of Nodes- Returns:
- NodeList
- Throws:
XPathExpressionException- invalid xpath
-
getNodeByXPath
Gets a List selected by the xpath- Parameters:
xpathExpr- the xpath to select the list of Nodes- Returns:
- Node
- Throws:
XPathExpressionException- invalid xpath
-
removeNodeByXPath
public Node removeNodeByXPath(String xpathExpr) throws XPathExpressionException, InvalidDataException Removes the node selected by the xpath- Parameters:
xpathExpr- xpath to select the Node- Returns:
- the Node removed
- Throws:
XPathExpressionException- invalid xpathInvalidDataException- invalid xpath
-
serialize
Serialize the given Document- Parameters:
prettyPrint- if the xml is pretty printed or notdoc- document to be serialized- Returns:
- the xml string
- Throws:
InvalidDataException- Transformer Exception
-
traverseChildElements
-
getRecordOfNode
Reads the all Attributes and child Elements of the given Node. Use TreeMap to keep the order of Nodes.- Parameters:
node- the node to work with- Returns:
- a Map as a key/value pairs of Attribute/Element names with their value
-
getRecord
Reads the all Attributes and child Elements of the root Element- Returns:
- a Map as a key/value pairs of Attribute/Element names with their value
-
getRecord
Reads the all Attributes and child Elements of the Node selected by the xpath- Parameters:
xpath- the xpath pointing to the Node- Returns:
- a Map as a key/value pairs of Attribute/Element names with their value
- Throws:
XPathExpressionException- xpath is invalid
-
getAllRecords
Reads all Attributes and child Elements of the list of Node selected by the xpath- Parameters:
xpath- selecting the list of Nodes- Returns:
- List of Maps as a key/value pairs of Attribute/Element names with their value
- Throws:
XPathExpressionException- xpath is invalid
-
getRecordOfElement
Reads list of values of the Attributes and child Elements of the given Element. The values are returned in the order specified in the names parameter. It only return values for the list of names. Null is added to the result if there is no value for the given name.- Parameters:
element- the Element to usenames- the the Attributes and Element names to retrieve- Returns:
- List of values
-
getRecord
Reads list of values of the Attributes and child Elements of the root Element. The values are returned in the order specified in the names parameter. It only return values for the list of names. Null is added to the result if there is no value for the given name.- Parameters:
names- the the Attributes and Element names to retrieve- Returns:
- List of values
-
getRecord
Reads list of values of the Attributes and child Elements of the Element selected by the xpath. The values are returned in the order specified in the names parameter. It only return values for the list of names. Null is added to the result if there is no value for the given name.- Parameters:
xpath- to select the Elementnames- the the Attributes and Element names to retrieve- Returns:
- List of values
- Throws:
XPathExpressionException- invalid xpath
-
getAllRecords
public List<List<String>> getAllRecords(String xpath, List<String> names) throws XPathExpressionException Reads list of list of values of the Attributes and child Elements of the list of Elements selected by the xpath. The values are returned in the order specified in the names parameter. It only return values for the list of names. Null is added to the result if there is no value for the given name.- Parameters:
xpath- to select the list of Elementnames- the the Attributes and Element names to retrieve- Returns:
- List of list of values
- Throws:
XPathExpressionException- invalid xpath
-
setRecord
Sets the values of Attributes and child Element of the root Element. It only updates existing elements.- Parameters:
record- Map with a key/value pairs to find the fields or attributes to update- Throws:
InvalidDataException- the name in the map was invalid
-
setRecord
public void setRecord(String xpath, Map<String, String> record) throws InvalidDataException, XPathExpressionExceptionSets the values of Attributes and child Element of the Element selected by xpath. It only updates existing elements.- Parameters:
xpath- apth to the Element to be updatedrecord- Map with a key/value pairs to find the fields or attributes to update- Throws:
InvalidDataException- the name in the map was invalidXPathExpressionException- the xpath was invalid
-
setRecord
Sets the values of Attributes and child Element of given Element. It only updates existing elements.- Parameters:
element- the element to be updatedrecord- Map with a key/value pairs to find the fields or attributes to update- Throws:
InvalidDataException- the name in the map was invalid
-
isIdentical
Checks if the Outcome is identical with the given input- Parameters:
other- the other Outcome to be compare with- Returns:
- true if the two Outcomes are identical, otherwise returns false
-
isIdentical
Utility method to comare 2 XML Documents- Parameters:
origDocument- XML documentotherDocument- the other XML document- Returns:
- true if the two XML Documents are identical, otherwise returns false
-
hasField
-
hasField
-
getRootName
-
toString
-
getSchemaName()instead