ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1685484 - in /webservices/axiom/branches/attrs-aspects: aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/ aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/ implementations/axiom-dom/src/main/java/org...
Date Sun, 14 Jun 2015 23:04:44 GMT
Author: veithen
Date: Sun Jun 14 23:04:44 2015
New Revision: 1685484

URL: http://svn.apache.org/r1685484
Log:
Start rewriting the namespace declaration code in LLOM.

Added:
    webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/NamespaceDeclarationMapper.java
  (with props)
Removed:
    webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSDeclIterator.java
Modified:
    webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj
    webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AxiomNodeFactory.java
    webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
    webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
    webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
    webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java

Modified: webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj?rev=1685484&r1=1685483&r2=1685484&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj
(original)
+++ webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomElementSupport.aj
Sun Jun 14 23:04:44 2015
@@ -44,6 +44,8 @@ import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMSourcedElement;
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.common.factory.AxiomNodeFactory;
+import org.apache.axiom.om.impl.util.OMSerializerUtil;
 import org.apache.axiom.util.namespace.MapBasedNamespaceContext;
 import org.apache.axiom.util.stax.XMLStreamReaderUtils;
 
@@ -319,4 +321,52 @@ public aspect AxiomElementSupport {
         }
         ((AxiomAttribute)attr).coreRemove(null);
     }
+
+    public final OMNamespace AxiomElement.addNamespaceDeclaration(String uri, String prefix)
{
+        OMNamespace ns = new OMNamespaceImpl(uri, prefix);
+        addNamespaceDeclaration(ns);
+        return ns;
+    }
+    
+    public final void AxiomElement.addNamespaceDeclaration(OMNamespace ns) {
+        try {
+            coreAppendAttribute(((AxiomNodeFactory)getOMFactory()).createNamespaceDeclaration(ns),
NodeMigrationPolicy.MOVE_ALWAYS);
+        } catch (NodeMigrationException ex) {
+            throw AxiomExceptionUtil.translate(ex);
+        }
+    }
+    
+    @SuppressWarnings("rawtypes")
+    public final Iterator AxiomElement.getAllDeclaredNamespaces() {
+        return coreGetAttributesByType(AxiomNamespaceDeclaration.class, NamespaceDeclarationMapper.INSTANCE);
+    }
+
+    public final OMNamespace AxiomElement.declareNamespace(OMNamespace namespace) {
+        String prefix = namespace.getPrefix();
+        if (prefix == null) {
+            prefix = OMSerializerUtil.getNextNSPrefix();
+            namespace = new OMNamespaceImpl(namespace.getNamespaceURI(), prefix);
+        }
+        if (prefix.length() > 0 && namespace.getNamespaceURI().length() == 0)
{
+            throw new IllegalArgumentException("Cannot bind a prefix to the empty namespace
name");
+        }
+        addNamespaceDeclaration(namespace);
+        return namespace;
+    }
+
+    public final OMNamespace AxiomElement.declareDefaultNamespace(String uri) {
+        OMNamespace elementNamespace = getNamespace();
+        if (elementNamespace == null && uri.length() > 0
+                || elementNamespace != null && elementNamespace.getPrefix().length()
== 0 && !elementNamespace.getNamespaceURI().equals(uri)) {
+            throw new OMException("Attempt to add a namespace declaration that conflicts
with " +
+                    "the namespace information of the element");
+        }
+        OMNamespace namespace = new OMNamespaceImpl(uri == null ? "" : uri, "");
+        addNamespaceDeclaration(namespace);
+        return namespace;
+    }
+
+    public final void AxiomElement.undeclarePrefix(String prefix) {
+        addNamespaceDeclaration(new OMNamespaceImpl("", prefix));
+    }
 }

