ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1740609 - in /webservices/axiom/trunk: aspects/dom-aspects/src/main/java/org/apache/axiom/dom/ aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/ implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ impleme...
Date Fri, 22 Apr 2016 21:30:20 GMT
Author: veithen
Date: Fri Apr 22 21:30:20 2016
New Revision: 1740609

URL: http://svn.apache.org/viewvc?rev=1740609&view=rev
Log:
Replace ID attribute handling by a better implementation (except for the fact that it rejects
namespace declarations as ID attributes).

Modified:
    webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMTypedAttribute.java
    webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMDocumentSupport.aj
    webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMElementSupport.aj
    webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMNamespaceDeclarationSupport.aj
    webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMTypedAttributeSupport.aj
    webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
    webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
    webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
    webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java

Modified: webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMTypedAttribute.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMTypedAttribute.java?rev=1740609&r1=1740608&r2=1740609&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMTypedAttribute.java
(original)
+++ webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMTypedAttribute.java
Fri Apr 22 21:30:20 2016
@@ -18,6 +18,8 @@
  */
 package org.apache.axiom.dom;
 
-public interface DOMTypedAttribute extends DOMAttribute, DOMNamedNode{
+import org.apache.axiom.core.CoreTypedAttribute;
+
+public interface DOMTypedAttribute extends DOMAttribute, DOMNamedNode, CoreTypedAttribute
{
 
 }

Modified: webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMDocumentSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMDocumentSupport.aj?rev=1740609&r1=1740608&r2=1740609&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMDocumentSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMDocumentSupport.aj
Fri Apr 22 21:30:20 2016
@@ -20,17 +20,23 @@ package org.apache.axiom.dom.impl.mixin;
 
 import static org.apache.axiom.dom.DOMExceptionUtil.newDOMException;
 
+import java.util.Iterator;
+
 import javax.xml.XMLConstants;
 
+import org.apache.axiom.core.Axis;
+import org.apache.axiom.core.CoreAttribute;
 import org.apache.axiom.core.CoreChildNode;
 import org.apache.axiom.core.CoreElement;
 import org.apache.axiom.core.CoreModelException;
+import org.apache.axiom.core.Mappers;
 import org.apache.axiom.dom.DOMAttribute;
 import org.apache.axiom.dom.DOMCDATASection;
 import org.apache.axiom.dom.DOMComment;
 import org.apache.axiom.dom.DOMConfigurationImpl;
 import org.apache.axiom.dom.DOMDocument;
 import org.apache.axiom.dom.DOMDocumentFragment;
+import org.apache.axiom.dom.DOMElement;
 import org.apache.axiom.dom.DOMEntityReference;
 import org.apache.axiom.dom.DOMExceptionUtil;
 import org.apache.axiom.dom.DOMNSAwareAttribute;
@@ -385,4 +391,20 @@ public aspect DOMDocumentSupport {
             throw newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
         }
     }
+
+    public final Element DOMDocument.getElementById(String elementId) {
+        try {
+            for (Iterator<DOMElement> it = coreGetNodes(Axis.DESCENDANTS, DOMElement.class,
Mappers.<DOMElement>identity(), DOMSemantics.INSTANCE); it.hasNext(); ) {
+                DOMElement element = it.next();
+                for (CoreAttribute attr = element.coreGetFirstAttribute(); attr != null;
attr = attr.coreGetNextAttribute()) {
+                    if (((DOMAttribute)attr).isId() && elementId.equals(attr.coreGetCharacterData().toString()))
{
+                        return element;
+                    }
+                }
+            }
+            return null;
+        } catch (CoreModelException ex) {
+            throw DOMExceptionUtil.toUncheckedException(ex);
+        }
+    }
 }

Modified: webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMElementSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMElementSupport.aj?rev=1740609&r1=1740608&r2=1740609&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMElementSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMElementSupport.aj
Fri Apr 22 21:30:20 2016
@@ -21,10 +21,12 @@ package org.apache.axiom.dom.impl.mixin;
 import javax.xml.XMLConstants;
 
 import org.apache.axiom.core.AttributeMatcher;
+import org.apache.axiom.core.CoreAttribute;
 import org.apache.axiom.core.CoreElement;
 import org.apache.axiom.core.CoreModelException;
 import org.apache.axiom.core.CoreNSAwareAttribute;
 import org.apache.axiom.core.CoreNamespaceDeclaration;
+import org.apache.axiom.core.CoreTypedAttribute;
 import org.apache.axiom.core.ElementAction;
 import org.apache.axiom.dom.AttributesNamedNodeMap;
 import org.apache.axiom.dom.DOMAttribute;
