001/* Handle MoML Parsing Errors 002 003 Copyright (c) 2003-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.test; 029 030import ptolemy.kernel.util.KernelException; 031import ptolemy.kernel.util.NamedObj; 032import ptolemy.moml.ErrorHandler; 033 034/////////////////////////////////////////////////////////////////// 035//// RecorderErrorHandler 036 037/** 038 Record MoML Errors and retrieve them later. 039 040 @see ptolemy.kernel.util.RecorderListener 041 @author Christopher Hylands Brooks 042 @version $Id$ 043 @since Ptolemy II 4.0 044 @Pt.ProposedRating Red (eal) 045 @Pt.AcceptedRating Red (reviewmoderator) 046 */ 047public class RecorderErrorHandler implements ErrorHandler { 048 /////////////////////////////////////////////////////////////////// 049 //// constructors //// 050 051 /** Create an error handler. 052 */ 053 public RecorderErrorHandler() { 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 /** Get the messages recorded so far. 067 * @return The messages. 068 */ 069 public String getMessages() { 070 return _buffer.toString(); 071 } 072 073 /** Handle an error by printing a description of the error to 074 * the stream specified in the constructor. 075 * @param element The XML element that triggered the error. 076 * @param context The container object for the element. 077 * @param exception The exception that was thrown. 078 * @return CONTINUE to request skipping this element. 079 */ 080 @Override 081 public int handleError(String element, NamedObj context, 082 Throwable exception) { 083 _buffer.append("RecorderErrorHandler: Error encountered in:\n" + element 084 + "\n" + KernelException.stackTraceToString(exception)); 085 return CONTINUE; 086 } 087 088 /** Clear the buffer. 089 */ 090 public void reset() { 091 _buffer = new StringBuffer(); 092 } 093 094 /////////////////////////////////////////////////////////////////// 095 //// private variables //// 096 private StringBuffer _buffer = new StringBuffer(); 097}