View Javadoc
1   package org.apache.maven.model.io;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.io.IOException;
24  import java.io.InputStream;
25  import java.io.Reader;
26  import java.util.Map;
27  
28  import org.apache.maven.model.Model;
29  
30  /**
31   * Handles deserialization of a model from some kind of textual format like XML.
32   *
33   * @author Benjamin Bentmann
34   */
35  public interface ModelReader
36  {
37  
38      /**
39       * The key for the option to enable strict parsing. This option is of type {@link Boolean} and defaults to {@code
40       * true}. If {@code false}, unknown elements will be ignored instead of causing a failure.
41       */
42      String IS_STRICT = "org.apache.maven.model.io.isStrict";
43  
44      /**
45       * The key for the option to enable tracking of line/column numbers. This option is of type
46       * {@link org.apache.maven.model.InputSource} and defaults to {@code null}. Providing an input source enables
47       * location tracking.
48       */
49      String INPUT_SOURCE = "org.apache.maven.model.io.inputSource";
50  
51      /**
52       * Reads the model from the specified file.
53       *
54       * @param input The file to deserialize the model from, must not be {@code null}.
55       * @param options The options to use for deserialization, may be {@code null} to use the default values.
56       * @return The deserialized model, never {@code null}.
57       * @throws IOException If the model could not be deserialized.
58       * @throws ModelParseException If the input format could not be parsed.
59       */
60      Model read( File input, Map<String, ?> options )
61          throws IOException, ModelParseException;
62  
63      /**
64       * Reads the model from the specified character reader. The reader will be automatically closed before the method
65       * returns.
66       *
67       * @param input The reader to deserialize the model from, must not be {@code null}.
68       * @param options The options to use for deserialization, may be {@code null} to use the default values.
69       * @return The deserialized model, never {@code null}.
70       * @throws IOException If the model could not be deserialized.
71       * @throws ModelParseException If the input format could not be parsed.
72       */
73      Model read( Reader input, Map<String, ?> options )
74          throws IOException, ModelParseException;
75  
76      /**
77       * Reads the model from the specified byte stream. The stream will be automatically closed before the method
78       * returns.
79       *
80       * @param input The stream to deserialize the model from, must not be {@code null}.
81       * @param options The options to use for deserialization, may be {@code null} to use the default values.
82       * @return The deserialized model, never {@code null}.
83       * @throws IOException If the model could not be deserialized.
84       * @throws ModelParseException If the input format could not be parsed.
85       */
86      Model read( InputStream input, Map<String, ?> options )
87          throws IOException, ModelParseException;
88  
89  }