001    /*
002    // $Id: Member.java 370 2010-11-22 07:32:50Z 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-2010 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 java.util.List;
013    
014    import org.olap4j.OlapException;
015    import org.olap4j.mdx.ParseTreeNode;
016    
017    /**
018     * <code>Member</code> is a data value in an OLAP Dimension.
019     *
020     * @author jhyde
021     * @version $Id: Member.java 370 2010-11-22 07:32:50Z jhyde $
022     * @since Aug 22, 2006
023     */
024    public interface Member extends MetadataElement {
025        /**
026         * Returns the children of this Member, indexed by name.
027         *
028         * <p>If access-control is in place, the list does not contain inaccessible
029         * children.
030         *
031         * <p>If the member has no children, returns an empty list: the result is
032         * never null.
033         *
034         * <p>The caller should assume that the list is immutable;
035         * if the caller modifies the list, behavior is undefined.</p>
036         *
037         * @see org.olap4j.OlapDatabaseMetaData#getMembers
038         *
039         * @return children of this member
040         *
041         * @throws OlapException if database error occurs
042         */
043        NamedList<? extends Member> getChildMembers() throws OlapException;
044    
045        /**
046         * Returns the number of children this Member has.
047         *
048         * <p>This method has the same effect as
049         * <code>getChildMembers().size()</code>, but is typically less expensive.
050         *
051         * @return number of children
052         *
053         * @throws OlapException if database error occurs
054         */
055        int getChildMemberCount() throws OlapException;
056    
057        /**
058         * Returns the parent of this Member, or null if it has no parent.
059         *
060         * @return Parent member, or null if member has no parent
061         */
062        Member getParentMember();
063    
064        /**
065         * Returns the Level of this Member.
066         *
067         * <p>Never returns null.</p>
068         *
069         * @return Level which this Member belongs to
070         */
071        Level getLevel();
072    
073        /**
074         * Returns the Hierarchy of this Member.
075         *
076         * <p>Never returns null.
077         * Result is always the same as <code>getLevel().getHierarchy()</code>.
078         *
079         * @return Hierarchy which this Member belongs to
080         */
081        Hierarchy getHierarchy();
082    
083        /**
084         * Returns the Dimension of this Member.
085         *
086         * <p>Never returns null. Result is always the same as
087         * <code>getLevel().getHierarchy().getDimension()</code>.
088         *
089         * @return Dimension which this Member belongs to
090         */
091        Dimension getDimension();
092    
093        /**
094         * Returns the type of this Member.
095         *
096         * <p>Never returns null.</p>
097         *
098         * @return What kind of member this is
099         */
100        Type getMemberType();
101    
102        /**
103         * Returns whether this Member represents the aggregation of all members
104         * in its Dimension.
105         *
106         * <p>An 'all' member is always the root of its Hierarchy; that is,
107         * its parent member is the null member, and
108         * {@link Hierarchy#getRootMembers()} returns the 'all'
109         * member and no others. Some hierarchies do not have an 'all' member.
110         *
111         * @see Hierarchy#hasAll()
112         *
113         * @return whether this Member is the 'all' member of its Dimension
114         */
115        boolean isAll();
116    
117        /**
118         * Enumeration of types of members.
119         *
120         * <p>The values are as specified by XMLA,
121         * plus the additional {@link #NULL} value not used by XMLA.
122         * For example, XMLA specifies <code>MDMEMBER_TYPE_REGULAR</code> with
123         * ordinal 1, which corresponds to value {@link #REGULAR}.
124         *
125         * <p>The {@link #FORMULA} value takes precedence over {@link #MEASURE}.
126         * For example, if there is a formula (calculated) member on the Measures
127         * dimension, it is listed as <code>FORMULA</code>.
128         */
129        enum Type {
130            UNKNOWN(0),
131            REGULAR(1),
132            ALL(2),
133            MEASURE(3),
134            FORMULA(4),
135            /**
136             * Indicates that this member is its hierarchy's NULL member (such as is
137             * returned by the expression
138             * <code>[Gender]&#46;[All Gender]&#46;PrevMember</code>, for example).
139             */
140            NULL(5);
141    
142            private Type(int ordinal) {
143                assert ordinal == ordinal();
144            }
145        }
146    
147        /**
148         * Returns whether <code>member</code> is equal to, a child of, or a
149         * descendent of this Member.
150         *
151         * @param member Member
152         * @return Whether the given Member is a descendent of this Member
153         */
154        boolean isChildOrEqualTo(Member member);
155    
156        /**
157         * Returns whether this member is calculated using a formula.
158         *
159         * <p>Examples of calculated members include
160         * those defined using a <code>WITH MEMBER</code> clause in an MDX query
161         * ({@link #getMemberType()} will return {@link Type#FORMULA} for these),
162         *  or a calculated member defined in a cube.
163         *
164         * @return Whether this Member is calculated
165         *
166         * @see #isCalculatedInQuery()
167         */
168        boolean isCalculated();
169    
170        /**
171         * Returns the solve order of this member in a formula.
172         *
173         * @return solve order of this Member
174         */
175        int getSolveOrder();
176    
177        /**
178         * Expression by which this member is derived, if it is a calculated
179         * member. If the member is not calulated, returns null.
180         *
181         * @return expression for this member
182         */
183        ParseTreeNode getExpression();
184    
185        /**
186         * Returns array of all members which are ancestor to <code>this</code>.
187         *
188         * @return ancestor Members
189         */
190        List<Member> getAncestorMembers();
191    
192        /**
193         * Returns whether this member is computed from a <code>WITH MEMBER</code>
194         * clause in an MDX query. (Calculated members can also be calculated in a
195         * cube.)
196         *
197         * @return Whether this member is calculated in a query
198         *
199         * @see #isCalculated()
200         */
201        boolean isCalculatedInQuery();
202    
203        /**
204         * Returns the value of a given property.
205         *
206         * <p>Returns null if the property is not set.</p>
207         *
208         * <p>Every member has certain system properties such as "name" and
209         * "caption" (the full list is described in the
210         * {@link org.olap4j.metadata.Property.StandardMemberProperty}
211         * enumeration), as well as extra properties defined for its Level
212         * (see {@link Level#getProperties()}).</p>
213         *
214         * @param property Property
215         *
216         * @return formatted value of the given property
217         *
218         * @see #getPropertyFormattedValue(Property)
219         *
220         * @throws OlapException if database error occurs
221         */
222        Object getPropertyValue(Property property) throws OlapException;
223    
224        /**
225         * Returns the formatted value of a given property.
226         *
227         * <p>Returns null if the property is not set.</p>
228         *
229         * <p>Every member has certain system properties such as "name" and
230         * "caption" (the full list is described in the
231         * {@link org.olap4j.metadata.Property.StandardMemberProperty}
232         * enumeration), as well as extra properties defined for its Level
233         * (see {@link Level#getProperties()}).</p>
234         *
235         * @param property Property
236         *
237         * @return formatted value of the given property
238         *
239         * @see #getPropertyValue(Property)
240         *
241         * @throws OlapException if database error occurs
242         */
243        String getPropertyFormattedValue(Property property) throws OlapException;
244    
245        /**
246         * Sets a property of this member to a given value.
247         *
248         * <p>Every member has certain system properties such as "name" and
249         * "caption" (the full list is described in the
250         * {@link org.olap4j.metadata.Property.StandardMemberProperty}
251         * enumeration), as well as extra properties defined for its Level
252         * (see {@link Level#getProperties()}).</p>
253         *
254         * @param property property
255         *
256         * @param value Property value
257         *
258         * @throws OlapException if the value not valid for this property
259         *   (for example, a String value assigned to a Boolean property)
260         */
261        void setProperty(Property property, Object value) throws OlapException;
262    
263        /**
264         * Returns the definitions of the properties this member may have.
265         *
266         * <p>For many providers, properties are defined against a Level, so result
267         * of this method will be identical to
268         * <code>member.getLevel().{@link Level#getProperties() getProperties}()</code>.
269         *
270         * @return properties of this Member
271         */
272        NamedList<Property> getProperties();
273    
274        /**
275         * Returns the ordinal of the member.
276         *
277         * @return ordinal of this Member
278         */
279        int getOrdinal();
280    
281        /**
282         * Returns whether this member is 'hidden', as per the rules which define
283         * a ragged hierarchy.
284         *
285         * @return whether this member is a hidden member of a ragged hierarchy
286         */
287        boolean isHidden();
288    
289        /**
290         * Returns the depth of this member.
291         *
292         * <p>In regular hierarchies, this is as the same as the level's depth,
293         * but in parent-child and ragged hierarchies the value may be
294         * different.</p>
295         *
296         * @return depth of this Member
297         */
298        int getDepth();
299    
300        /**
301         * Returns the system-generated data member that is associated with a
302         * non-leaf member of a dimension.
303         *
304         * <p>Returns this member if this member is a leaf member, or if the
305         * non-leaf member does not have an associated data member.</p>
306         *
307         * @return system-generated data member
308         */
309        Member getDataMember();
310    
311        /**
312         * Enumeration of tree operations which can be used when querying
313         * members.
314         *
315         * <p>Some of the values are as specified by XMLA.
316         * For example, XMLA specifies MDTREEOP_CHILDREN with ordinal 1,
317         * which corresponds to the value {@link #CHILDREN}.
318         *
319         * @see org.olap4j.OlapDatabaseMetaData#getMembers
320         */
321        public enum TreeOp implements XmlaConstant {
322            /**
323             * Tree operation which returns only the immediate children.
324             */
325            CHILDREN(
326                1,
327                "Tree operation which returns only the immediate children."),
328    
329            /**
330             * Tree operation which returns members on the same level.
331             */
332            SIBLINGS(
333                2,
334                "Tree operation which returns members on the same level."),
335    
336            /**
337             * Tree operation which returns only the immediate parent.
338             */
339            PARENT(
340                4,
341                "Tree operation which returns only the immediate parent."),
342    
343            /**
344             * Tree operation which returns itself in the list of returned rows.
345             */
346            SELF(
347                8,
348                "Tree operation which returns itself in the list of returned "
349                + "rows."),
350    
351            /**
352             * Tree operation which returns all of the descendants.
353             */
354            DESCENDANTS(
355                16,
356                "Tree operation which returns all of the descendants."),
357    
358            /**
359             * Tree operation which returns all of the ancestors.
360             */
361            ANCESTORS(
362                32,
363                "Tree operation which returns all of the ancestors.");
364    
365            private final int xmlaOrdinal;
366            private String description;
367    
368            private static final Dictionary<TreeOp> DICTIONARY =
369                DictionaryImpl.forClass(TreeOp.class);
370    
371            /**
372             * Per {@link org.olap4j.metadata.XmlaConstant}, returns a dictionary
373             * of all values of this enumeration.
374             *
375             * @return Dictionary of all values
376             */
377            public static Dictionary<TreeOp> getDictionary() {
378                return DICTIONARY;
379            }
380    
381            private TreeOp(int xmlaOrdinal, String description) {
382                this.xmlaOrdinal = xmlaOrdinal;
383                this.description = description;
384            }
385    
386            public String xmlaName() {
387                return "MDTREEOP_" + name();
388            }
389    
390            public String getDescription() {
391                return description;
392            }
393    
394            public int xmlaOrdinal() {
395                return xmlaOrdinal;
396            }
397        }
398    }
399    
400    // End Member.java