001: /*
002: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * [See end of file]
004: */
005:
006: package com.hp.hpl.jena.rdf.arp;
007:
008: import org.xml.sax.ErrorHandler;
009:
010: import com.hp.hpl.jena.rdf.arp.impl.DefaultErrorHandler;
011: import com.hp.hpl.jena.rdf.arp.impl.XMLHandler;
012:
013: /**
014: * The interface to set the various handlers on ARP. User defined
015: * implementations of this interface are not supported. This is a class rather
016: * than an interface to have better backward compatibilitiy with earlier
017: * versions, however constructing instances of this class is deprecated.
018: *
019: * @author Jeremy J. Carroll
020: *
021: */
022: public class ARPHandlers {
023:
024: /**
025: * Do not use this constructor.
026: * An example of not using this constructor is as follows.
027: * <br/>
028: * Deprecated usage:
029: * <br/>
030: * <pre>
031: ARP arp = new ARP();
032: ARPHandlers handlers = new ARPHandlers();
033: handlers.setStatementHandler(new MyStatementHandler());
034: </pre>
035: <br/>
036: * Preferred code:
037: * <br/>
038: * <pre>
039: ARP arp = new ARP();
040: ARPHandlers handlers = arp.getHandlers();
041: handlers.setStatementHandler(new MyStatementHandler());
042: </pre>
043: *@deprecated Use {@link ARPConfig#getHandlers()}
044: */
045: public ARPHandlers() {
046: }
047:
048: private ErrorHandler errorHandler = new DefaultErrorHandler();
049:
050: private ExtendedHandler scopeHandler = XMLHandler.nullScopeHandler;
051:
052: private StatementHandler statementHandler = XMLHandler.nullStatementHandler;
053:
054: private NamespaceHandler nameHandler = new NamespaceHandler() {
055:
056: public void startPrefixMapping(String prefix, String uri) {
057:
058: }
059:
060: public void endPrefixMapping(String prefix) {
061:
062: }
063: };
064:
065: /**
066: * Sets the ExtendedHandler that provides the callback mechanism for bnodes
067: * as they leave scope, and for the start and end of rdf:RDF elements.
068: * <p>
069: * See note about large files in {@link ARP} class documentation.
070: *
071: * @param sh
072: * The handler to use.
073: * @return The old handler.
074: */
075: public ExtendedHandler setExtendedHandler(ExtendedHandler sh) {
076: ExtendedHandler old = scopeHandler;
077: scopeHandler = sh;
078: return old;
079: }
080:
081: /**
082: * Sets the NamespaceHandler that provides the callback mechanism for XML
083: * namespace declarations.
084: *
085: * @param sh
086: * The handler to use.
087: * @return The old handler.
088: */
089: public NamespaceHandler setNamespaceHandler(NamespaceHandler sh) {
090: NamespaceHandler old = nameHandler;
091: nameHandler = sh;
092: return old;
093: }
094:
095: /**
096: * Sets the StatementHandler that provides the callback mechanism for each
097: * triple in the file.
098: *
099: * @param sh
100: * The statement handler to use.
101: * @return The old statement handler.
102: */
103: public StatementHandler setStatementHandler(StatementHandler sh) {
104: StatementHandler old = statementHandler;
105: statementHandler = sh;
106: return old;
107: }
108:
109: /**
110: * Sets the error handler, for both XML and RDF parse errors. XML errors are
111: * reported by Xerces, as instances of SAXParseException; the RDF errors are
112: * reported from ARP as instances of ParseException. Code that needs to
113: * distingusih between them may look like:
114: *
115: * <pre>
116: * void error( SAXParseException e ) throws SAXException {
117: * if ( e instanceof com.hp.hpl.jena.rdf.arp.ParseException ) {
118: * ...
119: * } else {
120: * ...
121: * }
122: * }
123: * </pre>
124: *
125: * <p>
126: * See the ARP documentation for ErrorHandler for details of the
127: * ErrorHandler semantics (in particular how to upgrade a warning to an
128: * error, and an error to a fatalError).
129: * </p>
130: * <p>
131: * The Xerces/SAX documentation for ErrorHandler is available on the web.
132: * </p>
133: *
134: * @param eh
135: * The error handler to use.
136: * @return The previous error handler.
137: */
138: public ErrorHandler setErrorHandler(ErrorHandler eh) {
139: ErrorHandler old = errorHandler;
140: errorHandler = eh;
141: return old;
142: }
143:
144: /**
145: * Gets the current error handler.
146: */
147: public ErrorHandler getErrorHandler() {
148: return errorHandler;
149: }
150:
151: /**
152: * Gets the current namespace handler.
153: */
154: public NamespaceHandler getNamespaceHandler() {
155: return nameHandler;
156: }
157:
158: /**
159: * Gets the current extended handler.
160: */
161: public ExtendedHandler getExtendedHandler() {
162: return scopeHandler;
163: }
164:
165: /**
166: * Gets the current statement handler.
167: */
168: public StatementHandler getStatementHandler() {
169: return statementHandler;
170: }
171:
172: }
173:
174: /*
175: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP All rights
176: * reserved.
177: *
178: * Redistribution and use in source and binary forms, with or without
179: * modification, are permitted provided that the following conditions are met:
180: * 1. Redistributions of source code must retain the above copyright notice,
181: * this list of conditions and the following disclaimer. 2. Redistributions in
182: * binary form must reproduce the above copyright notice, this list of
183: * conditions and the following disclaimer in the documentation and/or other
184: * materials provided with the distribution. 3. The name of the author may not
185: * be used to endorse or promote products derived from this software without
186: * specific prior written permission.
187: *
188: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
189: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
190: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
191: * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
192: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
193: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
194: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
195: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
196: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
197: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
198: */
|