KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.xml.sax.ErrorHandler JavaDoc;
9
10 /**
11  * Used for configuring user code to
12  * respond to statements and other events
13  * detected in input file.
14  * @author Jeremy J. Carroll
15  *
16  */

17 public class ARPHandlers implements Cloneable JavaDoc {
18     private ErrorHandler JavaDoc errorHandler = new DefaultErrorHandler();
19     private ExtendedHandler scopeHandler = nullScopeHandler;
20     private StatementHandler statementHandler = new StatementHandler() {
21             public void statement(AResource s, AResource p, AResource o) {
22             }
23             public void statement(AResource s, AResource p, ALiteral o) {
24             }
25         };
26     private NamespaceHandler nameHandler = new NamespaceHandler() {
27             
28                     public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri) {
29                         
30                     }
31             
32                     public void endPrefixMapping(String JavaDoc prefix) {
33                         
34                     }
35                 };
36
37     ARPHandlers copy() {
38         try {
39           return (ARPHandlers)clone();
40         }
41         catch (CloneNotSupportedException JavaDoc e){
42             throw new java.lang.RuntimeException JavaDoc(e);
43         }
44     }
45
46     /** Sets the ExtendedHandler that provides the callback mechanism
47          * for bnodes as they leave scope, and for the start and end of rdf:RDF
48          * elements.
49      * <p>
50      * See note about large files in class documentation.
51          * @param sh The handler to use.
52          * @return The old handler.
53          */

54     public ExtendedHandler setExtendedHandler(ExtendedHandler sh) {
55         ExtendedHandler old = scopeHandler;
56         scopeHandler = sh;
57         return old;
58     }
59
60     /** Sets the NamespaceHandler that provides the callback mechanism
61     * for XML namespace declarations.
62     * @param sh The handler to use.
63     * @return The old handler.
64     */

65     public NamespaceHandler setNamespaceHandler(NamespaceHandler sh) {
66         NamespaceHandler old = nameHandler;
67         nameHandler = sh;
68         return old;
69     }
70
71     /** Sets the StatementHandler that provides the callback mechanism
72      * for each triple in the file.
73      * @param sh The statement handler to use.
74      * @return The old statement handler.
75      */

76     public StatementHandler setStatementHandler(StatementHandler sh) {
77         StatementHandler old = statementHandler;
78         statementHandler = sh;
79         return old;
80     }
81
82     final static ExtendedHandler nullScopeHandler = new ExtendedHandler() {
83     
84             public void endBNodeScope(AResource bnode) {
85             }
86     
87             public void startRDF() {
88             }
89     
90             public void endRDF() {
91             }
92     
93             public boolean discardNodesWithNodeID() {
94                 return true;
95             }
96         };
97
98     /** Sets the error handler, for both XML and RDF parse errors.
99      * XML errors are reported by Xerces, as instances of
100      * SAXParseException;
101      * the RDF errors are reported from ARP as instances of
102      * ParseException.
103      * Code that needs to distingusih between them
104      * may look like:
105      * <pre>
106      * void error( SAXParseException e ) throws SAXException {
107      * if ( e instanceof com.hp.hpl.jena.rdf.arp.ParseException ) {
108      * ...
109      * } else {
110      * ...
111      * }
112      * }
113      * </pre>
114      * <p>
115      * See the ARP documentation for ErrorHandler for details of
116      * the ErrorHandler semantics (in particular how to upgrade a warning to
117      * an error, and an error to a fatalError).
118      * </p>
119      * <p>
120      * The Xerces/SAX documentation for ErrorHandler is available on the web.
121      * </p>
122      *
123      * @param eh The error handler to use.
124      * @return The previous error handler.
125      */

126     public ErrorHandler JavaDoc setErrorHandler(ErrorHandler JavaDoc eh) {
127         ErrorHandler JavaDoc old = errorHandler;
128         errorHandler = eh;
129         return old;
130     }
131
132     /**
133      * @return Returns the error handler.
134      */

135     ErrorHandler JavaDoc getErrorHandler() {
136         return errorHandler;
137     }
138     /**
139      * @return Returns the namespace handler.
140      */

141     NamespaceHandler getNamespaceHandler() {
142         return nameHandler;
143     }
144     /**
145      * @return Returns the extended handler.
146      */

147     ExtendedHandler getExtendedHandler() {
148         return scopeHandler;
149     }
150     /**
151      * @return Returns the extended handler.
152      */

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

187  
188
Popular Tags