001    /*
002    // $Id: DimensionNode.java 229 2009-05-08 19:11:29Z jhyde $
003    // This software is subject to the terms of the Eclipse Public License v1.0
004    // Agreement, available at the following URL:
005    // http://www.eclipse.org/legal/epl-v10.html.
006    // Copyright (C) 2007-2008 Julian Hyde
007    // All Rights Reserved.
008    // You must accept the terms of that agreement to use this software.
009    */
010    package org.olap4j.mdx;
011    
012    import org.olap4j.metadata.Dimension;
013    import org.olap4j.type.Type;
014    import org.olap4j.type.DimensionType;
015    
016    /**
017     * Usage of a {@link org.olap4j.metadata.Dimension} as an expression in an MDX
018     * parse tree.
019     *
020     * @author jhyde
021     * @version $Id: DimensionNode.java 229 2009-05-08 19:11:29Z jhyde $
022     * @since Jun 4, 2007
023     */
024    public class DimensionNode implements ParseTreeNode {
025        private final ParseRegion region;
026        private final Dimension dimension;
027    
028        /**
029         * Creates a DimensionNode.
030         *
031         * @param region Region of source code
032         * @param dimension Dimension which is used in the expression
033         */
034        public DimensionNode(
035            ParseRegion region,
036            Dimension dimension)
037        {
038            this.region = region;
039            this.dimension = dimension;
040        }
041    
042        public ParseRegion getRegion() {
043            return region;
044        }
045    
046        /**
047         * Returns the Dimension used in this expression.
048         *
049         * @return dimension used in this expression
050         */
051        public Dimension getDimension() {
052            return dimension;
053        }
054    
055        public <T> T accept(ParseTreeVisitor<T> visitor) {
056            return visitor.visit(this);
057        }
058    
059        public Type getType() {
060            return new DimensionType(dimension);
061        }
062    
063        public void unparse(ParseTreeWriter writer) {
064            writer.getPrintWriter().print(dimension.getUniqueName());
065        }
066    
067        public String toString() {
068            return dimension.getUniqueName();
069        }
070    
071        public DimensionNode deepCopy() {
072            // DimensionNode is immutable
073            return this;
074        }
075    }
076    
077    // End DimensionNode.java