org.gcube.common.searchservice.searchlibrary.resultset.elements
Class ResultElementGeneric

java.lang.Object
  extended by org.gcube.common.searchservice.searchlibrary.resultset.elements.ResultElementBase
      extended by org.gcube.common.searchservice.searchlibrary.resultset.elements.ResultElementGeneric
Direct Known Subclasses:
ResultElementBean, ResultElementXBean

public class ResultElementGeneric
extends ResultElementBase

This class acts as a generic placeholder for the records that can be inserted and extracted from the ResultSet payload parts

Author:
UoA

Field Summary
static java.lang.String RECORD_COLLECTION_NAME
          The name of the collection attribute holding the collection value
static java.lang.String RECORD_ID_NAME
          The name of the id attribute holding the identifier value
static java.lang.String RECORD_RANK_NAME
          The name of the rank attribute holding the record ranking
 
Constructor Summary
ResultElementGeneric()
          Default contructor nessecary for the framework
ResultElementGeneric(java.lang.String id, java.lang.String collection, java.lang.String payload)
          Creates a new ResultElementGeneric.
ResultElementGeneric(java.lang.String id, java.lang.String collection, java.lang.String rank, java.lang.String payload)
          Creates a new ResultElementGeneric
 
Method Summary
static java.lang.String extractValue(ResultElementGeneric element, java.lang.String which)
          This method receives a ResultElementGeneric and an expression in the form of element/element/element and traverses the payload expecting to find at every level it moves a child element with the name as provided, in the respective level, in the which parameter.
 void fromXML(java.lang.String xml)
          This method must be able to reconstruct the result elelement from a xml string as returned by ResultElementBase.toXML()
 java.lang.String getPayload()
          Retrieves the payload
static ResultElementGeneric merge(ResultElementGeneric element1, ResultElementGeneric element2)
          Merges the two provided ResultElementGeneric into a new one which has as the id the id of element1, and as payload the concatenation of the two elements payload
 java.lang.String toXML()
          This method must return a valid xml serialization of the result record payload.
 
Methods inherited from class org.gcube.common.searchservice.searchlibrary.resultset.elements.ResultElementBase
getRecordAttributes, getRecordAttributes, isValid, RS_fromXML, RS_toXML, setRecordAttributes
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RECORD_ID_NAME

public static final java.lang.String RECORD_ID_NAME
The name of the id attribute holding the identifier value

See Also:
Constant Field Values

RECORD_COLLECTION_NAME

public static final java.lang.String RECORD_COLLECTION_NAME
The name of the collection attribute holding the collection value

See Also:
Constant Field Values

RECORD_RANK_NAME

public static final java.lang.String RECORD_RANK_NAME
The name of the rank attribute holding the record ranking

See Also:
Constant Field Values
Constructor Detail

ResultElementGeneric

public ResultElementGeneric()
Default contructor nessecary for the framework


ResultElementGeneric

public ResultElementGeneric(java.lang.String id,
                            java.lang.String collection,
                            java.lang.String rank,
                            java.lang.String payload)
                     throws java.lang.Exception
Creates a new ResultElementGeneric

Parameters:
id - The value of the id. This cannot be null or an empty string
collection - The collection this id belongs to. This cannot be null or an empty string
rank - The rank this id got. This cannot be null or an empty string
payload - The payload of the record
Throws:
java.lang.Exception - The ResultElementGeneric could not be created

ResultElementGeneric

public ResultElementGeneric(java.lang.String id,
                            java.lang.String collection,
                            java.lang.String payload)
                     throws java.lang.Exception
Creates a new ResultElementGeneric. The rank attribute is set to 1.0

Parameters:
id - The value of the id. This cannot be null or an empty string
collection - The collection this id belongs to. This cannot be null or an empty string
payload - The payload of the record
Throws:
java.lang.Exception - The ResultElementGeneric could not be created
Method Detail

getPayload

public java.lang.String getPayload()
Retrieves the payload

Returns:
The payload

toXML

public java.lang.String toXML()
                       throws java.lang.Exception
Description copied from class: ResultElementBase
This method must return a valid xml serialization of the result record payload.

Specified by:
toXML in class ResultElementBase
Returns:
The serialized record payload
Throws:
java.lang.Exception - An unrecoverable for the operation error occured
See Also:
ResultElementBase.toXML()

fromXML

public void fromXML(java.lang.String xml)
             throws java.lang.Exception
Description copied from class: ResultElementBase
This method must be able to reconstruct the result elelement from a xml string as returned by ResultElementBase.toXML()

Specified by:
fromXML in class ResultElementBase
Parameters:
xml - The serialized string to populate the insance from
Throws:
java.lang.Exception - An unrecoverable for the operation error occured
See Also:
ResultElementBase.fromXML(java.lang.String)

extractValue

public static java.lang.String extractValue(ResultElementGeneric element,
                                            java.lang.String which)
This method receives a ResultElementGeneric and an expression in the form of element/element/element and traverses the payload expecting to find at every level it moves a child element with the name as provided, in the respective level, in the which parameter. It then retrieves and returns the content of the first child element with the name of the last element in the which argument. If the which argument is one of RECORD_COLLECTION_NAME, RECORD_ID_NAME, RECORD_RANK_NAME, the first value of the attribute whith the respective type is retrieved If the expression beggins with // the first element in the entire record document that is named as the provided expression will be returned.

Parameters:
element - The element to scan through
which - a path to the element whose contents must be retrieved
Returns:
The extracted value

merge

public static ResultElementGeneric merge(ResultElementGeneric element1,
                                         ResultElementGeneric element2)
                                  throws java.lang.Exception
Merges the two provided ResultElementGeneric into a new one which has as the id the id of element1, and as payload the concatenation of the two elements payload

Parameters:
element1 - One of the ResultElementGeneric that must be merged
element2 - One of the ResultElementGeneric that must be merged
Returns:
The newly created ResultElementGeneric
Throws:
java.lang.Exception - The merge operation could not be performed