001: /******************************************************************
002: * File: StandardValidityReport.java
003: * Created by: Dave Reynolds
004: * Created on: 09-Feb-03
005: *
006: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007: * [See end of file]
008: * $Id: StandardValidityReport.java,v 1.13 2008/01/02 12:07:00 andy_seaborne Exp $
009: *****************************************************************/package com.hp.hpl.jena.reasoner;
010:
011: import java.util.*;
012:
013: /**
014: * Default implementation of ValidityReport which simply stores a list
015: * of precomputed Report records.
016: *
017: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
018: * @version $Revision: 1.13 $ on $Date: 2008/01/02 12:07:00 $
019: */
020: public class StandardValidityReport implements ValidityReport {
021:
022: /** The total set of error reports */
023: protected List reports = new ArrayList();
024:
025: /** Flag to indicate if there are any error reports so far */
026: protected boolean isError;
027:
028: /**
029: * Add a new error report
030: * @param error true if the report is an error, false if it is just a warning
031: * @param type a string giving a reasoner-dependent classification for the report
032: * @param description a textual description of the problem
033: */
034: public void add(boolean error, String type, String description) {
035: add(error, type, description, null);
036: }
037:
038: /**
039: * Add a new error report
040: * @param error true if the report is an error, false if it is just a warning
041: * @param type a string giving a reasoner-dependent classification for the report
042: * @param description a textual description of the problem
043: * @param extension Optional argument with extension data about the reported error
044: */
045: public void add(boolean error, String type, String description,
046: Object extension) {
047: reports.add(new Report(error, type, description, extension));
048: if (error) {
049: isError = true;
050: }
051: }
052:
053: /**
054: * Add a new error report
055: * @param report a ValidityReport.Report to add, can be null
056: */
057: public void add(ValidityReport.Report report) {
058: if (report == null)
059: return;
060: reports.add(report);
061: if (report.isError) {
062: isError = true;
063: }
064: }
065:
066: /**
067: * Returns true if no logical inconsistencies were detected (in which case
068: * there will be at least one error Report included). Warnings may still
069: * be present. As of Jena 2.2 we regard classes which can't be instantiated
070: * as warnings rather than errors.
071: */
072: public boolean isValid() {
073: return !isError;
074: }
075:
076: /**
077: * Returns true if the model is both valid (logically consistent) and no
078: * warnings were generated.
079: */
080: public boolean isClean() {
081: return reports.isEmpty();
082: }
083:
084: /**
085: * Return a count of the number of warning or error reports
086: * generated by the validation.
087: */
088: public int size() {
089: return reports.size();
090: }
091:
092: /**
093: * Return an iterator over the separate ValidityReport.Report records.
094: */
095: public Iterator getReports() {
096: return reports.iterator();
097: }
098:
099: }
100:
101: /*
102: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
103: * All rights reserved.
104: *
105: * Redistribution and use in source and binary forms, with or without
106: * modification, are permitted provided that the following conditions
107: * are met:
108: * 1. Redistributions of source code must retain the above copyright
109: * notice, this list of conditions and the following disclaimer.
110: * 2. Redistributions in binary form must reproduce the above copyright
111: * notice, this list of conditions and the following disclaimer in the
112: * documentation and/or other materials provided with the distribution.
113: * 3. The name of the author may not be used to endorse or promote products
114: * derived from this software without specific prior written permission.
115: *
116: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
117: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
118: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
119: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
120: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
121: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
122: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
123: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
124: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
125: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
126: */
|