You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/08/02 15:57:33 UTC
svn commit: r800081 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/main/java/org/apache/axiom/om/impl/
axiom-api/src/main/java/org/apache/axiom/om/impl/util/
axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/ axiom-parser...
Author: veithen
Date: Sun Aug 2 13:57:32 2009
New Revision: 800081
URL: http://svn.apache.org/viewvc?rev=800081&view=rev
Log:
Improved compatibility with the StAX reference implementation. In particular, added the RI to the list of detected StAX dialects.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEADialect.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAOutputFactoryWrapper.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamWriterWrapper.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/resources/stax.properties
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialect.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java
webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/pom.xml
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java?rev=800081&r1=800080&r2=800081&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMDocumentImplUtil.java Sun Aug 2 13:57:32 2009
@@ -40,14 +40,15 @@
if (includeXMLDeclaration) {
//Check whether the OMOutput char encoding and OMDocument char
//encoding matches, if not use char encoding of OMOutput
- String outputCharEncoding = writer.getCharSetEncoding();
- if (outputCharEncoding == null || "".equals(outputCharEncoding)) {
- writer.getXmlStreamWriter().writeStartDocument(document.getCharsetEncoding(),
- document.getXMLVersion());
- } else {
- writer.getXmlStreamWriter().writeStartDocument(outputCharEncoding,
- document.getXMLVersion());
+ String encoding = writer.getCharSetEncoding();
+ if (encoding == null || "".equals(encoding)) {
+ encoding = document.getCharsetEncoding();
}
+ String version = document.getXMLVersion();
+ if (version == null) {
+ version = "1.0";
+ }
+ writer.getXmlStreamWriter().writeStartDocument(encoding, version);
}
Iterator children = document.getChildren();
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java?rev=800081&r1=800080&r2=800081&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java Sun Aug 2 13:57:32 2009
@@ -204,6 +204,7 @@
NamespaceContext nc = writer.getNamespaceContext();
ret = (nc == null ||
(nc.getClass().getName().indexOf("wstx") == -1 &&
+ nc.getClass().getName().indexOf("bea") == -1 &&
nc.getClass().getName().indexOf("weblogic") == -1 &&
nc.getClass().getName().indexOf("sun") == -1));
}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEADialect.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEADialect.java?rev=800081&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEADialect.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEADialect.java Sun Aug 2 13:57:32 2009
@@ -0,0 +1,66 @@
+/*
+ * 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 javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+class BEADialect extends AbstractStAXDialect {
+ public static final StAXDialect INSTANCE = new BEADialect();
+
+ public String getName() {
+ return "BEA";
+ }
+
+ public void enableCDataReporting(XMLInputFactory factory) {
+ factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
+ factory.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event",
+ Boolean.TRUE);
+ }
+
+ public XMLInputFactory makeThreadSafe(XMLInputFactory factory) {
+ // Factories are already thread safe
+ return factory;
+ }
+
+ public XMLOutputFactory makeThreadSafe(XMLOutputFactory factory) {
+ // Factories are already thread safe
+ return factory;
+ }
+
+ public XMLStreamReader normalize(XMLStreamReader reader) {
+ return new BEAStreamReaderWrapper(reader);
+ }
+
+ public XMLStreamWriter normalize(XMLStreamWriter writer) {
+ return new BEAStreamWriterWrapper(writer);
+ }
+
+ public XMLInputFactory normalize(XMLInputFactory factory) {
+ factory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.FALSE);
+ return new NormalizingXMLInputFactoryWrapper(factory, this);
+ }
+
+ public XMLOutputFactory normalize(XMLOutputFactory factory) {
+ return new BEAOutputFactoryWrapper(factory, this);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEADialect.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAOutputFactoryWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAOutputFactoryWrapper.java?rev=800081&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAOutputFactoryWrapper.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAOutputFactoryWrapper.java Sun Aug 2 13:57:32 2009
@@ -0,0 +1,43 @@
+/*
+ * 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.io.OutputStream;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+class BEAOutputFactoryWrapper extends NormalizingXMLOutputFactoryWrapper {
+ public BEAOutputFactoryWrapper(XMLOutputFactory parent, AbstractStAXDialect dialect) {
+ super(parent, dialect);
+ }
+
+ public XMLStreamWriter createXMLStreamWriter(OutputStream stream, String encoding)
+ throws XMLStreamException {
+ if (encoding == null) {
+ // We delegate to the other variant of createXMLStreamWriter to avoid a
+ // NullPointerException
+ return super.createXMLStreamWriter(stream);
+ } else {
+ return super.createXMLStreamWriter(stream, encoding);
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAOutputFactoryWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java?rev=800081&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java Sun Aug 2 13:57:32 2009
@@ -0,0 +1,41 @@
+/*
+ * 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 javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper;
+
+class BEAStreamReaderWrapper extends XMLStreamReaderWrapper {
+ public BEAStreamReaderWrapper(XMLStreamReader parent) {
+ super(parent);
+ }
+
+ public int next() throws XMLStreamException {
+ if (!hasNext()) {
+ // The reference implementation throws an XMLStreamException in this case.
+ // This can't be considered as compliant with the specifications.
+ throw new IllegalStateException("Already reached end of document");
+ } else {
+ return super.next();
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamWriterWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamWriterWrapper.java?rev=800081&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamWriterWrapper.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamWriterWrapper.java Sun Aug 2 13:57:32 2009
@@ -0,0 +1,41 @@
+/*
+ * 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 javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.util.stax.wrapper.XMLStreamWriterWrapper;
+
+class BEAStreamWriterWrapper extends XMLStreamWriterWrapper {
+ public BEAStreamWriterWrapper(XMLStreamWriter parent) {
+ super(parent);
+ }
+
+ public void writeStartDocument(String encoding, String version) throws XMLStreamException {
+ if (encoding == null) {
+ // We delegate to the other variant of writeStartDocument to avoid a
+ // NullPointerException
+ super.writeStartDocument(version);
+ } else {
+ super.writeStartDocument(encoding, version);
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamWriterWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialect.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialect.java?rev=800081&r1=800080&r2=800081&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialect.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialect.java Sun Aug 2 13:57:32 2009
@@ -21,7 +21,6 @@
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamReader;
/**
* Encapsulates the specific characteristics of a particular StAX implementation.
@@ -29,6 +28,23 @@
* readers and writers produced by the StAX implementation to make them conform to the
* StAX specifications. This is called <em>normalization</em>.
* <p>
+ * In addition to bugs in particular StAX implementations and clear violations of the StAX
+ * specifications, the following ambiguities and gray areas in the specifications are also addressed
+ * by the dialect implementations:
+ * <ul>
+ * <li>The specifications don't tell whether it is allowed to use a <code>null</code> value
+ * for the charset encoding parameter in the following methods:
+ * <ul>
+ * <li>{@link XMLOutputFactory#createXMLEventWriter(java.io.OutputStream, String)}</li>
+ * <li>{@link javax.xml.stream.XMLStreamWriter#writeStartDocument(String, String)}</li>
+ * </ul>
+ * Most implementations accept <code>null</code> values, but some throw a
+ * {@link NullPointerException}. To avoid portability issues, the dialect implementation
+ * normalizes the behavior of these methods so that they accept <code>null</code> values
+ * (in which case the methods will delegate to the corresponding variants without
+ * charset encoding parameter).</li>
+ * </ul>
+ * <p>
* Note that there are several ambiguities in the StAX specification which are not addressed by
* the different dialect implementations:
* <ul>
@@ -41,7 +57,12 @@
* {@link javax.xml.stream.XMLStreamReader#next()} about the exception that is thrown when
* this method is called after {@link javax.xml.stream.XMLStreamReader#hasNext()} returns
* false. It can either be {@link IllegalStateException} or
- * {@link java.util.NoSuchElementException}.</li>
+ * {@link java.util.NoSuchElementException}.
+ * <p>
+ * Note that some implementations (including the reference implementation) throw an
+ * {@link javax.xml.stream.XMLStreamException} in this case. This is considered as a
+ * violation of the specifications because this exception should only be used
+ * "if there is an error processing the underlying XML source", which is not the case.</li>
* <li>An XML document may contain a namespace declaration such as <tt>xmlns=""</tt>. In this
* case, it is not clear if {@link javax.xml.stream.XMLStreamReader#getNamespaceURI(int)}
* should return <code>null</code> or an empty string.</li>
@@ -57,10 +78,11 @@
/**
* Configure the given factory to enable reporting of CDATA sections by stream readers created
- * from it. The example in the documentation of the {@link XMLStreamReader#next()} method
- * suggests that even if the parser is non coalescing, CDATA sections should be reported as
- * CHARACTERS events. Some implementations strictly follow the example, while for others it is
- * sufficient to make the parser non coalescing.
+ * from it. The example in the documentation of the
+ * {@link java.xml.stream.XMLStreamReader#next()} method suggests that even if the parser is non
+ * coalescing, CDATA sections should be reported as CHARACTERS events. Some implementations
+ * strictly follow the example, while for others it is sufficient to make the parser non
+ * coalescing.
*
* @param factory
* the factory to configure; this may be an already normalized factory or a "raw"
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java?rev=800081&r1=800080&r2=800081&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java Sun Aug 2 13:57:32 2009
@@ -205,6 +205,8 @@
return WoodstoxDialect.INSTANCE;
} else if (title != null && title.indexOf("SJSXP") != -1) {
return SJSXPDialect.INSTANCE;
+ } else if ("BEA".equals(vendor)) {
+ return BEADialect.INSTANCE;
} else {
return null;
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/pom.xml?rev=800081&r1=800080&r2=800081&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/pom.xml Sun Aug 2 13:57:32 2009
@@ -150,6 +150,11 @@
<artifactId>sjsxp</artifactId>
<version>1.0.1</version>
</artifactItem>
+ <!-- artifactItem>
+ <groupId>stax</groupId>
+ <artifactId>stax</artifactId>
+ <version>1.2.0</version>
+ </artifactItem -->
</artifactItems>
<outputDirectory>${project.build.directory}/parsers</outputDirectory>
</configuration>
Added: webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/resources/stax.properties
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/resources/stax.properties?rev=800081&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/resources/stax.properties (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-parser-tests/src/test/resources/stax.properties Sun Aug 2 13:57:32 2009
@@ -0,0 +1,3 @@
+javax.xml.stream.XMLInputFactory=com.bea.xml.stream.MXParserFactory
+javax.xml.stream.XMLOutputFactory=com.bea.xml.stream.XMLOutputFactoryBase
+javax.xml.stream.XMLEventFactory=com.bea.xml.stream.EventFactory
\ No newline at end of file