01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core.util;
11:
12: import java.io.File;
13: import java.io.IOException;
14:
15: import javax.xml.parsers.DocumentBuilder;
16: import javax.xml.parsers.FactoryConfigurationError;
17: import javax.xml.parsers.ParserConfigurationException;
18:
19: import org.w3c.dom.Document;
20: import org.xml.sax.SAXException;
21:
22: /**
23: * DOMParserWrapper
24: *
25: */
26: public class DOMParserWrapper {
27:
28: protected DocumentBuilder fParser;
29: protected boolean isdisposed;
30:
31: /**
32: *
33: */
34: public DOMParserWrapper() throws ParserConfigurationException,
35: FactoryConfigurationError {
36: fParser = PDEXMLHelper.Instance().getDefaultDOMParser();
37: isdisposed = false;
38: }
39:
40: // Explicit disposal
41: public void dispose() {
42: if (isdisposed == false) {
43: PDEXMLHelper.Instance().recycleDOMParser(fParser);
44: isdisposed = true;
45: }
46: }
47:
48: public Document parse(File f) throws SAXException, IOException {
49: return fParser.parse(f);
50: }
51:
52: public Document newDocument() {
53: return fParser.newDocument();
54: }
55:
56: // NOTE: If other parser method calls are required, the corresponding
57: // wrapper method needs to be added here
58:
59: // Explicit disposal
60: protected void finalize() throws Throwable {
61: super.finalize();
62: dispose();
63: }
64:
65: }
|