001/*
002// This software is subject to the terms of the Eclipse Public License v1.0
003// Agreement, available at the following URL:
004// http://www.eclipse.org/legal/epl-v10.html.
005// You must accept the terms of that agreement to use this software.
006//
007// Copyright (C) 2007-2012 Pentaho
008// All Rights Reserved.
009*/
010package mondrian.olap4j;
011
012import org.olap4j.impl.Named;
013import org.olap4j.metadata.Datatype;
014import org.olap4j.metadata.Property;
015
016import java.util.*;
017
018/**
019 * Implementation of {@link org.olap4j.metadata.Property}
020 * for the Mondrian OLAP engine,
021 * as a wrapper around a mondrian
022 * {@link mondrian.olap.Property}.
023 *
024 * @author jhyde
025 * @since Nov 12, 2007
026 */
027class MondrianOlap4jProperty implements Property, Named {
028    /**
029     * Map of member properties that are built into Mondrian but are not in the
030     * olap4j standard.
031     */
032    static final Map<String, MondrianOlap4jProperty> MEMBER_EXTENSIONS =
033        new LinkedHashMap<String, MondrianOlap4jProperty>();
034
035    /**
036     * Map of cell properties that are built into Mondrian but are not in the
037     * olap4j standard.
038     */
039    static final Map<String, MondrianOlap4jProperty> CELL_EXTENSIONS =
040        new LinkedHashMap<String, MondrianOlap4jProperty>();
041
042    static {
043        // Build set of names of olap4j standard member properties.
044        final Set<String> memberNames = new HashSet<String>();
045        for (Property property : Property.StandardMemberProperty.values()) {
046            memberNames.add(property.getName());
047        }
048
049        final Set<String> cellNames = new HashSet<String>();
050        for (Property property : StandardCellProperty.values()) {
051            cellNames.add(property.getName());
052        }
053
054        for (mondrian.olap.Property o
055            : mondrian.olap.Property.enumeration.getValuesSortedByName())
056        {
057            if (o.isMemberProperty()
058                && !memberNames.contains(o.getName()))
059            {
060                MEMBER_EXTENSIONS.put(
061                    o.getName(),
062                    new MondrianOlap4jProperty(o));
063            }
064            if (o.isCellProperty()
065                && !cellNames.contains(o.getName()))
066            {
067                CELL_EXTENSIONS.put(
068                    o.getName(),
069                    new MondrianOlap4jProperty(o));
070            }
071        }
072    }
073
074    final mondrian.olap.Property property;
075
076    MondrianOlap4jProperty(mondrian.olap.Property property) {
077        this.property = property;
078    }
079
080    public Datatype getDatatype() {
081        switch (property.getType()) {
082        case TYPE_BOOLEAN:
083            return Datatype.BOOLEAN;
084        case TYPE_NUMERIC:
085            return Datatype.UNSIGNED_INTEGER;
086        case TYPE_STRING:
087            return Datatype.STRING;
088        case TYPE_OTHER:
089            return Datatype.VARIANT;
090        default:
091            throw new RuntimeException("unexpected: " + property.getType());
092        }
093    }
094
095    public Set<TypeFlag> getType() {
096        return property.isCellProperty()
097            ? TypeFlag.CELL_TYPE_FLAG
098            : TypeFlag.MEMBER_TYPE_FLAG;
099    }
100
101    public String getName() {
102        return property.name;
103    }
104
105    public String getUniqueName() {
106        return property.name;
107    }
108
109    public String getCaption() {
110        // todo: i18n
111        return property.getCaption();
112    }
113
114    public String getDescription() {
115        // todo: i18n
116        return property.getDescription();
117    }
118
119    public boolean isVisible() {
120        return !property.isInternal();
121    }
122
123    public ContentType getContentType() {
124        return ContentType.REGULAR;
125    }
126}
127
128// End MondrianOlap4jProperty.java