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; 021import org.forgerock.opendj.ldap.ResultCode; 022 023/** 024 * An abstract Extended result which can be used as the basis for implementing 025 * new Extended operations. 026 * 027 * @param <S> 028 * The type of Extended result. 029 */ 030public abstract class AbstractExtendedResult<S extends ExtendedResult> extends 031 AbstractResultImpl<S> implements ExtendedResult { 032 033 /** 034 * Creates a new extended result that is an exact copy of the provided 035 * result. 036 * 037 * @param extendedResult 038 * The extended result to be copied. 039 * @throws NullPointerException 040 * If {@code extendedResult} was {@code null} . 041 */ 042 protected AbstractExtendedResult(final ExtendedResult extendedResult) { 043 super(extendedResult); 044 } 045 046 /** 047 * Creates a new extended result using the provided result code. 048 * 049 * @param resultCode 050 * The result code. 051 * @throws NullPointerException 052 * If {@code resultCode} was {@code null}. 053 */ 054 protected AbstractExtendedResult(final ResultCode resultCode) { 055 super(resultCode); 056 } 057 058 @Override 059 public abstract String getOID(); 060 061 @Override 062 public abstract ByteString getValue(); 063 064 @Override 065 public abstract boolean hasValue(); 066 067 @Override 068 public String toString() { 069 final StringBuilder builder = new StringBuilder(); 070 builder.append("ExtendedResult(resultCode="); 071 builder.append(getResultCode()); 072 builder.append(", matchedDN="); 073 builder.append(getMatchedDN()); 074 builder.append(", diagnosticMessage="); 075 builder.append(getDiagnosticMessage()); 076 builder.append(", referrals="); 077 builder.append(getReferralURIs()); 078 builder.append(", responseName="); 079 builder.append(getOID() == null ? "" : getOID()); 080 if (hasValue()) { 081 builder.append(", responseValue="); 082 builder.append(getValue().toHexPlusAsciiString(4)); 083 } 084 builder.append(", controls="); 085 builder.append(getControls()); 086 builder.append(")"); 087 return builder.toString(); 088 } 089 090 @Override 091 @SuppressWarnings("unchecked") 092 final S getThis() { 093 return (S) this; 094 } 095}