Added: webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/NamespaceDeclarationMapper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/NamespaceDeclarationMapper.java?rev=1685484&view=auto
==============================================================================
--- webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/NamespaceDeclarationMapper.java
(added)
+++ webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/NamespaceDeclarationMapper.java
Sun Jun 14 23:04:44 2015
@@ -0,0 +1,32 @@
+/*
+ * 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 org.apache.axiom.core.Mapper;
+import org.apache.axiom.om.OMNamespace;
+
+public class NamespaceDeclarationMapper implements Mapper<AxiomNamespaceDeclaration,OMNamespace>
{
+    public static final NamespaceDeclarationMapper INSTANCE = new NamespaceDeclarationMapper();
+    
+    private NamespaceDeclarationMapper() {}
+    
+    public OMNamespace map(AxiomNamespaceDeclaration namespaceDeclaration) {
+        return namespaceDeclaration.getDeclaredNamespace();
+    }
+}

Propchange: webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/NamespaceDeclarationMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AxiomNodeFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AxiomNodeFactory.java?rev=1685484&r1=1685483&r2=1685484&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AxiomNodeFactory.java
(original)
+++ webservices/axiom/branches/attrs-aspects/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/AxiomNodeFactory.java
Sun Jun 14 23:04:44 2015
@@ -19,8 +19,10 @@
 package org.apache.axiom.om.impl.common.factory;
 
 import org.apache.axiom.core.NodeFactory;
+import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.impl.builder.OMFactoryEx;
+import org.apache.axiom.om.impl.common.AxiomNamespaceDeclaration;
 
 public interface AxiomNodeFactory extends NodeFactory, OMFactoryEx {
-
+    AxiomNamespaceDeclaration createNamespaceDeclaration(OMNamespace namespace);
 }

Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1685484&r1=1685483&r2=1685484&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
(original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
Sun Jun 14 23:04:44 2015
@@ -195,47 +195,6 @@ public class ElementImpl extends ParentN
         }
     }
 
-    public OMNamespace addNamespaceDeclaration(String uri, String prefix) {
-        OMNamespace ns = new OMNamespaceImpl(uri, prefix);
-        addNamespaceDeclaration(ns);
-        return ns;
-    }
-    
-    public void addNamespaceDeclaration(OMNamespace ns) {
-        try {
-            coreAppendAttribute(new NamespaceDeclaration(null, ns, getOMFactory()), NodeMigrationPolicy.MOVE_ALWAYS);
-        } catch (NodeMigrationException ex) {
-            throw DOMExceptionUtil.translate(ex);
-        }
-    }
-
-    /**
-     * Allows overriding an existing declaration if the same prefix was used.
-     *
-     * @see org.apache.axiom.om.OMElement#declareNamespace (org.apache.axiom.om.OMNamespace)
-     */
-    public OMNamespace declareNamespace(OMNamespace namespace) {
-        if (namespace != null) {
-            String prefix = namespace.getPrefix();
-            if (prefix == null) {
-                prefix = OMSerializerUtil.getNextNSPrefix();
-                namespace = new OMNamespaceImpl(namespace.getNamespaceURI(), prefix);
-            }
-            if (prefix.length() > 0 && namespace.getNamespaceURI().length() ==
0) {
-                throw new IllegalArgumentException("Cannot bind a prefix to the empty namespace
name");
-            }
-
-            if (!namespace.getPrefix().startsWith(XMLConstants.XMLNS_ATTRIBUTE)) {
-                setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix.length() == 0
? XMLConstants.XMLNS_ATTRIBUTE : XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix, namespace.getNamespaceURI());
-            }
-        }
-        return namespace;
-    }
-
-    public void undeclarePrefix(String prefix) {
-        setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix.length() == 0 ? XMLConstants.XMLNS_ATTRIBUTE
: XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix, "");
-    }
-
     public OMNamespace declareNamespace(String uri, String prefix) {
         if ("".equals(prefix)) {
             log.warn("Deprecated usage of OMElement#declareNamespace(String,String) with
empty prefix");
@@ -246,18 +205,6 @@ public class ElementImpl extends ParentN
         return declareNamespace(ns);
     }
 
-    public OMNamespace declareDefaultNamespace(String uri) {
-        OMNamespace namespace = getNamespace();
-        if (namespace == null && uri.length() > 0
-                || namespace != null && namespace.getPrefix().length() == 0 &&
!namespace.getNamespaceURI().equals(uri)) {
-            throw new OMException("Attempt to add a namespace declaration that conflicts
with " +
-                    "the namespace information of the element");
-        }
-
-        setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE,
uri);
-        return new OMNamespaceImpl(uri, "");
-    }
-
     public OMNamespace getDefaultNamespace() {
         Attr decl = getAttributeNodeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE);
         if (decl != null) {
@@ -408,11 +355,6 @@ public class ElementImpl extends ParentN
         return new String(baos.toByteArray());
     }
 
-    /** @see org.apache.axiom.om.OMElement#getAllDeclaredNamespaces() */
-    public Iterator getAllDeclaredNamespaces() throws OMException {
-        return new NSDeclIterator(getAttributes());
-    }
-
     public OMElement cloneOMElement() {
         return (OMElement)clone(new OMCloneOptions());
     }

Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java?rev=1685484&r1=1685483&r2=1685484&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
(original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
Sun Jun 14 23:04:44 2015
@@ -44,6 +44,7 @@ import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.OMContainerEx;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.common.AxiomNamespaceDeclaration;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
 import org.apache.axiom.om.impl.common.factory.AxiomNodeFactory;
 import org.apache.axiom.om.impl.dom.CDATASectionImpl;
@@ -356,4 +357,8 @@ public class OMDOMFactory implements Axi
             String prefix, String namespaceURI) {
         return new NamespaceDeclaration((DocumentImpl)document, new OMNamespaceImpl(namespaceURI
== null ? "" : namespaceURI, prefix), this);
     }
+
+    public final AxiomNamespaceDeclaration createNamespaceDeclaration(OMNamespace namespace)
{
+        return new NamespaceDeclaration(null, namespace, this);
+    }
 }

Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=1685484&r1=1685483&r2=1685484&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
(original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
Sun Jun 14 23:04:44 2015
@@ -142,23 +142,6 @@ public class OMElementImpl extends OMNod
         return declareNamespace(ns);
     }
 
