001/*
002// $Id: XmlaConstant.java 482 2012-01-05 23:27:27Z jhyde $
003//
004// Licensed to Julian Hyde under one or more contributor license
005// agreements. See the NOTICE file distributed with this work for
006// additional information regarding copyright ownership.
007//
008// Julian Hyde licenses this file to you under the Apache License,
009// Version 2.0 (the "License"); you may not use this file except in
010// compliance with the License. You may obtain a copy of the License at:
011//
012// http://www.apache.org/licenses/LICENSE-2.0
013//
014// Unless required by applicable law or agreed to in writing, software
015// distributed under the License is distributed on an "AS IS" BASIS,
016// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017// See the License for the specific language governing permissions and
018// limitations under the License.
019*/
020package org.olap4j.metadata;
021
022import java.util.List;
023import java.util.Set;
024
025/**
026 * Enumerated value that belongs to a set of constants in the XML for Analysis
027 * (XMLA) specification.
028 *
029 * <p>Every {@code enum} E that implements this interface also has a method to
030 * get the {@link org.olap4j.metadata.XmlaConstant.Dictionary} of all its values:
031 *
032 * <blockquote>public static Dictionary&lt;E&gt; getDictionary();</blockquote>
033 *
034 * <p>Here is a collection of enum classes and the prefix used to generate
035 * their XMLA constant names.
036 *
037 * <table border='1'>
038 * <tr>
039 * <th>Prefix</th>
040 * <th>Enum class</th>
041 * </tr>
042 *
043 * <tr>
044 * <td>DBTYPE_</td>
045 * <td>{@link Datatype}</td>
046 * </tr>
047 *
048 * <tr>
049 * <td>MD_DIMTYPE_</td>
050 * <td>{@link org.olap4j.metadata.Dimension.Type}</td>
051 * </tr>
052 *
053 * <tr>
054 * <td>MDLEVEL_TYPE_</td>
055 * <td>{@link org.olap4j.metadata.Level.Type}</td>
056 * </tr>
057 *
058 * <tr>
059 * <td>MDMEASURE_AGG_</td>
060 * <td>{@link org.olap4j.metadata.Measure.Aggregator}</td>
061 * </tr>
062 *
063 * <tr>
064 * <td>MDTREEOP_</td>
065 * <td>{@link org.olap4j.metadata.Member.TreeOp}</td>
066 * </tr>
067 *
068 * <tr>
069 * <td>MD_PROPTYPE_</td>
070 * <td>{@link org.olap4j.metadata.Property.ContentType}</td>
071 * </tr>
072 *
073 * <tr>
074 * <td>MDPROP_</td>
075 * <td>{@link org.olap4j.metadata.Property.TypeFlag}</td>
076 * </tr>
077 *
078 * <tr>
079 * <td>none</td>
080 * <td>{@link org.olap4j.metadata.XmlaConstants.Access}</td>
081 * </tr>
082 *
083 * <tr>
084 * <td>MDACTION_TYPE_</td>
085 * <td>{@link org.olap4j.metadata.XmlaConstants.ActionType}</td>
086 * </tr>
087 *
088 * <tr>
089 * <td>none</td>
090 * <td>{@link org.olap4j.metadata.XmlaConstants.AuthenticationMode}</td>
091 * </tr>
092 *
093 * <tr>
094 * <td>none</td>
095 * <td>{@link org.olap4j.metadata.XmlaConstants.AxisFormat}</td>
096 * </tr>
097 *
098 * <tr>
099 * <td>DBTYPE_</td>
100 * <td>{@link org.olap4j.metadata.XmlaConstants.DBType}</td>
101 * </tr>
102 *
103 * <tr>
104 * <td>MDFF_</td>
105 * <td>{@link org.olap4j.metadata.XmlaConstants.FontFlag}</td>
106 * </tr>
107 *
108 * <tr>
109 * <td>none</td>
110 * <td>{@link org.olap4j.metadata.XmlaConstants.Format}</td>
111 * </tr>
112 *
113 * <tr>
114 * <td>DBLITERAL_</td>
115 * <td>{@link org.olap4j.metadata.XmlaConstants.Literal}</td>
116 * </tr>
117 *
118 * <tr>
119 * <td>none</td>
120 * <td>{@link org.olap4j.metadata.XmlaConstants.Method}</td>
121 * </tr>
122 *
123 * <tr>
124 * <td>none</td>
125 * <td>{@link org.olap4j.metadata.XmlaConstants.ProviderType}</td>
126 * </tr>
127 *
128 * <tr>
129 * <td>none</td>
130 * <td>{@link org.olap4j.metadata.XmlaConstants.Updateable}</td>
131 * </tr>
132 *
133 * <tr>
134 * <td>DBPROPVAL_VISUAL_MODE_</td>
135 * <td>{@link org.olap4j.metadata.XmlaConstants.VisualMode}</td>
136 * </tr>
137 *
138 * </table>
139 *
140 * @author jhyde
141 * @version $Id: XmlaConstant.java 482 2012-01-05 23:27:27Z jhyde $
142 */
143public interface XmlaConstant {
144    /**
145     * Returns the name of this constant as specified by XMLA.
146     *
147     * <p>Often the name is an enumeration-specific prefix plus the name of
148     * the Java enum constant. For example,
149     * {@link org.olap4j.metadata.Dimension.Type} has
150     * prefix "MD_DIMTYPE_", and therefore this method returns
151     * "MD_DIMTYPE_PRODUCTS" for the enum constant
152     * {@link org.olap4j.metadata.Dimension.Type#PRODUCTS}.
153     *
154     * @return ordinal code as specified by XMLA.
155     */
156    String xmlaName();
157
158    /**
159     * Returns the description of this constant.
160     *
161     * @return Description of this constant.
162     */
163    String getDescription();
164
165    /**
166     * Returns the code of this constant as specified by XMLA.
167     *
168     * <p>For example, the XMLA specification says that the ordinal of
169     * MD_DIMTYPE_PRODUCTS is 8, and therefore this method returns 8
170     * for {@link org.olap4j.metadata.Dimension.Type#PRODUCTS}.
171     *
172     * @return ordinal code as specified by XMLA.
173     */
174    int xmlaOrdinal();
175
176    interface Dictionary<E extends Enum<E> & XmlaConstant> {
177
178        /**
179         * Returns the enumeration value with the given ordinal in the XMLA
180         * specification, or null if there is no such.
181         *
182         * @param xmlaOrdinal XMLA ordinal
183         * @return Enumeration value
184         */
185        E forOrdinal(int xmlaOrdinal);
186
187        /**
188         * Returns the enumeration value with the given name in the XMLA
189         * specification, or null if there is no such.
190         *
191         * @param xmlaName XMLA name
192         * @return Enumeration value
193         */
194        E forName(String xmlaName);
195
196        /**
197         * Creates a set of values by parsing a mask.
198         *
199         * @param xmlaOrdinalMask Bit mask
200         * @return Set of E values
201         */
202        Set<E> forMask(int xmlaOrdinalMask);
203
204        /**
205         * Converts a set of enum values to an integer by logical OR-ing their
206         * codes.
207         *
208         * @param set Set of enum values
209         * @return Bitmap representing set of enum values
210         */
211        int toMask(Set<E> set);
212
213        /**
214         * Returns all values of the enum.
215         *
216         * <p>This method may be more efficient than
217         * {@link Class#getEnumConstants()} because the latter is required to
218         * create a new array every call to prevent corruption.
219         *
220         * @return List of enum values
221         */
222        List<E> getValues();
223
224        /**
225         * Returns the class that the enum values belong to.
226         *
227         * @return enum class
228         */
229        Class<E> getEnumClass();
230    }
231}
232
233// End XmlaConstant.java