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 2010 Sun Microsystems, Inc. 015 * Portions copyright 2012 ForgeRock AS. 016 */ 017 018package org.forgerock.opendj.ldap.requests; 019 020import org.forgerock.opendj.ldap.ByteString; 021import org.forgerock.opendj.ldap.responses.ExtendedResult; 022import org.forgerock.opendj.ldap.responses.ExtendedResultDecoder; 023 024/** 025 * An abstract Extended request which can be used as the basis for implementing 026 * new Extended operations. 027 * 028 * @param <R> 029 * The type of extended request. 030 * @param <S> 031 * The type of result. 032 */ 033public abstract class AbstractExtendedRequest<R extends ExtendedRequest<S>, S extends ExtendedResult> 034 extends AbstractRequestImpl<R> implements ExtendedRequest<S> { 035 036 /** 037 * Creates a new abstract extended request. 038 */ 039 protected AbstractExtendedRequest() { 040 // Nothing to do. 041 } 042 043 /** 044 * Creates a new extended request that is an exact copy of the provided 045 * request. 046 * 047 * @param extendedRequest 048 * The extended request to be copied. 049 * @throws NullPointerException 050 * If {@code extendedRequest} was {@code null} . 051 */ 052 protected AbstractExtendedRequest(final ExtendedRequest<S> extendedRequest) { 053 super(extendedRequest); 054 } 055 056 @Override 057 public abstract String getOID(); 058 059 @Override 060 public abstract ExtendedResultDecoder<S> getResultDecoder(); 061 062 @Override 063 public abstract ByteString getValue(); 064 065 @Override 066 public abstract boolean hasValue(); 067 068 @Override 069 public String toString() { 070 final StringBuilder builder = new StringBuilder(); 071 builder.append("ExtendedRequest(requestName="); 072 builder.append(getOID()); 073 if (hasValue()) { 074 builder.append(", requestValue="); 075 builder.append(getValue().toHexPlusAsciiString(4)); 076 } 077 builder.append(", controls="); 078 builder.append(getControls()); 079 builder.append(")"); 080 return builder.toString(); 081 } 082 083 @Override 084 @SuppressWarnings("unchecked") 085 final R getThis() { 086 return (R) this; 087 } 088 089}