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