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