001/* Simply handle MoML Parsing Errors by throwing an Exception. 002 003 Copyright (c) 2012-2014 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 */ 028package ptolemy.moml; 029 030import ptolemy.kernel.util.InternalErrorException; 031import ptolemy.kernel.util.NamedObj; 032 033/////////////////////////////////////////////////////////////////// 034//// SimpleErrorHandler 035 036/** 037 Simple error handler for the MoMLParser class. This error handler reports 038 errors by throwing an exception. 039 040 @see MoMLParser 041 @author Christopher Brooks, based on StreamErrorHandler by Edward A. Lee 042 @version $Id$ 043 @since Ptolemy II 10.0 044 @Pt.ProposedRating Red (cxh) 045 @Pt.AcceptedRating Red (cxh) 046 */ 047public class SimpleErrorHandler implements ErrorHandler { 048 /////////////////////////////////////////////////////////////////// 049 //// constructors //// 050 051 /** Create an error handler that throws an exception. 052 */ 053 public SimpleErrorHandler() { 054 } 055 056 /////////////////////////////////////////////////////////////////// 057 //// public methods //// 058 059 /** Enable or disable skipping of errors. This method does nothing. 060 * @param enable True to enable skipping, false to disable. 061 */ 062 @Override 063 public void enableErrorSkipping(boolean enable) { 064 } 065 066 /** Handle an error by throwing an exception. 067 * @param element The XML element that triggered the error. 068 * @param context The container object for the element. 069 * @param exception The exception that was thrown. 070 * @return Never returns. 071 */ 072 @Override 073 public int handleError(String element, NamedObj context, 074 Throwable exception) { 075 throw new InternalErrorException(context, exception, 076 "Element " + element + " caused an exception to be thrown."); 077 } 078}