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 String getLocation();
54
55 String getMessage();
56
57 SeverityType getSeverityType();
58
59 Exception getException();
60
61
62
63
64 enum SeverityType {
65 ERROR,
66 WARNING
67 }
68
69
70
71
72 class Builder {
73
74 private String message;
75 private SeverityType severityType;
76 private Exception exception = null;
77 private String location;
78
79 public Builder withMessage(String message) {
80 this.message = message;
81 return this;
82 }
83
84 public Builder withSeverityType(SeverityType severityType) {
85 this.severityType = severityType;
86 return this;
87 }
88
89 public Builder withLocation(String location) {
90 this.location = location;
91 return this;
92 }
93
94 public Builder withException(Exception exception) {
95 this.exception = exception;
96 return this;
97 }
98
99 public TransformationProblem build() {
100 return new TransformationProblemImpl(message, location, severityType, exception);
101 }
102
103
104
105
106 class TransformationProblemImpl implements TransformationProblem {
107 private String location;
108 private String message;
109 private SeverityType severityType;
110 private Exception exception;
111
112 public TransformationProblemImpl(String message, String location, SeverityType severityType, Exception exception) {
113 this.location = location;
114 this.message = message;
115 this.severityType = severityType;
116 this.exception = exception;
117 }
118
119 @Override
120 public String getLocation() {
121 return this.location;
122 }
123
124 public String getMessage() {
125 return this.message;
126 }
127
128 public SeverityType getSeverityType() {
129 return this.severityType;
130 }
131
132 public Exception getException() {
133 return this.exception;
134 }
135 }
136 }
137
138 }