Skip to content

Commit

Permalink
Add experimental org.olap4j.transform package, and method ParseTreeNo…
Browse files Browse the repository at this point in the history
…de.deepCopy() (contributed by Etienne Dube)

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@107 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Aug 14, 2008
1 parent daeb88e commit 7846791
Show file tree
Hide file tree
Showing 31 changed files with 1,632 additions and 22 deletions.
12 changes: 11 additions & 1 deletion src/org/olap4j/mdx/AxisNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007-2007 Julian Hyde
// Copyright (C) 2007-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package org.olap4j.mdx;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;

Expand Down Expand Up @@ -158,6 +159,15 @@ public Type getType() {
// Try AxisNode.getExpression().getType() instead.
return null;
}

public AxisNode deepCopy() {
return new AxisNode(
this.region,
this.nonEmpty,
this.axis,
MdxUtil.deepCopyList(dimensionProperties),
this.expression.deepCopy());
}
}

// End AxisNode.java
14 changes: 11 additions & 3 deletions src/org/olap4j/mdx/CallNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007-2007 Julian Hyde
// Copyright (C) 2007-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -49,7 +49,7 @@ public class CallNode implements ParseTreeNode {
* <p>The <code>syntax</code> argument determines whether this is a prefix,
* infix or postfix operator, a function call, and so forth.
*
* <p>The list of arguuments <code>args</code> must be specified, even if
* <p>The list of arguments <code>args</code> must be specified, even if
* there are zero arguments, and each argument must be not null.
*
* <p>The type is initially null, but can be set using {@link #setType}
Expand Down Expand Up @@ -99,7 +99,7 @@ public CallNode(
* <p>The <code>syntax</code> argument determines whether this is a prefix,
* infix or postfix operator, a function call, and so forth.
*
* <p>The list of arguuments <code>args</code> must be specified, even if
* <p>The list of arguments <code>args</code> must be specified, even if
* there are zero arguments, and each argument must be not null.
*
* @param region Region of source code
Expand Down Expand Up @@ -177,6 +177,14 @@ public Syntax getSyntax() {
public List<ParseTreeNode> getArgList() {
return argList;
}

public CallNode deepCopy() {
return new CallNode(
this.region,
this.name,
this.syntax,
MdxUtil.deepCopyList(argList));
}
}

// End CallNode.java
8 changes: 7 additions & 1 deletion src/org/olap4j/mdx/CubeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007-2007 Julian Hyde
// Copyright (C) 2007-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -67,6 +67,12 @@ public void unparse(ParseTreeWriter writer) {
public String toString() {
return cube.getUniqueName();
}

public CubeNode deepCopy() {
// CubeNode is immutable
return this;
}

}

// End CubeNode.java
7 changes: 6 additions & 1 deletion src/org/olap4j/mdx/DimensionNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007-2007 Julian Hyde
// Copyright (C) 2007-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -67,6 +67,11 @@ public void unparse(ParseTreeWriter writer) {
public String toString() {
return dimension.getUniqueName();
}

public DimensionNode deepCopy() {
// DimensionNode is immutable
return this;
}
}

// End DimensionNode.java
7 changes: 6 additions & 1 deletion src/org/olap4j/mdx/HierarchyNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007-2007 Julian Hyde
// Copyright (C) 2007-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -69,6 +69,11 @@ public void unparse(ParseTreeWriter writer) {
public String toString() {
return hierarchy.getUniqueName();
}

public HierarchyNode deepCopy() {
// HierarchyNode is immutable
return this;
}
}

// End HierarchyNode.java
9 changes: 7 additions & 2 deletions src/org/olap4j/mdx/IdentifierNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007-2007 Julian Hyde
// Copyright (C) 2007-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -137,6 +137,11 @@ public String toString() {
return buf.toString();
}

public IdentifierNode deepCopy() {
// IdentifierNode is immutable
return this;
}

/**
* Parses an MDX identifier into a list of segments.
*
Expand Down Expand Up @@ -270,7 +275,7 @@ static void quoteMdxIdentifier(String id, StringBuilder buf) {
*
* <p>For example, {"Store", "USA",
* "California"} becomes "[Store].[USA].[California]".
*
*
* @param ids List of segments
* @return Segments as quoted string
*/
Expand Down
8 changes: 7 additions & 1 deletion src/org/olap4j/mdx/LevelNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007-2007 Julian Hyde
// Copyright (C) 2007-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -70,6 +70,12 @@ public void unparse(ParseTreeWriter writer) {
public String toString() {
return level.getUniqueName();
}

public LevelNode deepCopy() {
// LevelNode is immutable
return this;
}

}

