1 package org.codehaus.mojo.jaxb2.javageneration;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import com.sun.tools.xjc.XJCListener;
23 import org.apache.maven.plugin.logging.Log;
24 import org.codehaus.mojo.jaxb2.shared.Validate;
25 import org.xml.sax.SAXParseException;
26
27
28
29
30
31
32
33 public class XjcLogAdapter extends XJCListener {
34
35
36 private Log log;
37
38
39
40
41
42
43 public XjcLogAdapter(final Log log) {
44
45
46 Validate.notNull(log, "log");
47
48
49 this.log = log;
50 }
51
52
53
54
55 @Override
56 public void generatedFile(final String fileName, final int current, final int total) {
57 if (log.isDebugEnabled()) {
58 log.debug("Processing file [" + current + "/" + total + "]: " + fileName);
59 }
60 }
61
62
63
64
65 @Override
66 public void error(final SAXParseException exception) {
67 log.error(getLocation(exception), exception);
68 }
69
70
71
72
73 @Override
74 public void fatalError(final SAXParseException exception) {
75 log.error(getLocation(exception), exception);
76 }
77
78
79
80
81 @Override
82 public void warning(final SAXParseException exception) {
83 log.warn(getLocation(exception), exception);
84 }
85
86
87
88
89 @Override
90 public void info(final SAXParseException exception) {
91 log.info(getLocation(exception), exception);
92 }
93
94
95
96
97
98 private String getLocation(final SAXParseException e) {
99
100 final String exceptionId = e.getPublicId() == null ? e.getSystemId() : e.getPublicId();
101 return exceptionId + " [" + e.getLineNumber() + "," + e.getColumnNumber() + "] ";
102 }
103 }