001 /***************************************************************************/
002 /* Copyright (C) 2010-2011, Sebastian Hellmann */
003 /* Note: If you need parts of NLP2RDF in another licence due to licence */
004 /* incompatibility, please mail hellmann@informatik.uni-leipzig.de */
005 /* */
006 /* This file is part of NLP2RDF. */
007 /* */
008 /* NLP2RDF is free software; you can redistribute it and/or modify */
009 /* it under the terms of the GNU General Public License as published by */
010 /* the Free Software Foundation; either version 3 of the License, or */
011 /* (at your option) any later version. */
012 /* */
013 /* NLP2RDF is distributed in the hope that it will be useful, */
014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
016 /* GNU General Public License for more details. */
017 /* */
018 /* You should have received a copy of the GNU General Public License */
019 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
020 /***************************************************************************/
021
022 package org.nlp2rdf.core;
023
024 import com.hp.hpl.jena.ontology.OntModel;
025 import eu.lod2.nlp2rdf.schema.error.*;
026 import eu.lod2.nlp2rdf.schema.error.Error;
027
028 /**
029 * @author Sebastian Hellmann
030 * Date: 11/18/11
031 */
032 public class ErrorHandling {
033
034 private static ErrorHandling errorHandling = new ErrorHandling();
035
036 private int counter = 0;
037
038 /**
039 * writes an error into the model with the given message
040 * source is not added, please add it yourself
041 * Note that the error is already written to model.
042 * The URI was generated by prefix+"error"+counter
043 * where counter is increased everytime the method is called.
044 *
045 * @param fatal if true the :fatal "1"^^xsd:boolean is added else "0"
046 * @param prefix used to create the URI
047 * @param message
048 * @param model
049 * @return the error object
050 */
051 public static eu.lod2.nlp2rdf.schema.error.Error createError(boolean fatal, String prefix, String message, OntModel model) {
052 model.setNsPrefix("error", "http://nlp2rdf.lod2.eu/schema/error/");
053 String filler = "";
054 if (!(prefix.endsWith("/") || prefix.endsWith("#"))) {
055 filler = "/";
056 }
057 Error e = Error.create(prefix + filler + "error" + errorHandling.getCounter(), model);
058
059 e.setFatal(fatal);
060 e.addMessage(message);
061 return e;
062 }
063
064 private synchronized int getCounter() {
065 return counter++;
066 }
067
068 }