// End LevelNode.java
10 changes: 9 additions & 1 deletion src/org/olap4j/mdx/LiteralNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007-2007 Julian Hyde
// Copyright (C) 2007-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand All @@ -20,6 +20,8 @@
* <code>Order([Store].Members, [Measures].[Unit Sales], ASC)</code>, are
* also represented as Literals.
*
* <p>A LiteralNode is immutable.
*
* @version $Id$
* @author jhyde
*/
Expand Down Expand Up @@ -174,6 +176,12 @@ public void unparse(ParseTreeWriter writer) {
throw new AssertionError("unexpected literal type " + type);
}
}

public LiteralNode deepCopy() {
// No need to copy: literal nodes are immutable.
return this;
}

}

// End LiteralNode.java
32 changes: 29 additions & 3 deletions src/org/olap4j/mdx/MdxUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007-2007 Julian Hyde
// Copyright (C) 2007-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package org.olap4j.mdx;

import java.util.regex.Pattern;
import java.util.*;
import java.io.StringWriter;
import java.io.PrintWriter;

Expand All @@ -28,6 +29,9 @@ class MdxUtil {

/**
* Converts a string into a double-quoted string.
*
* @param val String
* @return String enclosed in double-quotes
*/
static String quoteForMdx(String val) {
StringBuilder buf = new StringBuilder(val.length() + 20);
Expand All @@ -48,21 +52,43 @@ static String toString(ParseTreeNode node) {

/**
* Encodes string for MDX (escapes ] as ]] inside a name).
*
* @param st String
* @return String escaped for inclusion in an MDX identifier
*/
static String mdxEncodeString(String st) {
StringBuilder retString = new StringBuilder(st.length() + 20);
for (int i = 0; i < st.length(); i++) {
char c = st.charAt(i);
if ((c == ']') &&
((i+1) < st.length()) &&
(st.charAt(i+1) != '.')) {
((i + 1) < st.length()) &&
(st.charAt(i + 1) != '.')) {

retString.append(']'); //escaping character
}
retString.append(c);
}
return retString.toString();
}

/**
* Creates a deep copy of a list.
*
* @param list List to be copied
* @return Copy of list, with each element deep copied
*/
@SuppressWarnings({"unchecked"})
static <E extends ParseTreeNode> List<E> deepCopyList(List<E> list) {
// Don't make a copy of the system empty list. '==' is intentional.
if (list == Collections.EMPTY_LIST) {
return list;
}
final ArrayList<E> listCopy = new ArrayList<E>(list.size());
for (E e : list) {
listCopy.add((E) e.deepCopy());
}
return listCopy;
}
}

// End MdxUtil.java
7 changes: 6 additions & 1 deletion src/org/olap4j/mdx/MemberNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007-2007 Julian Hyde
// Copyright (C) 2007-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -71,6 +71,11 @@ public void unparse(ParseTreeWriter writer) {
public String toString() {
return member.getUniqueName();
}

public MemberNode deepCopy() {
// MemberNode is immutable
return this;
}
}

// End MemberNode.java
10 changes: 9 additions & 1 deletion src/org/olap4j/mdx/ParameterNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007-2007 Julian Hyde
// Copyright (C) 2007-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -41,6 +41,7 @@ public class ParameterNode implements ParseTreeNode {
* <code>defaultValueExpression</code> must be consistent with the
* <code>type</code>.
*
* @param region Region of source code
* @param name Name of parameter
* @param type Type of parameter
* @param defaultValueExpression Expression which yields the default value
Expand Down Expand Up @@ -133,6 +134,13 @@ public void setDefaultValueExpression(ParseTreeNode defaultValueExpression) {
this.defaultValueExpression = defaultValueExpression;
}

public ParameterNode deepCopy() {
return new ParameterNode(
this.region,
this.name,
this.type, // types are immutable
this.defaultValueExpression.deepCopy());
}
}

// End ParameterNode.java
13 changes: 12 additions & 1 deletion src/org/olap4j/mdx/ParseTreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007-2007 Julian Hyde
// Copyright (C) 2007-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -66,6 +66,17 @@ public interface ParseTreeNode {
* created by parsing
*/
ParseRegion getRegion();

/**
* Creates a deep copy of this ParseTreeNode object.
*
* <p>Note: implementing classes can return the concrete type instead
* of ParseTreeNode (using Java 1.5 covariant return types)
*
* @return The deep copy of this ParseTreeNode
*/
ParseTreeNode deepCopy();

}

// End ParseTreeNode.java
9 changes: 8 additions & 1 deletion src/org/olap4j/mdx/PropertyValueNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007-2007 Julian Hyde
// Copyright (C) 2007-2008 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -81,6 +81,13 @@ public void unparse(ParseTreeWriter writer) {
writer.getPrintWriter().print(name + " = ");
expression.unparse(writer);
}

public PropertyValueNode deepCopy() {
return new PropertyValueNode(
this.region,
this.name,
this.expression.deepCopy());
}
}

// End PropertyValueNode.java
Loading

0 comments on commit 7846791

Please sign in to comment.