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 2009-2010 Sun Microsystems, Inc.
015 * Portions copyright 2011-2015 ForgeRock AS.
016 */
017
018package org.forgerock.opendj.ldap.spi;
019
020import org.forgerock.opendj.ldap.DecodeException;
021import org.forgerock.opendj.ldap.DecodeOptions;
022import org.forgerock.opendj.ldap.IntermediateResponseHandler;
023import org.forgerock.opendj.ldap.LdapException;
024import org.forgerock.opendj.ldap.ResultCode;
025import org.forgerock.opendj.ldap.requests.ExtendedRequest;
026import org.forgerock.opendj.ldap.requests.StartTLSExtendedRequest;
027import org.forgerock.opendj.ldap.responses.ExtendedResult;
028import org.forgerock.util.promise.PromiseImpl;
029
030/**
031 * Extended result promise implementation.
032 *
033 * @param <S>
034 *         The type of result returned by this promise.
035 */
036public final class ExtendedResultLdapPromiseImpl<S extends ExtendedResult> extends
037        ResultLdapPromiseImpl<ExtendedRequest<S>, S> {
038    ExtendedResultLdapPromiseImpl(
039            final PromiseImpl<S, LdapException> impl,
040            final int requestID,
041            final ExtendedRequest<S> request,
042            final IntermediateResponseHandler intermediateResponseHandler) {
043        super(impl, requestID, request, intermediateResponseHandler);
044    }
045
046    /**
047     * Decode an extended result.
048     *
049     * @param result
050     *         Extended result to decode.
051     * @param options
052     *         Decoding options.
053     * @return The decoded extended result.
054     * @throws DecodeException
055     *         If a problem occurs during decoding.
056     */
057    public S decodeResult(final ExtendedResult result, final DecodeOptions options) throws DecodeException {
058        return getRequest().getResultDecoder().decodeExtendedResult(result, options);
059    }
060
061    @Override
062    public boolean isBindOrStartTLS() {
063        return StartTLSExtendedRequest.OID.equals(getRequest().getOID());
064    }
065
066    @Override
067    S newErrorResult(final ResultCode resultCode, final String diagnosticMessage, final Throwable cause) {
068        return getRequest().getResultDecoder().newExtendedErrorResult(resultCode, "", diagnosticMessage);
069    }
070}