Example usage for javax.xml.stream XMLOutputFactory getClass

List of usage examples for javax.xml.stream XMLOutputFactory getClass

Introduction

In this page you can find the example usage for javax.xml.stream XMLOutputFactory getClass.

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:ca.uhn.fhir.util.XmlUtil.java

private static XMLOutputFactory createOutputFactory() throws FactoryConfigurationError {
    try {//w  w  w . j a  v a 2 s . co  m
        // Detect if we're running with the Android lib, and force repackaged Woodstox to be used
        Class.forName("ca.uhn.fhir.repackage.javax.xml.stream.XMLOutputFactory");
        System.setProperty("javax.xml.stream.XMLOutputFactory", "com.ctc.wstx.stax.WstxOutputFactory");
    } catch (ClassNotFoundException e) {
        // ok
    }

    XMLOutputFactory outputFactory = newOutputFactory();

    if (!ourHaveLoggedStaxImplementation) {
        logStaxImplementation(outputFactory.getClass());
    }

    /*
     * Note that these properties are Woodstox specific and they cause a crash in environments where SJSXP is
     * being used (e.g. glassfish) so we don't set them there.
     */
    try {
        Class.forName("com.ctc.wstx.stax.WstxOutputFactory");
        if (outputFactory instanceof WstxOutputFactory) {
            outputFactory.setProperty(XMLOutputFactory2.P_TEXT_ESCAPER, new MyEscaper());
        }
    } catch (ClassNotFoundException e) {
        ourLog.debug("WstxOutputFactory (Woodstox) not found on classpath");
    }
    return outputFactory;
}

From source file:org.apache.axiom.om.util.StAXUtils.java

private static XMLOutputFactory newXMLOutputFactory(final ClassLoader classLoader,
        final StAXWriterConfiguration configuration) {
    return (XMLOutputFactory) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            ClassLoader savedClassLoader;
            if (classLoader == null) {
                savedClassLoader = null;
            } else {
                savedClassLoader = Thread.currentThread().getContextClassLoader();
                Thread.currentThread().setContextClassLoader(classLoader);
            }/*from  www .j a v a  2 s  . co m*/
            try {
                XMLOutputFactory factory = XMLOutputFactory.newInstance();
                factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.FALSE);
                Map props = loadFactoryProperties("XMLOutputFactory.properties");
                if (props != null) {
                    for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
                        Map.Entry entry = (Map.Entry) it.next();
                        factory.setProperty((String) entry.getKey(), entry.getValue());
                    }
                }
                StAXDialect dialect = StAXDialectDetector.getDialect(factory.getClass());
                if (configuration != null) {
                    factory = configuration.configure(factory, dialect);
                }
                return new ImmutableXMLOutputFactory(dialect.normalize(dialect.makeThreadSafe(factory)));
            } finally {
                if (savedClassLoader != null) {
                    Thread.currentThread().setContextClassLoader(savedClassLoader);
                }
            }
        }
    });
}

From source file:org.apache.axiom.om.util.StAXUtils.java

/**
 * @return XMLOutputFactory for the current classloader
 *//*from w  ww.  j  ava2s  .c o m*/
private static XMLOutputFactory getXMLOutputFactory_perClassLoader(StAXWriterConfiguration configuration) {
    ClassLoader cl = getContextClassLoader();
    XMLOutputFactory factory;
    if (cl == null) {
        factory = getXMLOutputFactory_singleton(configuration);
    } else {
        if (configuration == null) {
            configuration = StAXWriterConfiguration.DEFAULT;
        }
        Map map = (Map) outputFactoryPerCLMap.get(configuration);
        if (map == null) {
            map = Collections.synchronizedMap(new WeakHashMap());
            outputFactoryPerCLMap.put(configuration, map);
            factory = null;
        } else {
            factory = (XMLOutputFactory) map.get(cl);
        }

        if (factory == null) {
            if (log.isDebugEnabled()) {
                log.debug("About to create XMLOutputFactory implementation with " + "classloader=" + cl);
                log.debug("The classloader for javax.xml.stream.XMLOutputFactory is: "
                        + XMLOutputFactory.class.getClassLoader());
            }
            try {
                factory = newXMLOutputFactory(null, configuration);
            } catch (ClassCastException cce) {
                if (log.isDebugEnabled()) {
                    log.debug("Failed creation of XMLOutputFactory implementation with " + "classloader=" + cl);
                    log.debug("Exception is=" + cce);
                    log.debug("Attempting with classloader: " + XMLOutputFactory.class.getClassLoader());
                }
                factory = newXMLOutputFactory(XMLOutputFactory.class.getClassLoader(), configuration);
            }
            if (factory != null) {
                map.put(cl, factory);
                if (log.isDebugEnabled()) {
                    log.debug("Created XMLOutputFactory = " + factory.getClass() + " for classloader=" + cl);
                    log.debug("Configuration = " + configuration);
                    log.debug("Size of XMLOutFactory map for this configuration = " + map.size());
                    log.debug("Configurations for which factories have been cached = "
                            + outputFactoryPerCLMap.keySet());
                }
            } else {
                factory = getXMLOutputFactory_singleton(configuration);
            }
        }

    }
    return factory;
}

From source file:org.apache.axiom.om.util.StAXUtils.java

/**
 * @return XMLOutputFactory singleton loaded with the StAXUtils classloader
 *///ww  w.jav a  2  s.co m
private static XMLOutputFactory getXMLOutputFactory_singleton(StAXWriterConfiguration configuration) {
    if (configuration == null) {
        configuration = StAXWriterConfiguration.DEFAULT;
    }
    XMLOutputFactory f = (XMLOutputFactory) outputFactoryMap.get(configuration);
    if (f == null) {
        f = newXMLOutputFactory(StAXUtils.class.getClassLoader(), configuration);
        outputFactoryMap.put(configuration, f);
        if (log.isDebugEnabled()) {
            if (f != null) {
                log.debug("Created singleton XMLOutputFactory " + f.getClass() + " with configuration "
                        + configuration);
            }
        }
    }
    return f;
}

From source file:org.apache.axiom.util.stax.dialect.StAXDialectDetector.java

/**
 * Detect the dialect of a given {@link XMLOutputFactory} and normalize it.
 * /* w w  w . j  a  v a 2s .  c o m*/
 * @param factory the factory to normalize
 * @return the normalized factory
 * 
 * @see StAXDialect#normalize(XMLOutputFactory)
 */
public static XMLOutputFactory normalize(XMLOutputFactory factory) {
    return getDialect(factory.getClass()).normalize(factory);
}