KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > util > SAXParserWrapper


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.core.util;
13
14 import java.io.File JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.io.InputStream JavaDoc;
17
18 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
19 import javax.xml.parsers.ParserConfigurationException JavaDoc;
20 import javax.xml.parsers.SAXParser JavaDoc;
21
22 import org.xml.sax.InputSource JavaDoc;
23 import org.xml.sax.SAXException JavaDoc;
24 import org.xml.sax.helpers.DefaultHandler JavaDoc;
25
26 /**
27  * SAXParserWrapper
28  *
29  */

30 public class SAXParserWrapper {
31
32     protected SAXParser JavaDoc fParser;
33     protected boolean isdisposed;
34     
35     /**
36      *
37      */

38     public SAXParserWrapper() throws ParserConfigurationException JavaDoc, SAXException JavaDoc, FactoryConfigurationError JavaDoc {
39         fParser = PDEXMLHelper.Instance().getDefaultSAXParser();
40         isdisposed = false;
41     }
42     
43     // Explicit disposal
44
public void dispose() {
45         if (isdisposed == false) {
46             PDEXMLHelper.Instance().recycleSAXParser(fParser);
47             isdisposed = true;
48         }
49     }
50     
51     public void parse(File JavaDoc f, DefaultHandler JavaDoc dh) throws SAXException JavaDoc, IOException JavaDoc {
52         fParser.parse(f, dh);
53     }
54     
55     public void parse(InputStream JavaDoc is, DefaultHandler JavaDoc dh) throws SAXException JavaDoc, IOException JavaDoc {
56         fParser.parse(is, dh);
57     }
58     
59     public void parse(InputSource JavaDoc is, DefaultHandler JavaDoc dh) throws SAXException JavaDoc, IOException JavaDoc {
60         fParser.parse(is, dh);
61     }
62     
63     // NOTE: If other parser method calls are required, the corresponding
64
// wrapper method needs to be added here
65

66     // Implicit disposal
67
protected void finalize() throws Throwable JavaDoc {
68         super.finalize();
69         dispose();
70     }
71     
72 }
73
Popular Tags