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