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 2009 Sun Microsystems, Inc.
025 *      Portions copyright 2012-2013 ForgeRock AS.
026 */
027
028package org.forgerock.opendj.ldap.responses;
029
030import java.util.List;
031
032import org.forgerock.opendj.ldap.DecodeException;
033import org.forgerock.opendj.ldap.DecodeOptions;
034import org.forgerock.opendj.ldap.controls.Control;
035import org.forgerock.opendj.ldap.controls.ControlDecoder;
036
037/**
038 * The base class of all Responses provides methods for querying and
039 * manipulating the set of Controls included with a Response.
040 */
041public interface Response {
042
043    /**
044     * Adds the provided control to this response.
045     *
046     * @param control
047     *            The control to be added.
048     * @return This response.
049     * @throws UnsupportedOperationException
050     *             If this response does not permit controls to be added.
051     * @throws NullPointerException
052     *             If {@code control} was {@code null}.
053     */
054    Response addControl(Control control);
055
056    /**
057     * Returns {@code true} if this response contains the specified response
058     * control.
059     *
060     * @param oid
061     *            The numeric OID of the response control.
062     * @return {@code true} if this response contains the specified response
063     *         control.
064     */
065    boolean containsControl(String oid);
066
067    /**
068     * Decodes and returns the first control in this response having an OID
069     * corresponding to the provided control decoder.
070     *
071     * @param <C>
072     *            The type of control to be decoded and returned.
073     * @param decoder
074     *            The control decoder.
075     * @param options
076     *            The set of decode options which should be used when decoding
077     *            the control.
078     * @return The decoded control, or {@code null} if the control is not
079     *         included with this response.
080     * @throws DecodeException
081     *             If the control could not be decoded because it was malformed
082     *             in some way (e.g. the control value was missing, or its
083     *             content could not be decoded).
084     * @throws NullPointerException
085     *             If {@code decoder} or {@code options} was {@code null}.
086     */
087    <C extends Control> C getControl(ControlDecoder<C> decoder, DecodeOptions options)
088            throws DecodeException;
089
090    /**
091     * Returns a {@code List} containing the controls included with this
092     * response. The returned {@code List} may be modified if permitted by this
093     * response.
094     *
095     * @return A {@code List} containing the controls.
096     */
097    List<Control> getControls();
098
099}