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