001 /*
002 // $Id: Axis.java 360 2010-10-28 18:14:32Z 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;
011
012 import java.util.Locale;
013
014 /**
015 * Enumeration of axis types.
016 *
017 * <p>The most commonly used values are
018 * <code>COLUMNS</code> (the first axis of a 2-dimensional query),
019 * <code>ROWS</code> (the second axis of a 2-dimensional query) and
020 * <code>FILTER</code> (also known as the slicer axis, denoted by a
021 * <code>WHERE</code> clause in an MDX statement).
022 *
023 * @author jhyde
024 * @version $Id: Axis.java 360 2010-10-28 18:14:32Z jhyde $
025 * @since Oct 23, 2006
026 */
027 public interface Axis {
028
029 /**
030 * Abbreviation for {@link org.olap4j.Axis.Standard#FILTER}.
031 */
032 Standard FILTER = Standard.FILTER;
033
034 /**
035 * Abbreviation for {@link org.olap4j.Axis.Standard#COLUMNS}.
036 */
037 Standard COLUMNS = Standard.COLUMNS;
038
039 /**
040 * Abbreviation for {@link org.olap4j.Axis.Standard#ROWS}.
041 */
042 Standard ROWS = Standard.ROWS;
043
044 /**
045 * Abbreviation for {@link org.olap4j.Axis.Standard#PAGES}.
046 */
047 Standard PAGES = Standard.PAGES;
048
049 /**
050 * Abbreviation for {@link org.olap4j.Axis.Standard#CHAPTERS}.
051 */
052 Standard SECTIONS = Standard.SECTIONS;
053
054 /**
055 * Abbreviation for {@link org.olap4j.Axis.Standard#FILTER}.
056 */
057 Standard CHAPTERS = Standard.CHAPTERS;
058
059 /**
060 * Returns the name of this axis, e.g. "COLUMNS", "FILTER", "AXIS(17)".
061 *
062 * @return Name of the axis
063 */
064 String name();
065
066 /**
067 * Returns whether this is the filter (slicer) axis.
068 *
069 * @return whether this is the filter axis
070 */
071 boolean isFilter();
072
073
074 /**
075 * Returns the ordinal which is to be used for retrieving this axis from
076 * the {@link org.olap4j.CellSet#getAxes()}, or retrieving its
077 * coordinate from {@link Cell#getCoordinateList()}.
078 *
079 * <p>For example:
080 * <ul>
081 * <li>-1 {@link org.olap4j.Axis.Standard#FILTER FILTER}</li>
082 * <li>0 {@link org.olap4j.Axis.Standard#COLUMNS COLUMNS}</li>
083 * <li>1 {@link org.olap4j.Axis.Standard#ROWS ROWS}</li>
084 * <li>2 {@link org.olap4j.Axis.Standard#PAGES PAGES}</li>
085 * <li>3 {@link org.olap4j.Axis.Standard#CHAPTERS CHAPTERS}</li>
086 * <li>4 {@link org.olap4j.Axis.Standard#SECTIONS SECTIONS}</li>
087 * <li>5 {@link org.olap4j.Axis.Standard#SECTIONS SECTIONS}</li>
088 * <li>6 AXES(6)</li>
089 * <li>123 AXES(123)</li>
090 * </ul>
091 *
092 * @return ordinal of this axis
093 */
094 int axisOrdinal();
095
096 /**
097 * Returns localized name for this Axis.
098 *
099 * <p>Examples: "FILTER", "ROWS", "COLUMNS", "AXIS(10)".
100 *
101 * @param locale Locale for which to give the name
102 * @return localized name for this Axis
103 */
104 String getCaption(Locale locale);
105
106 /**
107 * Enumeration of standard, named axes descriptors.
108 */
109 public enum Standard implements Axis {
110 /**
111 * Filter axis, also known as the slicer axis, and represented by the
112 * WHERE clause of an MDX query.
113 */
114 FILTER,
115
116 /** COLUMNS axis, also known as X axis and AXIS(0). */
117 COLUMNS,
118
119 /** ROWS axis, also known as Y axis and AXIS(1). */
120 ROWS,
121
122 /** PAGES axis, also known as AXIS(2). */
123 PAGES,
124
125 /** CHAPTERS axis, also known as AXIS(3). */
126 CHAPTERS,
127
128 /** SECTIONS axis, also known as AXIS(4). */
129 SECTIONS;
130
131 public int axisOrdinal() {
132 return ordinal() - 1;
133 }
134
135 public boolean isFilter() {
136 return this == FILTER;
137 }
138
139 public String getCaption(Locale locale) {
140 // TODO: localize
141 return name();
142 }
143 }
144
145 /**
146 * Container class for various Axis factory methods.
147 */
148 class Factory {
149 private static final Standard[] STANDARD_VALUES = Standard.values();
150
151 /**
152 * Returns the axis with a given ordinal.
153 *
154 * <p>For example, {@code forOrdinal(0)} returns the COLUMNS axis;
155 * {@code forOrdinal(-1)} returns the SLICER axis;
156 * {@code forOrdinal(100)} returns AXIS(100).
157 *
158 * @param ordinal Axis ordinal
159 * @return Axis whose ordinal is as given
160 */
161 public static Axis forOrdinal(final int ordinal) {
162 if (ordinal < -1) {
163 throw new IllegalArgumentException(
164 "Axis ordinal must be -1 or higher");
165 }
166 if (ordinal + 1 < STANDARD_VALUES.length) {
167 return STANDARD_VALUES[ordinal + 1];
168 }
169 return new Axis() {
170 public String toString() {
171 return name();
172 }
173
174 public String name() {
175 return "AXIS(" + ordinal + ")";
176 }
177
178 public boolean isFilter() {
179 return false;
180 }
181
182 public int axisOrdinal() {
183 return ordinal;
184 }
185
186 public String getCaption(Locale locale) {
187 // TODO: localize
188 return name();
189 }
190 };
191 }
192 }
193 }
194
195 // End Axis.java