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.api.model.InputSource; 29 import org.apache.maven.api.model.Model; 30 31 /** 32 * Handles deserialization of a model from some kind of textual format like XML. 33 * 34 * @author Benjamin Bentmann 35 */ 36 public interface ModelReader 37 { 38 39 /** 40 * The key for the option to enable strict parsing. This option is of type {@link Boolean} and defaults to {@code 41 * true}. If {@code false}, unknown elements will be ignored instead of causing a failure. 42 */ 43 String IS_STRICT = "org.apache.maven.model.io.isStrict"; 44 45 /** 46 * The key for the option to enable tracking of line/column numbers. This option is of type 47 * {@link InputSource} and defaults to {@code null}. Providing an input source enables 48 * location tracking. 49 */ 50 String INPUT_SOURCE = "org.apache.maven.model.io.inputSource"; 51 52 /** 53 * The key for the option to provide a transformer context, which can be used to transform the input while reading 54 * to get an advanced version of the model. 55 */ 56 String TRANSFORMER_CONTEXT = "transformerContext"; 57 58 /** 59 * Reads the model from the specified file. 60 * 61 * @param input The file to deserialize the model from, must not be {@code null}. 62 * @param options The options to use for deserialization, may be {@code null} to use the default values. 63 * @return The deserialized model, never {@code null}. 64 * @throws IOException If the model could not be deserialized. 65 * @throws ModelParseException If the input format could not be parsed. 66 */ 67 Model read( File input, Map<String, ?> options ) 68 throws IOException, ModelParseException; 69 70 /** 71 * Reads the model from the specified character reader. The reader will be automatically closed before the method 72 * returns. 73 * 74 * @param input The reader to deserialize the model from, must not be {@code null}. 75 * @param options The options to use for deserialization, may be {@code null} to use the default values. 76 * @return The deserialized model, never {@code null}. 77 * @throws IOException If the model could not be deserialized. 78 * @throws ModelParseException If the input format could not be parsed. 79 */ 80 Model read( Reader input, Map<String, ?> options ) 81 throws IOException, ModelParseException; 82 83 /** 84 * Reads the model from the specified byte stream. The stream will be automatically closed before the method 85 * returns. 86 * 87 * @param input The stream to deserialize the model from, must not be {@code null}. 88 * @param options The options to use for deserialization, may be {@code null} to use the default values. 89 * @return The deserialized model, never {@code null}. 90 * @throws IOException If the model could not be deserialized. 91 * @throws ModelParseException If the input format could not be parsed. 92 */ 93 Model read( InputStream input, Map<String, ?> options ) 94 throws IOException, ModelParseException; 95 96 }