@@ -229,4 +231,31 @@ public aspect DOMElementSupport {
     public final NodeList DOMElement.getElementsByTagNameNS(String namespaceURI, String localName)
{
         return new ElementsByTagNameNS(this, namespaceURI, localName);
     }
+
+    public final void DOMElement.setIdAttribute(String name, boolean isId) throws DOMException
{
+        CoreAttribute attr = coreGetAttribute(DOMSemantics.DOM1_ATTRIBUTE_MATCHER, null,
name);
+        if (attr == null) {
+            throw DOMExceptionUtil.newDOMException(DOMException.NOT_FOUND_ERR);
+        } else {
+            ((CoreTypedAttribute)attr).coreSetType(isId ? "ID" : "CDATA");
+        }
+    }
+
+    public final void DOMElement.setIdAttributeNS(String namespaceURI, String localName,
boolean isId) throws DOMException {
+        // Here, we assume that a namespace declaration can never be an ID attribute
+        CoreAttribute attr = coreGetAttribute(DOMSemantics.DOM2_ATTRIBUTE_MATCHER, NSUtil.normalizeNamespaceURI(namespaceURI),
localName);
+        if (attr == null) {
+            throw DOMExceptionUtil.newDOMException(DOMException.NOT_FOUND_ERR);
+        } else {
+            ((CoreTypedAttribute)attr).coreSetType(isId ? "ID" : "CDATA");
+        }
+    }
+
+    public final void DOMElement.setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException
{
+        if (idAttr.getOwnerElement() != this) {
+            throw DOMExceptionUtil.newDOMException(DOMException.NOT_FOUND_ERR);
+        } else {
+            ((CoreTypedAttribute)idAttr).coreSetType(isId ? "ID" : "CDATA");
+        }
+    }
 }

Modified: webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMNamespaceDeclarationSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMNamespaceDeclarationSupport.aj?rev=1740609&r1=1740608&r2=1740609&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMNamespaceDeclarationSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMNamespaceDeclarationSupport.aj
Fri Apr 22 21:30:20 2016
@@ -52,4 +52,8 @@ public aspect DOMNamespaceDeclarationSup
             return XMLConstants.XMLNS_ATTRIBUTE + ":" + declaredPrefix;
         }
     }
+
+    public final boolean DOMNamespaceDeclaration.isId() {
+        return false;
+    }
 }

