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  
25  import org.apache.maven.api.annotations.Experimental;
26  import org.apache.maven.api.annotations.Nonnull;
27  import org.apache.maven.api.annotations.Nullable;
28  
29  /**
30   * An XML writer request.
31   *
32   * @since 4.0.0
33   * @param <T> the object type to read
34   */
35  @Experimental
36  public interface XmlWriterRequest<T> {
37  
38      @Nullable
39      Path getPath();
40  
41      @Nullable
42      OutputStream getOutputStream();
43  
44      @Nullable
45      Writer getWriter();
46  
47      @Nonnull
48      T getContent();
49  
50      static <T> XmlWriterRequestBuilder<T> builder() {
51          return new XmlWriterRequestBuilder<>();
52      }
53  
54      class XmlWriterRequestBuilder<T> {
55          Path path;
56          OutputStream outputStream;
57          Writer writer;
58          T content;
59  
60          public XmlWriterRequestBuilder<T> path(Path path) {
61              this.path = path;
62              return this;
63          }
64  
65          public XmlWriterRequestBuilder<T> outputStream(OutputStream outputStream) {
66              this.outputStream = outputStream;
67              return this;
68          }
69  
70          public XmlWriterRequestBuilder<T> writer(Writer writer) {
71              this.writer = writer;
72              return this;
73          }
74  
75          public XmlWriterRequestBuilder<T> content(T content) {
76              this.content = content;
77              return this;
78          }
79  
80          public XmlWriterRequest<T> build() {
81              return new DefaultXmlWriterRequest<>(path, outputStream, writer, content);
82          }
83  
84          private static class DefaultXmlWriterRequest<T> implements XmlWriterRequest<T> {
85              final Path path;
86              final OutputStream outputStream;
87              final Writer writer;
88              final T content;
89  
90              DefaultXmlWriterRequest(Path path, OutputStream outputStream, Writer writer, T content) {
91                  this.path = path;
92                  this.outputStream = outputStream;
93                  this.writer = writer;
94                  this.content = content;
95              }
96  
97              @Override
98              public Path getPath() {
99                  return path;
100             }
101 
102             @Override
103             public OutputStream getOutputStream() {
104                 return outputStream;
105             }
106 
107             @Override
108             public Writer getWriter() {
109                 return writer;
110             }
111 
112             @Override
113             public T getContent() {
114                 return content;
115             }
116         }
117     }
118 }