001 /*
002 // $Id: AxisTransform.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) 2008-2008 Julian Hyde
007 // All Rights Reserved.
008 // You must accept the terms of that agreement to use this software.
009 */
010 package org.olap4j.transform;
011
012 import org.olap4j.Axis;
013 import org.olap4j.mdx.AxisNode;
014 import org.olap4j.mdx.ParseTreeNode;
015 import org.olap4j.mdx.SelectNode;
016
017 /**
018 * Abstract representation of an MDX query transform acting on
019 * a single query axis (e.g. drill-down on member, roll-up, ...)
020 *
021 * @author etdub
022 * @version $Id: AxisTransform.java 229 2009-05-08 19:11:29Z jhyde $
023 * @since Aug 7, 2008
024 *
025 */
026 public abstract class AxisTransform implements MdxQueryTransform {
027
028 protected final Axis axis;
029
030 protected AxisTransform(Axis axis) {
031 this.axis = axis;
032 }
033
034 public SelectNode apply(SelectNode sn) {
035 // do a deep copy of the existing query SelectNode before
036 // modifying it:
037 SelectNode newSelectNode = sn.deepCopy();
038
039 for (AxisNode an : newSelectNode.getAxisList()) {
040 if (an.getAxis() == axis) {
041 // this is the axis we're drilling
042
043 ParseTreeNode initialAxisExp = an.getExpression();
044
045 // apply the drill operation
046 ParseTreeNode newAxisExp =
047 processAxisExp(initialAxisExp);
048
049 // replace the expression in the axis by the new generated one
050 an.setExpression(newAxisExp);
051 }
052 }
053 return newSelectNode;
054 }
055
056 protected abstract ParseTreeNode processAxisExp(ParseTreeNode axisExp);
057
058 }
059
060 // End AxisTransform.java