001/*
002 * Copyright 2007-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2007-2024 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2007-2024 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk;
037
038
039
040import java.io.Serializable;
041import java.util.List;
042
043import com.unboundid.util.NotExtensible;
044import com.unboundid.util.NotNull;
045import com.unboundid.util.Nullable;
046import com.unboundid.util.ThreadSafety;
047import com.unboundid.util.ThreadSafetyLevel;
048
049
050
051/**
052 * This interface defines a set of methods that may be safely called in an LDAP
053 * request without altering its contents.  This interface must not be
054 * implemented by any class outside of the LDAP SDK.
055 * <BR><BR>
056 * This interface does not inherently provide the assurance of thread safety for
057 * the methods that it exposes, because it is still possible for a thread
058 * referencing the object which implements this interface to alter the request
059 * using methods not included in this interface.  However, if it can be
060 * guaranteed that no thread will alter the underlying object, then the methods
061 * exposed by this interface can be safely invoked concurrently by any number of
062 * threads.
063 */
064@NotExtensible()
065@ThreadSafety(level=ThreadSafetyLevel.INTERFACE_NOT_THREADSAFE)
066public interface ReadOnlyLDAPRequest
067       extends Serializable
068{
069  /**
070   * Retrieves the set of controls for this request.  The caller must not alter
071   * this set of controls.
072   *
073   * @return  The set of controls for this request.
074   */
075  @NotNull()
076  Control[] getControls();
077
078
079
080  /**
081   * Retrieves a list containing the set of controls for this request.
082   *
083   * @return  A list containing the set of controls for this request.
084   */
085  @NotNull()
086  List<Control> getControlList();
087
088
089
090  /**
091   * Indicates whether this request contains at least one control.
092   *
093   * @return  {@code true} if this request contains at least one control, or
094   *          {@code false} if not.
095   */
096  boolean hasControl();
097
098
099
100  /**
101   * Indicates whether this request contains at least one control with the
102   * specified OID.
103   *
104   * @param  oid  The object identifier for which to make the determination.  It
105   *              must not be {@code null}.
106   *
107   * @return  {@code true} if this request contains at least one control with
108   *          the specified OID, or {@code false} if not.
109   */
110  boolean hasControl(@NotNull String oid);
111
112
113
114  /**
115   * Retrieves the control with the specified OID from this request.  If this
116   * request has multiple controls with the specified OID, then the first will
117   * be returned.
118   *
119   * @param  oid  The object identifier for which to retrieve the corresponding
120   *              control.  It must not be {@code null}.
121   *
122   * @return  The first control found with the specified OID, or {@code null} if
123   *          no control with that OID is included in this request.
124   */
125  @Nullable()
126  Control getControl(@NotNull String oid);
127
128
129
130  /**
131   * Retrieves the maximum length of time in milliseconds that processing on
132   * this operation should be allowed to block while waiting for a response from
133   * the server.
134   *
135   * @param  connection  The connection to use in order to retrieve the default
136   *                     value, if appropriate.  It may be {@code null} to
137   *                     retrieve the request-specific timeout (which may be
138   *                     negative if no response-specific timeout has been set).
139   *
140   * @return  The maximum length of time in milliseconds that processing on this
141   *          operation should be allowed to block while waiting for a response
142   *          from the server, or zero if no timeout should be enforced.
143   */
144  long getResponseTimeoutMillis(@Nullable LDAPConnection connection);
145
146
147
148  /**
149   * Indicates whether to automatically follow any referrals encountered while
150   * processing this request.  If a value has been set for this request, then it
151   * will be returned.  Otherwise, the default from the connection options for
152   * the provided connection will be used.
153   *
154   * @param  connection  The connection whose connection options may be used in
155   *                     the course of making the determination.  It must not
156   *                     be {@code null}.
157   *
158   * @return  {@code true} if any referrals encountered during processing should
159   *          be automatically followed, or {@code false} if not.
160   */
161  boolean followReferrals(@NotNull LDAPConnection connection);
162
163
164
165  /**
166   * Retrieves the referral connector that should be used when establishing a
167   * connection for the purpose of automatically following a referral.
168   *
169   * @param  connection  The connection that may be used in the course of
170   *                     obtaining the appropriate referral connector.  It must
171   *                     not be {@code null}.
172   *
173   * @return  The referral connector that should be used for the purpose of
174   *          automatically following a referral.  It will not be {@code null}.
175   */
176  @NotNull()
177  ReferralConnector getReferralConnector(@NotNull LDAPConnection connection);
178
179
180
181  /**
182   * Creates a new instance of this LDAP request that may be modified without
183   * impacting this request.
184   *
185   * @return  A new instance of this LDAP request that may be modified without
186   *          impacting this request.
187   */
188  @NotNull()
189  LDAPRequest duplicate();
190
191
192
193  /**
194   * Creates a new instance of this LDAP request that may be modified without
195   * impacting this request.  The provided controls will be used for the new
196   * request instead of duplicating the controls from this request.
197   *
198   * @param  controls  The set of controls to include in the duplicate request.
199   *
200   * @return  A new instance of this LDAP request that may be modified without
201   *          impacting this request.
202   */
203  @NotNull()
204  LDAPRequest duplicate(@Nullable Control[] controls);
205
206
207
208  /**
209   * Retrieves a string representation of this request.
210   *
211   * @return  A string representation of this request.
212   */
213  @Override()
214  @NotNull()
215  String toString();
216
217
218
219  /**
220   * Appends a string representation of this request to the provided buffer.
221   *
222   * @param  buffer  The buffer to which to append a string representation of
223   *                 this request.
224   */
225  void toString(@NotNull StringBuilder buffer);
226
227
228
229  /**
230   * Appends a number of lines comprising the Java source code that can be used
231   * to recreate this request to the given list.
232   *
233   * @param  lineList           The list to which the source code lines should
234   *                            be added.
235   * @param  requestID          The name that should be used as an identifier
236   *                            for the request.  If this is {@code null} or
237   *                            empty, then a generic ID will be used.
238   * @param  indentSpaces       The number of spaces that should be used to
239   *                            indent the generated code.  It must not be
240   *                            negative.
241   * @param  includeProcessing  Indicates whether the generated code should
242   *                            include code required to actually process the
243   *                            request and handle the result (if {@code true}),
244   *                            or just to generate the request (if
245   *                            {@code false}).
246   */
247  void toCode(@NotNull List<String> lineList, @NotNull String requestID,
248              int indentSpaces, boolean includeProcessing);
249}