001package org.apache.maven.model.io;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.File;
023import java.io.IOException;
024import java.io.OutputStream;
025import java.io.Writer;
026import java.util.Map;
027
028import org.apache.maven.model.Model;
029
030/**
031 * Handles serialization of a model into some kind of textual format like XML.
032 *
033 * @author Benjamin Bentmann
034 */
035public interface ModelWriter
036{
037
038    /**
039     * Writes the supplied model to the specified file. Any non-existing parent directories of the output file will be
040     * created automatically.
041     *
042     * @param output The file to serialize the model to, must not be {@code null}.
043     * @param options The options to use for serialization, may be {@code null} to use the default values.
044     * @param model The model to serialize, must not be {@code null}.
045     * @throws IOException If the model could not be serialized.
046     */
047    void write( File output, Map<String, Object> options, Model model )
048        throws IOException;
049
050    /**
051     * Writes the supplied model to the specified character writer. The writer will be automatically closed before the
052     * method returns.
053     *
054     * @param output The writer to serialize the model to, must not be {@code null}.
055     * @param options The options to use for serialization, may be {@code null} to use the default values.
056     * @param model The model to serialize, must not be {@code null}.
057     * @throws IOException If the model could not be serialized.
058     */
059    void write( Writer output, Map<String, Object> options, Model model )
060        throws IOException;
061
062    /**
063     * Writes the supplied model to the specified byte stream. The stream will be automatically closed before the method
064     * returns.
065     *
066     * @param output The stream to serialize the model to, must not be {@code null}.
067     * @param options The options to use for serialization, may be {@code null} to use the default values.
068     * @param model The model to serialize, must not be {@code null}.
069     * @throws IOException If the model could not be serialized.
070     */
071    void write( OutputStream output, Map<String, Object> options, Model model )
072        throws IOException;
073
074}