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) 2001-2005 Julian Hyde
008// Copyright (C) 2005-2009 Pentaho and others
009// All Rights Reserved.
010//
011// jhyde, 22 December, 2001
012*/
013package mondrian.rolap;
014
015import mondrian.olap.Id;
016import mondrian.olap.Util;
017import mondrian.resource.MondrianResource;
018
019import java.util.Collections;
020import java.util.List;
021
022/**
023 * <code>ArrayMemberSource</code> implements a flat, static hierarchy. There is
024 * no root member, and all members are siblings.
025 *
026 * @author jhyde
027 * @since 22 December, 2001
028 */
029abstract class ArrayMemberSource implements MemberSource {
030
031    protected final RolapHierarchy hierarchy;
032    protected final List<RolapMember> members;
033
034    ArrayMemberSource(RolapHierarchy hierarchy, List<RolapMember> members) {
035        this.hierarchy = hierarchy;
036        this.members = members;
037    }
038    public RolapHierarchy getHierarchy() {
039        return hierarchy;
040    }
041    public boolean setCache(MemberCache cache) {
042        return false; // we do not support cache writeback
043    }
044    public List<RolapMember> getMembers() {
045        return members;
046    }
047    public int getMemberCount() {
048        return members.size();
049    }
050
051    public List<RolapMember> getRootMembers() {
052        return Collections.emptyList();
053    }
054
055    public void getMemberChildren(
056        RolapMember parentMember,
057        List<RolapMember> children)
058    {
059        // there are no children
060    }
061
062    public void getMemberChildren(
063        List<RolapMember> parentMembers,
064        List<RolapMember> children)
065    {
066        // there are no children
067    }
068
069    public RolapMember lookupMember(
070        List<Id.Segment> uniqueNameParts,
071        boolean failIfNotFound)
072    {
073        String uniqueName = Util.implode(uniqueNameParts);
074        for (RolapMember member : members) {
075            if (member.getUniqueName().equals(uniqueName)) {
076                return member;
077            }
078        }
079        if (failIfNotFound) {
080            throw MondrianResource.instance().MdxCantFindMember.ex(uniqueName);
081        } else {
082            return null;
083        }
084    }
085}
086
087// End ArrayMemberSource.java