org.quattor.pan.dml
Class AbstractOperation

java.lang.Object
  extended by org.quattor.pan.dml.AbstractOperation
All Implemented Interfaces:
Operation
Direct Known Subclasses:
Add, Assign, BitAnd, BitIOR, BitNot, BitXOR, BuiltInFunction, Div, DML, For, Foreach, Function, IfElse, ListVariable, LogicalAnd, LogicalEQ, LogicalGE, LogicalGT, LogicalLE, LogicalLT, LogicalNE, LogicalNot, LogicalOr, Mod, Mult, SetValue, Sub, UnaryMinus, UnaryPlus, Variable, While

public abstract class AbstractOperation
extends java.lang.Object
implements Operation

Abstract class which implements the Operation interface and provides some functionality common to all DML components.

Author:
loomis

Field Summary
protected  Operation[] ops
          Array of arguments (as operations) for this operation.
protected  SourceRange sourceRange
          Source location of this operation and its arguments.
 
Constructor Summary
AbstractOperation(SourceRange sourceRange, Operation... operations)
          Set the source location information and arguments for this operation.
 
Method Summary
protected  Element[] calculateArgs(Context context)
          A utility method which calls execute on each of this operation's arguments and returns an array of the results.
protected  Term[] calculateTerms(Context context)
          A utility method that creates a list of terms from the given arguments.
 void checkInvalidSelfContext()
          Default implementation recursively calls this method on all of the contained operations (arguments).
 void checkRestrictedContext()
          Default implementation recursively calls this method on all of the contained operations (arguments).
abstract  Element execute(Context context)
          Execute this operation within the given context.
 Operation[] getOperations()
          Allow a copy of the raw operations to be retrieved.
 SourceRange getSourceRange()
          Retrieve the source information from this operation.
 java.lang.String toString()
          Default string representation of an operation is the class' simple name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sourceRange

protected final SourceRange sourceRange
Source location of this operation and its arguments.


ops

protected final Operation[] ops
Array of arguments (as operations) for this operation.

Constructor Detail

AbstractOperation

public AbstractOperation(SourceRange sourceRange,
                         Operation... operations)
Set the source location information and arguments for this operation.

Parameters:
sourceRange - source location of this operation and arguments
operations - list of arguments (as operations) for this operation
Method Detail

execute

public abstract Element execute(Context context)
                         throws EvaluationException
Description copied from interface: Operation
Execute this operation within the given context. If an error occurs, an EvaluationException will be thrown with the details.

Specified by:
execute in interface Operation
Parameters:
context - evaluation context for the statement
Returns:
Element produced by running operation
Throws:
EvaluationException - if an error occurs during processing

checkRestrictedContext

public void checkRestrictedContext()
                            throws SyntaxException
Default implementation recursively calls this method on all of the contained operations (arguments). Subclasses that cannot appear in a restricted context (array indices or function arguments) should override this method and throw a SyntaxException.

Specified by:
checkRestrictedContext in interface Operation
Throws:
SyntaxException - if operation cannot appear in restricted context

checkInvalidSelfContext

public void checkInvalidSelfContext()
                             throws SyntaxException
Default implementation recursively calls this method on all of the contained operations (arguments). Subclasses that reference SELF should override this method and throw a SyntaxException.

Specified by:
checkInvalidSelfContext in interface Operation
Throws:
SyntaxException - if operation references SELF

calculateArgs

protected Element[] calculateArgs(Context context)
                           throws EvaluationException
A utility method which calls execute on each of this operation's arguments and returns an array of the results.

Parameters:
context - evaluation context to use
Returns:
array of the results of executing the arguments
Throws:
EvaluationException

calculateTerms

protected Term[] calculateTerms(Context context)
                         throws EvaluationException
A utility method that creates a list of terms from the given arguments.

Parameters:
context - evaluation context to use
Returns:
array of terms calculated from the operations
Throws:
EvaluationException - if any error occurs when evaluating the arguments or if the resulting value is not a valid Term

getSourceRange

public SourceRange getSourceRange()
Retrieve the source information from this operation. The SourceRange is available to subclasses as a protected field, so subclasses can access the value directly.

Returns:
SourceRange giving location of this operation and its arguments

getOperations

public Operation[] getOperations()
Allow a copy of the raw operations to be retrieved.


toString

public java.lang.String toString()
Default string representation of an operation is the class' simple name.

Overrides:
toString in class java.lang.Object
Returns:
string of class' simple name


Copyright © 2011 Quattor. All Rights Reserved.