-    public OMNamespace declareDefaultNamespace(String uri) {
-        OMNamespace elementNamespace = getNamespace();
-        if (elementNamespace == null && uri.length() > 0
-                || elementNamespace != null && elementNamespace.getPrefix().length()
== 0 && !elementNamespace.getNamespaceURI().equals(uri)) {
-            throw new OMException("Attempt to add a namespace declaration that conflicts
with " +
-            		"the namespace information of the element");
-        }
-
-        OMNamespaceImpl namespace = new OMNamespaceImpl(uri == null ? "" : uri, "");
-
-        if (namespaces == null) {
-            this.namespaces = new HashMap(5);
-        }
-        namespaces.put("", namespace);
-        return namespace;
-    }
-
     public OMNamespace getDefaultNamespace() {
         OMNamespace defaultNS;
         if (namespaces != null && (defaultNS = (OMNamespace) namespaces.get(""))
!= null) {
@@ -172,43 +155,6 @@ public class OMElementImpl extends OMNod
         return null;
     }
 
-    public OMNamespace addNamespaceDeclaration(String uri, String prefix) {
-        OMNamespace ns = new OMNamespaceImpl(uri, prefix);
-        addNamespaceDeclaration(ns);
-        return ns;
-    }
-    
-    public void addNamespaceDeclaration(OMNamespace ns) {
-        if (namespaces == null) {
-            this.namespaces = new HashMap(5);
-        }
-        namespaces.put(ns.getPrefix(), ns);
-    }
-
-    /** @return Returns namespace. */
-    public OMNamespace declareNamespace(OMNamespace namespace) {
-        if (namespaces == null) {
-            this.namespaces = new HashMap(5);
-        }
-        String prefix = namespace.getPrefix();
-        if (prefix == null) {
-            prefix = OMSerializerUtil.getNextNSPrefix();
-            namespace = new OMNamespaceImpl(namespace.getNamespaceURI(), prefix);
-        }
-        if (prefix.length() > 0 && namespace.getNamespaceURI().length() == 0)
{
-            throw new IllegalArgumentException("Cannot bind a prefix to the empty namespace
name");
-        }
-        namespaces.put(prefix, namespace);
-        return namespace;
-    }
-
-    public void undeclarePrefix(String prefix) {
-        if (namespaces == null) {
-            this.namespaces = new HashMap(5);
-        }
-        namespaces.put(prefix, new OMNamespaceImpl("", prefix));
-    }
-
     /**
      * Finds a namespace with the given uri and prefix, in the scope of the document. Starts
to find
      * from the current element and goes up in the hiararchy until one is found. If none
is found,
@@ -313,19 +259,6 @@ public class OMElementImpl extends OMNod
         return null;
     }
 
-
-    /**
-     * Method getAllDeclaredNamespaces.
-     *
-     * @return Returns Iterator.
-     */
-    public Iterator getAllDeclaredNamespaces() {
-        if (namespaces == null) {
-            return EMPTY_ITERATOR;
-        }
-        return namespaces.values().iterator();
-    }
-
     /**
      * Inserts an attribute to this element. Implementor can decide as to insert this in
the front
      * or at the end of set of attributes.

Modified: webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java?rev=1685484&r1=1685483&r2=1685484&view=diff
==============================================================================
--- webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
(original)
+++ webservices/axiom/branches/attrs-aspects/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
Sun Jun 14 23:04:44 2015
@@ -43,10 +43,12 @@ import org.apache.axiom.om.OMSourcedElem
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.common.AxiomNamespaceDeclaration;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
 import org.apache.axiom.om.impl.common.factory.AxiomNodeFactory;
 import org.apache.axiom.om.impl.llom.CDATASectionImpl;
 import org.apache.axiom.om.impl.llom.CharacterDataImpl;
+import org.apache.axiom.om.impl.llom.NamespaceDeclaration;
 import org.apache.axiom.om.impl.llom.OMAttributeImpl;
 import org.apache.axiom.om.impl.llom.OMCommentImpl;
 import org.apache.axiom.om.impl.llom.OMDocTypeImpl;
@@ -364,4 +366,10 @@ public class OMLinkedListImplFactory imp
         // TODO
         throw new UnsupportedOperationException();
     }
+
+    public final AxiomNamespaceDeclaration createNamespaceDeclaration(OMNamespace namespace)
{
+        NamespaceDeclaration decl = new NamespaceDeclaration(this);
+        decl.setDeclaredNamespace(namespace);
+        return decl;
+    }
 }



Mime
View raw message