View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.api.services.xml;
20  
21  import java.io.OutputStream;
22  import java.io.Writer;
23  import java.nio.file.Path;
24  import org.apache.maven.api.annotations.Experimental;
25  
26  /**
27   * An XML writer request.
28   *
29   * @since 4.0
30   * @param <T> the object type to read
31   */
32  @Experimental
33  public interface XmlWriterRequest<T> {
34  
35      Path getPath();
36  
37      OutputStream getOutputStream();
38  
39      Writer getWriter();
40  
41      T getContent();
42  
43      static <T> XmlWriterRequestBuilder<T> builder() {
44          return new XmlWriterRequestBuilder<>();
45      }
46  
47      class XmlWriterRequestBuilder<T> {
48          Path path;
49          OutputStream outputStream;
50          Writer writer;
51          T content;
52  
53          public XmlWriterRequestBuilder<T> path(Path path) {
54              this.path = path;
55              return this;
56          }
57  
58          public XmlWriterRequestBuilder<T> outputStream(OutputStream outputStream) {
59              this.outputStream = outputStream;
60              return this;
61          }
62  
63          public XmlWriterRequestBuilder<T> writer(Writer writer) {
64              this.writer = writer;
65              return this;
66          }
67  
68          public XmlWriterRequestBuilder<T> content(T content) {
69              this.content = content;
70              return this;
71          }
72  
73          public XmlWriterRequest<T> build() {
74              return new DefaultXmlWriterRequest<>(path, outputStream, writer, content);
75          }
76  
77          private static class DefaultXmlWriterRequest<T> implements XmlWriterRequest<T> {
78              final Path path;
79              final OutputStream outputStream;
80              final Writer writer;
81              final T content;
82  
83              DefaultXmlWriterRequest(Path path, OutputStream outputStream, Writer writer, T content) {
84                  this.path = path;
85                  this.outputStream = outputStream;
86                  this.writer = writer;
87                  this.content = content;
88              }
89  
90              @Override
91              public Path getPath() {
92                  return path;
93              }
94  
95              @Override
96              public OutputStream getOutputStream() {
97                  return outputStream;
98              }
99  
100             @Override
101             public Writer getWriter() {
102                 return writer;
103             }
104 
105             @Override
106             public T getContent() {
107                 return content;
108             }
109         }
110     }
111 }