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