mondrian.olap
Class ValidatorImpl

java.lang.Object
  extended by mondrian.olap.ValidatorImpl
All Implemented Interfaces:
Validator

abstract class ValidatorImpl
extends Object
implements Validator

Default implementation of Validator.

Uses a stack to help us guess the type of our parent expression before we've completely resolved our children -- necessary, unfortunately, when figuring out whether the "*" operator denotes multiplication or crossjoin.

Keeps track of which nodes have already been resolved, so we don't try to resolve nodes which have already been resolved. (That would not be wrong, but can cause resolution to be an O(2^N) operation.)

The concrete implementing class needs to implement Validator.getQuery() and defineParameter(Parameter).

Version:
$Id: //open/mondrian/src/main/mondrian/olap/ValidatorImpl.java#7 $
Author:
jhyde

Field Summary
protected  ArrayStack<QueryPart> stack
           
 
Constructor Summary
protected ValidatorImpl(FunTable funTable)
          Creates a ValidatorImpl.
 
Method Summary
 boolean alwaysResolveFunDef()
          Whether to resolve function name and arguments to a function definition each time a node is validated, not just the first time.
 boolean canConvert(int ordinal, Exp fromExp, int to, List<Resolver.Conversion> conversions)
          Returns whether we can convert an argument to a parameter type.
 Parameter createOrLookupParam(boolean definition, String name, Type type, Exp defaultExp, String description)
          Creates or retrieves the parameter corresponding to a "Parameter" or "ParamRef" function call.
protected abstract  void defineParameter(Parameter param)
          Defines a parameter.
 FunDef getDef(Exp[] args, String funName, Syntax syntax)
          Resolves a function call to a particular function.
 FunTable getFunTable()
          Returns the table of function and operator definitions.
 boolean requiresExpression()
          Returns whether the current context requires an expression.
(package private)  boolean requiresExpression(UnresolvedFunCall funCall, int k)
          Returns whether the kth argument to a function call has to be an expression.
 Exp validate(Exp exp, boolean scalar)
          Validates an expression, and returns the expression it resolves to.
 void validate(Formula formula)
          Validates a formula.
 void validate(MemberProperty memberProperty)
          Validates a child member property.
 void validate(ParameterExpr parameterExpr)
          Validates a usage of a parameter.
 void validate(QueryAxis axis)
          Validates an axis.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface mondrian.olap.Validator
getQuery, getSchemaReader
 

Field Detail

stack

protected final ArrayStack<QueryPart> stack
Constructor Detail

ValidatorImpl

protected ValidatorImpl(FunTable funTable)
Creates a ValidatorImpl.

Parameters:
funTable - Function table
Pre-condition:
funTable != null
Method Detail

validate

public Exp validate(Exp exp,
                    boolean scalar)
Description copied from interface: Validator
Validates an expression, and returns the expression it resolves to.

Specified by:
validate in interface Validator
Parameters:
exp - Expression to validate
scalar - Whether the context requires that the expression is evaluated to a value, as opposed to a tuple

validate

public void validate(ParameterExpr parameterExpr)
Description copied from interface: Validator
Validates a usage of a parameter.

It must resolve to the same object (although sub-objects may change).

Specified by:
validate in interface Validator

validate

public void validate(MemberProperty memberProperty)
Description copied from interface: Validator
Validates a child member property.

It must resolve to the same object (although sub-objects may change).

Specified by:
validate in interface Validator

validate

public void validate(QueryAxis axis)
Description copied from interface: Validator
Validates an axis. It must resolve to the same object (although sub-objects may change).

Specified by:
validate in interface Validator

validate

public void validate(Formula formula)
Description copied from interface: Validator
Validates a formula. It must resolve to the same object (although sub-objects may change).

Specified by:
validate in interface Validator

getDef

public FunDef getDef(Exp[] args,
                     String funName,
                     Syntax syntax)
Description copied from interface: Validator
Resolves a function call to a particular function. If the function is overloaded, returns as precise a match to the argument types as possible.

Specified by:
getDef in interface Validator

alwaysResolveFunDef

public boolean alwaysResolveFunDef()
Description copied from interface: Validator
Whether to resolve function name and arguments to a function definition each time a node is validated, not just the first time.

Default implementation returns false.

Specified by:
alwaysResolveFunDef in interface Validator
Returns:
whether to resolve function each time

canConvert

public boolean canConvert(int ordinal,
                          Exp fromExp,
                          int to,
                          List<Resolver.Conversion> conversions)
Description copied from interface: Validator
Returns whether we can convert an argument to a parameter type.

Specified by:
canConvert in interface Validator
Parameters:
ordinal - argument ordinal
fromExp - argument type
to - parameter type
conversions - List of conversions performed; method adds an element for each non-trivial conversion (for example, converting a member to a level).
Returns:
Whether we can convert an argument to a parameter type

requiresExpression

public boolean requiresExpression()
Description copied from interface: Validator
Returns whether the current context requires an expression.

Specified by:
requiresExpression in interface Validator

requiresExpression

boolean requiresExpression(UnresolvedFunCall funCall,
                           int k)
Returns whether the kth argument to a function call has to be an expression.


getFunTable

public FunTable getFunTable()
Description copied from interface: Validator
Returns the table of function and operator definitions.

Specified by:
getFunTable in interface Validator

createOrLookupParam

public Parameter createOrLookupParam(boolean definition,
                                     String name,
                                     Type type,
                                     Exp defaultExp,
                                     String description)
Description copied from interface: Validator
Creates or retrieves the parameter corresponding to a "Parameter" or "ParamRef" function call.

Specified by:
createOrLookupParam in interface Validator

defineParameter

protected abstract void defineParameter(Parameter param)
Defines a parameter.

Parameters:
param - Parameter

Get Mondrian at SourceForge.net. Fast, secure and free Open Source software downloads