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