001    /*
002    // $Id: Dimension.java 229 2009-05-08 19:11:29Z jhyde $
003    // This software is subject to the terms of the Eclipse Public License v1.0
004    // Agreement, available at the following URL:
005    // http://www.eclipse.org/legal/epl-v10.html.
006    // Copyright (C) 2006-2009 Julian Hyde
007    // All Rights Reserved.
008    // You must accept the terms of that agreement to use this software.
009    */
010    package org.olap4j.metadata;
011    
012    import org.olap4j.OlapException;
013    
014    import java.util.HashMap;
015    import java.util.Map;
016    
017    /**
018     * An organized hierarchy of categories, known as levels, that describes data
019     * in a cube.
020     *
021     * <p>A Dimension typically describes a similar set of members upon which the
022     * user wants to base an analysis.
023     *
024     * <p>A Dimension must have at least one Hierarchy, and may have more than one,
025     * but most have exactly one Hierarchy.</p>
026     *
027     * @author jhyde
028     * @version $Id: Dimension.java 229 2009-05-08 19:11:29Z jhyde $
029     * @since Aug 22, 2006
030     */
031    public interface Dimension extends MetadataElement {
032    
033        /**
034         * Returns the hierarchies in this Dimension.
035         *
036         * <p>Many dimensions have only one Hierarchy, whose name is the same as the
037         * Dimension.
038         *
039         * <p>The caller should assume that the list is immutable;
040         * if the caller modifies the list, behavior is undefined.</p>
041         *
042         * @see org.olap4j.OlapDatabaseMetaData#getHierarchies
043         *
044         * @return hierarchies in this dimension
045         */
046        NamedList<Hierarchy> getHierarchies();
047    
048        /**
049         * Returns the type of this Dimension.
050         *
051         * @return dimension type
052         *
053         * @throws OlapException if database error occurs
054         */
055        Dimension.Type getDimensionType() throws OlapException;
056    
057        /**
058         * Returns the default <code>Hierarchy</code> of this Dimension.
059         *
060         * @return default hierarchy
061         */
062        Hierarchy getDefaultHierarchy();
063    
064        /**
065         * Enumeration of the types of a <code>Dimension</code>.
066         *
067         * <p>Some of the values are as specified by XMLA.
068         * For example, XMLA specifies MD_DIMTYPE_PRODUCTS with ordinal 8,
069         * which corresponds to the value {@link #PRODUCTS},
070         * whose {@link #xmlaOrdinal} is 8.
071         *
072         * @see Level.Type
073         * @see Member.Type
074         * @see Dimension#getDimensionType
075         */
076        public enum Type {
077            /**
078             * Indicates that the dimension is not related to time.
079             */
080            UNKNOWN(0),
081    
082            /**
083             * Indicates that a dimension is a time dimension.
084             */
085            TIME(1),
086    
087            /**
088             * Indicates that a dimension is the Measures dimension.
089             */
090            MEASURE(2),
091    
092            OTHER(3),
093            QUANTITATIVE(5),
094            ACCOUNTS(6),
095            CUSTOMERS(7),
096            PRODUCTS(8),
097            SCENARIO(9),
098            UTILITY(10),
099            CURRENCY(11),
100            RATES(12),
101            CHANNEL(13),
102            PROMOTION(14),
103            ORGANIZATION(15),
104            BILL_OF_MATERIALS(16),
105            GEOGRAPHY(17);
106    
107            private final int xmlaOrdinal;
108    
109            private static final Map<Integer, Type> xmlaOrdinalTypeMap;
110    
111            static {
112                Map<Integer, Type> map = new HashMap<Integer, Type>();
113                for (Type type : values()) {
114                    map.put(type.xmlaOrdinal, type);
115                }
116                xmlaOrdinalTypeMap = map;
117            }
118    
119            /**
120             * Creates a Dimension Type.
121             *
122             * @param xmlaOrdinal Ordinal code as specified by XMLA
123             */
124            private Type(int xmlaOrdinal) {
125                this.xmlaOrdinal = xmlaOrdinal;
126            }
127    
128            /**
129             * Returns the ordinal code as specified by XMLA.
130             *
131             * <p>For example, the XMLA specification says that the ordinal of
132             * {@link #PRODUCTS} is 8.
133             *
134             * @return ordinal code as specified by XMLA.
135             */
136            public final int xmlaOrdinal() {
137                return xmlaOrdinal;
138            }
139    
140            /**
141             * Returns the type whose XMLA ordinal code is as given.
142             *
143             * @param xmlaOrdinal Ordinal code as specified by XMLA
144             * @return Dimension type, or null
145             */
146            public static Type forXmlaOrdinal(int xmlaOrdinal) {
147                return xmlaOrdinalTypeMap.get(xmlaOrdinal);
148            }
149        }
150    }
151    
152    // End Dimension.java