001 /*
002 // $Id: //open/mondrian-release/3.0/src/main/mondrian/olap/Exp.java#2 $
003 // This software is subject to the terms of the Common Public License
004 // Agreement, available at the following URL:
005 // http://www.opensource.org/licenses/cpl.html.
006 // Copyright (C) 1999-2002 Kana Software, Inc.
007 // Copyright (C) 2001-2006 Julian Hyde and others
008 // All Rights Reserved.
009 // You must accept the terms of that agreement to use this software.
010 //
011 // jhyde, 20 January, 1999
012 */
013
014 package mondrian.olap;
015
016 import mondrian.olap.type.Type;
017 import mondrian.calc.Calc;
018 import mondrian.calc.ExpCompiler;
019 import mondrian.mdx.MdxVisitorImpl;
020 import mondrian.mdx.MdxVisitor;
021
022 import java.io.PrintWriter;
023
024 /**
025 * An <code>Exp</code> is an MDX expression.
026 *
027 * @author jhyde
028 * @since 1.0
029 * @version $Id: //open/mondrian-release/3.0/src/main/mondrian/olap/Exp.java#2 $
030 */
031 public interface Exp {
032
033 Exp clone();
034
035 /**
036 * Returns the {@link Category} of the expression.
037 *
038 * @post Category.instance().isValid(return)
039 */
040 int getCategory();
041
042 /**
043 * Returns the type of this expression. Never null.
044 */
045 Type getType();
046
047 /**
048 * Writes the MDX representation of this expression to a print writer.
049 * Sub-expressions are invoked recursively.
050 *
051 * @param pw PrintWriter
052 */
053 void unparse(PrintWriter pw);
054
055 /**
056 * Validates this expression.
057 *
058 * The validator acts in the role of 'visitor' (see Gang of Four
059 * 'visitor pattern'), and an expression in the role of 'visitee'.
060 *
061 * @param validator Validator contains validation context
062 *
063 * @return The validated expression; often but not always the same as
064 * this expression
065 */
066 Exp accept(Validator validator);
067
068 /**
069 * Converts this expression into an a tree of expressions which can be
070 * efficiently evaluated.
071 *
072 * @param compiler
073 * @return A compiled expression
074 */
075 Calc accept(ExpCompiler compiler);
076
077 /**
078 * Accepts a visitor to this Exp.
079 * The implementation should generally dispatches to the
080 * {@link MdxVisitor#visit} method appropriate to the type of expression.
081 *
082 * @param visitor Visitor
083 */
084 Object accept(MdxVisitor visitor);
085 }
086
087 // End Exp.java