Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/NextAfterEndDocumentTestCase.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/NextAfterEndDocumentTestCase.java?rev=1328131&r1=1328130&r2=1328131&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/NextAfterEndDocumentTestCase.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/NextAfterEndDocumentTestCase.java Thu Apr 19 22:14:11 2012 @@ -30,8 +30,12 @@ import javax.xml.stream.XMLStreamReader; * has already been reached. */ public class NextAfterEndDocumentTestCase extends DialectTestCase { + public NextAfterEndDocumentTestCase(StAXImplementation staxImpl) { + super(staxImpl); + } + protected void runTest() throws Throwable { - XMLInputFactory factory = newNormalizedXMLInputFactory(); + XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory(); XMLStreamReader reader = factory.createXMLStreamReader(new StringReader("<root/>")); while (reader.next() != XMLStreamReader.END_DOCUMENT) { // Just loop
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/SetPrefixScopeTestCase.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/SetPrefixScopeTestCase.java?rev=1328131&r1=1328130&r2=1328131&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/SetPrefixScopeTestCase.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/SetPrefixScopeTestCase.java Thu Apr 19 22:14:11 2012 @@ -24,8 +24,12 @@ import javax.xml.stream.XMLOutputFactory import javax.xml.stream.XMLStreamWriter; public class SetPrefixScopeTestCase extends DialectTestCase { + public SetPrefixScopeTestCase(StAXImplementation staxImpl) { + super(staxImpl); + } + protected void runTest() throws Throwable { - XMLOutputFactory factory = newNormalizedXMLOutputFactory(); + XMLOutputFactory factory = staxImpl.newNormalizedXMLOutputFactory(); XMLStreamWriter writer = factory.createXMLStreamWriter(new ByteArrayOutputStream()); writer.writeStartDocument(); writer.writeStartElement("root"); Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/StAXImplementation.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/StAXImplementation.java?rev=1328131&view=auto ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/StAXImplementation.java (added) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/StAXImplementation.java Thu Apr 19 22:14:11 2012 @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.axiom.util.stax.dialect; + +import java.util.Properties; + +import javax.xml.stream.FactoryConfigurationError; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +public final class StAXImplementation { + private final String name; + private final ClassLoader classLoader; + private final Properties props; + private StAXDialect dialect; + + public StAXImplementation(String name, ClassLoader classLoader, Properties props) { + this.name = name; + this.classLoader = classLoader; + this.props = props; + } + + public String getName() { + return name; + } + + public XMLInputFactory newXMLInputFactory() { + String className = props == null ? null : props.getProperty(XMLInputFactory.class.getName()); + XMLInputFactory factory; + if (className == null) { + ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(classLoader); + try { + factory = XMLInputFactory.newInstance(); + } finally { + Thread.currentThread().setContextClassLoader(savedClassLoader); + } + } else { + try { + factory = (XMLInputFactory)classLoader.loadClass(className).newInstance(); + } catch (Exception ex) { + throw new FactoryConfigurationError(ex); + } + } + // Check that the parser has actually been loaded from the expected class loader. + // If the parser has been loaded from the JRE, then comparing the class loaders + // is not reliable (because it may be null). Hence the check on ParentLastURLClassLoader. + if (classLoader instanceof ParentLastURLClassLoader + && factory.getClass().getClassLoader() != classLoader) { + throw new FactoryConfigurationError("Wrong factory: got " + factory.getClass().getName() + + " loaded from " + factory.getClass().getClassLoader()); + } + return factory; + } + + public XMLInputFactory newNormalizedXMLInputFactory() { + XMLInputFactory factory = newXMLInputFactory(); + if (dialect == null) { + dialect = StAXDialectDetector.getDialect(factory.getClass()); + } + return dialect.normalize(factory); + } + + public XMLOutputFactory newXMLOutputFactory() { + String className = props == null ? null : props.getProperty(XMLOutputFactory.class.getName()); + XMLOutputFactory factory; + if (className == null) { + ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(classLoader); + try { + factory = XMLOutputFactory.newInstance(); + } finally { + Thread.currentThread().setContextClassLoader(savedClassLoader); + } + } else { + try { + factory = (XMLOutputFactory)classLoader.loadClass(className).newInstance(); + } catch (Exception ex) { + throw new FactoryConfigurationError(ex); + } + } + if (classLoader != ClassLoader.getSystemClassLoader() + && factory.getClass().getClassLoader() != classLoader) { + throw new FactoryConfigurationError("Wrong factory: got " + factory.getClass().getName() + + " loaded from " + factory.getClass().getClassLoader()); + } + return factory; + } + + public XMLOutputFactory newNormalizedXMLOutputFactory() { + XMLOutputFactory factory = newXMLOutputFactory(); + if (dialect == null) { + dialect = StAXDialectDetector.getDialect(factory.getClass()); + } + return dialect.normalize(factory); + } + + public StAXDialect getDialect() { + return dialect; + } + + public ClassLoader getClassLoader() { + return classLoader; + } +} Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/StAXImplementation.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/StandaloneSetTestCase.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/StandaloneSetTestCase.java?rev=1328131&r1=1328130&r2=1328131&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/StandaloneSetTestCase.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/StandaloneSetTestCase.java Thu Apr 19 22:14:11 2012 @@ -24,8 +24,12 @@ import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; public class StandaloneSetTestCase extends DialectTestCase { + public StandaloneSetTestCase(StAXImplementation staxImpl) { + super(staxImpl); + } + protected void runTest() throws Throwable { - XMLInputFactory factory = newNormalizedXMLInputFactory(); + XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory(); XMLStreamReader reader = factory.createXMLStreamReader( new StringReader("<?xml version='1.0'?><root/>")); assertEquals(false, reader.standaloneSet()); Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/UnwrapTestCase.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/UnwrapTestCase.java?rev=1328131&r1=1328130&r2=1328131&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/UnwrapTestCase.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/UnwrapTestCase.java Thu Apr 19 22:14:11 2012 @@ -26,10 +26,14 @@ import javax.xml.stream.XMLStreamReader; import org.apache.axiom.util.stax.XMLStreamReaderUtils; public class UnwrapTestCase extends DialectTestCase { + public UnwrapTestCase(StAXImplementation staxImpl) { + super(staxImpl); + } + protected void runTest() throws Throwable { - XMLInputFactory factory = newNormalizedXMLInputFactory(); + XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory(); XMLStreamReader reader = factory.createXMLStreamReader(new StringReader("<root/>")); XMLStreamReader originalReader = XMLStreamReaderUtils.getOriginalXMLStreamReader(reader); - assertSame(getImplementationClassLoader(), originalReader.getClass().getClassLoader()); + assertSame(staxImpl.getClassLoader(), originalReader.getClass().getClassLoader()); } } Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/WriteStartDocumentWithNullEncodingTestCase.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/WriteStartDocumentWithNullEncodingTestCase.java?rev=1328131&r1=1328130&r2=1328131&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/WriteStartDocumentWithNullEncodingTestCase.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/WriteStartDocumentWithNullEncodingTestCase.java Thu Apr 19 22:14:11 2012 @@ -21,8 +21,12 @@ package org.apache.axiom.util.stax.diale import javax.xml.stream.XMLStreamWriter; public class WriteStartDocumentWithNullEncodingTestCase extends DialectTestCase { + public WriteStartDocumentWithNullEncodingTestCase(StAXImplementation staxImpl) { + super(staxImpl); + } + protected void runTest() throws Throwable { - XMLStreamWriter writer = newNormalizedXMLOutputFactory().createXMLStreamWriter(System.out, "UTF-8"); + XMLStreamWriter writer = staxImpl.newNormalizedXMLOutputFactory().createXMLStreamWriter(System.out, "UTF-8"); try { writer.writeStartDocument(null, "1.0"); } catch (Throwable ex) {
