You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2011/10/15 11:23:46 UTC
svn commit: r1183608 - in
/webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common:
OMStAXWrapper.java StreamSwitch.java SwitchingWrapper.java
Author: veithen
Date: Sat Oct 15 09:23:45 2011
New Revision: 1183608
URL: http://svn.apache.org/viewvc?rev=1183608&view=rev
Log:
OMStAXWrapper refactoring step 1
Added:
webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StreamSwitch.java (with props)
Modified:
webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMStAXWrapper.java
webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMStAXWrapper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMStAXWrapper.java?rev=1183608&r1=1183607&r2=1183608&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMStAXWrapper.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMStAXWrapper.java Sat Oct 15 09:23:45 2011
@@ -45,7 +45,7 @@ import org.apache.commons.logging.LogFac
public class OMStAXWrapper extends StreamReaderDelegate implements OMXMLStreamReaderEx {
private static final Log log = LogFactory.getLog(OMStAXWrapper.class);
- private final SwitchingWrapper switchingWrapper;
+ private final StreamSwitch streamSwitch = new StreamSwitch();
private XOPEncodingStreamReader xopEncoder;
/**
@@ -70,8 +70,8 @@ public class OMStAXWrapper extends Strea
*/
public OMStAXWrapper(OMXMLParserWrapper builder, OMContainer startNode,
boolean cache) {
- switchingWrapper = new SwitchingWrapper(builder, startNode, cache);
- setParent(switchingWrapper);
+ streamSwitch.setParent(new SwitchingWrapper(builder, startNode, cache));
+ setParent(streamSwitch);
}
public boolean isInlineMTOM() {
@@ -85,14 +85,14 @@ public class OMStAXWrapper extends Strea
if (value) {
if (xopEncoder != null) {
xopEncoder = null;
- setParent(switchingWrapper);
+ setParent(streamSwitch);
}
} else {
if (xopEncoder == null) {
// Since the intention is to support an efficient way to pass binary content to a
// consumer that is not aware of our data handler extension (see WSCOMMONS-344), we
// use OptimizationPolicy.ALL, i.e. we ignore OMText#isOptimized().
- xopEncoder = new XOPEncodingStreamReader(switchingWrapper, ContentIDGenerator.DEFAULT,
+ xopEncoder = new XOPEncodingStreamReader(streamSwitch, ContentIDGenerator.DEFAULT,
OptimizationPolicy.ALL);
setParent(xopEncoder);
}
@@ -107,7 +107,7 @@ public class OMStAXWrapper extends Strea
}
// Temporary workaround for WSCOMMONS-485:
- OMXMLParserWrapper builder = switchingWrapper.getBuilder();
+ OMXMLParserWrapper builder = streamSwitch.getBuilder();
if (builder != null &&
builder instanceof OMAttachmentAccessor) {
DataHandler dh = ((OMAttachmentAccessor)builder).getDataHandler(contentID);
@@ -134,22 +134,22 @@ public class OMStAXWrapper extends Strea
// some of them should also be defined properly by an interface
public boolean isClosed() {
- return switchingWrapper.isClosed();
+ return streamSwitch.isClosed();
}
public void releaseParserOnClose(boolean value) {
- switchingWrapper.releaseParserOnClose(value);
+ streamSwitch.releaseParserOnClose(value);
}
public void setNamespaceURIInterning(boolean b) {
- switchingWrapper.setNamespaceURIInterning(b);
+ streamSwitch.setNamespaceURIInterning(b);
}
public OMDataSource getDataSource() {
- return switchingWrapper.getDataSource();
+ return streamSwitch.getDataSource();
}
public void enableDataSourceEvents(boolean value) {
- switchingWrapper.enableDataSourceEvents(value);
+ streamSwitch.enableDataSourceEvents(value);
}
}
Added: webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StreamSwitch.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StreamSwitch.java?rev=1183608&view=auto
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StreamSwitch.java (added)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StreamSwitch.java Sat Oct 15 09:23:45 2011
@@ -0,0 +1,81 @@
+/*
+ * 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.om.impl.common;
+
+import javax.xml.stream.util.StreamReaderDelegate;
+
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMXMLParserWrapper;
+
+public class StreamSwitch extends StreamReaderDelegate {
+ // namespaceURI interning
+ // default is false because most XMLStreamReader implementations don't do interning
+ // due to performance impacts
+ private boolean namespaceURIInterning = false;
+
+ /**
+ * Set namespace uri interning
+ * @param b
+ */
+ public void setNamespaceURIInterning(boolean b) {
+ this.namespaceURIInterning = b;
+ }
+
+ /**
+ * @return if namespace uri interning
+ */
+ public boolean isNamespaceURIInterning() {
+ return this.namespaceURIInterning;
+ }
+
+ public OMXMLParserWrapper getBuilder() {
+ return ((SwitchingWrapper)getParent()).getBuilder();
+ }
+
+ public boolean isClosed() {
+ return ((SwitchingWrapper)getParent()).isClosed();
+ }
+
+ public void releaseParserOnClose(boolean value) {
+ ((SwitchingWrapper)getParent()).releaseParserOnClose(value);
+ }
+
+ public OMDataSource getDataSource() {
+ return ((SwitchingWrapper)getParent()).getDataSource();
+ }
+
+ public void enableDataSourceEvents(boolean value) {
+ ((SwitchingWrapper)getParent()).enableDataSourceEvents(value);
+ }
+
+ // TODO: one would expect that the same is applied to other methods returning namespace URIs, but this was not the case in the original OMStAXWrapper code
+ public String getNamespaceURI() {
+ String namespaceURI = super.getNamespaceURI();
+
+ // By default most parsers don't intern the namespace.
+ // Unfortunately the property to detect interning on the delegate parsers is hard to detect.
+ // Woodstox has a proprietary property on the XMLInputFactory.
+ // IBM has a proprietary property on the XMLStreamReader.
+ // For now only force the interning if requested.
+ if (this.isNamespaceURIInterning()) {
+ namespaceURI = (namespaceURI != null) ? namespaceURI.intern() : null;
+ }
+ return namespaceURI;
+ }
+}
Propchange: webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/StreamSwitch.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java?rev=1183608&r1=1183607&r2=1183608&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java Sat Oct 15 09:23:45 2011
@@ -120,11 +120,6 @@ class SwitchingWrapper extends AbstractX
*/
private final boolean cache;
- // namespaceURI interning
- // default is false because most XMLStreamReader implementations don't do interning
- // due to performance impacts
- boolean namespaceURIInterning = false;
-
/** Field elementStack */
private Stack nodeStack = null;
@@ -159,21 +154,6 @@ class SwitchingWrapper extends AbstractX
private OMNamespace[] namespaces = new OMNamespace[16];
/**
- * Set namespace uri interning
- * @param b
- */
- public void setNamespaceURIInterning(boolean b) {
- this.namespaceURIInterning = b;
- }
-
- /**
- * @return if namespace uri interning
- */
- public boolean isNamespaceURIInterning() {
- return this.namespaceURIInterning;
- }
-
- /**
* Constructor.
*
* @param builder
@@ -249,34 +229,23 @@ class SwitchingWrapper extends AbstractX
* @see javax.xml.stream.XMLStreamReader#getNamespaceURI()
*/
public String getNamespaceURI() {
- String returnStr;
if (parser != null && currentEvent != END_DOCUMENT) {
- returnStr = parser.getNamespaceURI();
+ return parser.getNamespaceURI();
} else {
if ((currentEvent == START_ELEMENT)
|| (currentEvent == END_ELEMENT)
|| (currentEvent == NAMESPACE)) {
OMNamespace ns = ((OMElement) lastNode).getNamespace();
if (ns == null) {
- returnStr = null;
+ return null;
} else {
String namespaceURI = ns.getNamespaceURI();
- returnStr = namespaceURI.length() == 0 ? null : namespaceURI;
+ return namespaceURI.length() == 0 ? null : namespaceURI;
}
} else {
throw new IllegalStateException();
}
}
-
- // By default most parsers don't intern the namespace.
- // Unfortunately the property to detect interning on the delegate parsers is hard to detect.
- // Woodstox has a proprietary property on the XMLInputFactory.
- // IBM has a proprietary property on the XMLStreamReader.
- // For now only force the interning if requested.
- if (this.isNamespaceURIInterning()) {
- returnStr = (returnStr != null) ? returnStr.intern() : null;
- }
- return returnStr;
}
/**