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 2006-2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014 ForgeRock AS
026 */
027package org.opends.server.protocols.ldap;
028
029import org.forgerock.opendj.io.ASN1Writer;
030
031import java.io.IOException;
032
033
034/**
035 * This class defines the structures and methods for an LDAP protocol op, which
036 * is the core of an LDAP message.
037 */
038public abstract class ProtocolOp
039{
040  /**
041   * Retrieves the BER type for this protocol op.
042   *
043   * @return  The BER type for this protocol op.
044   */
045  public abstract byte getType();
046
047
048
049  /**
050   * Retrieves the name for this protocol op type.
051   *
052   * @return  The name for this protocol op type.
053   */
054  public abstract String getProtocolOpName();
055
056
057
058  /**
059   * Writes this protocol op to an ASN.1 output stream.
060   *
061   * @param stream The ASN.1 output stream to write to.
062   * @throws IOException If a problem occurs while writing to the stream.
063   */
064  public abstract void write(ASN1Writer stream) throws IOException;
065
066
067  /**
068   * Retrieves a string representation of this LDAP protocol op.
069   *
070   * @return  A string representation of this LDAP protocol op.
071   */
072  public String toString()
073  {
074    StringBuilder buffer = new StringBuilder();
075    toString(buffer);
076    return buffer.toString();
077  }
078
079
080
081  /**
082   * Appends a string representation of this LDAP protocol op to the provided
083   * buffer.
084   *
085   * @param  buffer  The buffer to which the string should be appended.
086   */
087  public abstract void toString(StringBuilder buffer);
088
089
090
091  /**
092   * Appends a multi-line string representation of this LDAP protocol op to the
093   * provided buffer.
094   *
095   * @param  buffer  The buffer to which the information should be appended.
096   * @param  indent  The number of spaces from the margin that the lines should
097   *                 be indented.
098   */
099  public abstract void toString(StringBuilder buffer, int indent);
100}
101