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 Sun Microsystems, Inc.
025 *      Portions copyright 2012 ForgeRock AS.
026 */
027
028package org.forgerock.opendj.ldif;
029
030import java.io.Closeable;
031import java.io.Flushable;
032import java.io.IOException;
033
034import org.forgerock.opendj.ldap.requests.AddRequest;
035import org.forgerock.opendj.ldap.requests.DeleteRequest;
036import org.forgerock.opendj.ldap.requests.ModifyDNRequest;
037import org.forgerock.opendj.ldap.requests.ModifyRequest;
038
039/**
040 * An interface for writing change records to a data source, typically an LDIF
041 * file.
042 */
043public interface ChangeRecordWriter extends Closeable, Flushable {
044    /**
045     * Closes this change record writer, flushing it first. Closing a previously
046     * closed change record writer has no effect.
047     *
048     * @throws IOException
049     *             If an unexpected IO error occurred while closing.
050     */
051    void close() throws IOException;
052
053    /**
054     * Flushes this change record writer so that any buffered data is written
055     * immediately to underlying stream, flushing the stream if it is also
056     * {@code Flushable}.
057     * <p>
058     * If the intended destination of this stream is an abstraction provided by
059     * the underlying operating system, for example a file, then flushing the
060     * stream guarantees only that bytes previously written to the stream are
061     * passed to the operating system for writing; it does not guarantee that
062     * they are actually written to a physical device such as a disk drive.
063     *
064     * @throws IOException
065     *             If an unexpected IO error occurred while flushing.
066     */
067    void flush() throws IOException;
068
069    /**
070     * Writes an {@code Add} change record.
071     *
072     * @param change
073     *            The {@code AddRequest} to be written as an {@code Add} change
074     *            record.
075     * @return A reference to this change record writer.
076     * @throws IOException
077     *             If an unexpected IO error occurred while writing the change
078     *             record.
079     * @throws NullPointerException
080     *             If {@code change} was {@code null}.
081     */
082    ChangeRecordWriter writeChangeRecord(AddRequest change) throws IOException;
083
084    /**
085     * Writes a change record.
086     *
087     * @param change
088     *            The {@code ChangeRecord} to be written.
089     * @return A reference to this change record writer.
090     * @throws IOException
091     *             If an unexpected IO error occurred while writing the change
092     *             record.
093     * @throws NullPointerException
094     *             If {@code change} was {@code null}.
095     */
096    ChangeRecordWriter writeChangeRecord(ChangeRecord change) throws IOException;
097
098    /**
099     * Writes a {@code Delete} change record.
100     *
101     * @param change
102     *            The {@code DeleteRequest} to be written as an {@code Delete}
103     *            change record.
104     * @return A reference to this change record writer.
105     * @throws IOException
106     *             If an unexpected IO error occurred while writing the change
107     *             record.
108     * @throws NullPointerException
109     *             If {@code change} was {@code null}.
110     */
111    ChangeRecordWriter writeChangeRecord(DeleteRequest change) throws IOException;
112
113    /**
114     * Writes a {@code ModifyDN} change record.
115     *
116     * @param change
117     *            The {@code ModifyDNRequest} to be written as an
118     *            {@code ModifyDN} change record.
119     * @return A reference to this change record writer.
120     * @throws IOException
121     *             If an unexpected IO error occurred while writing the change
122     *             record.
123     * @throws NullPointerException
124     *             If {@code change} was {@code null}.
125     */
126    ChangeRecordWriter writeChangeRecord(ModifyDNRequest change) throws IOException;
127
128    /**
129     * Writes a {@code Modify} change record.
130     *
131     * @param change
132     *            The {@code ModifyRequest} to be written as an {@code Modify}
133     *            change record.
134     * @return A reference to this change record writer.
135     * @throws IOException
136     *             If an unexpected IO error occurred while writing the change
137     *             record.
138     * @throws NullPointerException
139     *             If {@code change} was {@code null}.
140     */
141    ChangeRecordWriter writeChangeRecord(ModifyRequest change) throws IOException;
142
143    /**
144     * Writes a comment.
145     *
146     * @param comment
147     *            The {@code CharSequence} to be written as a comment.
148     * @return A reference to this change record writer.
149     * @throws IOException
150     *             If an unexpected IO error occurred while writing the comment.
151     * @throws NullPointerException
152     *             If {@code comment} was {@code null}.
153     */
154    ChangeRecordWriter writeComment(CharSequence comment) throws IOException;
155
156}