Java XML DocumentBuilder Create getDocumentBuilder()

Here you can find the source of getDocumentBuilder()

Description

get Document Builder

License

Open Source License

Declaration

private static synchronized DocumentBuilder getDocumentBuilder() 

Method Source Code

//package com.java2s;
/*/*www. ja  va  2 s  . com*/
 * Helma License Notice
 *
 * The contents of this file are subject to the Helma License
 * Version 2.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://adele.helma.org/download/helma/license.txt
 *
 * Copyright 1998-2003 Helma Software. All Rights Reserved.
 *
 * $RCSfile$
 * $Author$
 * $Revision$
 * $Date$
 */

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import java.util.WeakHashMap;

public class Main {
    private static final DocumentBuilderFactory domBuilderFactory = javax.xml.parsers.DocumentBuilderFactory
            .newInstance();
    private static final WeakHashMap domBuilders = new WeakHashMap();

    private static synchronized DocumentBuilder getDocumentBuilder() {
        DocumentBuilder domBuilder = (DocumentBuilder) domBuilders.get(Thread.currentThread());

        if (domBuilder != null) {
            return domBuilder;
        } else {
            try {
                domBuilder = domBuilderFactory.newDocumentBuilder();
                domBuilders.put(Thread.currentThread(), domBuilder);

                return domBuilder;
            } catch (ParserConfigurationException e) {
                throw new RuntimeException("Cannot build parser: " + e.toString());
            }
        }
    }
}

Related

  1. getDocumentBuilder()
  2. getDocumentBuilder()
  3. getDocumentBuilder()
  4. getDocumentBuilder()
  5. getDocumentBuilder()
  6. getDocumentBuilder()
  7. getDocumentBuilder()
  8. getDocumentBuilder()
  9. getDocumentBuilder()