Example usage for javax.xml.parsers DocumentBuilder getClass

List of usage examples for javax.xml.parsers DocumentBuilder getClass

Introduction

In this page you can find the example usage for javax.xml.parsers DocumentBuilder getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.microsoft.tfs.util.xml.JAXPUtils.java

/**
 * A convenience method to create a new {@link DocumentBuilder} using the
 * given {@link DocumentBuilderFactory}. The new {@link DocumentBuilder} is
 * not configured in any way by this method.
 *
 * @throws XMLException//  w w  w .j  a  va2  s  . c  o  m
 *         if a new {@link DocumentBuilder} can't be created
 *
 * @param factory
 *        the {@link DocumentBuilderFactory} to use or <code>null</code> to
 *        create a new factory using the
 *        {@link #newDocumentBuilderFactory()} method
 * @return a new {@link DocumentBuilder} created from the given
 *         {@link DocumentBuilderFactory} (never <code>null</code>)
 */
public static DocumentBuilder newDocumentBuilder(DocumentBuilderFactory factory) {
    if (factory == null) {
        factory = newDocumentBuilderFactory();
    }

    try {
        final DocumentBuilder builder = factory.newDocumentBuilder();

        if (log.isTraceEnabled()) {
            final String messageFormat = "Created a new DocumentBuilder: {0} (loaded from: {1}) (factory: {2})"; //$NON-NLS-1$
            final String message = MessageFormat.format(messageFormat, builder.getClass().getName(),
                    builder.getClass().getClassLoader(), factory.getClass().getName());
            log.trace(message);
        }

        return builder;
    } catch (final ParserConfigurationException e) {
        throw new XMLException(e);
    }
}

From source file:ambit.data.qmrf.QMRFObject.java

protected Document buildDocument() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    factory.setNamespaceAware(true);//from w  w  w.j  a  v a 2  s. c om
    factory.setValidating(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    builder.setErrorHandler(new SimpleErrorHandler(builder.getClass().getName()));
    Document doc = builder.newDocument();
    Element e = toXML(doc);
    doc.appendChild(e);
    return doc;
}