001    /*
002    // $Id: //open/mondrian/src/main/mondrian/rolap/ArrayMemberSource.java#19 $
003    // This software is subject to the terms of the Common Public License
004    // Agreement, available at the following URL:
005    // http://www.opensource.org/licenses/cpl.html.
006    // Copyright (C) 2001-2002 Kana Software, Inc.
007    // Copyright (C) 2001-2008 Julian Hyde and others
008    // All Rights Reserved.
009    // You must accept the terms of that agreement to use this software.
010    //
011    // jhyde, 22 December, 2001
012    */
013    
014    package mondrian.rolap;
015    
016    import mondrian.olap.Id;
017    import mondrian.olap.Util;
018    import mondrian.resource.MondrianResource;
019    
020    import java.util.Collections;
021    import java.util.List;
022    
023    /**
024     * <code>ArrayMemberSource</code> implements a flat, static hierarchy. There is
025     * no root member, and all members are siblings.
026     *
027     * @author jhyde
028     * @since 22 December, 2001
029     * @version $Id: //open/mondrian/src/main/mondrian/rolap/ArrayMemberSource.java#19 $
030     */
031    abstract class ArrayMemberSource implements MemberSource {
032    
033        protected final RolapHierarchy hierarchy;
034        protected final List<RolapMember> members;
035    
036        ArrayMemberSource(RolapHierarchy hierarchy, List<RolapMember> members) {
037            this.hierarchy = hierarchy;
038            this.members = members;
039        }
040        public RolapHierarchy getHierarchy() {
041            return hierarchy;
042        }
043        public boolean setCache(MemberCache cache) {
044            return false; // we do not support cache writeback
045        }
046        public List<RolapMember> getMembers() {
047            return members;
048        }
049        public int getMemberCount() {
050            return members.size();
051        }
052    
053        public List<RolapMember> getRootMembers() {
054            return Collections.emptyList();
055        }
056    
057        public void getMemberChildren(RolapMember parentMember, List<RolapMember> children) {
058            // there are no children
059        }
060        public void getMemberChildren(List<RolapMember> parentMembers, List<RolapMember> children) {
061            // there are no children
062        }
063        public RolapMember lookupMember(List<Id.Segment> uniqueNameParts,
064                                        boolean failIfNotFound) {
065            String uniqueName = Util.implode(uniqueNameParts);
066            for (RolapMember member : members) {
067                if (member.getUniqueName().equals(uniqueName)) {
068                    return member;
069                }
070            }
071            if (failIfNotFound) {
072                throw MondrianResource.instance().MdxCantFindMember.ex(uniqueName);
073            } else {
074                return null;
075            }
076        }
077    }
078    
079    // End ArrayMemberSource.java