1 /* 2 wsmo4j - a WSMO API and Reference Implementation 3 Copyright (c) 2005, University of Innsbruck, Austria 4 This library is free software; you can redistribute it and/or modify it under 5 the terms of the GNU Lesser General Public License as published by the Free 6 Software Foundation; either version 2.1 of the License, or (at your option) 7 any later version. 8 This library is distributed in the hope that it will be useful, but WITHOUT 9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 10 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 11 details. 12 You should have received a copy of the GNU Lesser General Public License along 13 with this library; if not, write to the Free Software Foundation, Inc., 14 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15 */ 16 package org.deri.wsmo4j.io.parser.rdf; 17 18 import java.util.List; 19 20 import org.openrdf.model.Statement; 21 import org.openrdf.rio.ParseErrorListener; 22 23 /** 24 * Implementation of an interface defining methods 25 * for receiving warning and error messages from an RDF parser. 26 * 27 * <pre> 28 * Created on May 02, 2006 29 * Committed by $Author: morcen $ 30 * $Source$ 31 * </pre> 32 * 33 * @author nathalie.steinmetz@deri.org 34 * @version $Revision: 1946 $ $Date: 2007-04-02 15:13:28 +0300 (Mon, 02 Apr 2007) $ 35 */ 36 public class RDFParseErrorListener implements ParseErrorListener{ 37 38 private List <RDFParserWarning> warnings = null; 39 40 private List <RDFParserError> errors = null; 41 42 public RDFParseErrorListener(List <RDFParserWarning> warnings, List <RDFParserError> errors) { 43 this.warnings = warnings; 44 this.errors = errors; 45 } 46 47 /** 48 * All warnings that occur during the parsing or the transformation 49 * to a WSMO object model are collected in a List of warnings. 50 * 51 * @param msg warning message 52 * @param lineNo a line number related to the warning, or -1 if not available or applicable 53 * @param colNo a column number related to the warning, or -1 if not available or applicable 54 * @see org.openrdf.rio.ParseErrorListener#warning(java.lang.String, int, int) 55 * @see RDFParseErrorListener#warning(String msg, int lineNo, int colNo, Statement statement) 56 */ 57 public void warning(String msg, int lineNo, int colNo) { 58 warning(msg, lineNo, colNo, null); 59 } 60 61 /** 62 * All warnings that occur during the parsing or the transformation 63 * to a WSMO object model are collected in a List of warnings. All statements that 64 * are concerned by one type of warning are put into a Set of triples belonging 65 * to this warning. 66 * 67 * @param msg warning message 68 * @param lineNo a line number related to the warning, or -1 if not available or applicable 69 * @param colNo a column number related to the warning, or -1 if not available or applicable 70 * @param statement the RDF triple that is concerned by this warning 71 */ 72 public void warning(String msg, int lineNo, int colNo, Statement statement) { 73 RDFParserWarning w = new RDFParserWarning(msg, lineNo, colNo); 74 if (!warnings.contains(w)) { 75 warnings.add(w); 76 } 77 if (statement != null) { 78 w = warnings.get(warnings.indexOf(w)); 79 w.addToTriples(statement); 80 } 81 } 82 83 /** 84 * All errors that occur during the parsing or the transformation 85 * to a WSMO object model are collected in a List of erros. 86 * 87 * @param msg error message 88 * @param lineNo a line number related to the error, or -1 if not available or applicable 89 * @param colNo a column number related to the error, or -1 if not available or applicable 90 * @see org.openrdf.rio.ParseErrorListener#error(java.lang.String, int, int) 91 */ 92 public void error(String msg, int lineNo, int colNo) { 93 RDFParserError e = new RDFParserError(msg, lineNo, colNo); 94 if (!errors.contains(e)) { 95 errors.add(e); 96 } 97 } 98 99 /** 100 * 101 * @param msg fatal error message 102 * @param lineNo a line number related to the fatalError, or -1 if not available or applicable 103 * @param colNo a column number related to the fatalError, or -1 if not available or applicable 104 * @see org.openrdf.rio.ParseErrorListener#fatalError(java.lang.String, int, int) 105 */ 106 public void fatalError(String msg, int lineNo, int colNo) { 107 RDFParserError e = new RDFParserError(msg, lineNo, colNo); 108 if (!errors.contains(e)) { 109 errors.add(e); 110 } 111 } 112 113 } 114 /* 115 * $Log$ 116 * Revision 1.3 2007/04/02 12:13:23 morcen 117 * Generics support added to wsmo-api, wsmo4j and wsmo-test 118 * 119 * Revision 1.2 2006/11/16 09:53:28 nathaliest 120 * added RDFParserError 121 * 122 * Revision 1.1 2006/05/03 13:32:49 nathaliest 123 * adding RDF parser 124 * 125 * 126 */