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