001    /*
002    // $Id: //open/mondrian/src/main/mondrian/mdx/DimensionExpr.java#5 $
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) 2006-2006 Julian Hyde
007    // All Rights Reserved.
008    // You must accept the terms of that agreement to use this software.
009    */
010    package mondrian.mdx;
011    
012    import mondrian.olap.*;
013    import mondrian.olap.type.DimensionType;
014    import mondrian.olap.type.Type;
015    import mondrian.calc.*;
016    import mondrian.calc.impl.ConstantCalc;
017    
018    /**
019     * Usage of a {@link mondrian.olap.Dimension} as an MDX expression.
020     *
021     * @author jhyde
022     * @version $Id: //open/mondrian/src/main/mondrian/mdx/DimensionExpr.java#5 $
023     * @since Sep 26, 2005
024     */
025    public class DimensionExpr extends ExpBase implements Exp {
026        private final Dimension dimension;
027    
028        /**
029         * Creates a dimension expression.
030         *
031         * @param dimension Dimension
032         * @pre dimension != null
033         */
034        public DimensionExpr(Dimension dimension) {
035            Util.assertPrecondition(dimension != null, "dimension != null");
036            this.dimension = dimension;
037        }
038    
039        /**
040         * Returns the dimension.
041         *
042         * @post return != null
043         */
044        public Dimension getDimension() {
045            return dimension;
046        }
047    
048        public String toString() {
049            return dimension.getUniqueName();
050        }
051    
052        public Type getType() {
053            return DimensionType.forDimension(dimension);
054        }
055    
056        public DimensionExpr clone() {
057            return new DimensionExpr(dimension);
058        }
059    
060        public int getCategory() {
061            return Category.Dimension;
062        }
063    
064        public Exp accept(Validator validator) {
065            return this;
066        }
067    
068        public Calc accept(ExpCompiler compiler) {
069            return ConstantCalc.constantDimension(dimension);
070        }
071    
072        public Object accept(MdxVisitor visitor) {
073            return visitor.visit(this);
074        }
075    
076    }
077    
078    // End DimensionExpr.java