001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package com.sun.tools.xjc.reader.xmlschema;
037:
038: import com.sun.tools.xjc.ErrorReceiver;
039: import com.sun.tools.xjc.reader.Ring;
040:
041: import org.xml.sax.ErrorHandler;
042: import org.xml.sax.Locator;
043: import org.xml.sax.SAXParseException;
044:
045: /**
046: * Provides error report capability to other owner components
047: * by encapsulating user-specified {@link ErrorHandler}
048: * and exposing utlity methods.
049: *
050: * <p>
051: * This class also wraps SAXException to a RuntimeException
052: * so that the exception thrown inside the error handler
053: * can abort the process.
054: *
055: * <p>
056: * At the end of the day, we need to know if there was any error.
057: * So it is important that all the error messages go through this
058: * object. This is done by hiding the errorHandler from the rest
059: * of the components.
060: *
061: * @author
062: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
063: */
064: public final class ErrorReporter extends BindingComponent {
065:
066: /**
067: * Error handler to report any binding error to.
068: * To report errors, use the error method.
069: */
070: private final ErrorReceiver errorReceiver = Ring
071: .get(ErrorReceiver.class);
072:
073: //
074: // helper methods for classes in this package.
075: // properties are localized through the Messages.properties file
076: // in this package
077: //
078: void error(Locator loc, String prop, Object... args) {
079: errorReceiver.error(loc, Messages.format(prop, args));
080: }
081:
082: void warning(Locator loc, String prop, Object... args) {
083: errorReceiver.warning(new SAXParseException(Messages.format(
084: prop, args), loc));
085: }
086:
087: /*
088: private String format( String prop, Object[] args ) {
089: // use a bit verbose code to make it portable.
090: String className = this.getClass().getName();
091: int idx = className.lastIndexOf('.');
092: String packageName = className.substring(0,idx);
093:
094: String fmt = ResourceBundle.getBundle(packageName+".Messages").getString(prop);
095:
096: return MessageFormat.format(fmt,args);
097: }
098: */
099:
100: ////
101: ////
102: //// ErrorHandler implementation
103: ////
104: ////
105: // public void error(SAXParseException exception) {
106: // errorReceiver.error(exception);
107: // }
108: //
109: // public void fatalError(SAXParseException exception) {
110: // errorReceiver.fatalError(exception);
111: // }
112: //
113: // public void warning(SAXParseException exception) {
114: // errorReceiver.warning(exception);
115: // }
116: }
|