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-2010 Sun Microsystems, Inc.
015 * Portions copyright 2012-2013 ForgeRock AS.
016 */
017
018package org.forgerock.opendj.ldap.requests;
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 Requests provides methods for querying and manipulating
029 * the set of Controls included with a Request.
030 */
031public interface Request {
032
033    /**
034     * Adds the provided control to this request.
035     *
036     * @param control
037     *            The control to be added to this request.
038     * @return This request.
039     * @throws UnsupportedOperationException
040     *             If this request does not permit controls to be added.
041     * @throws NullPointerException
042     *             If {@code control} was {@code null}.
043     */
044    Request addControl(Control control);
045
046    /**
047     * Returns {@code true} if this request contains the specified request
048     * control.
049     *
050     * @param oid
051     *            The numeric OID of the request control.
052     * @return {@code true} if this request contains the specified request
053     *         control.
054     */
055    boolean containsControl(String oid);
056
057    /**
058     * Decodes and returns the first control in this request 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 request.
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     * request. The returned {@code List} may be modified if permitted by this
083     * request.
084     *
085     * @return A {@code List} containing the controls.
086     */
087    List<Control> getControls();
088
089}