Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
../../../../img/srcFileCovDistChart7.png 62% of files have more coverage
37   188   17   3,08
8   80   0,46   12
12     1,42  
1    
 
  SourceFileException       Line # 33 37 17 66,7% 0.6666667
 
  (30)
 
1    /* $Id: SourceFileException.java,v 1.5 2008/07/26 07:59:40 m31 Exp $
2    *
3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
4    *
5    * Copyright 2000-2008, Michael Meyling <mime@qedeq.org>.
6    *
7    * "Hilbert II" is free software; you can redistribute
8    * it and/or modify it under the terms of the GNU General Public
9    * License as published by the Free Software Foundation; either
10    * version 2 of the License, or (at your option) any later version.
11    *
12    * This program is distributed in the hope that it will be useful,
13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    * GNU General Public License for more details.
16    */
17   
18    package org.qedeq.kernel.common;
19   
20    import java.io.File;
21    import java.io.IOException;
22    import java.net.URL;
23   
24    import org.qedeq.base.io.IoUtility;
25   
26   
27    /**
28    * Data validation error. Shows an error within a source file.
29    *
30    * @version $Revision: 1.5 $
31    * @author Michael Meyling
32    */
 
33    public class SourceFileException extends QedeqException {
34   
35    /** Serialization information. */
36    private static final long serialVersionUID = -4109767904038020052L;
37   
38    /** Start of error location. */
39    private final SourceArea errorArea;
40   
41    /** End of error location. */
42    private final SourceArea referenceArea;
43   
44    /**
45    * Constructor.
46    *
47    * @param errorCode Error code.
48    * @param errorText Error text.
49    * @param exception Exception to wrap.
50    * @param errorArea Error location.
51    * @param referenceArea Error reference location.
52    */
 
53  149 toggle public SourceFileException(final int errorCode, final String errorText,
54    final Throwable exception, final SourceArea errorArea, final SourceArea referenceArea) {
55  149 super(errorCode, errorText, exception);
56  149 this.errorArea = errorArea;
57  149 this.referenceArea = referenceArea;
58    }
59   
60   
61    /**
62    * Constructor.
63    *
64    * @param exception Exception to wrap.
65    * @param errorArea Error location.
66    * @param referenceArea Error reference location.
67    */
 
68  131 toggle public SourceFileException(final QedeqException exception, final SourceArea errorArea,
69    final SourceArea referenceArea) {
70  131 this(exception.getErrorCode(), exception.getMessage(), exception, errorArea, referenceArea);
71    }
72   
73   
74    /**
75    * Constructor.
76    *
77    * @param url Parsed file.
78    * @param exception Exception to wrap.
79    */
 
80  0 toggle public SourceFileException(final URL url, final Exception exception) {
81  0 super(9997, exception.toString(), exception); // TODO mime 20071116: error code refac
82  0 errorArea = new SourceArea(url, new SourcePosition(url, 1, 1),
83    new SourcePosition(url, 1, 1));
84  0 referenceArea = null;
85    }
86   
87    /**
88    * Constructor.
89    *
90    * @param file Parsed file.
91    * @param exception Exception to wrap.
92    * @deprecated use URL
93    */
 
94  0 toggle public SourceFileException(final File file, final Exception exception) {
95  0 super(9998, exception.getMessage(), exception); // TODO mime 20071116: error code refac
96  0 final URL url = IoUtility.toUrl(file);
97  0 errorArea = new SourceArea(url, new SourcePosition(url, 1, 1),
98    new SourcePosition(url, 1, 1));
99  0 referenceArea = null;
100    }
101   
102    /**
103    * Constructor.
104    *
105    * @param exception Exception to wrap.
106    */
 
107  6 toggle public SourceFileException(final Exception exception) {
108  6 super(9999, exception.getMessage(), exception); // TODO mime 20071116: error code refac
109  6 errorArea = null;
110  6 referenceArea = null;
111    }
112   
113    /**
114    * Constructor.
115    *
116    * @param exception Exception to wrap.
117    */
 
118  0 toggle public SourceFileException(final Throwable exception) {
119  0 super(1000, exception.toString(), exception); // TODO mime 20071116: error code refac
120  0 errorArea = null;
121  0 referenceArea = null;
122    }
123   
124    /**
125    * Constructor.
126    *
127    * @param exception Exception to wrap.
128    */
 
129  1 toggle public SourceFileException(final IOException exception) {
130  1 super(9997, exception.toString(), exception); // TODO mime 20071116: error code refac
131  1 errorArea = null;
132  1 referenceArea = null;
133    }
134   
135    /**
136    * Get position information about error location.
137    *
138    * @return Error location position.
139    */
 
140  132 toggle public SourceArea getSourceArea() {
141  132 return errorArea;
142    }
143   
144    /**
145    * Get additional position information about another associated location.
146    *
147    * @return Additional error location position.
148    */
 
149  0 toggle public SourceArea getReferenceArea() {
150  0 return referenceArea;
151    }
152   
 
153  245 toggle public String getMessage() {
154  245 if (getCause() != null) {
155  245 if (getCause() instanceof IOException) {
156  2 return getCause().toString();
157    }
158  243 if (getCause().getCause() != null) {
159  0 return getCause().getCause().getMessage();
160    }
161  243 return getCause().getMessage();
162    }
163  0 return super.getMessage();
164    }
165   
166    /**
167    * Get detailed error description.
168    * The first line contains {@link #getErrorCode()} and {@link #getMessage()}.
169    * The second line contains the local address, the line and column.
170    *
171    * @return Error description.
172    */
 
173  177 toggle public String getDescription() {
174  177 final StringBuffer buffer = new StringBuffer();
175  177 buffer.append(getErrorCode() + ": " + getMessage());
176  177 if (errorArea != null && errorArea.getStartPosition() != null) {
177  176 final SourcePosition start = errorArea.getStartPosition();
178  176 buffer.append("\n");
179  176 buffer.append(errorArea.getAddress() + ":" + start.getLine() + ":"
180    + start.getColumn());
181    }
182  177 return buffer.toString();
183    }
184   
 
185  173 toggle public String toString() {
186  173 return getDescription();
187    }
188    }