Source Code Cross Referenced for ErrorHandlerWrapper.java in  » XML » xerces-2_9_1 » org » apache » xerces » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML » xerces 2_9_1 » org.apache.xerces.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.xerces.util;
019:
020:        import org.apache.xerces.xni.XMLLocator;
021:        import org.apache.xerces.xni.XNIException;
022:        import org.apache.xerces.xni.parser.XMLErrorHandler;
023:        import org.apache.xerces.xni.parser.XMLParseException;
024:        import org.xml.sax.ErrorHandler;
025:        import org.xml.sax.SAXException;
026:        import org.xml.sax.SAXParseException;
027:
028:        /**
029:         * This class wraps a SAX error handler in an XNI error handler.
030:         *
031:         * @see ErrorHandler
032:         *
033:         * @author Andy Clark, IBM
034:         * 
035:         * @version $Id: ErrorHandlerWrapper.java 447241 2006-09-18 05:12:57Z mrglavas $
036:         */
037:        public class ErrorHandlerWrapper implements  XMLErrorHandler {
038:
039:            //
040:            // Data
041:            //
042:
043:            /** The SAX error handler. */
044:            protected ErrorHandler fErrorHandler;
045:
046:            //
047:            // Constructors
048:            //
049:
050:            /** Default constructor. */
051:            public ErrorHandlerWrapper() {
052:            }
053:
054:            /** Wraps the specified SAX error handler. */
055:            public ErrorHandlerWrapper(ErrorHandler errorHandler) {
056:                setErrorHandler(errorHandler);
057:            } // <init>(ErrorHandler)
058:
059:            //
060:            // Public methods
061:            //
062:
063:            /** Sets the SAX error handler. */
064:            public void setErrorHandler(ErrorHandler errorHandler) {
065:                fErrorHandler = errorHandler;
066:            } // setErrorHandler(ErrorHandler)
067:
068:            /** Returns the SAX error handler. */
069:            public ErrorHandler getErrorHandler() {
070:                return fErrorHandler;
071:            } // getErrorHandler():ErrorHandler
072:
073:            //
074:            // XMLErrorHandler methods
075:            //
076:
077:            /**
078:             * Reports a warning. Warnings are non-fatal and can be safely ignored
079:             * by most applications.
080:             *
081:             * @param domain    The domain of the warning. The domain can be any
082:             *                  string but is suggested to be a valid URI. The
083:             *                  domain can be used to conveniently specify a web
084:             *                  site location of the relevent specification or
085:             *                  document pertaining to this warning.
086:             * @param key       The warning key. This key can be any string and
087:             *                  is implementation dependent.
088:             * @param exception Exception.
089:             *
090:             * @throws XNIException Thrown to signal that the parser should stop
091:             *                      parsing the document.
092:             */
093:            public void warning(String domain, String key,
094:                    XMLParseException exception) throws XNIException {
095:
096:                if (fErrorHandler != null) {
097:                    SAXParseException saxException = createSAXParseException(exception);
098:
099:                    try {
100:                        fErrorHandler.warning(saxException);
101:                    } catch (SAXParseException e) {
102:                        throw createXMLParseException(e);
103:                    } catch (SAXException e) {
104:                        throw createXNIException(e);
105:                    }
106:                }
107:
108:            } // warning(String,String,XMLParseException)
109:
110:            /**
111:             * Reports an error. Errors are non-fatal and usually signify that the
112:             * document is invalid with respect to its grammar(s).
113:             *
114:             * @param domain    The domain of the error. The domain can be any
115:             *                  string but is suggested to be a valid URI. The
116:             *                  domain can be used to conveniently specify a web
117:             *                  site location of the relevent specification or
118:             *                  document pertaining to this error.
119:             * @param key       The error key. This key can be any string and
120:             *                  is implementation dependent.
121:             * @param exception Exception.
122:             *
123:             * @throws XNIException Thrown to signal that the parser should stop
124:             *                      parsing the document.
125:             */
126:            public void error(String domain, String key,
127:                    XMLParseException exception) throws XNIException {
128:
129:                if (fErrorHandler != null) {
130:                    SAXParseException saxException = createSAXParseException(exception);
131:
132:                    try {
133:                        fErrorHandler.error(saxException);
134:                    } catch (SAXParseException e) {
135:                        throw createXMLParseException(e);
136:                    } catch (SAXException e) {
137:                        throw createXNIException(e);
138:                    }
139:                }
140:
141:            } // error(String,String,XMLParseException)
142:
143:            /**
144:             * Report a fatal error. Fatal errors usually occur when the document
145:             * is not well-formed and signifies that the parser cannot continue
146:             * normal operation.
147:             * <p>
148:             * <strong>Note:</strong> The error handler should <em>always</em>
149:             * throw an <code>XNIException</code> from this method. This exception
150:             * can either be the same exception that is passed as a parameter to
151:             * the method or a new XNI exception object. If the registered error
152:             * handler fails to throw an exception, the continuing operation of
153:             * the parser is undetermined.
154:             *
155:             * @param domain    The domain of the fatal error. The domain can be 
156:             *                  any string but is suggested to be a valid URI. The
157:             *                  domain can be used to conveniently specify a web
158:             *                  site location of the relevent specification or
159:             *                  document pertaining to this fatal error.
160:             * @param key       The fatal error key. This key can be any string 
161:             *                  and is implementation dependent.
162:             * @param exception Exception.
163:             *
164:             * @throws XNIException Thrown to signal that the parser should stop
165:             *                      parsing the document.
166:             */
167:            public void fatalError(String domain, String key,
168:                    XMLParseException exception) throws XNIException {
169:
170:                if (fErrorHandler != null) {
171:                    SAXParseException saxException = createSAXParseException(exception);
172:
173:                    try {
174:                        fErrorHandler.fatalError(saxException);
175:                    } catch (SAXParseException e) {
176:                        throw createXMLParseException(e);
177:                    } catch (SAXException e) {
178:                        throw createXNIException(e);
179:                    }
180:                }
181:
182:            } // fatalError(String,String,XMLParseException)
183:
184:            //
185:            // Protected methods
186:            //
187:
188:            /** Creates a SAXParseException from an XMLParseException. */
189:            protected static SAXParseException createSAXParseException(
190:                    XMLParseException exception) {
191:                return new SAXParseException(exception.getMessage(), exception
192:                        .getPublicId(), exception.getExpandedSystemId(),
193:                        exception.getLineNumber(), exception.getColumnNumber(),
194:                        exception.getException());
195:            } // createSAXParseException(XMLParseException):SAXParseException
196:
197:            /** Creates an XMLParseException from a SAXParseException. */
198:            protected static XMLParseException createXMLParseException(
199:                    SAXParseException exception) {
200:                final String fPublicId = exception.getPublicId();
201:                final String fExpandedSystemId = exception.getSystemId();
202:                final int fLineNumber = exception.getLineNumber();
203:                final int fColumnNumber = exception.getColumnNumber();
204:                XMLLocator location = new XMLLocator() {
205:                    public String getPublicId() {
206:                        return fPublicId;
207:                    }
208:
209:                    public String getExpandedSystemId() {
210:                        return fExpandedSystemId;
211:                    }
212:
213:                    public String getBaseSystemId() {
214:                        return null;
215:                    }
216:
217:                    public String getLiteralSystemId() {
218:                        return null;
219:                    }
220:
221:                    public int getColumnNumber() {
222:                        return fColumnNumber;
223:                    }
224:
225:                    public int getLineNumber() {
226:                        return fLineNumber;
227:                    }
228:
229:                    public int getCharacterOffset() {
230:                        return -1;
231:                    }
232:
233:                    public String getEncoding() {
234:                        return null;
235:                    }
236:
237:                    public String getXMLVersion() {
238:                        return null;
239:                    }
240:                };
241:                return new XMLParseException(location, exception.getMessage(),
242:                        exception);
243:            } // createXMLParseException(SAXParseException):XMLParseException
244:
245:            /** Creates an XNIException from a SAXException. 
246:                NOTE:  care should be taken *not* to call this with a SAXParseException; this will
247:                lose information!!! */
248:            protected static XNIException createXNIException(
249:                    SAXException exception) {
250:                return new XNIException(exception.getMessage(), exception);
251:            } // createXNIException(SAXException):XMLParseException
252:        } // class ErrorHandlerWrapper
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.