Example usage for javax.xml.stream XMLInputFactory newInstance

List of usage examples for javax.xml.stream XMLInputFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.stream XMLInputFactory newInstance.

Prototype

@Deprecated(since = "1.7")
public static XMLInputFactory newInstance(String factoryId, ClassLoader classLoader)
        throws FactoryConfigurationError 

Source Link

Document

Create a new instance of the factory

Usage

From source file:com.cedarsoft.serialization.test.performance.StaxMateDelegatePerformance.java

private void benchWithDelegate() {
    runBenchmark(new Runnable() {
        @Override//w  w  w  . ja  va 2 s . c o  m
        public void run() {
            try {
                SMInputFactory inf = new SMInputFactory(XMLInputFactory
                        .newInstance("com.ctc.wstx.stax.WstxInputFactory", getClass().getClassLoader()));
                benchRoundTrip(inf.getStaxFactory(),
                        new FileTypeSerializerDelegates(new ExtensionSerializer()));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }, 4);
}

From source file:com.cedarsoft.serialization.test.performance.StaxMateDelegatePerformance.java

private void benchHardCoded() {
    runBenchmark(new Runnable() {
        @Override//from ww w .jav a  2 s.c  om
        public void run() {
            try {
                SMInputFactory inf = new SMInputFactory(XMLInputFactory
                        .newInstance("com.ctc.wstx.stax.WstxInputFactory", getClass().getClassLoader()));
                benchRoundTrip(inf.getStaxFactory(),
                        new FileTypeSerializerHardCoded(new ExtensionSerializer()));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }, 4);
}

From source file:com.cedarsoft.serialization.test.performance.XmlParserPerformance.java

public void benchWoodstox() {
    runBenchmark(new Runnable() {
        @Override//from  w  ww .j  a  va  2  s  . co  m
        public void run() {
            try {
                XMLInputFactory inputFactory = XMLInputFactory.newInstance("com.ctc.wstx.stax.WstxInputFactory",
                        getClass().getClassLoader());

                benchParse(inputFactory, CONTENT_SAMPLE);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }, 4);
}

From source file:com.cedarsoft.serialization.test.performance.XmlParserPerformance.java

public void benchStaxMateWoodstox() {
    runBenchmark(new Runnable() {
        @Override//from   w w  w  .j av  a2  s. c  om
        public void run() {
            try {
                SMInputFactory inf = new SMInputFactory(XMLInputFactory
                        .newInstance("com.ctc.wstx.stax.WstxInputFactory", getClass().getClassLoader()));

                benchParse(inf.getStaxFactory(), CONTENT_SAMPLE);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }, 4);
}

From source file:com.cedarsoft.serialization.test.performance.XmlParserPerformance.java

public void benchStaxRI() {
    runBenchmark(new Runnable() {
        @Override/*from  ww w  .j  a v a 2  s .c om*/
        public void run() {
            try {
                benchParse(XMLInputFactory.newInstance("com.bea.xml.stream.MXParserFactory",
                        getClass().getClassLoader()), CONTENT_SAMPLE);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }, 4);
}

From source file:net.xy.jcms.controller.configurations.parser.TranslationParser.java

/**
 * parses an xml configuration from an input streams. throwes
 * IllegalArgumentExceptions in case of syntax error.
 * /*from w  w w.  j  a  v a 2  s .c  o m*/
 * @param in
 * @return value
 * @throws XMLStreamException
 * @throws ClassNotFoundException
 *             in case there are problems with an params type converter
 */
public static TranslationRule[] parse(final InputStream in, final ClassLoader loader)
        throws XMLStreamException, ClassNotFoundException {
    @SuppressWarnings("deprecation")
    final XMLInputFactory factory = XMLInputFactory.newInstance(
            "com.sun.xml.internal.stream.XMLInputFactoryImpl", TranslationParser.class.getClassLoader());
    LOG.info("XMLInputFactory loaded: " + factory.getClass().getName());
    factory.setProperty("javax.xml.stream.isCoalescing", true);
    // not supported be the reference implementation
    // factory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.TRUE);
    final XMLStreamReader parser = factory.createXMLStreamReader(in);
    while (parser.hasNext()) {
        final int event = parser.next();
        if (event == XMLStreamConstants.START_ELEMENT && parser.getName().getLocalPart().equals("rules")) {
            return parseRules(parser, loader);
        }
    }
    throw new IllegalArgumentException("No rules section found.");
}

From source file:net.xy.jcms.controller.configurations.parser.TranslationParser.java

/**
 * parses an single file translation/*  w  w  w. j  a  v  a2s  .c  o  m*/
 * 
 * @param in
 * @param loader
 * @return value
 * @throws XMLStreamException
 * @throws ClassNotFoundException
 *             in case there are problems with an params type converter
 */
public static TranslationRule parseSingle(final InputStream in, final ClassLoader loader)
        throws XMLStreamException, ClassNotFoundException {
    @SuppressWarnings("deprecation")
    final XMLInputFactory factory = XMLInputFactory.newInstance(
            "com.sun.xml.internal.stream.XMLInputFactoryImpl", TranslationParser.class.getClassLoader());
    LOG.info("XMLInputFactory loaded: " + factory.getClass().getName());
    factory.setProperty("javax.xml.stream.isCoalescing", true);
    final XMLStreamReader parser = factory.createXMLStreamReader(in);
    while (parser.hasNext()) {
        final int event = parser.next();
        if (event == XMLStreamConstants.START_ELEMENT && parser.getName().getLocalPart().equals("rule")) {
            return parseRule(parser, loader);
        }
    }
    throw new IllegalArgumentException("No rules section found.");
}