1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.transformer;
35
36
37
38
39 public interface TransformationProblem {
40
41 static Builder error(String message, Object... args) {
42 return new Builder()
43 .withSeverityType(SeverityType.ERROR)
44 .withMessage(String.format(message, args));
45 }
46
47 static Builder warning(String message, Object... args) {
48 return new Builder()
49 .withSeverityType(SeverityType.WARNING)
50 .withMessage(String.format(message, args));
51 }
52
53 static Builder deprecated(String message, Object... args) {
54 return new Builder()
55 .withSeverityType(SeverityType.DEPRECATED)
56 .withMessage(String.format(message, args));
57 }
58
59
60 String getLocation();
61
62 String getMessage();
63
64 SeverityType getSeverityType();
65
66 Exception getException();
67
68
69
70
71 enum SeverityType {
72 ERROR,
73 WARNING,
74 DEPRECATED
75 }
76
77
78
79
80 class Builder {
81
82 private String message;
83 private SeverityType severityType;
84 private Exception exception = null;
85 private String location;
86
87 public Builder withMessage(String message) {
88 this.message = message;
89 return this;
90 }
91
92 public Builder withSeverityType(SeverityType severityType) {
93 this.severityType = severityType;
94 return this;
95 }
96
97 public Builder withLocation(String location) {
98 this.location = location;
99 return this;
100 }
101
102 public Builder withException(Exception exception) {
103 this.exception = exception;
104 return this;
105 }
106
107 public TransformationProblem build() {
108 return new TransformationProblemImpl(message, location, severityType, exception);
109 }
110
111
112
113
114 class TransformationProblemImpl implements TransformationProblem {
115 private String location;
116 private String message;
117 private SeverityType severityType;
118 private Exception exception;
119
120 public TransformationProblemImpl(String message, String location, SeverityType severityType, Exception exception) {
121 this.location = location;
122 this.message = message;
123 this.severityType = severityType;
124 this.exception = exception;
125 }
126
127 @Override
128 public String getLocation() {
129 return this.location;
130 }
131
132 public String getMessage() {
133 return this.message;
134 }
135
136 public SeverityType getSeverityType() {
137 return this.severityType;
138 }
139
140 public Exception getException() {
141 return this.exception;
142 }
143 }
144 }
145
146 }