Author: veithen
Date: Sat Aug 8 18:40:05 2009
New Revision: 802433
URL: http://svn.apache.org/viewvc?rev=802433&view=rev
Log:
Added StAX dialect detection for XLXP2.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/NamespaceContextCorrectingXMLStreamReaderWrapper.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/XLXP2Dialect.java
(with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/ScopedNamespaceContext.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-api/src/main/java/org/apache/axiom/util/stax/dialect/XLXPDialect.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/ScopedNamespaceContext.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/ScopedNamespaceContext.java?rev=802433&r1=802432&r2=802433&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/ScopedNamespaceContext.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/namespace/ScopedNamespaceContext.java
Sat Aug 8 18:40:05 2009
@@ -65,10 +65,14 @@
* well as each nested scope, unless the prefix is bound to a different
namespace URI in that
* scope.
*
- * @param prefix the prefix to bind
- * @param namespaceURI the corresponding namespace URI
+ * @param prefix the prefix to bind or the empty string to set the default
namespace; may not
+ * be <code>null</code>
+ * @param namespaceURI the corresponding namespace URI; may not be
<code>null</code>
*/
public void setPrefix(String prefix, String namespaceURI) {
+ if (prefix == null || namespaceURI == null) {
+ throw new IllegalArgumentException("prefix and namespaceURI may
not be null");
+ }
if (bindings == prefixArray.length) {
int len = prefixArray.length;
int newLen = len*2;
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/NamespaceContextCorrectingXMLStreamReaderWrapper.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/NamespaceContextCorrectingXMLStreamReaderWrapper.java?rev=802433&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/NamespaceContextCorrectingXMLStreamReaderWrapper.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/NamespaceContextCorrectingXMLStreamReaderWrapper.java
Sat Aug 8 18:40:05 2009
@@ -0,0 +1,87 @@
+/*
+ * 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.namespace.NamespaceContext;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.util.namespace.ScopedNamespaceContext;
+import org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper;
+
+/**
+ * {...@link XMLStreamReader} wrapper that tracks the namespace bindings on
behalf of the underlying
+ * reader. This class may be used to wrap {...@link XMLStreamReader} instances
known to have issues in
+ * their namespace context implementation. It tracks the namespace bindings
using the
+ * {...@link XMLStreamReader#getNamespacePrefix(int)} and {...@link
XMLStreamReader#getNamespaceURI(int)}
+ * methods and exposes this information by overriding the
+ * {...@link XMLStreamReader#getNamespaceContext()} and {...@link
XMLStreamReader#getNamespaceURI(String)}
+ * methods. Invocations of these two methods will therefore never reach the
underlying reader.
+ */
+public class NamespaceContextCorrectingXMLStreamReaderWrapper extends
XMLStreamReaderWrapper {
+ private final ScopedNamespaceContext namespaceContext = new
ScopedNamespaceContext();
+
+ /**
+ * Constructor.
+ *
+ * @param parent the parent reader
+ */
+ public NamespaceContextCorrectingXMLStreamReaderWrapper(XMLStreamReader
parent) {
+ super(parent);
+ }
+
+ private void startElement() {
+ namespaceContext.startScope();
+ for (int i=0, c=getNamespaceCount(); i<c; i++) {
+ String prefix = getNamespacePrefix(i);
+ namespaceContext.setPrefix(prefix == null ? "" : prefix,
getNamespaceURI(i));
+ }
+ }
+
+ public int next() throws XMLStreamException {
+ if (isEndElement()) {
+ namespaceContext.endScope();
+ }
+ int event = super.next();
+ if (event == START_ELEMENT) {
+ startElement();
+ }
+ return event;
+ }
+
+ public int nextTag() throws XMLStreamException {
+ if (isEndElement()) {
+ namespaceContext.endScope();
+ }
+ int event = super.nextTag();
+ if (event == START_ELEMENT) {
+ startElement();
+ }
+ return event;
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ return namespaceContext;
+ }
+
+ public String getNamespaceURI(String prefix) {
+ return namespaceContext.getNamespaceURI(prefix);
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/NamespaceContextCorrectingXMLStreamReaderWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
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=802433&r1=802432&r2=802433&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
Sat Aug 8 18:40:05 2009
@@ -53,6 +53,15 @@
private static final Attributes.Name IMPLEMENTATION_VERSION =
new Attributes.Name("Implementation-Version");
+ private static final Attributes.Name BUNDLE_SYMBOLIC_NAME =
+ new Attributes.Name("Bundle-SymbolicName");
+
+ private static final Attributes.Name BUNDLE_VENDOR =
+ new Attributes.Name("Bundle-Vendor");
+
+ private static final Attributes.Name BUNDLE_VERSION =
+ new Attributes.Name("Bundle-Version");
+
/**
* Map that stores detected dialects by location. The location is the URL
corresponding to the
* root folder of the classpath entry from which the StAX implementation
is loaded. Note that
@@ -191,13 +200,27 @@
}
Attributes attrs = manifest.getMainAttributes();
String title = attrs.getValue(IMPLEMENTATION_TITLE);
+ String symbolicName = attrs.getValue(BUNDLE_SYMBOLIC_NAME);
+ if (symbolicName != null) {
+ int i = symbolicName.indexOf(';');
+ if (i != -1) {
+ symbolicName = symbolicName.substring(0, i);
+ }
+ }
String vendor = attrs.getValue(IMPLEMENTATION_VENDOR);
+ if (vendor == null) {
+ vendor = attrs.getValue(BUNDLE_VENDOR);
+ }
String version = attrs.getValue(IMPLEMENTATION_VERSION);
+ if (version == null) {
+ version = attrs.getValue(BUNDLE_VERSION);
+ }
if (log.isDebugEnabled()) {
log.debug("StAX implementation at " + rootUrl + " is:\n" +
- " Title: " + title + "\n" +
- " Vendor: " + vendor + "\n" +
- " Version: " + version);
+ " Title: " + title + "\n" +
+ " Symbolic name: " + symbolicName + "\n" +
+ " Vendor: " + vendor + "\n" +
+ " Version: " + version);
}
// For the moment, the dialect detection is quite simple, but in the
future we will probably
// have to differentiate by version number
@@ -207,6 +230,8 @@
return SJSXPDialect.INSTANCE;
} else if ("BEA".equals(vendor)) {
return BEADialect.INSTANCE;
+ } else if ("com.ibm.ws.prereq.banshee".equals(symbolicName)) {
+ return XLXP2Dialect.INSTANCE;
} else {
return null;
}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/XLXP2Dialect.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/XLXP2Dialect.java?rev=802433&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/XLXP2Dialect.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/XLXP2Dialect.java
Sat Aug 8 18:40:05 2009
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+public class XLXP2Dialect extends AbstractStAXDialect {
+ public static final StAXDialect INSTANCE = new XLXP2Dialect();
+
+ public String getName() {
+ return "XLXP2";
+ }
+
+ public void enableCDataReporting(XMLInputFactory factory) {
+ factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
+ }
+
+ public XMLInputFactory makeThreadSafe(XMLInputFactory factory) {
+ // XLXP's factories are thread safe
+ return factory;
+ }
+
+ public XMLOutputFactory makeThreadSafe(XMLOutputFactory factory) {
+ // XLXP's factories are thread safe
+ return factory;
+ }
+
+ public XMLStreamReader normalize(XMLStreamReader reader) {
+ // XLXP2's getNamespaceContext implementation is broken
+ return new NamespaceContextCorrectingXMLStreamReaderWrapper(reader);
+ }
+
+ public XMLStreamWriter normalize(XMLStreamWriter writer) {
+ return new XLXPStreamWriterWrapper(writer);
+ }
+
+ public XMLInputFactory normalize(XMLInputFactory factory) {
+ return new NormalizingXMLInputFactoryWrapper(factory, this);
+ }
+
+ public XMLOutputFactory normalize(XMLOutputFactory factory) {
+ return new NormalizingXMLOutputFactoryWrapper(factory, this);
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/XLXP2Dialect.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/XLXPDialect.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/XLXPDialect.java?rev=802433&r1=802432&r2=802433&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/XLXPDialect.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/XLXPDialect.java
Sat Aug 8 18:40:05 2009
@@ -37,7 +37,6 @@
}
public void enableCDataReporting(XMLInputFactory factory) {
- // TODO: check if that is enough
factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
}