KickJava   Java API By Example, From Geeks To Geeks.

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


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
17 import javax.xml.parsers.DocumentBuilder JavaDoc;
18 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
19 import javax.xml.parsers.ParserConfigurationException JavaDoc;
20
21 import org.w3c.dom.Document JavaDoc;
22 import org.xml.sax.SAXException JavaDoc;
23
24 /**
25  * DOMParserWrapper
26  *
27  */

28 public class DOMParserWrapper {
29
30     protected DocumentBuilder JavaDoc fParser;
31     protected boolean isdisposed;
32     
33     /**
34      *
35      */

36     public DOMParserWrapper() throws ParserConfigurationException JavaDoc, FactoryConfigurationError JavaDoc {
37         fParser = PDEXMLHelper.Instance().getDefaultDOMParser();
38         isdisposed = false;
39     }
40
41     // Explicit disposal
42
public void dispose() {
43         if (isdisposed == false) {
44             PDEXMLHelper.Instance().recycleDOMParser(fParser);
45             isdisposed = true;
46         }
47     }
48     
49     public Document JavaDoc parse(File JavaDoc f) throws SAXException JavaDoc, IOException JavaDoc {
50         return fParser.parse(f);
51     }
52     
53     public Document JavaDoc newDocument() {
54         return fParser.newDocument();
55     }
56     
57     // NOTE: If other parser method calls are required, the corresponding
58
// wrapper method needs to be added here
59

60     // Explicit disposal
61
protected void finalize() throws Throwable JavaDoc {
62         super.finalize();
63         dispose();
64     }
65     
66 }
67
Popular Tags