01: /*
02: * Copyright 2006 Dan Shellman
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.iscreen.impl.xml;
17:
18: import org.iscreen.ConfigurationException;
19:
20: /**
21: * This runtime exception is specifically for XML configuration issues.
22: *
23: * @author Shellman, Dan
24: */
25: public class XmlConfigurationException extends ConfigurationException {
26: public XmlConfigurationException(String message) {
27: super (message);
28: } //end XmlConfigurationException()
29:
30: public XmlConfigurationException(String message, Throwable t) {
31: super (message, t);
32: } //end XmlConfigurationException()
33:
34: public XmlConfigurationException(PositionContext position,
35: String expectation, String found) {
36: super (generateMessage(position, expectation, found));
37: } //end XmlConfigurationException()
38:
39: public XmlConfigurationException(PositionContext position,
40: String expectation, String found, Throwable t) {
41: super (generateMessage(position, expectation, found), t);
42: } //end XmlConfigurationException()
43:
44: // ***
45: // Protected methods
46: // ***
47:
48: /**
49: * Generates an error message based upon the passed-in parameters.
50: *
51: * @param position The location of the error in the XML file.
52: * @param expectation The expected results.
53: * @param found The error found.
54: *
55: * @return Returns a message representing the error.
56: */
57: protected static String generateMessage(PositionContext position,
58: String expectation, String found) {
59: StringBuffer buf = new StringBuffer();
60:
61: buf.append("An error occurred parsing the XML located at ");
62: buf.append(position.getFileLocation());
63: buf.append(". The location within the file is at ");
64: buf.append(position.getLocation());
65: buf.append(".");
66:
67: //Append the "expected" message.
68: if (expectation != null && !expectation.trim().equals("")) {
69: buf.append(" The following was expected: ");
70: buf.append(expectation);
71: buf.append(".");
72: }
73:
74: //Append the "found" message.
75: if (found != null && !found.trim().equals("")) {
76: buf
77: .append(" The following was found that was in error: ");
78: buf.append(found);
79: buf.append(".");
80: }
81:
82: return buf.toString();
83: }
84: } //end XmlConfigurationException
|