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 2006-2008 Sun Microsystems, Inc.
015 * Portions Copyright 2011-2016 ForgeRock AS.
016 */
017package org.opends.server.core;
018
019import java.util.List;
020import java.util.Map;
021
022import org.forgerock.i18n.LocalizableMessage;
023import org.forgerock.i18n.LocalizableMessageBuilder;
024import org.forgerock.opendj.ldap.ResultCode;
025import org.opends.server.api.ClientConnection;
026import org.opends.server.controls.ControlDecoder;
027import org.opends.server.types.AdditionalLogItem;
028import org.opends.server.types.CancelRequest;
029import org.opends.server.types.CancelResult;
030import org.opends.server.types.CanceledOperationException;
031import org.opends.server.types.Control;
032import org.forgerock.opendj.ldap.DN;
033import org.opends.server.types.DirectoryException;
034import org.opends.server.types.DisconnectReason;
035import org.opends.server.types.Entry;
036import org.opends.server.types.Operation;
037import org.opends.server.types.OperationType;
038
039/**
040 * This abstract class is a generic operation wrapper intended to be subclassed
041 * by a specific operation wrapper.
042 *
043 * @param <W>
044 *          the type of the object wrapped by this class
045 */
046public class OperationWrapper<W extends Operation> implements Operation
047{
048  /** The wrapped operation. */
049  private W operation;
050
051  /**
052   * Creates a new generic operation wrapper.
053   *
054   * @param operation  the generic operation to wrap
055   */
056  public OperationWrapper(W operation)
057  {
058    this.operation = operation;
059  }
060
061  @Override
062  public void addRequestControl(Control control)
063  {
064    operation.addRequestControl(control);
065  }
066
067  @Override
068  public void addResponseControl(Control control)
069  {
070    operation.addResponseControl(control);
071  }
072
073  @Override
074  public void appendErrorMessage(LocalizableMessage message)
075  {
076    operation.appendErrorMessage(message);
077  }
078
079  @Override
080  public void appendMaskedErrorMessage(LocalizableMessage maskedMessage)
081  {
082    operation.appendMaskedErrorMessage(maskedMessage);
083  }
084
085  @Override
086  public CancelResult cancel(CancelRequest cancelRequest)
087  {
088    return operation.cancel(cancelRequest);
089  }
090
091  @Override
092  public void abort(CancelRequest cancelRequest)
093  {
094    operation.abort(cancelRequest);
095  }
096
097  @Override
098  public void disconnectClient(
099          DisconnectReason disconnectReason,
100          boolean sendNotification,
101          LocalizableMessage message
102  )
103  {
104    operation.disconnectClient(
105      disconnectReason, sendNotification, message);
106  }
107
108  @Override
109  public boolean dontSynchronize()
110  {
111    return operation.dontSynchronize();
112  }
113
114  @Override
115  public <T> T getAttachment(String name)
116  {
117    return operation.getAttachment(name);
118  }
119
120  @Override
121  public Map<String, Object> getAttachments()
122  {
123    return operation.getAttachments();
124  }
125
126  @Override
127  public DN getAuthorizationDN()
128  {
129    return operation.getAuthorizationDN();
130  }
131
132  @Override
133  public Entry getAuthorizationEntry()
134  {
135    return operation.getAuthorizationEntry();
136  }
137
138  @Override
139  public DN getProxiedAuthorizationDN()
140  {
141    return operation.getProxiedAuthorizationDN();
142  }
143
144  @Override
145  public void setProxiedAuthorizationDN(DN proxiedAuthorizationDN)
146  {
147    operation.setProxiedAuthorizationDN(proxiedAuthorizationDN);
148  }
149
150  @Override
151  public CancelRequest getCancelRequest()
152  {
153    return operation.getCancelRequest();
154  }
155
156  @Override
157  public CancelResult getCancelResult()
158  {
159    return operation.getCancelResult();
160  }
161
162  @Override
163  public ClientConnection getClientConnection()
164  {
165    return operation.getClientConnection();
166  }
167
168  @Override
169  public long getConnectionID()
170  {
171    return operation.getConnectionID();
172  }
173
174  @Override
175  public LocalizableMessageBuilder getErrorMessage()
176  {
177    return operation.getErrorMessage();
178  }
179
180  @Override
181  public LocalizableMessageBuilder getMaskedErrorMessage()
182  {
183    return operation.getMaskedErrorMessage();
184  }
185
186  @Override
187  public ResultCode getMaskedResultCode()
188  {
189    return operation.getMaskedResultCode();
190  }
191
192  @Override
193  public DN getMatchedDN()
194  {
195    return operation.getMatchedDN();
196  }
197
198  @Override
199  public int getMessageID()
200  {
201    return operation.getMessageID();
202  }
203
204  /**
205   * Returns the wrapped {@link Operation}.
206   *
207   * @return the wrapped {@link Operation}.
208   */
209  protected W getOperation()
210  {
211    return operation;
212  }
213
214  @Override
215  public long getOperationID()
216  {
217    return operation.getOperationID();
218  }
219
220  @Override
221  public OperationType getOperationType()
222  {
223    return operation.getOperationType();
224  }
225
226  @Override
227  public long getProcessingStartTime()
228  {
229    return operation.getProcessingStartTime();
230  }
231
232  @Override
233  public long getProcessingStopTime()
234  {
235    return operation.getProcessingStopTime();
236  }
237
238  @Override
239  public long getProcessingTime()
240  {
241    return operation.getProcessingTime();
242  }
243
244  @Override
245  public long getProcessingNanoTime()
246  {
247    return operation.getProcessingNanoTime();
248  }
249
250  @Override
251  public List<String> getReferralURLs()
252  {
253    return operation.getReferralURLs();
254  }
255
256  @Override
257  public List<Control> getRequestControls()
258  {
259    return operation.getRequestControls();
260  }
261
262  @Override
263  public <T extends Control> T getRequestControl(
264      ControlDecoder<T> d)throws DirectoryException
265  {
266    return operation.getRequestControl(d);
267  }
268
269  @Override
270  public List<Control> getResponseControls()
271  {
272    return operation.getResponseControls();
273  }
274
275  @Override
276  public ResultCode getResultCode()
277  {
278    return operation.getResultCode();
279  }
280
281  @Override
282  public boolean isInnerOperation()
283  {
284    return operation.isInnerOperation();
285  }
286
287  @Override
288  public boolean isInternalOperation()
289  {
290    return operation.isInternalOperation();
291  }
292
293  @Override
294  public boolean isSynchronizationOperation()
295  {
296    return operation.isSynchronizationOperation();
297  }
298
299  @Override
300  public void operationCompleted()
301  {
302    operation.operationCompleted();
303  }
304
305  @Override
306  public <T> T removeAttachment(String name)
307  {
308    return operation.removeAttachment(name);
309  }
310
311  @Override
312  public void removeResponseControl(Control control)
313  {
314    operation.removeResponseControl(control);
315  }
316
317  @Override
318  public <T> T setAttachment(String name, Object value)
319  {
320    return operation.setAttachment(name, value);
321  }
322
323  @Override
324  public void setAttachments(Map<String, Object> attachments)
325  {
326    operation.setAttachments(attachments);
327  }
328
329  @Override
330  public void setAuthorizationEntry(Entry authorizationEntry)
331  {
332    operation.setAuthorizationEntry(authorizationEntry);
333  }
334
335  @Override
336  public void setDontSynchronize(boolean dontSynchronize)
337  {
338    operation.setDontSynchronize(dontSynchronize);
339  }
340
341  @Override
342  public void setErrorMessage(LocalizableMessageBuilder errorMessage)
343  {
344    operation.setErrorMessage(errorMessage);
345  }
346
347  @Override
348  public void setInnerOperation(boolean isInnerOperation)
349  {
350    operation.setInnerOperation(isInnerOperation);
351  }
352
353  @Override
354  public void setInternalOperation(boolean isInternalOperation)
355  {
356    operation.setInternalOperation(isInternalOperation);
357  }
358
359  @Override
360  public void setMaskedErrorMessage(LocalizableMessageBuilder maskedErrorMessage)
361  {
362    operation.setMaskedErrorMessage(maskedErrorMessage);
363  }
364
365  @Override
366  public void setMaskedResultCode(ResultCode maskedResultCode)
367  {
368    operation.setMaskedResultCode(maskedResultCode);
369  }
370
371  @Override
372  public void setMatchedDN(DN matchedDN)
373  {
374    operation.setMatchedDN(matchedDN);
375  }
376
377  @Override
378  public void setReferralURLs(List<String> referralURLs)
379  {
380    operation.setReferralURLs(referralURLs);
381  }
382
383  @Override
384  public void setResponseData(DirectoryException directoryException)
385  {
386    operation.setResponseData(directoryException);
387  }
388
389  @Override
390  public void setResultCode(ResultCode resultCode)
391  {
392    operation.setResultCode(resultCode);
393  }
394
395  @Override
396  public void setSynchronizationOperation(boolean isSynchronizationOperation)
397  {
398    operation.setSynchronizationOperation(isSynchronizationOperation);
399  }
400
401  @Override
402  public final int hashCode()
403  {
404    return getClientConnection().hashCode() * (int) getOperationID();
405  }
406
407  @Override
408  public final boolean equals(Object obj)
409  {
410    if (this == obj)
411    {
412      return true;
413    }
414
415    if (obj instanceof Operation)
416    {
417      Operation other = (Operation) obj;
418      if (other.getClientConnection().equals(getClientConnection()))
419      {
420        return other.getOperationID() == getOperationID();
421      }
422    }
423
424    return false;
425  }
426
427  @Override
428  public String toString()
429  {
430    return "Wrapped " + operation;
431  }
432
433  @Override
434  public void toString(StringBuilder buffer)
435  {
436    operation.toString(buffer);
437  }
438
439  @Override
440  final synchronized public void checkIfCanceled(boolean signalTooLate)
441      throws CanceledOperationException {
442    operation.checkIfCanceled(signalTooLate);
443  }
444
445  @Override
446  public void registerPostResponseCallback(Runnable callback)
447  {
448    operation.registerPostResponseCallback(callback);
449  }
450
451  @Override
452  public void run()
453  {
454    operation.run();
455  }
456
457  @Override
458  public List<AdditionalLogItem> getAdditionalLogItems()
459  {
460    return operation.getAdditionalLogItems();
461  }
462
463  @Override
464  public void addAdditionalLogItem(AdditionalLogItem item)
465  {
466    operation.addAdditionalLogItem(item);
467  }
468}