001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.internal.xjc.reader.xmlschema;
027:
028: import com.sun.tools.internal.xjc.ErrorReceiver;
029: import com.sun.tools.internal.xjc.reader.Ring;
030:
031: import org.xml.sax.ErrorHandler;
032: import org.xml.sax.Locator;
033: import org.xml.sax.SAXParseException;
034:
035: /**
036: * Provides error report capability to other owner components
037: * by encapsulating user-specified {@link ErrorHandler}
038: * and exposing utlity methods.
039: *
040: * <p>
041: * This class also wraps SAXException to a RuntimeException
042: * so that the exception thrown inside the error handler
043: * can abort the process.
044: *
045: * <p>
046: * At the end of the day, we need to know if there was any error.
047: * So it is important that all the error messages go through this
048: * object. This is done by hiding the errorHandler from the rest
049: * of the components.
050: *
051: * @author
052: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
053: */
054: public final class ErrorReporter extends BindingComponent {
055:
056: /**
057: * Error handler to report any binding error to.
058: * To report errors, use the error method.
059: */
060: private final ErrorReceiver errorReceiver = Ring
061: .get(ErrorReceiver.class);
062:
063: //
064: // helper methods for classes in this package.
065: // properties are localized through the Messages.properties file
066: // in this package
067: //
068: void error(Locator loc, String prop, Object... args) {
069: errorReceiver.error(loc, Messages.format(prop, args));
070: }
071:
072: void warning(Locator loc, String prop, Object... args) {
073: errorReceiver.warning(new SAXParseException(Messages.format(
074: prop, args), loc));
075: }
076:
077: /*
078: private String format( String prop, Object[] args ) {
079: // use a bit verbose code to make it portable.
080: String className = this.getClass().getName();
081: int idx = className.lastIndexOf('.');
082: String packageName = className.substring(0,idx);
083:
084: String fmt = ResourceBundle.getBundle(packageName+".Messages").getString(prop);
085:
086: return MessageFormat.format(fmt,args);
087: }
088: */
089:
090: ////
091: ////
092: //// ErrorHandler implementation
093: ////
094: ////
095: // public void error(SAXParseException exception) {
096: // errorReceiver.error(exception);
097: // }
098: //
099: // public void fatalError(SAXParseException exception) {
100: // errorReceiver.fatalError(exception);
101: // }
102: //
103: // public void warning(SAXParseException exception) {
104: // errorReceiver.warning(exception);
105: // }
106: }
|