1 package org.apache.maven.settings.building;
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 public class DefaultSettingsProblem
30 implements SettingsProblem
31 {
32
33 private final String source;
34
35 private final int lineNumber;
36
37 private final int columnNumber;
38
39 private final String message;
40
41 private final Exception exception;
42
43 private final Severity severity;
44
45
46
47
48
49
50
51
52
53
54
55
56 public DefaultSettingsProblem( String message, Severity severity, String source, int lineNumber, int columnNumber,
57 Exception exception )
58 {
59 this.message = message;
60 this.severity = ( severity != null ) ? severity : Severity.ERROR;
61 this.source = ( source != null ) ? source : "";
62 this.lineNumber = lineNumber;
63 this.columnNumber = columnNumber;
64 this.exception = exception;
65 }
66
67 @Override
68 public String getSource()
69 {
70 return source;
71 }
72
73 @Override
74 public int getLineNumber()
75 {
76 return lineNumber;
77 }
78
79 @Override
80 public int getColumnNumber()
81 {
82 return columnNumber;
83 }
84
85 @Override
86 public String getLocation()
87 {
88 StringBuilder buffer = new StringBuilder( 256 );
89
90 if ( getSource().length() > 0 )
91 {
92 if ( buffer.length() > 0 )
93 {
94 buffer.append( ", " );
95 }
96 buffer.append( getSource() );
97 }
98
99 if ( getLineNumber() > 0 )
100 {
101 if ( buffer.length() > 0 )
102 {
103 buffer.append( ", " );
104 }
105 buffer.append( "line " ).append( getLineNumber() );
106 }
107
108 if ( getColumnNumber() > 0 )
109 {
110 if ( buffer.length() > 0 )
111 {
112 buffer.append( ", " );
113 }
114 buffer.append( "column " ).append( getColumnNumber() );
115 }
116
117 return buffer.toString();
118 }
119
120 @Override
121 public Exception getException()
122 {
123 return exception;
124 }
125
126 @Override
127 public String getMessage()
128 {
129 String msg;
130
131 if ( message != null && message.length() > 0 )
132 {
133 msg = message;
134 }
135 else
136 {
137 msg = exception.getMessage();
138
139 if ( msg == null )
140 {
141 msg = "";
142 }
143 }
144
145 return msg;
146 }
147
148 @Override
149 public Severity getSeverity()
150 {
151 return severity;
152 }
153
154 @Override
155 public String toString()
156 {
157 StringBuilder buffer = new StringBuilder( 128 );
158
159 buffer.append( "[" ).append( getSeverity() ).append( "] " );
160 buffer.append( getMessage() );
161 buffer.append( " @ " ).append( getLocation() );
162
163 return buffer.toString();
164 }
165
166 }