Skip to content

Commit

Permalink
Fix JDK1.4 compatability.
Browse files Browse the repository at this point in the history
Upgrade version of mondrian (previous version did not implement latest API).


git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@302 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Feb 22, 2010
1 parent 43c9cab commit 97812f2
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 26 deletions.
2 changes: 1 addition & 1 deletion ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<dependency org="hsqldb" name="hsqldb" rev="1.8.0.7"
transitive="false" conf="test->default" />

<dependency org="pentaho" name="mondrian" rev="4.0.0.13109"
<dependency org="pentaho" name="mondrian" rev="3.2.0.13406"
transitive="false" changing="true" conf="test->default" />

<dependency org="eigenbase" name="eigenbase-xom" rev="1.3.0.11999"
Expand Down
6 changes: 4 additions & 2 deletions src/org/olap4j/driver/xmla/XmlaOlap4jCube.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2009 Julian Hyde
// Copyright (C) 2007-2010 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -424,7 +424,9 @@ public XmlaOlap4jMember lookupMemberByUniqueName(
NamedList<XmlaOlap4jMember> list =
new NamedListImpl<XmlaOlap4jMember>();
lookupMemberRelatives(
EnumSet.of(Member.TreeOp.SELF), memberUniqueName, list);
Olap4jUtil.enumSetOf(Member.TreeOp.SELF),
memberUniqueName,
list);
switch (list.size()) {
case 0:
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/org/olap4j/driver/xmla/XmlaOlap4jMember.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public NamedList<? extends Member> getChildMembers() throws OlapException {
getCube()
.getMetadataReader()
.lookupMemberRelatives(
EnumSet.of(TreeOp.CHILDREN),
Olap4jUtil.enumSetOf(TreeOp.CHILDREN),
uniqueName,
list);
return list;
Expand Down
47 changes: 46 additions & 1 deletion src/org/olap4j/impl/Olap4jUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public static RuntimeException needToImplement(Object o) {
/**
* Parses a unique name.
*
* <p>For example, {@code uniqueNameToStringArray("[foo].[bar]")} returns
* <p>For example, <tt>uniqueNameToStringArray("[foo].[bar]")</tt> returns
* {@code ["foo", "bar"]}.
*
* @see org.olap4j.mdx.IdentifierNode#parseIdentifier(String)
Expand All @@ -410,6 +410,9 @@ public static List<String> parseUniqueName(String uniqueName) {
/**
* Converts the contents of an array of strings to
* a proper String representation.
*
* @param array Array of strings
* @return string representation of the array
*/
public static String stringArrayToString(String[] array) {
StringBuilder sb = new StringBuilder("[");
Expand All @@ -428,6 +431,48 @@ public static <T> NamedList<T> emptyNamedList() {
return (NamedList<T>) EMPTY_NAMED_LIST;
}

/**
* Equivalent to {@link java.util.EnumSet#of(Enum, Enum[])} on JDK 1.5 or
* later. Otherwise, returns an ordinary set.
*
* @param first an element that the set is to contain initially
* @param rest the remaining elements the set is to contain initially
* @throws NullPointerException if any of the specified elements are null,
* or if <tt>rest</tt> is null
* @return an enum set initially containing the specified elements
*/
public static <E extends Enum<E>> Set<E> enumSetOf(E first, E... rest) {
return compatible.enumSetOf(first, rest);
}

/**
* Equivalent to {@link java.util.EnumSet#noneOf(Class)} on JDK 1.5 or
* later. Otherwise, returns an ordinary set.
*
* @param elementType the class object of the element type for this enum
* set
* @return an empty enum set
*/
public static <E extends Enum<E>> Set<E> enumSetNoneOf(
Class<E> elementType)
{
return compatible.enumSetNoneOf(elementType);
}

/**
* Equivalent to {@link java.util.EnumSet#allOf(Class)} on JDK 1.5 or later.
* Otherwise, returns an ordinary set.
* @param elementType the class object of the element type for this enum
* set
* @return an enum set containing all elements of the given enum class
*/
public static <E extends Enum<E>> Set<E> enumSetAllOf(
Class<E> elementType)
{
return compatible.enumSetAllOf(elementType);
}

private enum DummyEnum {
}

Expand Down
28 changes: 27 additions & 1 deletion src/org/olap4j/impl/Olap4jUtilCompatible.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2008 Julian Hyde
// Copyright (C) 2007-2010 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package org.olap4j.impl;

import java.util.Set;

/**
* Interface containing methods which are implemented differently in different
* versions of the JDK.
Expand All @@ -27,7 +29,31 @@
* @since Feb 5, 2007
*/
public interface Olap4jUtilCompatible {
/**
* Returns a literal pattern String for the specified String.
*
* <p>Specification as for {@link java.util.regex.Pattern#quote(String)},
* which was introduced in JDK 1.5.
*
* @param s The string to be literalized
* @return A literal string replacement
*/
String quotePattern(String s);

/**
* See {@link org.olap4j.impl.Olap4jUtil#enumSetOf(Enum, Enum[])}.
*/
<E extends Enum<E>> Set<E> enumSetOf(E first, E... rest);

/**
* See {@link org.olap4j.impl.Olap4jUtil#enumSetNoneOf(Class)}.
*/
<E extends Enum<E>> Set<E> enumSetNoneOf(Class<E> elementType);

/**
* See {@link org.olap4j.impl.Olap4jUtil#enumSetAllOf(Class)}.
*/
<E extends Enum<E>> Set<E> enumSetAllOf(Class<E> elementType);
}

// End Olap4jUtilCompatible.java
22 changes: 20 additions & 2 deletions src/org/olap4j/impl/Olap4jUtilCompatibleJdk14.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2008 Julian Hyde
// Copyright (C) 2007-2010 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package org.olap4j.impl;

import java.util.*;

/**
* Implementation of {@link Olap4jUtilCompatible} which runs in
* JDK 1.4.
Expand All @@ -18,7 +20,7 @@
* @since Feb 5, 2007
*/
public class Olap4jUtilCompatibleJdk14 implements Olap4jUtilCompatible {
public String quotePattern(String s) {
public final String quotePattern(String s) {
int slashEIndex = s.indexOf("\\E");
if (slashEIndex == -1) {
return "\\Q" + s + "\\E";
Expand All @@ -35,6 +37,22 @@ public String quotePattern(String s) {
sb.append("\\E");
return sb.toString();
}

public final <E extends Enum<E>> Set<E> enumSetOf(E first, E... rest) {
HashSet<E> set = new HashSet<E>();
set.add(first);
set.addAll(Arrays.asList(rest));
return set;
}

public final <E extends Enum<E>> Set<E> enumSetNoneOf(Class<E> elementType)
{
return new HashSet<E>();
}

public final <E extends Enum<E>> Set<E> enumSetAllOf(Class<E> elementType) {
return new HashSet<E>(Arrays.asList(elementType.getEnumConstants()));
}
}

// End Olap4jUtilCompatibleJdk14.java
19 changes: 17 additions & 2 deletions src/org/olap4j/impl/Olap4jUtilCompatibleJdk15.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2008 Julian Hyde
// Copyright (C) 2007-2010 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package org.olap4j.impl;

import java.util.EnumSet;
import java.util.Set;
import java.util.regex.Pattern;

/**
Expand All @@ -24,9 +26,22 @@
* @since Feb 5, 2007
*/
public class Olap4jUtilCompatibleJdk15 implements Olap4jUtilCompatible {
public String quotePattern(String s) {
public final String quotePattern(String s) {
return Pattern.quote(s);
}

public final <E extends Enum<E>> Set<E> enumSetOf(E first, E... rest) {
return EnumSet.of(first, rest);
}

public final <E extends Enum<E>> Set<E> enumSetNoneOf(Class<E> elementType)
{
return EnumSet.noneOf(elementType);
}

public final <E extends Enum<E>> Set<E> enumSetAllOf(Class<E> elementType) {
return EnumSet.allOf(elementType);
}
}

// End Olap4jUtilCompatibleJdk15.java
33 changes: 29 additions & 4 deletions src/org/olap4j/metadata/DictionaryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
package org.olap4j.metadata;

import org.olap4j.impl.Olap4jUtil;

import java.util.*;

/**
Expand All @@ -23,16 +25,35 @@ class DictionaryImpl<E extends Enum<E> & XmlaConstant>
private final Class<E> clazz;
private final Map<String, E> byName = new HashMap<String, E>();
private final Map<Integer, E> byOrdinal = new HashMap<Integer, E>();
private final List<E> values;
private List<E> values;

private static final Map<Class, DictionaryImpl> map =
new HashMap<Class, DictionaryImpl>();

public DictionaryImpl(Class<E> clazz) {
this.clazz = clazz;
init();
}

private void init() {
if (values != null) {
// Already initialized.
return;
}
// The following statement throws NullPointerException under JDK1.4
// (that is, when retrowoven) if clazz has not finished loading. This
// happens when a static member of clazz is a Dictionary. If this
// happens, swallow the NullPointerException and return null. init will
// be called later.
final E[] constants;
try {
constants = clazz.getEnumConstants();
} catch (NullPointerException e) {
return;
}
this.values =
Collections.unmodifiableList(
Arrays.asList(clazz.getEnumConstants()));
Arrays.asList(constants));
for (E e : values) {
byName.put(e.xmlaName(), e);
byOrdinal.put(e.xmlaOrdinal(), e);
Expand All @@ -56,19 +77,22 @@ public static <E extends Enum<E> & XmlaConstant> DictionaryImpl<E> forClass(

public E forOrdinal(int xmlaOrdinal)
{
init();
return byOrdinal.get(xmlaOrdinal);
}

public E forName(String xmlaName)
{
init();
return byName.get(xmlaName);
}

public Set<E> forMask(
int xmlaOrdinalMask)
{
Set<E> set = EnumSet.noneOf(clazz);
for (E e : clazz.getEnumConstants()) {
init();
Set<E> set = Olap4jUtil.enumSetNoneOf(clazz);
for (E e : values) {
if ((xmlaOrdinalMask & e.xmlaOrdinal()) != 0) {
set.add(e);
}
Expand All @@ -86,6 +110,7 @@ public int toMask(Set<E> set)
}

public List<E> getValues() {
init();
return values;
}

Expand Down
8 changes: 6 additions & 2 deletions src/org/olap4j/metadata/Property.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
package org.olap4j.metadata;

import org.olap4j.impl.Olap4jUtil;

import java.util.*;

/**
Expand Down Expand Up @@ -79,9 +81,11 @@ enum TypeFlag implements XmlaConstant {
private final int xmlaOrdinal;

public static final Set<TypeFlag> CELL_TYPE_FLAG =
Collections.unmodifiableSet(EnumSet.of(TypeFlag.CELL));
Collections.unmodifiableSet(
Olap4jUtil.enumSetOf(TypeFlag.CELL));
public static final Set<TypeFlag> MEMBER_TYPE_FLAG =
Collections.unmodifiableSet(EnumSet.of(TypeFlag.MEMBER));
Collections.unmodifiableSet(
Olap4jUtil.enumSetOf(TypeFlag.MEMBER));
private static final DictionaryImpl<TypeFlag> DICTIONARY =
DictionaryImpl.forClass(TypeFlag.class);

Expand Down
Loading

0 comments on commit 97812f2

Please sign in to comment.