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) 2001-2005 Julian Hyde
008// Copyright (C) 2005-2010 Pentaho and others
009// All Rights Reserved.
010*/
011package mondrian.rolap;
012
013import mondrian.olap.*;
014
015import java.util.List;
016
017/**
018 * RolapCubeDimension wraps a RolapDimension for a specific Cube.
019 *
020 * @author Will Gorman, 19 October 2007
021 */
022public class RolapCubeDimension extends RolapDimension {
023
024    RolapCube cube;
025
026    RolapDimension rolapDimension;
027    int cubeOrdinal;
028    MondrianDef.CubeDimension xmlDimension;
029
030    /**
031     * Creates a RolapCubeDimension.
032     *
033     * @param cube Cube
034     * @param rolapDim Dimension wrapped by this dimension
035     * @param cubeDim XML element definition
036     * @param name Name of dimension
037     * @param cubeOrdinal Ordinal of dimension within cube
038     * @param hierarchyList List of hierarchies in cube
039     * @param highCardinality Whether high cardinality dimension
040     */
041    public RolapCubeDimension(
042        RolapCube cube,
043        RolapDimension rolapDim,
044        MondrianDef.CubeDimension cubeDim,
045        String name,
046        int cubeOrdinal,
047        List<RolapHierarchy> hierarchyList,
048        final boolean highCardinality)
049    {
050        super(
051            null,
052            name,
053            cubeDim.caption != null
054                ? cubeDim.caption
055                : rolapDim.getCaption(),
056            cubeDim.visible,
057            cubeDim.caption != null
058                ? cubeDim.description
059                : rolapDim.getDescription(),
060            null,
061            highCardinality,
062            RolapHierarchy.createAnnotationMap(cubeDim.annotations));
063        this.xmlDimension = cubeDim;
064        this.rolapDimension = rolapDim;
065        this.cubeOrdinal = cubeOrdinal;
066        this.cube = cube;
067        this.caption = cubeDim.caption;
068
069        // create new hierarchies
070        hierarchies = new RolapCubeHierarchy[rolapDim.getHierarchies().length];
071
072        for (int i = 0; i < rolapDim.getHierarchies().length; i++) {
073            final RolapCubeHierarchy cubeHierarchy =
074                new RolapCubeHierarchy(
075                    this,
076                    cubeDim,
077                    (RolapHierarchy) rolapDim.getHierarchies()[i],
078                    ((HierarchyBase) rolapDim.getHierarchies()[i]).getSubName(),
079                    hierarchyList.size());
080            hierarchies[i] = cubeHierarchy;
081            hierarchyList.add(cubeHierarchy);
082        }
083    }
084
085    public RolapCube getCube() {
086        return cube;
087    }
088
089    public Schema getSchema() {
090        return rolapDimension.getSchema();
091    }
092
093    // this method should eventually replace the call below
094    public int getOrdinal() {
095        return cubeOrdinal;
096    }
097
098    public boolean equals(Object o) {
099        if (this == o) {
100            return true;
101        }
102        if (!(o instanceof RolapCubeDimension)) {
103            return false;
104        }
105
106        RolapCubeDimension that = (RolapCubeDimension)o;
107        if (!cube.equals(that.cube)) {
108            return false;
109        }
110        return getUniqueName().equals(that.getUniqueName());
111    }
112
113    RolapCubeHierarchy newHierarchy(
114        String subName, boolean hasAll, RolapHierarchy closureFor)
115    {
116        throw new UnsupportedOperationException();
117    }
118
119    public String getCaption() {
120        if (caption != null) {
121            return caption;
122        }
123        return rolapDimension.getCaption();
124    }
125
126    public void setCaption(String caption) {
127        if (true) {
128            throw new UnsupportedOperationException();
129        }
130        rolapDimension.setCaption(caption);
131    }
132
133    public DimensionType getDimensionType() {
134        return rolapDimension.getDimensionType();
135    }
136
137}
138
139// End RolapCubeDimension.java