|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmessif.operations.AbstractOperation
public abstract class AbstractOperation
The base class for all operations.
Operations allows to manipulate and query the data held by algorithms.
An algorithm is not required to provide implementation for each operation.
However, to support an operation, simply create a method with a specific operation
class as an argument. See Algorithm
for more information.
To ease the task of building interfaces, each operation should provide
an annotation AbstractOperation.OperationName
to specify a user-friendly name of
the operation. Also the constructors should be annotated by AbstractOperation.OperationConstructor
to specify descriptors for its arguments. See Convert.stringToType(java.lang.String, java.lang.Class
for
the list of types that can be used in operation constructors.
QueryOperation
,
Algorithm
,
Serialized FormNested Class Summary | |
---|---|
static class |
AbstractOperation.DataEqualOperation
A wrapper class that allows to hash/equal abstract objects using their data and not ID. |
static interface |
AbstractOperation.OperationConstructor
Annotation for operation constructors. |
static interface |
AbstractOperation.OperationName
Annotation that specifies operation user-friendly name. |
Field Summary | |
---|---|
protected ErrorCode |
errValue
Operation result code |
protected java.util.UUID |
operID
An universaly unique identification of the operation |
java.lang.Object |
suppData
Supplemental data object |
Constructor Summary | |
---|---|
AbstractOperation()
|
Method Summary | ||
---|---|---|
protected void |
appendArguments(java.lang.StringBuilder str)
Appends the constructor arguments of this query to the specified string. |
|
protected void |
appendErrorCode(java.lang.StringBuilder str)
Appends the error code of this query to the specified string. |
|
void |
clearSurplusData()
Clear non-messif data stored in operation. |
|
AbstractOperation |
clone()
Create a duplicate of this operation. |
|
static
|
createOperation(java.lang.Class<E> operationClass,
java.lang.Object... arguments)
Creates a new operation of the specified class. |
|
boolean |
dataEquals(AbstractOperation operation)
Indicates whether some other operation has the same data as this one. |
|
protected abstract boolean |
dataEqualsImpl(AbstractOperation operation)
Indicates whether some other operation has the same data as this one. |
|
abstract int |
dataHashCode()
Returns a hash code value for the data of this operation. |
|
abstract void |
endOperation()
End operation successfully. |
|
void |
endOperation(ErrorCode errValue)
End operation with a specific error code. |
|
boolean |
equals(java.lang.Object obj)
Indicates whether another operation is equal to this operation. |
|
static
|
getAnnotatedConstructor(java.lang.Class<? extends T> operationClass)
Searches the given operationClass for an annotated constructor. |
|
static
|
getAnnotatedConstructor(java.lang.Class<? extends T> operationClass,
int argumentsCount)
Searches the given operationClass for an annotated constructor
that has the given argumentsCount . |
|
java.lang.Object |
getArgument(int index)
Returns argument that was passed while constructing instance. |
|
int |
getArgumentCount()
Returns number of arguments that were passed while constructing this instance. |
|
static java.lang.String[] |
getConstructorArgumentDescriptions(java.lang.Class<? extends AbstractOperation> operationClass)
Returns constructor argument descriptions for the provided operation class. |
|
static java.lang.String[] |
getConstructorArgumentDescriptions(java.lang.Class<? extends AbstractOperation> operationClass,
int nArguments)
Returns constructor argument descriptions for the provided operation class with given number of arguments. |
|
static java.lang.Class<?>[] |
getConstructorArguments(java.lang.Class<? extends AbstractOperation> operationClass)
Returns constructor argument types for the provided operation class. |
|
static java.lang.Class<?>[] |
getConstructorArguments(java.lang.Class<? extends AbstractOperation> operationClass,
int nArguments)
Returns constructor arguments for the provided operation class for an annotated constructor with given number of arguments. |
|
static java.lang.String |
getConstructorDescription(java.lang.Class<? extends AbstractOperation> operationClass)
Returns full constructor description for the provided operation class. |
|
ErrorCode |
getErrorCode()
Returns the result code of this operation. |
|
java.lang.String |
getName()
Returns the name of this operation. |
|
static java.lang.String |
getName(java.lang.Class<? extends AbstractOperation> operationClass)
Returns the name of operation represented by the provided class. |
|
java.util.UUID |
getOperationID()
Returns the current operation ID. |
|
int |
hashCode()
Returns a hash code value based on this operation ID. |
|
boolean |
isFinished()
Returns true if this operation has finished its processing - either successfully or unsuccessfully. |
|
java.lang.String |
toString()
Returns a string representation of this operation. |
|
void |
updateFrom(AbstractOperation operation)
Update the error code of this operation from another operation. |
|
abstract boolean |
wasSuccessful()
Returns true if this operation has finished successfuly. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public java.lang.Object suppData
protected final java.util.UUID operID
protected ErrorCode errValue
Constructor Detail |
---|
public AbstractOperation()
Method Detail |
---|
public java.util.UUID getOperationID()
public final int hashCode()
hashCode
in class java.lang.Object
public final boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the reference object with which to compare
true
if this object is the same as the obj
argument; false
otherwisepublic final boolean dataEquals(AbstractOperation operation)
operation
- the reference object with which to compare.
true
if this object has the same data as the obj
argument; false
otherwise.protected abstract boolean dataEqualsImpl(AbstractOperation operation)
operation
- the reference object with which to compare.
true
if this object has the same data as the obj
argument; false
otherwise.public abstract int dataHashCode()
public abstract boolean wasSuccessful()
public ErrorCode getErrorCode()
public boolean isFinished()
not set
,
false is returned.
public void endOperation(ErrorCode errValue) throws java.lang.IllegalArgumentException
errValue
- the error code to set
java.lang.IllegalArgumentException
- if the specified error value is null or ErrorCode.NOT_SET
public abstract void endOperation()
public AbstractOperation clone() throws java.lang.CloneNotSupportedException
suppData
) is not clonned.
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- if the operation instance cannot be clonedpublic void updateFrom(AbstractOperation operation) throws java.lang.ClassCastException
operation
- the source operation from which to get the update
java.lang.ClassCastException
- if the specified operation is incompatible with this operationpublic void clearSurplusData()
clearSurplusData
in interface Clearable
protected void appendArguments(java.lang.StringBuilder str)
str
- the string to add the arguments toprotected void appendErrorCode(java.lang.StringBuilder str)
was successful
, the "was successful" string is added.
Otherwise, a string "failed: " with the error code name is added.
Leading space is added.
str
- the string to add the error code topublic java.lang.String toString()
toString
in class java.lang.Object
public static java.lang.String getName(java.lang.Class<? extends AbstractOperation> operationClass)
operationClass
- the operation class for which to get the name
public java.lang.String getName()
public static <T extends AbstractOperation> java.lang.reflect.Constructor<T> getAnnotatedConstructor(java.lang.Class<? extends T> operationClass) throws java.lang.NoSuchMethodException
operationClass
for an annotated constructor.
The constructor with the smallest number of arguments is returned.
T
- the operation classoperationClass
- the operation class to search the constructor for
java.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
public static <T extends AbstractOperation> java.lang.reflect.Constructor<T> getAnnotatedConstructor(java.lang.Class<? extends T> operationClass, int argumentsCount) throws java.lang.NoSuchMethodException
operationClass
for an annotated constructor
that has the given argumentsCount
.
T
- the operation classoperationClass
- the operation class to search the constructor forargumentsCount
- number of arguments that the constructor must have
java.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
public static java.lang.String[] getConstructorArgumentDescriptions(java.lang.Class<? extends AbstractOperation> operationClass) throws java.lang.NoSuchMethodException
operationClass
- class to get the descriptions for
java.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
public static java.lang.String[] getConstructorArgumentDescriptions(java.lang.Class<? extends AbstractOperation> operationClass, int nArguments) throws java.lang.NoSuchMethodException
operationClass
- class to get the descriptions fornArguments
- the number of arguments of the constructor
java.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
public static java.lang.Class<?>[] getConstructorArguments(java.lang.Class<? extends AbstractOperation> operationClass) throws java.lang.NoSuchMethodException
operationClass
- class to get the constructor types for
java.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
public static java.lang.Class<?>[] getConstructorArguments(java.lang.Class<? extends AbstractOperation> operationClass, int nArguments) throws java.lang.NoSuchMethodException
operationClass
- class to get the constructor types fornArguments
- the number of arguments of the constructor
java.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
public static java.lang.String getConstructorDescription(java.lang.Class<? extends AbstractOperation> operationClass) throws java.lang.NoSuchMethodException
operationClass
- class to get the constructor types for
java.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
public static <E extends AbstractOperation> E createOperation(java.lang.Class<E> operationClass, java.lang.Object... arguments) throws java.lang.NoSuchMethodException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException
E
- the class of the operation that should be createdoperationClass
- the class of the operation that should be createdarguments
- arguments supplied to the constructor; they should match the types of getConstructorArguments(operationClass)
java.lang.NoSuchMethodException
- if either the operationClass
is null or the class is not annotated using AbstractOperation.OperationName
java.lang.IllegalArgumentException
- if the argument count or their types don't match the specified operation class constructor
java.lang.reflect.InvocationTargetException
- if there was an exception in the operation's constructorpublic java.lang.Object getArgument(int index) throws java.lang.IndexOutOfBoundsException, java.lang.UnsupportedOperationException
index
- zero-based index of an argument passed to constructor
java.lang.IndexOutOfBoundsException
- if index parameter is out of range
java.lang.UnsupportedOperationException
- if this operation doesn't support construction argument retrievalpublic int getArgumentCount()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |