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 2010 Sun Microsystems, Inc.
025 */
026package org.forgerock.opendj.ldap.controls;
027
028import org.forgerock.opendj.ldap.ByteString;
029
030/**
031 * Controls provide a mechanism whereby the semantics and arguments of existing
032 * LDAP operations may be extended. One or more controls may be attached to a
033 * single LDAP message. A control only affects the semantics of the message it
034 * is attached to. Controls sent by clients are termed 'request controls', and
035 * those sent by servers are termed 'response controls'.
036 * <p>
037 * To determine whether a directory server supports a given control, read the
038 * list of supported controls from the root DSE to get a collection of control
039 * OIDs, and then check for a match:
040 *
041 * <pre>
042 * Connection connection = ...;
043 * Collection&lt;String&gt; supported =
044 *     RootDSE.readRootDSE(connection).getSupportedControls();
045 *
046 * Control control = ...;
047 * String OID = control.getOID();
048 * if (supported != null && !supported.isEmpty() && supported.contains(OID)) {
049 *     // The control is supported. Use it here...
050 * }
051 * </pre>
052 *
053 * @see <a href="http://tools.ietf.org/html/rfc4511">RFC 4511 - Lightweight
054 *      Directory Access Protocol (LDAP): The Protocol </a>
055 */
056public interface Control {
057
058    /**
059     * Returns the numeric OID associated with this control.
060     *
061     * @return The numeric OID associated with this control.
062     */
063    String getOID();
064
065    /**
066     * Returns the value, if any, associated with this control. Its format is
067     * defined by the specification of this control.
068     *
069     * @return The value associated with this control, or {@code null} if there
070     *         is no value.
071     */
072    ByteString getValue();
073
074    /**
075     * Returns {@code true} if this control has a value. In some circumstances
076     * it may be useful to determine if a control has a value, without actually
077     * calculating the value and incurring any performance costs.
078     *
079     * @return {@code true} if this control has a value, or {@code false} if
080     *         there is no value.
081     */
082    boolean hasValue();
083
084    /**
085     * Returns {@code true} if it is unacceptable to perform the operation
086     * without applying the semantics of this control.
087     * <p>
088     * The criticality field only has meaning in controls attached to request
089     * messages (except UnbindRequest). For controls attached to response
090     * messages and the UnbindRequest, the criticality field SHOULD be
091     * {@code false}, and MUST be ignored by the receiving protocol peer. A
092     * value of {@code true} indicates that it is unacceptable to perform the
093     * operation without applying the semantics of the control.
094     *
095     * @return {@code true} if this control must be processed by the Directory
096     *         Server, or {@code false} if it can be ignored.
097     */
098    boolean isCritical();
099
100}