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