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