Modified: webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMTypedAttributeSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMTypedAttributeSupport.aj?rev=1740609&r1=1740608&r2=1740609&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMTypedAttributeSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/impl/mixin/DOMTypedAttributeSupport.aj
Fri Apr 22 21:30:20 2016
@@ -24,4 +24,8 @@ public aspect DOMTypedAttributeSupport {
     public final String DOMTypedAttribute.getName() {
         return internalGetName();
     }
+
+    public final boolean DOMTypedAttribute.isId() {
+        return "ID".equals(coreGetType());
+    }
 }

Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java?rev=1740609&r1=1740608&r2=1740609&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
(original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
Fri Apr 22 21:30:20 2016
@@ -23,10 +23,5 @@ import org.apache.axiom.dom.DOMAttribute
 
 /** Implementation of <code>org.w3c.dom.Attr</code> and <code>org.apache.axiom.om.OMAttribute</code>
*/
 public abstract class AttrImpl extends ParentNode implements DOMAttribute {
-    /** Flag used to mark an attribute as per the DOM Level 3 specification */
-    protected boolean isId;
 
-    public boolean isId() {
-        return isId;
-    }
 }

Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=1740609&r1=1740608&r2=1740609&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
(original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
Fri Apr 22 21:30:20 2016
@@ -21,9 +21,7 @@ package org.apache.axiom.om.impl.dom;
 
 import static org.apache.axiom.dom.DOMExceptionUtil.newDOMException;
 
-import java.util.Enumeration;
 import java.util.Hashtable;
-import java.util.Vector;
 
 import org.apache.axiom.dom.DOMDocument;
 import org.apache.axiom.om.impl.intf.AxiomDocument;
@@ -35,29 +33,8 @@ import org.w3c.dom.Node;
 import org.w3c.dom.ProcessingInstruction;
 
 public class DocumentImpl extends ParentNode implements DOMDocument, AxiomDocument {
-    private Vector idAttrs;
-
     protected Hashtable identifiers;
     
-    public Element getElementById(String elementId) {
-
-        //If there are no id attrs
-        if (this.idAttrs == null) {
-            return null;
-        }
-
-        Enumeration attrEnum = this.idAttrs.elements();
-        while (attrEnum.hasMoreElements()) {
-            Attr tempAttr = (Attr) attrEnum.nextElement();
-            if (tempAttr.getValue().equals(elementId)) {
-                return tempAttr.getOwnerElement();
-            }
-        }
-
-        //If we reach this point then, there's no such attr 
-        return null;
-    }
-
     public Node importNode(Node importedNode, boolean deep) throws DOMException {
 
         short type = importedNode.getNodeType();
@@ -147,20 +124,6 @@ public class DocumentImpl extends Parent
 
     }
 
-    protected void addIdAttr(Attr attr) {
-        if (this.idAttrs == null) {
-            this.idAttrs = new Vector();
-        }
-        this.idAttrs.add(attr);
-    }
-
-    protected void removeIdAttr(Attr attr) {
-        if (this.idAttrs != null) {
-            this.idAttrs.remove(attr);
-        }
-
-    }
-
     /*
     * DOM-Level 3 methods
     */

Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1740609&r1=1740608&r2=1740609&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
(original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
Fri Apr 22 21:30:20 2016
@@ -19,61 +19,8 @@
 
 package org.apache.axiom.om.impl.dom;
 
-import static org.apache.axiom.dom.DOMExceptionUtil.newDOMException;
-
-import org.apache.axiom.dom.DOMAttribute;
 import org.apache.axiom.dom.DOMElement;
-import org.w3c.dom.Attr;
-import org.w3c.dom.DOMException;
 
 public abstract class ElementImpl extends ParentNode implements DOMElement {
-    /*
-     * DOM-Level 3 methods
-     */
-
-    public final void setIdAttribute(String name, boolean isId) throws DOMException {
-        //find the attr
-        AttrImpl tempAttr = (AttrImpl) this.getAttributeNode(name);
-        if (tempAttr == null) {
-            throw newDOMException(DOMException.NOT_FOUND_ERR);
-        }
-
-        this.updateIsId(isId, tempAttr);
-    }
-
-    public final void setIdAttributeNS(String namespaceURI, String localName, boolean isId)
-            throws DOMException {
-        //find the attr
-        AttrImpl tempAttr = (AttrImpl) this.getAttributeNodeNS(namespaceURI, localName);
-        if (tempAttr == null) {
-            throw newDOMException(DOMException.NOT_FOUND_ERR);
-        }
-
-        this.updateIsId(isId, tempAttr);
-    }
-
-    public final void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException {
-        //find the attr
-        if (((DOMAttribute)idAttr).coreGetOwnerElement() != this) {
-            throw newDOMException(DOMException.NOT_FOUND_ERR);
-        }
-        this.updateIsId(isId, (AttrImpl)idAttr);
-    }
 
-    /**
-     * Updates the id state of the attr and notifies the document
-     *
-     * @param isId
-     * @param tempAttr
-     */
-    private void updateIsId(boolean isId, AttrImpl tempAttr) {
-        if (tempAttr.isId != isId) {
-            tempAttr.isId = isId;
-            if (isId) {
-                ownerDocument().addIdAttr(tempAttr);
-            } else {
-                ownerDocument().removeIdAttr(tempAttr);
-            }
-        }
-    }
 }

Modified: webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java?rev=1740609&r1=1740608&r2=1740609&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
(original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
Fri Apr 22 21:30:20 2016
@@ -74,7 +74,6 @@ public class DOMImplementationTest exten
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/domimplementationcreatedocumenttype01)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/domimplementationcreatedocumenttype02)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/domimplementationcreatedocumenttype04)");
-        builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/getElementById01)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/getElementsByTagNameNS01)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/getElementsByTagNameNS08)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/hc_nodedocumentfragmentnormalize1)");
@@ -94,8 +93,6 @@ public class DOMImplementationTest exten
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/prefix06)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/prefix07)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level2/core/removeAttributeNS02)");
-        builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/attrisid04)");
-        builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/attrisid05)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/canonicalform06)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/checkcharacternormalization01)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/documentadoptnode07)");
@@ -171,9 +168,18 @@ public class DOMImplementationTest exten
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/domstringlistitem01)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/domstringlistitem02)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementcontentwhitespace01)");
+        builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributenode01)");
+        builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributenode04)");
+        builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributenode08)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributenode09)");
+        builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributens01)");
+        builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributens03)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributens05)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributens09)");
+        builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributens10)");
+        builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributens11)");
+        builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributens13)");
+        builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/elementsetidattributens14)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/entities03)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/handleerror01)");
         builder.exclude(W3CTestCase.class, "(id=http://www.w3.org/2001/DOM-Test-Suite/level3/core/handleerror02)");



Mime
View raw message