001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2013-2014 ForgeRock AS
026 */
027package org.opends.server.types;
028
029import java.io.Closeable;
030
031/**
032 * This class defines a mechanism that may be used to iterate over the
033 * members of a group.  It uses an interface that is similar to that
034 * of {@code java.util.Iterator}, but is specific to group membership
035 * and that provides the ability to throw an exception when attempting
036 * to retrieve the next member (e.g., if the group contains a
037 * malformed DN or references a member that doesn't exist).
038 */
039@org.opends.server.types.PublicAPI(
040     stability=org.opends.server.types.StabilityLevel.VOLATILE,
041     mayInstantiate=false,
042     mayExtend=true,
043     mayInvoke=true)
044public abstract class MemberList implements Closeable
045{
046
047  /**
048   * Indicates whether the group contains any more members.
049   *
050   * @return  {@code true} if the group has at least one more member,
051   *          or {@code false} if not.
052   */
053  public abstract boolean hasMoreMembers();
054
055
056
057  /**
058   * Retrieves the DN of the next group member.
059   *
060   * @return  The DN of the next group member, or {@code null} if
061   *          there are no more members.
062   *
063   * @throws  MembershipException  If a problem occurs while
064   *                               attempting to retrieve the next
065   *                               member DN.
066   */
067  public DN nextMemberDN()
068         throws MembershipException
069  {
070    Entry e = nextMemberEntry();
071    if (e != null)
072    {
073      return e.getName();
074    }
075    return null;
076  }
077
078
079
080  /**
081   * Retrieves the entry for the next group member.
082   *
083   * @return  The entry for the next group member, or {@code null} if
084   *          there are no more members.
085   *
086   * @throws  MembershipException  If a problem occurs while
087   *                               attempting to retrieve the next
088   *                               entry.
089   */
090  public abstract Entry nextMemberEntry()
091         throws MembershipException;
092
093
094
095  /**
096   * Indicates that this member list is no longer required and that
097   * the server may clean up any resources that may have been used in
098   * the course of processing.  This method must be called if the
099   * caller wishes to stop iterating across the member list before the
100   * end has been reached, although it will not be necessary if the
101   * call to {@code hasMoreMembers} returns {@code false}.
102   */
103  @Override
104  public abstract void close();
105}
106