KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > util > ErrorHandlerProxy


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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
17 package org.apache.xerces.util;
18
19 import org.apache.xerces.xni.parser.XMLErrorHandler;
20 import org.xml.sax.ErrorHandler JavaDoc;
21 import org.xml.sax.SAXException JavaDoc;
22 import org.xml.sax.SAXParseException JavaDoc;
23
24 /**
25  * Wraps {@link XMLErrorHandler} and make it look like a SAX {@link ErrorHandler}.
26  *
27  * <p>
28  * The derived class should override the {@link #getErrorHandler()} method
29  * so that it will return the correct {@link XMLErrorHandler} instance.
30  * This method will be called whenever an error/warning is found.
31  *
32  * <p>
33  * Experience shows that it is better to store the actual
34  * {@link XMLErrorHandler} in one place and looks up that variable,
35  * rather than copying it into every component that needs an error handler
36  * and update all of them whenever it is changed, IMO.
37  *
38  * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
39  *
40  * @version $Id: ErrorHandlerProxy.java,v 1.3 2005/06/22 03:58:12 mrglavas Exp $
41  */

42 public abstract class ErrorHandlerProxy implements ErrorHandler {
43     
44     public void error(SAXParseException JavaDoc e) throws SAXException JavaDoc {
45         XMLErrorHandler eh = getErrorHandler();
46         if (eh instanceof ErrorHandlerWrapper) {
47             ((ErrorHandlerWrapper)eh).fErrorHandler.error(e);
48         }
49         else {
50             eh.error("","",ErrorHandlerWrapper.createXMLParseException(e));
51         }
52         // if an XNIException is thrown, just let it go.
53
// REVISIT: is this OK? or should we try to wrap it into SAXException?
54
}
55
56     public void fatalError(SAXParseException JavaDoc e) throws SAXException JavaDoc {
57         XMLErrorHandler eh = getErrorHandler();
58         if (eh instanceof ErrorHandlerWrapper) {
59             ((ErrorHandlerWrapper)eh).fErrorHandler.fatalError(e);
60         }
61         else {
62             eh.fatalError("","",ErrorHandlerWrapper.createXMLParseException(e));
63         }
64     }
65
66     public void warning(SAXParseException JavaDoc e) throws SAXException JavaDoc {
67         XMLErrorHandler eh = getErrorHandler();
68         if (eh instanceof ErrorHandlerWrapper) {
69             ((ErrorHandlerWrapper)eh).fErrorHandler.warning(e);
70         }
71         else {
72             eh.warning("","",ErrorHandlerWrapper.createXMLParseException(e));
73         }
74     }
75
76     protected abstract XMLErrorHandler getErrorHandler();
77 }
78
Popular Tags