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 import java.util.function.Function;
25
26 import org.apache.maven.api.annotations.Experimental;
27 import org.apache.maven.api.annotations.Nonnull;
28 import org.apache.maven.api.annotations.Nullable;
29
30
31
32
33
34
35
36 @Experimental
37 public interface XmlWriterRequest<T> {
38
39 @Nullable
40 Path getPath();
41
42 @Nullable
43 OutputStream getOutputStream();
44
45 @Nullable
46 Writer getWriter();
47
48 @Nonnull
49 T getContent();
50
51 @Nullable
52 Function<Object, String> getInputLocationFormatter();
53
54 static <T> XmlWriterRequestBuilder<T> builder() {
55 return new XmlWriterRequestBuilder<>();
56 }
57
58 class XmlWriterRequestBuilder<T> {
59 Path path;
60 OutputStream outputStream;
61 Writer writer;
62 T content;
63 Function<Object, String> inputLocationFormatter;
64
65 public XmlWriterRequestBuilder<T> path(Path path) {
66 this.path = path;
67 return this;
68 }
69
70 public XmlWriterRequestBuilder<T> outputStream(OutputStream outputStream) {
71 this.outputStream = outputStream;
72 return this;
73 }
74
75 public XmlWriterRequestBuilder<T> writer(Writer writer) {
76 this.writer = writer;
77 return this;
78 }
79
80 public XmlWriterRequestBuilder<T> content(T content) {
81 this.content = content;
82 return this;
83 }
84
85 public XmlWriterRequestBuilder<T> inputLocationFormatter(Function<Object, String> inputLocationFormatter) {
86 this.inputLocationFormatter = inputLocationFormatter;
87 return this;
88 }
89
90 public XmlWriterRequest<T> build() {
91 return new DefaultXmlWriterRequest<>(path, outputStream, writer, content, inputLocationFormatter);
92 }
93
94 private static class DefaultXmlWriterRequest<T> implements XmlWriterRequest<T> {
95 final Path path;
96 final OutputStream outputStream;
97 final Writer writer;
98 final T content;
99 final Function<Object, String> inputLocationFormatter;
100
101 DefaultXmlWriterRequest(
102 Path path,
103 OutputStream outputStream,
104 Writer writer,
105 T content,
106 Function<Object, String> inputLocationFormatter) {
107 this.path = path;
108 this.outputStream = outputStream;
109 this.writer = writer;
110 this.content = content;
111 this.inputLocationFormatter = inputLocationFormatter;
112 }
113
114 @Override
115 public Path getPath() {
116 return path;
117 }
118
119 @Override
120 public OutputStream getOutputStream() {
121 return outputStream;
122 }
123
124 @Override
125 public Writer getWriter() {
126 return writer;
127 }
128
129 @Override
130 public T getContent() {
131 return content;
132 }
133
134 @Override
135 public Function<Object, String> getInputLocationFormatter() {
136 return inputLocationFormatter;
137 }
138 }
139 }
140 }