KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
9 import org.xml.sax.ext.*;
10
11 /**
12  * This class is public merely to reduce the amount of irrelevant documentation
13  * generated by Javadoc for {@link SAX2RDF}.
14  *
15  * There is nothing of interest in this JavaDoc. This if (depth>0) superclass
16  * implements the functionality needed by {@link SAX2RDF}. The API given here
17  * is the familiar SAX.
18  *
19  * @author Jeremy J. Carroll
20  *
21  */

22 public class SAX2RDFImpl extends XMLHandler implements LexicalHandler,
23         ContentHandler, ErrorHandler {
24     private int depth;
25     private ARPRunnable rdf;
26     final private String JavaDoc lang;
27     SAX2RDFImpl(String JavaDoc base, String JavaDoc l) {
28       lang = l;
29     }
30
31     protected void initParse(String JavaDoc b) throws MalformedURIException {
32         super.initParse(b);
33         if (lang != null && !lang.equals(""))
34             documentContext = documentContext.withLang(lang);
35     }
36     /*
37      * (non-Javadoc)
38      *
39      * @see org.xml.sax.ext.LexicalHandler#endCDATA()
40      */

41     public void endCDATA() throws SAXException {
42         if (depth > 0)
43             super.endCDATA();
44
45     }
46
47     /*
48      * (non-Javadoc)
49      *
50      * @see org.xml.sax.ext.LexicalHandler#endDTD()
51      */

52     public void endDTD() throws SAXException {
53         if (depth > 0)
54             super.endDTD();
55
56     }
57
58     /*
59      * (non-Javadoc)
60      *
61      * @see org.xml.sax.ext.LexicalHandler#startCDATA()
62      */

63     public void startCDATA() throws SAXException {
64         if (depth > 0)
65             super.startCDATA();
66
67     }
68
69     /*
70      * (non-Javadoc)
71      *
72      * @see org.xml.sax.ext.LexicalHandler#comment(char[], int, int)
73      */

74     public void comment(char[] ch, int start, int length) throws SAXParseException {
75         if (depth > 0)
76             super.comment(ch, start, length);
77
78     }
79
80     /*
81      * (non-Javadoc)
82      *
83      * @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String)
84      */

85     public void endEntity(String JavaDoc name) throws SAXException {
86         if (depth > 0)
87             super.endEntity(name);
88
89     }
90
91     /*
92      * (non-Javadoc)
93      *
94      * @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String)
95      */

96     public void startEntity(String JavaDoc name) throws SAXException {
97         if (depth > 0)
98             super.startEntity(name);
99
100     }
101
102     /*
103      * (non-Javadoc)
104      *
105      * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String,
106      * java.lang.String, java.lang.String)
107      */

108     public void startDTD(String JavaDoc name, String JavaDoc publicId, String JavaDoc systemId)
109             throws SAXException {
110         if (depth > 0)
111             super.startDTD(name, publicId, systemId);
112
113     }
114
115     /*
116      * (non-Javadoc)
117      *
118      * @see org.xml.sax.ContentHandler#endDocument()
119      */

120     public void endDocument() throws SAXException {
121         if (depth > 0)
122             super.endDocument();
123
124     }
125
126     /*
127      * (non-Javadoc)
128      *
129      * @see org.xml.sax.ContentHandler#startDocument()
130      */

131     public void startDocument() throws SAXException {
132         if (depth > 0)
133             super.startDocument();
134
135     }
136
137     /*
138      * (non-Javadoc)
139      *
140      * @see org.xml.sax.ContentHandler#characters(char[], int, int)
141      */

142     public void characters(char[] ch, int start, int length)
143             throws SAXException {
144         if (depth > 0)
145             super.characters(ch, start, length);
146
147     }
148
149     /*
150      * (non-Javadoc)
151      *
152      * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
153      */

154     public void ignorableWhitespace(char[] ch, int start, int length)
155             throws SAXException {
156         if (depth > 0)
157             super.ignorableWhitespace(ch, start, length);
158
159     }
160
161     /*
162      * (non-Javadoc)
163      *
164      * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
165      */

166     public void endPrefixMapping(String JavaDoc prefix) {
167         if (depth > 0)
168             super.endPrefixMapping(prefix);
169
170     }
171
172     /*
173      * (non-Javadoc)
174      *
175      * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
176      */

177     public void skippedEntity(String JavaDoc name) throws SAXException {
178         if (depth > 0)
179             super.skippedEntity(name);
180
181     }
182
183
184
185     /*
186      * (non-Javadoc)
187      *
188      * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String,
189      * java.lang.String)
190      */

191     public void processingInstruction(String JavaDoc target, String JavaDoc data)
192             throws SAXException {
193         if (depth > 0)
194             super.processingInstruction(target, data);
195
196     }
197
198     /*
199      * (non-Javadoc)
200      *
201      * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String,
202      * java.lang.String)
203      */

204     public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri) {
205         super.startPrefixMapping(prefix, uri);
206
207     }
208
209     /*
210      * (non-Javadoc)
211      *
212      * @see org.xml.sax.ContentHandler#endElement(java.lang.String,
213      * java.lang.String, java.lang.String)
214      */

