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 2016/02/14 11:05:56 UTC
svn commit: r1730307 - in
/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push:
NamespaceHelper.java SerializerImpl.java XsiTypeFilterHandler.java
Author: veithen
Date: Sun Feb 14 10:05:56 2016
New Revision: 1730307
URL: http://svn.apache.org/viewvc?rev=1730307&view=rev
Log:
Cleanly reimplement AXIOM-107.
Added:
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/XsiTypeFilterHandler.java (with props)
Modified:
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/NamespaceHelper.java
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/SerializerImpl.java
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/NamespaceHelper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/NamespaceHelper.java?rev=1730307&r1=1730306&r2=1730307&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/NamespaceHelper.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/NamespaceHelper.java Sun Feb 14 10:05:56 2016
@@ -18,23 +18,16 @@
*/
package org.apache.axiom.om.impl.common.serializer.push;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.impl.stream.StreamException;
import org.apache.axiom.om.impl.stream.XmlHandler;
import org.apache.axiom.om.impl.stream.XmlHandlerWrapper;
final class NamespaceHelper extends XmlHandlerWrapper {
- private static final String XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
- private static final String XSI_LOCAL_NAME = "type";
-
private final SerializerImpl serializer;
- private final OMElement contextElement;
- NamespaceHelper(SerializerImpl serializer, XmlHandler handler, OMElement contextElement) {
+ NamespaceHelper(SerializerImpl serializer, XmlHandler handler) {
super(handler);
this.serializer = serializer;
- this.contextElement = contextElement;
}
public void startElement(String namespaceURI, String localName, String prefix) throws StreamException {
@@ -44,16 +37,6 @@ final class NamespaceHelper extends XmlH
public void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) throws StreamException {
mapNamespace(prefix, namespaceURI, true);
- if (contextElement != null && namespaceURI.equals(XSI_URI) && localName.equals(XSI_LOCAL_NAME)) {
- String trimmedValue = value.trim();
- if (trimmedValue.indexOf(":") > 0) {
- String refPrefix = trimmedValue.substring(0, trimmedValue.indexOf(":"));
- OMNamespace ns = contextElement.findNamespaceURI(refPrefix);
- if (ns != null) {
- mapNamespace(refPrefix, ns.getNamespaceURI(), true);
- }
- }
- }
super.processAttribute(namespaceURI, localName, prefix, value, type, specified);
}
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/SerializerImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/SerializerImpl.java?rev=1730307&r1=1730306&r2=1730307&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/SerializerImpl.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/SerializerImpl.java Sun Feb 14 10:05:56 2016
@@ -64,11 +64,15 @@ public abstract class SerializerImpl imp
contextElement = null;
}
XmlHandler handler = this;
- if (preserveNamespaceContext && contextElement != null) {
- handler = new NamespaceContextPreservationFilterHandler(handler, (CoreElement)contextElement);
+ if (contextElement != null) {
+ if (preserveNamespaceContext) {
+ handler = new NamespaceContextPreservationFilterHandler(handler, (CoreElement)contextElement);
+ } else {
+ handler = new XsiTypeFilterHandler(handler, (CoreElement)contextElement);
+ }
}
if (namespaceRepairing) {
- handler = new NamespaceHelper(this, handler, contextElement);
+ handler = new NamespaceHelper(this, handler);
}
return handler;
}
Added: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/XsiTypeFilterHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/XsiTypeFilterHandler.java?rev=1730307&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/XsiTypeFilterHandler.java (added)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/XsiTypeFilterHandler.java Sun Feb 14 10:05:56 2016
@@ -0,0 +1,105 @@
+/*
+ * 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.serializer.push;
+
+import org.apache.axiom.core.CoreElement;
+import org.apache.axiom.core.CoreModelException;
+import org.apache.axiom.om.impl.common.AxiomSemantics;
+import org.apache.axiom.om.impl.stream.StreamException;
+import org.apache.axiom.om.impl.stream.XmlHandler;
+import org.apache.axiom.om.impl.stream.XmlHandlerWrapper;
+
+public class XsiTypeFilterHandler extends XmlHandlerWrapper {
+ private final CoreElement contextElement;
+ private String[] prefixes = new String[16];
+ private int prefixCount;
+ private int[] scopeStack = new int[8];
+ private int scopes;
+ private String xsiType;
+
+ public XsiTypeFilterHandler(XmlHandler parent, CoreElement contextElement) {
+ super(parent);
+ this.contextElement = contextElement;
+ }
+
+ @Override
+ public void startElement(String namespaceURI, String localName, String prefix) throws StreamException {
+ super.startElement(namespaceURI, localName, prefix);
+ if (scopes == scopeStack.length) {
+ int[] newScopeStack = new int[scopeStack.length*2];
+ System.arraycopy(scopeStack, 0, newScopeStack, 0, scopeStack.length);
+ scopeStack = newScopeStack;
+ }
+ scopeStack[scopes++] = prefixCount;
+ }
+
+ @Override
+ public void endElement() throws StreamException {
+ prefixCount = scopeStack[--scopes];
+ super.endElement();
+ }
+
+ @Override
+ public void processNamespaceDeclaration(String prefix, String namespaceURI) throws StreamException {
+ super.processNamespaceDeclaration(prefix, namespaceURI);
+ if (prefixes.length == prefixCount) {
+ String[] newPrefixes = new String[prefixes.length*2];
+ System.arraycopy(prefixes, 0, newPrefixes, 0, prefixes.length);
+ prefixes = newPrefixes;
+ }
+ prefixes[prefixCount++] = prefix;
+ }
+
+ @Override
+ public void processAttribute(String namespaceURI, String localName, String prefix, String value,
+ String type, boolean specified) throws StreamException {
+ super.processAttribute(namespaceURI, localName, prefix, value, type, specified);
+ if (namespaceURI.equals("http://www.w3.org/2001/XMLSchema-instance")
+ && localName.equals("type")) {
+ xsiType = value.trim();
+ }
+ }
+
+ @Override
+ public void attributesCompleted() throws StreamException {
+ try {
+ if (xsiType != null) {
+ int idx = xsiType.indexOf(':');
+ String prefix = idx == -1 ? "" : xsiType.substring(0, idx);
+ boolean bound = false;
+ for (int i=0; i<prefixCount; i++) {
+ if (prefixes[i] == prefix) {
+ bound = true;
+ break;
+ }
+ }
+ if (!bound) {
+ String namespaceURI = contextElement.coreLookupNamespaceURI(prefix, AxiomSemantics.INSTANCE);
+ if (namespaceURI != null && !namespaceURI.isEmpty()) {
+ processNamespaceDeclaration(prefix, namespaceURI);
+ }
+ }
+ }
+ } catch (CoreModelException ex) {
+ throw new StreamException(ex);
+ }
+ super.attributesCompleted();
+ xsiType = null;
+ }
+}
Propchange: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/XsiTypeFilterHandler.java
------------------------------------------------------------------------------
svn:eol-style = native