001 /* 002 // $Id: //open/mondrian/src/main/mondrian/olap4j/MondrianOlap4jHierarchy.java#3 $ 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) 2007-2008 Julian Hyde 007 // All Rights Reserved. 008 // You must accept the terms of that agreement to use this software. 009 */ 010 package mondrian.olap4j; 011 012 import java.util.*; 013 014 import org.olap4j.impl.AbstractNamedList; 015 import org.olap4j.impl.Named; 016 import org.olap4j.impl.NamedListImpl; 017 import org.olap4j.impl.Olap4jUtil; 018 import org.olap4j.metadata.Dimension; 019 import org.olap4j.metadata.Hierarchy; 020 import org.olap4j.metadata.Level; 021 import org.olap4j.metadata.Member; 022 import org.olap4j.metadata.NamedList; 023 024 /** 025 * Implementation of {@link org.olap4j.metadata.Hierarchy} 026 * for the Mondrian OLAP engine. 027 * 028 * @author jhyde 029 * @version $Id: //open/mondrian/src/main/mondrian/olap4j/MondrianOlap4jHierarchy.java#3 $ 030 * @since May 25, 2007 031 */ 032 class MondrianOlap4jHierarchy implements Hierarchy, Named { 033 private final MondrianOlap4jSchema olap4jSchema; 034 private final mondrian.olap.Hierarchy hierarchy; 035 036 MondrianOlap4jHierarchy( 037 MondrianOlap4jSchema olap4jSchema, 038 mondrian.olap.Hierarchy hierarchy) 039 { 040 this.olap4jSchema = olap4jSchema; 041 this.hierarchy = hierarchy; 042 } 043 044 public boolean equals(Object obj) { 045 return obj instanceof MondrianOlap4jHierarchy && 046 hierarchy.equals(((MondrianOlap4jHierarchy) obj).hierarchy); 047 } 048 049 public int hashCode() { 050 return hierarchy.hashCode(); 051 } 052 053 public Dimension getDimension() { 054 return new MondrianOlap4jDimension( 055 olap4jSchema, hierarchy.getDimension()); 056 } 057 058 public NamedList<Level> getLevels() { 059 final NamedList<MondrianOlap4jLevel> list = 060 new NamedListImpl<MondrianOlap4jLevel>(); 061 final MondrianOlap4jConnection olap4jConnection = 062 olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; 063 for (mondrian.olap.Level level : hierarchy.getLevels()) { 064 list.add(olap4jConnection.toOlap4j(level)); 065 } 066 return Olap4jUtil.cast(list); 067 } 068 069 public boolean hasAll() { 070 return hierarchy.hasAll(); 071 } 072 073 public Member getDefaultMember() { 074 final MondrianOlap4jConnection olap4jConnection = 075 olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; 076 return olap4jConnection.toOlap4j(hierarchy.getDefaultMember()); 077 } 078 079 public NamedList<Member> getRootMembers() { 080 final MondrianOlap4jConnection olap4jConnection = 081 olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; 082 final List<mondrian.olap.Member> levelMembers = 083 olap4jConnection.connection.getSchemaReader().getLevelMembers( 084 hierarchy.getLevels()[0], true); 085 086 return new AbstractNamedList<Member>() { 087 protected String getName(Member member) { 088 return member.getName(); 089 } 090 091 public Member get(int index) { 092 return olap4jConnection.toOlap4j(levelMembers.get(index)); 093 } 094 095 public int size() { 096 return levelMembers.size(); 097 } 098 }; 099 } 100 101 public String getName() { 102 return hierarchy.getName(); 103 } 104 105 public String getUniqueName() { 106 return hierarchy.getUniqueName(); 107 } 108 109 public String getCaption(Locale locale) { 110 // todo: localize caption 111 return hierarchy.getCaption(); 112 } 113 114 public String getDescription(Locale locale) { 115 // todo: localize description 116 return hierarchy.getDescription(); 117 } 118 } 119 120 // End MondrianOlap4jHierarchy.java