215     public void endElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName)
216             throws SAXException {
217         if (depth <= 0) {
218             // Does not return.
219
fatalError(new SAXParseException("Unmatched end tag: " + qName,
220                     getLocator()));
221         }
222         super.endElement(namespaceURI, localName, qName);
223         if (--depth == 0) {
224           close();
225         }
226
227     }
228     
229     void close() throws SAXException {
230         if (pipe() != null) {
231             pipe().close();
232             if (!pipe().exactlyExhausted()) {
233                 // Note this happens with
234
// rdfms-nested-bagIDs/test001.rdf
235
// and test003.rdf
236
this.getHandlers().getErrorHandler().error(new SAXParseException("Too many XML events for RDF grammar; error condition not thought through, please report on jena-dev.",getLocator()));
237             }
238         }
239         endBnodeScope();
240     }
241
242     /*
243      * (non-Javadoc)
244      *
245      * @see org.xml.sax.ContentHandler#startElement(java.lang.String,
246      * java.lang.String, java.lang.String, org.xml.sax.Attributes)
247      */

248     public void startElement(String JavaDoc namespaceURI, String JavaDoc localName,
249             String JavaDoc qName, Attributes atts) throws SAXException {
250         if (depth++==0) {
251             // start up RDF parser
252
rdf = new ARPRunnable() {
253                 public void run() throws ParseException {
254     // ((PushMePullYouPipe)pipe).pullerSleep();
255
RDFParser p = new RDFParser(pipe, SAX2RDFImpl.this);
256                         if (getOptions().getEmbedding())
257                             p.embeddedFile(documentContext);
258                         else
259                             p.rdfFile(documentContext);
260                     
261                 }
262             };
263             pipe = new PushMePullYouPipe( rdf);
264             ((PushMePullYouPipe)pipe).start();
265             
266             
267         }
268         super.startElement(namespaceURI, localName, qName, atts);
269
270     }
271
272     /*
273      * (non-Javadoc)
274      *
275      * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
276      */

277     public void error(SAXParseException exception) throws SAXParseException {
278         if (depth > 0)
279             super.error(exception);
280
281     }
282
283     /*
284      * (non-Javadoc)
285      * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
286      */

287     public void fatalError(SAXParseException exception) throws SAXException {
288         if (depth > 0)
289         try {
290             super.fatalError(exception);
291         }
292         catch (FatalParsingErrorException e){
293             pipe().close();
294             throw exception;
295         }
296     }
297     
298     private PushMePullYouPipe pipe() {
299         return ((PushMePullYouPipe)pipe);
300     }
301
302     /*
303      * (non-Javadoc)
304      *
305      * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
306      */

307     public void warning(SAXParseException exception) throws SAXParseException {
308         if (depth > 0)
309             super.warning(exception);
310
311     }
312 }
313
314 /*
315  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP All rights
316  * reserved.
317  *
318  * Redistribution and use in source and binary forms, with or without
319  * modification, are permitted provided that the following conditions are met:
320  * 1. Redistributions of source code must retain the above copyright notice,
321  * this list of conditions and the following disclaimer. 2. Redistributions in
322  * binary form must reproduce the above copyright notice, this list of
323  * conditions and the following disclaimer in the documentation and/or other
324  * materials provided with the distribution. 3. The name of the author may not
325  * be used to endorse or promote products derived from this software without
326  * specific prior written permission.
327  *
328  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
329  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
330  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
331  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
333  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
334  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
335  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
336  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
337  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
338  */

339
340
Popular Tags