KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > StandardValidityReport


1 /******************************************************************
2  * File: StandardValidityReport.java
3  * Created by: Dave Reynolds
4  * Created on: 09-Feb-03
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: StandardValidityReport.java,v 1.10 2005/02/21 12:16:16 andy_seaborne Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.reasoner;
11
12 import java.util.*;
13
14 /**
15  * Default implementation of ValidityReport which simply stores a list
16  * of precomputed Report records.
17  *
18  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
19  * @version $Revision: 1.10 $ on $Date: 2005/02/21 12:16:16 $
20  */

21 public class StandardValidityReport implements ValidityReport {
22
23     /** The total set of error reports */
24     protected List reports = new ArrayList();
25     
26     /** Flag to indicate if there are any error reports so far */
27     protected boolean isError;
28     
29     /**
30      * Add a new error report
31      * @param error true if the report is an error, false if it is just a warning
32      * @param type a string giving a reasoner-dependent classification for the report
33      * @param description a textual description of the problem
34      */

35     public void add(boolean error, String JavaDoc type, String JavaDoc description) {
36         add(error, type, description, null);
37     }
38     
39     /**
40      * Add a new error report
41      * @param error true if the report is an error, false if it is just a warning
42      * @param type a string giving a reasoner-dependent classification for the report
43      * @param description a textual description of the problem
44      * @param extension Optional argument with extension data about the reported error
45      */

46     public void add(boolean error, String JavaDoc type, String JavaDoc description, Object JavaDoc extension) {
47         reports.add(new Report(error, type, description, extension));
48         if (error) {
49             isError = true;
50         }
51     }
52     
53     /**
54      * Add a new error report
55      * @param report a ValidityReport.Report to add, can be null
56      */

57     public void add(ValidityReport.Report report) {
58         if (report == null) return;
59         reports.add(report);
60         if (report.isError) {
61             isError = true;
62         }
63     }
64     
65     
66     /**
67      * Returns true if no logical inconsistencies were detected (in which case
68      * there will be at least one error Report included). Warnings may still
69      * be present. As of Jena 2.2 we regard classes which can't be instantiated
70      * as warnings rather than errors.
71      */

72     public boolean isValid() {
73         return !isError;
74     }
75     
76     /**
77      * Returns true if the model is both valid (logically consistent) and no
78      * warnings were generated.
79      */

80     public boolean isClean() {
81         return reports.isEmpty();
82     }
83     
84     /**
85      * Return a count of the number of warning or error reports
86      * generated by the validation.
87      */

88     public int size() {
89         return reports.size();
90     }
91     
92     
93     /**
94      * Return an iterator over the separate ValidityReport.Report records.
95      */

96     public Iterator getReports() {
97         return reports.iterator();
98     }
99
100
101 }
102
103 /*
104  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
105  * All rights reserved.
106  *
107  * Redistribution and use in source and binary forms, with or without
108  * modification, are permitted provided that the following conditions
109  * are met:
110  * 1. Redistributions of source code must retain the above copyright
111  * notice, this list of conditions and the following disclaimer.
112  * 2. Redistributions in binary form must reproduce the above copyright
113  * notice, this list of conditions and the following disclaimer in the
114  * documentation and/or other materials provided with the distribution.
115  * 3. The name of the author may not be used to endorse or promote products
116  * derived from this software without specific prior written permission.
117  *
118  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
119  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
120  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
121  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
122  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
123  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
124  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
125  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
126  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
127  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
128  */

129
130
Popular Tags