001 /*
002 // $Id: CubeNode.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.Cube;
013 import org.olap4j.type.CubeType;
014 import org.olap4j.type.Type;
015
016 /**
017 * Usage of a {@link org.olap4j.metadata.Cube} as an expression in an MDX
018 * parse tree.
019 *
020 * @author jhyde
021 * @version $Id: CubeNode.java 229 2009-05-08 19:11:29Z jhyde $
022 * @since Jun 4, 2007
023 */
024 public class CubeNode implements ParseTreeNode {
025 private final ParseRegion region;
026 private final Cube cube;
027
028 /**
029 * Creates a CubeNode.
030 *
031 * @param region Region of source code
032 * @param cube Cube
033 */
034 public CubeNode(
035 ParseRegion region,
036 Cube cube)
037 {
038 this.region = region;
039 this.cube = cube;
040 }
041
042 public ParseRegion getRegion() {
043 return region;
044 }
045
046 /**
047 * Returns the Cube used in this expression.
048 *
049 * @return cube used in this expression
050 */
051 public Cube getCube() {
052 return cube;
053 }
054
055 public <T> T accept(ParseTreeVisitor<T> visitor) {
056 return visitor.visit(this);
057 }
058
059 public Type getType() {
060 return new CubeType(cube);
061 }
062
063 public void unparse(ParseTreeWriter writer) {
064 writer.getPrintWriter().print(cube.getUniqueName());
065 }
066
067 public String toString() {
068 return cube.getUniqueName();
069 }
070
071 public CubeNode deepCopy() {
072 // CubeNode is immutable
073 return this;
074 }
075
076 }
077
078 // End CubeNode.java