KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > arp > ARPOptions


1 /*
2  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 package com.hp.hpl.jena.rdf.arp;
7
8
9 /**
10  * Configure error reporting options etc on
11  * {@link ARP}, {@link SAX2RDF} and {@link SAX2Model}
12  * instances.
13  * @author Jeremy J. Carroll
14  *
15  */

16 public class ARPOptions implements ARPErrorNumbers {
17     private static int defaultErrorMode[] = new int[400];
18     private boolean embedding = false;
19
20     ARPOptions copy() {
21         ARPOptions rslt = new ARPOptions();
22         rslt.errorMode = (int[])errorMode.clone() ;
23         rslt.embedding = embedding;
24         return rslt;
25     }
26     static {
27         for (int i = 0; i < defaultErrorMode.length; i++)
28             defaultErrorMode[i] = i / 100;
29     }
30     private int errorMode[] = (int[]) defaultErrorMode.clone();
31
32     int getErrorMode()[] {
33             return errorMode;
34     }
35     /** Sets or gets the error handling mode for a specific error condition.
36      * Changes that cannot be honoured are silently ignored.
37      * Illegal error numbers may result in an ArrayIndexOutOfBoundsException but
38      * are usually ignored.
39      * @param errno The specific error condition to change.
40      * @param mode The new mode one of:
41      * <dl>
42      * <dt>IGNORE</dt>
43      * <dd>Ignore this condition.</dd>
44      * <dt>WARNING</dt>
45      * <dt>Invoke ErrorHandler.warning() for this condition.</dd>
46      * <dt>ERROR</dt>
47      * <dt>Invoke ErrorHandler.error() for this condition.</dd>
48      * <dt>FATAL</dt>
49      * <dt>Aborts parse and invokes ErrorHandler.fatalError() for this condition.
50      * In unusual situations, a few further warnings and errors may be reported.
51      * </dd>
52      * </dl>
53      * @return The old error mode for this condition.
54      */

55     public int setErrorMode(int errno, int mode) {
56         int old = errorMode[errno];
57         switch (mode) {
58             case EM_WARNING :
59             case EM_IGNORE :
60                 if (errno >= 100 * EM_ERROR && errno != ERR_NOT_WHITESPACE)
61                     break;
62             case EM_ERROR :
63             case EM_FATAL :
64                 switch (errno) {
65                     //case ERR_UNABLE_TO_RECOVER :
66
// break;
67
default :
68                         errorMode[errno] = mode;
69                 }
70         }
71         return old;
72     }
73
74     /** Resets error mode to the default values:
75      * most errors are reported as warnings, but triples are produced.
76      */

77     public void setDefaultErrorMode() {
78         errorMode = (int[]) defaultErrorMode.clone();
79     }
80
81     /** As many errors as possible are ignored.
82      * As many triples as possible are produced.
83      */

84     public void setLaxErrorMode() {
85         setDefaultErrorMode();
86         for (int i = 100; i < 200; i++)
87             setErrorMode(i, EM_IGNORE);
88         setErrorMode(WARN_MINOR_INTERNAL_ERROR, EM_WARNING);
89     }
90
91     /** This method tries to emulate the latest Working Group recommendations.
92      */

93     public void setStrictErrorMode() {
94         setStrictErrorMode(EM_IGNORE);
95     }
96
97     /**
98      * This method detects and prohibits errors according to
99      *the latest Working Group recommendations.
100      * For other conditions, such as
101      {@link ARPErrorNumbers#WARN_PROCESSING_INSTRUCTION_IN_RDF} and
102      {@link ARPErrorNumbers#WARN_LEGAL_REUSE_OF_ID}, nonErrorMode is used.
103      *@param nonErrorMode The way of treating non-error conditions.
104      */

105     public void setStrictErrorMode(int nonErrorMode) {
106         setDefaultErrorMode();
107         for (int i = 1; i < 100; i++)
108             setErrorMode(i, nonErrorMode);
109         int warning = EM_WARNING;
110         int error = EM_ERROR;
111         switch (nonErrorMode) {
112             case EM_ERROR :
113                 warning = EM_ERROR;
114                 break;
115             case EM_FATAL :
116                 warning = error = EM_FATAL;
117                 break;
118         }
119         for (int i = 100; i < 200; i++)
120             setErrorMode(i, error);
121         // setErrorMode(IGN_XMLBASE_USED,warning);
122
// setErrorMode(IGN_XMLBASE_SIGNIFICANT,error);
123
setErrorMode(WARN_MINOR_INTERNAL_ERROR, warning);
124         setErrorMode(WARN_MINOR_INTERNAL_ERROR, warning);
125         setErrorMode(WARN_DEPRECATED_XMLLANG, warning);
126         setErrorMode(WARN_STRING_NOT_NORMAL_FORM_C, warning);
127         // setErrorMode(WARN_EMPTY_ABOUT_EACH,nonErrorMode);
128
setErrorMode(WARN_UNKNOWN_PARSETYPE, warning);
129         // setErrorMode(WARN_BAD_XML, nonErrorMode);
130
setErrorMode(WARN_PROCESSING_INSTRUCTION_IN_RDF, nonErrorMode);
131 // setErrorMode(WARN_LEGAL_REUSE_OF_ID, nonErrorMode);
132
setErrorMode(WARN_RDF_NN_AS_TYPE, nonErrorMode);
133         setErrorMode(WARN_UNKNOWN_RDF_ELEMENT, warning);
134         setErrorMode(WARN_UNKNOWN_RDF_ATTRIBUTE, warning);
135         setErrorMode(WARN_UNQUALIFIED_RDF_ATTRIBUTE, warning);
136         setErrorMode(WARN_UNKNOWN_XML_ATTRIBUTE, nonErrorMode);
137         // setErrorMode(WARN_QNAME_AS_ID, error);
138
// setErrorMode(WARN_BAD_XML, error);
139
setErrorMode(WARN_SAX_WARNING, warning);
140         setErrorMode(IGN_DAML_COLLECTION, error);
141     }
142
143     /** Sets whether the XML document is only RDF, or contains RDF embedded in other XML.
144      * The default is non-embedded mode.
145      * Embedded mode also matches RDF documents that use the
146      * rdf:RDF tag at the top-level.
147      * Non-embeded mode matches RDF documents which omit that optional tag, and consist of a single rdf:Description or
148      * typed node.
149      * To find embedded RDF it is necessary to setEmbedding(true).
150      * @param embed true: Look for embedded RDF; or false: match a typed node or rdf:Description against the whole document (the default).
151      * @return Previous setting.
152      */

153     public boolean setEmbedding(boolean embed) {
154         boolean old = embedding;
155         embedding = embed;
156         return old;
157     }
158     boolean getEmbedding() {
159         return embedding;
160     }
161
162 }
163
164
165 /*
166  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
167  * All rights reserved.
168  *
169  * Redistribution and use in source and binary forms, with or without
170  * modification, are permitted provided that the following conditions
171  * are met:
172  * 1. Redistributions of source code must retain the above copyright
173  * notice, this list of conditions and the following disclaimer.
174  * 2. Redistributions in binary form must reproduce the above copyright
175  * notice, this list of conditions and the following disclaimer in the
176  * documentation and/or other materials provided with the distribution.
177  * 3. The name of the author may not be used to endorse or promote products
178  * derived from this software without specific prior written permission.
179  *
180  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
181  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
182  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
183  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
184  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
185  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
186  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
187  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
188  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
189  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
190  */

191  
192
Popular Tags