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