messif.operations
Class SingletonQueryOperation

java.lang.Object
  extended by messif.operations.AbstractOperation
      extended by messif.operations.QueryOperation<AbstractObject>
          extended by messif.operations.SingletonQueryOperation
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Clearable
Direct Known Subclasses:
GetObjectByLocatorOperation, GetObjectQueryOperation, GetRandomObjectQueryOperation

public abstract class SingletonQueryOperation
extends QueryOperation<AbstractObject>

The base class for query operations that return a single object. These are, for example, operations that retrieve objects by ID or locator.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class messif.operations.AbstractOperation
AbstractOperation.DataEqualOperation, AbstractOperation.OperationConstructor, AbstractOperation.OperationName
 
Field Summary
 
Fields inherited from class messif.operations.QueryOperation
answerType
 
Fields inherited from class messif.operations.AbstractOperation
errValue, operID, suppData
 
Constructor Summary
protected SingletonQueryOperation()
          Creates a new instance of SingletonQueryOperation.
protected SingletonQueryOperation(AnswerType answerType)
          Creates a new instance of ListingQueryOperation.
 
Method Summary
 boolean addToAnswer(AbstractObject object)
          Add an object to the answer.
 void clearSurplusData()
          Clear non-messif data stored in operation.
 SingletonQueryOperation clone()
          Create a duplicate of this operation.
 java.util.Iterator<AbstractObject> getAnswer()
          Returns an iterator over all objects in the answer to this query.
 java.util.Iterator<AbstractObject> getAnswer(int skip, int count)
          Returns an iterator over all objects in the answer skipping the first skip items and returning only count elements.
 java.lang.Class<? extends AbstractObject> getAnswerClass()
          Returns the class of objects this operation stores in its answer.
 int getAnswerCount()
          Returns the number of objects in this query answer.
 AbstractObject getAnswerObject()
          Returns an object that is the answer to this query.
 java.util.Iterator<AbstractObject> getAnswerObjects()
          Returns an iterator over all AbstractObjects in the answer to this query.
 void resetAnswer()
          Reset the current query answer.
 void updateFrom(AbstractOperation operation)
          Update the error code and answer of this operation from another operation.
 
Methods inherited from class messif.operations.QueryOperation
appendErrorCode, endOperation, evaluate, getAnswerType, wasSuccessful
 
Methods inherited from class messif.operations.AbstractOperation
appendArguments, createOperation, dataEquals, dataEqualsImpl, dataHashCode, endOperation, equals, getAnnotatedConstructor, getAnnotatedConstructor, getArgument, getArgumentCount, getConstructorArgumentDescriptions, getConstructorArgumentDescriptions, getConstructorArguments, getConstructorArguments, getConstructorDescription, getErrorCode, getName, getName, getOperationID, hashCode, isFinished, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SingletonQueryOperation

protected SingletonQueryOperation()
Creates a new instance of SingletonQueryOperation. The object stored in answer is cleared and clonned.


SingletonQueryOperation

protected SingletonQueryOperation(AnswerType answerType)
Creates a new instance of ListingQueryOperation.

Parameters:
answerType - the type of object this operation stores in its answer
Method Detail

clone

public SingletonQueryOperation clone()
                              throws java.lang.CloneNotSupportedException
Create a duplicate of this operation. The answer of the query is not clonned.

Overrides:
clone in class AbstractOperation
Returns:
a clone of this operation
Throws:
java.lang.CloneNotSupportedException - if the operation instance cannot be cloned

getAnswerClass

public java.lang.Class<? extends AbstractObject> getAnswerClass()
Returns the class of objects this operation stores in its answer.

Specified by:
getAnswerClass in class QueryOperation<AbstractObject>
Returns:
the class of objects this operation stores in its answer

getAnswerCount

public int getAnswerCount()
Returns the number of objects in this query answer. For this operation, only 0 or 1 can be returned.

Specified by:
getAnswerCount in class QueryOperation<AbstractObject>
Returns:
the number of objects in this query answer

getAnswer

public java.util.Iterator<AbstractObject> getAnswer()
Returns an iterator over all objects in the answer to this query.

Specified by:
getAnswer in class QueryOperation<AbstractObject>
Returns:
an iterator over all objects in the answer to this query

getAnswer

public java.util.Iterator<AbstractObject> getAnswer(int skip,
                                                    int count)
Description copied from class: QueryOperation
Returns an iterator over all objects in the answer skipping the first skip items and returning only count elements. If count is less than or equal to zero, all objects from the answer (except for skip) are returned.

Specified by:
getAnswer in class QueryOperation<AbstractObject>
Parameters:
skip - number of answer objects to skip
count - number of answer objects to iterate (maximally, actual number of results can be smaller)
Returns:
an iterator over the objects in the answer to this query

getAnswerObjects

public java.util.Iterator<AbstractObject> getAnswerObjects()
Description copied from class: QueryOperation
Returns an iterator over all AbstractObjects in the answer to this query. This method unwraps the objects from the results.

Specified by:
getAnswerObjects in class QueryOperation<AbstractObject>
Returns:
an iterator over all AbstractObjects in the answer to this query

getAnswerObject

public AbstractObject getAnswerObject()
Returns an object that is the answer to this query.

Returns:
an object that is the answer to this query

addToAnswer

public boolean addToAnswer(AbstractObject object)
                    throws java.lang.IllegalArgumentException
Add an object to the answer. The object is updated according to QueryOperation.answerType.

Parameters:
object - the object to add
Returns:
true if the object has been added to the answer. Otherwise false.
Throws:
java.lang.IllegalArgumentException - if the object cannot be added to the answer, e.g. because it cannot be clonned

resetAnswer

public void resetAnswer()
Reset the current query answer.

Specified by:
resetAnswer in class QueryOperation<AbstractObject>

updateFrom

public void updateFrom(AbstractOperation operation)
                throws java.lang.IllegalArgumentException
Update the error code and answer of this operation from another operation. Answer of this operation is updated only it is not set yet.

Overrides:
updateFrom in class AbstractOperation
Parameters:
operation - the source operation from which to get the update
Throws:
java.lang.IllegalArgumentException - if the answer of the specified operation is incompatible with this one

clearSurplusData

public void clearSurplusData()
Clear non-messif data stored in operation. This method is intended to be called whenever the operation is sent back to client in order to minimize problems with unknown classes after deserialization.

Specified by:
clearSurplusData in interface Clearable
Overrides:
clearSurplusData in class AbstractOperation