001 /* 002 // $Id: //open/mondrian/src/main/mondrian/olap4j/MondrianOlap4jDimension.java#1 $ 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-2007 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 mondrian.olap.DimensionType; 013 import mondrian.olap.Util; 014 import org.olap4j.OlapException; 015 import org.olap4j.impl.*; 016 import org.olap4j.metadata.*; 017 018 import java.util.Locale; 019 020 /** 021 * Implementation of {@link org.olap4j.metadata.Dimension} 022 * for the Mondrian OLAP engine. 023 * 024 * @author jhyde 025 * @version $Id: //open/mondrian/src/main/mondrian/olap4j/MondrianOlap4jDimension.java#1 $ 026 * @since May 24, 2007 027 */ 028 class MondrianOlap4jDimension implements Dimension, Named { 029 private final MondrianOlap4jSchema olap4jSchema; 030 private final mondrian.olap.Dimension dimension; 031 032 MondrianOlap4jDimension( 033 MondrianOlap4jSchema olap4jSchema, 034 mondrian.olap.Dimension dimension) 035 { 036 this.olap4jSchema = olap4jSchema; 037 this.dimension = dimension; 038 } 039 040 public boolean equals(Object obj) { 041 return obj instanceof MondrianOlap4jDimension && 042 dimension.equals(((MondrianOlap4jDimension) obj).dimension); 043 } 044 045 public int hashCode() { 046 return dimension.hashCode(); 047 } 048 049 public NamedList<Hierarchy> getHierarchies() { 050 final NamedList<MondrianOlap4jHierarchy> list = 051 new NamedListImpl<MondrianOlap4jHierarchy>(); 052 final MondrianOlap4jConnection olap4jConnection = 053 olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; 054 for (mondrian.olap.Hierarchy hierarchy : dimension.getHierarchies()) { 055 list.add(olap4jConnection.toOlap4j(hierarchy)); 056 } 057 return Olap4jUtil.cast(list); 058 } 059 060 public Hierarchy getDefaultHierarchy() { 061 return getHierarchies().get(0); 062 } 063 064 public Type getDimensionType() throws OlapException { 065 final DimensionType dimensionType = dimension.getDimensionType(); 066 switch (dimensionType) { 067 case StandardDimension: 068 return Type.OTHER; 069 case MeasuresDimension: 070 return Type.MEASURE; 071 case TimeDimension: 072 return Type.TIME; 073 default: 074 throw Util.unexpected(dimensionType); 075 } 076 } 077 078 public String getName() { 079 return dimension.getName(); 080 } 081 082 public String getUniqueName() { 083 return dimension.getUniqueName(); 084 } 085 086 public String getCaption(Locale locale) { 087 // TODO: locale caption 088 return dimension.getCaption(); 089 } 090 091 public String getDescription(Locale locale) { 092 // TODO: locale description 093 return dimension.getDescription(); 094 } 095 } 096 097 // End MondrianOlap4jDimension.java