001    /*
002    // $Id: //open/mondrian/src/main/mondrian/rolap/RolapCubeDimension.java#7 $
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-2008 Julian Hyde and others
008    // All Rights Reserved.
009    // You must accept the terms of that agreement to use this software.
010    //
011    // wgorman, 19 October 2007
012    */
013    package mondrian.rolap;
014    
015    import mondrian.olap.Cube;
016    import mondrian.olap.DimensionType;
017    import mondrian.olap.HierarchyBase;
018    import mondrian.olap.MondrianDef;
019    import mondrian.olap.Schema;
020    
021    /**
022     * RolapCubeDimension wraps a RolapDimension for a specific Cube.
023     *
024     * @author Will Gorman (wgorman@pentaho.org)
025     * @version $Id: //open/mondrian/src/main/mondrian/rolap/RolapCubeDimension.java#7 $
026     */
027    public class RolapCubeDimension extends RolapDimension {
028    
029        RolapCube parent;
030    
031        RolapDimension rolapDimension;
032        int cubeOrdinal;
033        MondrianDef.CubeDimension xmlDimension;
034    
035        public RolapCubeDimension(RolapCube parent, RolapDimension rolapDim,
036                MondrianDef.CubeDimension cubeDim, String name, int cubeOrdinal,
037                final boolean highCardinality) {
038            super(null, name, null, highCardinality);
039            this.xmlDimension = cubeDim;
040            this.rolapDimension = rolapDim;
041            this.cubeOrdinal = cubeOrdinal;
042            this.parent = parent;
043            this.caption = cubeDim.caption;
044    
045            // create new hierarchies
046            hierarchies = new RolapCubeHierarchy[rolapDim.getHierarchies().length];
047    
048            for (int i = 0; i < rolapDim.getHierarchies().length; i++) {
049                hierarchies[i] = new RolapCubeHierarchy(this, cubeDim,
050                        (RolapHierarchy)rolapDim.getHierarchies()[i],
051                        ((HierarchyBase)rolapDim.getHierarchies()[i]).getSubName());
052            }
053        }
054    
055        public RolapCube getCube() {
056            return parent;
057        }
058    
059        public Schema getSchema() {
060            return rolapDimension.getSchema();
061        }
062    
063        // this method should eventually replace the call below
064        public int getOrdinal() {
065            return cubeOrdinal;
066        }
067    
068        // note that the cube is not necessary here
069        public int getOrdinal(Cube cube) {
070            // this is temporary to validate that internals are consistant
071            assert cube == parent;
072            return cubeOrdinal;
073        }
074    
075        public boolean equals(Object o) {
076            if (this == o) {
077                return true;
078            }
079            if (!(o instanceof RolapCubeDimension)) {
080                return false;
081            }
082    
083            RolapCubeDimension that = (RolapCubeDimension)o;
084            if (!parent.equals(that.parent)) {
085                return false;
086            }
087            return getUniqueName().equals(that.getUniqueName());
088        }
089    
090        RolapCubeHierarchy newHierarchy(String subName, boolean hasAll) {
091            throw new UnsupportedOperationException();
092        }
093    
094        public String getCaption() {
095            if (caption != null) {
096                return caption;
097            }
098            return rolapDimension.getCaption();
099        }
100    
101        public void setCaption(String caption) {
102            if (true) {
103                throw new UnsupportedOperationException();
104            }
105            rolapDimension.setCaption(caption);
106        }
107    
108        public DimensionType getDimensionType() {
109            return rolapDimension.getDimensionType();
110        }
111    
112    }
113    
114    // End RolapCubeDimension.java