001/*
002 * Copyright 2008-2014 UnboundID Corp.
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2008-2014 UnboundID Corp.
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.ldap.sdk.controls;
022
023
024
025import com.unboundid.ldap.sdk.Control;
026import com.unboundid.ldap.sdk.LDAPException;
027import com.unboundid.ldap.sdk.ResultCode;
028import com.unboundid.util.NotMutable;
029import com.unboundid.util.ThreadSafety;
030import com.unboundid.util.ThreadSafetyLevel;
031
032import static com.unboundid.ldap.sdk.controls.ControlMessages.*;
033
034
035
036/**
037 * This class provides an implementation of the LDAP subentries request control
038 * as defined in draft-ietf-ldup-subentry.  It may be included in a search
039 * request to indicate that the entries with the {@code ldapSubentry} object
040 * class should be included in the search results.
041 * <BR><BR>
042 * Entries containing the {@code ldapSubentry} object class are special in that
043 * they are normally excluded from search results, unless the target entry is
044 * requested with a base-level search.  They are used to store operational
045 * information that controls how the server should behave rather than user data.
046 * Because they do not hold user data, it is generally desirable to have them
047 * excluded from search results, but for cases in which a client needs to
048 * retrieve such an entry, then this subentries request control may be included
049 * in the search request.
050 * <BR><BR>
051 * There is no corresponding response control.
052 * <BR><BR>
053 * <H2>Example</H2>
054 * The following example illustrates the use of the subentries request control
055 * to retrieve subentries that may not otherwise be returned.
056 * <PRE>
057 * // First, perform a search to retrieve an entry with a cn of "test subentry"
058 * // but without including the subentries request control.  This should not
059 * // return any matching entries.
060 * SearchRequest searchRequest = new SearchRequest("dc=example,dc=com",
061 *      SearchScope.SUB, Filter.createEqualityFilter("cn", "test subentry"));
062 * SearchResult resultWithoutControl = connection.search(searchRequest);
063 * LDAPTestUtils.assertResultCodeEquals(resultWithoutControl,
064 *      ResultCode.SUCCESS);
065 * LDAPTestUtils.assertEntriesReturnedEquals(resultWithoutControl, 0);
066 *
067 * // Update the search request to add a subentries request control so that
068 * // subentries should be included in search results.  This should cause the
069 * // subentry to be returned.
070 * searchRequest.addControl(new SubentriesRequestControl());
071 * SearchResult resultWithControl = connection.search(searchRequest);
072 * LDAPTestUtils.assertResultCodeEquals(resultWithControl, ResultCode.SUCCESS);
073 * LDAPTestUtils.assertEntriesReturnedEquals(resultWithControl, 1);
074 * </PRE>
075 */
076@NotMutable()
077@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
078public final class SubentriesRequestControl
079       extends Control
080{
081  /**
082   * The OID (1.3.6.1.4.1.7628.5.101.1) for the LDAP subentries request control.
083   */
084  public static final String SUBENTRIES_REQUEST_OID =
085       "1.3.6.1.4.1.7628.5.101.1";
086
087
088
089  /**
090   * The serial version UID for this serializable class.
091   */
092  private static final long serialVersionUID = 4772130172594841481L;
093
094
095
096  /**
097   * Creates a new subentries request control.  it will not be marked critical.
098   */
099  public SubentriesRequestControl()
100  {
101    this(false);
102  }
103
104
105
106  /**
107   * Creates a new subentries request control with the specified criticality.
108   *
109   * @param  isCritical  Indicates whether this control should be marked
110   *                     critical.
111   */
112  public SubentriesRequestControl(final boolean isCritical)
113  {
114    super(SUBENTRIES_REQUEST_OID, isCritical, null);
115  }
116
117
118
119  /**
120   * Creates a new subentries request control which is decoded from the provided
121   * generic control.
122   *
123   * @param  control  The generic control to be decoded as a subentries request
124   *                  control.
125   *
126   * @throws  LDAPException  If the provided control cannot be decoded as a
127   *                         subentries request control.
128   */
129  public SubentriesRequestControl(final Control control)
130         throws LDAPException
131  {
132    super(control);
133
134    if (control.hasValue())
135    {
136      throw new LDAPException(ResultCode.DECODING_ERROR,
137                              ERR_SUBENTRIES_HAS_VALUE.get());
138    }
139  }
140
141
142
143  /**
144   * {@inheritDoc}
145   */
146  @Override()
147  public String getControlName()
148  {
149    return INFO_CONTROL_NAME_SUBENTRIES_REQUEST.get();
150  }
151
152
153
154  /**
155   * {@inheritDoc}
156   */
157  @Override()
158  public void toString(final StringBuilder buffer)
159  {
160    buffer.append("SubentriesRequestControl(isCritical=");
161    buffer.append(isCritical());
162    buffer.append(')');
163  }
164}