001 /* 002 // $Id: //open/mondrian/src/main/mondrian/olap/LevelBase.java#21 $ 003 // This software is subject to the terms of the Common Public License 004 // Agreement, available at the following URL: 005 // http://www.opensource.org/licenses/cpl.html. 006 // Copyright (C) 2001-2002 Kana Software, Inc. 007 // Copyright (C) 2001-2007 Julian Hyde and others 008 // All Rights Reserved. 009 // You must accept the terms of that agreement to use this software. 010 // 011 // jhyde, 6 August, 2001 012 */ 013 014 package mondrian.olap; 015 016 import mondrian.resource.MondrianResource; 017 018 /** 019 * Skeleton implementation of {@link Level} 020 * 021 * @author jhyde 022 * @since 6 August, 2001 023 * @version $Id: //open/mondrian/src/main/mondrian/olap/LevelBase.java#21 $ 024 */ 025 public abstract class LevelBase 026 extends OlapElementBase 027 implements Level { 028 029 protected final Hierarchy hierarchy; 030 protected final String name; 031 protected final String uniqueName; 032 protected String description; 033 protected final int depth; 034 protected final LevelType levelType; 035 protected MemberFormatter memberFormatter; 036 protected int approxRowCount; 037 038 protected LevelBase( 039 Hierarchy hierarchy, 040 String name, 041 int depth, 042 LevelType levelType) { 043 this.hierarchy = hierarchy; 044 this.name = name; 045 this.uniqueName = Util.makeFqName(hierarchy, name); 046 this.depth = depth; 047 this.levelType = levelType; 048 } 049 050 /** 051 * Sets the approximate number of members in this Level. 052 * @see #getApproxRowCount() 053 */ 054 public void setApproxRowCount(int approxRowCount) { 055 this.approxRowCount = approxRowCount; 056 } 057 058 // from Element 059 public String getQualifiedName() { 060 return MondrianResource.instance().MdxLevelName.str(getUniqueName()); 061 } 062 063 public LevelType getLevelType() { 064 return levelType; 065 } 066 067 public String getUniqueName() { 068 return uniqueName; 069 } 070 071 public String getName() { 072 return name; 073 } 074 075 public String getDescription() { 076 return description; 077 } 078 079 public Hierarchy getHierarchy() { 080 return hierarchy; 081 } 082 083 public Dimension getDimension() { 084 return hierarchy.getDimension(); 085 } 086 087 public int getDepth() { 088 return depth; 089 } 090 091 public Level getChildLevel() { 092 int childDepth = depth + 1; 093 Level[] levels = hierarchy.getLevels(); 094 return (childDepth < levels.length) 095 ? levels[childDepth] 096 : null; 097 } 098 099 public Level getParentLevel() { 100 int parentDepth = depth - 1; 101 Level[] levels = hierarchy.getLevels(); 102 return (parentDepth >= 0) 103 ? levels[parentDepth] 104 : null; 105 } 106 107 public abstract boolean isAll(); 108 109 public boolean isMeasure() { 110 return hierarchy.getName().equals("Measures"); 111 } 112 113 public OlapElement lookupChild(SchemaReader schemaReader, Id.Segment s) { 114 return lookupChild(schemaReader, s, MatchType.EXACT); 115 } 116 117 public OlapElement lookupChild( 118 SchemaReader schemaReader, Id.Segment s, MatchType matchType) 119 { 120 return areMembersUnique() 121 ? Util.lookupHierarchyRootMember( 122 schemaReader, hierarchy, s, matchType) 123 : null; 124 } 125 126 /** 127 * Returns the object which is used to format members of this level. 128 */ 129 public MemberFormatter getMemberFormatter() { 130 return memberFormatter; 131 } 132 } 133 134 135 // End LevelBase.java