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.responses; 019 020import org.forgerock.opendj.ldap.ByteString; 021 022/** 023 * An abstract Intermediate response which can be used as the basis for 024 * implementing new Intermediate responses. 025 * 026 * @param <S> 027 * The type of Intermediate response. 028 */ 029public abstract class AbstractIntermediateResponse<S extends IntermediateResponse> extends 030 AbstractResponseImpl<S> implements IntermediateResponse { 031 032 /** 033 * Creates a new intermediate response. 034 */ 035 protected AbstractIntermediateResponse() { 036 // Nothing to do. 037 } 038 039 /** 040 * Creates a new intermediate response that is an exact copy of the provided 041 * response. 042 * 043 * @param intermediateResponse 044 * The intermediate response to be copied. 045 * @throws NullPointerException 046 * If {@code intermediateResponse} was {@code null} . 047 */ 048 protected AbstractIntermediateResponse(final IntermediateResponse intermediateResponse) { 049 super(intermediateResponse); 050 } 051 052 @Override 053 public abstract String getOID(); 054 055 @Override 056 public abstract ByteString getValue(); 057 058 @Override 059 public abstract boolean hasValue(); 060 061 @Override 062 public String toString() { 063 final StringBuilder builder = new StringBuilder(); 064 builder.append("IntermediateResponse(responseName="); 065 builder.append(getOID() == null ? "" : getOID()); 066 if (hasValue()) { 067 builder.append(", responseValue="); 068 builder.append(getValue().toHexPlusAsciiString(4)); 069 } 070 builder.append(", controls="); 071 builder.append(getControls()); 072 builder.append(")"); 073 return builder.toString(); 074 } 075 076 @Override 077 @SuppressWarnings("unchecked") 078 final S getThis() { 079 return (S) this; 080 } 081}