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