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.requests;
029
030import org.forgerock.opendj.ldap.ByteString;
031import org.forgerock.opendj.ldap.responses.ExtendedResult;
032import org.forgerock.opendj.ldap.responses.ExtendedResultDecoder;
033
034/**
035 * An abstract Extended request which can be used as the basis for implementing
036 * new Extended operations.
037 *
038 * @param <R>
039 *            The type of extended request.
040 * @param <S>
041 *            The type of result.
042 */
043public abstract class AbstractExtendedRequest<R extends ExtendedRequest<S>, S extends ExtendedResult>
044        extends AbstractRequestImpl<R> implements ExtendedRequest<S> {
045
046    /**
047     * Creates a new abstract extended request.
048     */
049    protected AbstractExtendedRequest() {
050        // Nothing to do.
051    }
052
053    /**
054     * Creates a new extended request that is an exact copy of the provided
055     * request.
056     *
057     * @param extendedRequest
058     *            The extended request to be copied.
059     * @throws NullPointerException
060     *             If {@code extendedRequest} was {@code null} .
061     */
062    protected AbstractExtendedRequest(final ExtendedRequest<S> extendedRequest) {
063        super(extendedRequest);
064    }
065
066    @Override
067    public abstract String getOID();
068
069    @Override
070    public abstract ExtendedResultDecoder<S> getResultDecoder();
071
072    @Override
073    public abstract ByteString getValue();
074
075    @Override
076    public abstract boolean hasValue();
077
078    @Override
079    public String toString() {
080        final StringBuilder builder = new StringBuilder();
081        builder.append("ExtendedRequest(requestName=");
082        builder.append(getOID());
083        if (hasValue()) {
084            builder.append(", requestValue=");
085            builder.append(getValue().toHexPlusAsciiString(4));
086        }
087        builder.append(", controls=");
088        builder.append(getControls());
089        builder.append(")");
090        return builder.toString();
091    }
092
093    @Override
094    @SuppressWarnings("unchecked")
095    final R getThis() {
096        return (R) this;
097    }
098
099}