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