1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
31
32
33
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 }