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 2015/09/19 12:24:26 UTC

svn commit: r1703975 - in /webservices/axiom/trunk: aspects/fom-aspects/src/main/java/org/apache/axiom/fom/ implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/ testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/ testing/fom-t...

Author: veithen
Date: Sat Sep 19 10:24:26 2015
New Revision: 1703975

URL: http://svn.apache.org/viewvc?rev=1703975&view=rev
Log:
Rewrite setAttributeValue to use the core model API.

Added:
    webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestSetAttributeValueQNameNew.java   (with props)
    webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestSetAttributeValueQNameRemove.java   (with props)
Modified:
    webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/Policies.java
    webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
    webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/FOMTestSuiteBuilder.java
    webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestGetFactory.java

Modified: webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/Policies.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/Policies.java?rev=1703975&r1=1703974&r2=1703975&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/Policies.java (original)
+++ webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/Policies.java Sat Sep 19 10:24:26 2015
@@ -18,11 +18,13 @@
  */
 package org.apache.axiom.fom;
 
+import org.apache.axiom.core.AttributeMatcher;
 import org.apache.axiom.core.CoreDocument;
 import org.apache.axiom.core.CoreParentNode;
 import org.apache.axiom.core.DetachPolicy;
+import org.apache.axiom.core.NSAwareAttributeMatcher;
 
-final class Policies {
+public final class Policies {
     private Policies() {}
     
     public static final DetachPolicy DETACH_POLICY = new DetachPolicy() {
@@ -30,4 +32,6 @@ final class Policies {
             return null;
         }
     };
+    
+    public static final AttributeMatcher ATTRIBUTE_MATCHER = new NSAwareAttributeMatcher(DETACH_POLICY, false, false);
 }

Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java?rev=1703975&r1=1703974&r2=1703975&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java (original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java Sat Sep 19 10:24:26 2015
@@ -58,6 +58,7 @@ import org.apache.abdera.util.MimeTypeHe
 import org.apache.abdera.writer.Writer;
 import org.apache.abdera.writer.WriterOptions;
 import org.apache.axiom.fom.AbderaElement;
+import org.apache.axiom.fom.Policies;
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMComment;
 import org.apache.axiom.om.OMContainer;
@@ -209,27 +210,10 @@ public class FOMElement extends FOMChild
     }
 
     public <T extends Element> T setAttributeValue(QName qname, String value) {
-        OMAttribute attr = this.getAttribute(qname);
-        if (attr != null && value != null) {
-            attr.setAttributeValue(value);
+        if (value == null) {
+            coreRemoveAttribute(Policies.ATTRIBUTE_MATCHER, qname.getNamespaceURI(), qname.getLocalPart());
         } else {
-            if (value != null) {
-                String uri = qname.getNamespaceURI();
-                String prefix = qname.getPrefix();
-                OMFactory factory = getOMFactory();
-                if (uri != null) {
-                    OMNamespace ns = findNamespace(uri, prefix);
-                    if (ns == null)
-                        ns = factory.createOMNamespace(uri, prefix);
-                    attr = factory.createOMAttribute(qname.getLocalPart(), ns, value);
-                } else {
-                    attr = factory.createOMAttribute(qname.getLocalPart(), null, value);
-                }
-                if (attr != null)
-                    addAttribute(attr);
-            } else if (attr != null) {
-                removeAttribute(attr);
-            }
+            coreSetAttribute(Policies.ATTRIBUTE_MATCHER, qname.getNamespaceURI(), qname.getLocalPart(), qname.getPrefix(), value);
         }
         return (T)this;
     }

Modified: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/FOMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/FOMTestSuiteBuilder.java?rev=1703975&r1=1703974&r2=1703975&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/FOMTestSuiteBuilder.java (original)
+++ webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/FOMTestSuiteBuilder.java Sat Sep 19 10:24:26 2015
@@ -18,6 +18,8 @@
  */
 package org.apache.axiom.ts.fom;
 
+import javax.xml.namespace.QName;
+
 import org.apache.abdera.Abdera;
 import org.apache.axiom.testutils.suite.MatrixTestSuiteBuilder;
 
@@ -31,5 +33,9 @@ public class FOMTestSuiteBuilder extends
     @Override
     protected void addTests() {
         addTest(new org.apache.axiom.ts.fom.attribute.TestGetFactory(abdera));
+        addTest(new org.apache.axiom.ts.fom.attribute.TestSetAttributeValueQNameNew(abdera, new QName("attr")));
+        addTest(new org.apache.axiom.ts.fom.attribute.TestSetAttributeValueQNameNew(abdera, new QName("urn:test", "attr")));
+        addTest(new org.apache.axiom.ts.fom.attribute.TestSetAttributeValueQNameNew(abdera, new QName("urn:test", "attr", "p")));
+        addTest(new org.apache.axiom.ts.fom.attribute.TestSetAttributeValueQNameRemove(abdera));
     }
 }

Modified: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestGetFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestGetFactory.java?rev=1703975&r1=1703974&r2=1703975&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestGetFactory.java (original)
+++ webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestGetFactory.java Sat Sep 19 10:24:26 2015
@@ -20,11 +20,12 @@ package org.apache.axiom.ts.fom.attribut
 
 import static com.google.common.truth.Truth.assertThat;
 
+import javax.xml.namespace.QName;
+
 import org.apache.abdera.Abdera;
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.model.Attribute;
 import org.apache.abdera.model.Element;
-import org.apache.abdera.model.Feed;
 import org.apache.axiom.ts.fom.AbderaTestCase;
 
 /**
@@ -39,9 +40,9 @@ public class TestGetFactory extends Abde
     @Override
     protected void runTest() throws Throwable {
         Factory factory = abdera.getFactory();
-        Feed feed = factory.newFeed();
-        feed.setAttributeValue("attr", "value");
-        Object xpathResult = abdera.getXPath().selectSingleNode("./@attr", feed);
+        Element element = factory.newElement(new QName("test"));
+        element.setAttributeValue("attr", "value");
+        Object xpathResult = abdera.getXPath().selectSingleNode("./@attr", element);
         assertThat(xpathResult).isInstanceOf(Attribute.class);
         assertThat(((Attribute)xpathResult).getFactory()).isSameAs(factory);
     }

Added: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestSetAttributeValueQNameNew.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestSetAttributeValueQNameNew.java?rev=1703975&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestSetAttributeValueQNameNew.java (added)
+++ webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestSetAttributeValueQNameNew.java Sat Sep 19 10:24:26 2015
@@ -0,0 +1,52 @@
+/*
+ * 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.ts.fom.attribute;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Element;
+import org.apache.axiom.ts.fom.AbderaTestCase;
+
+public class TestSetAttributeValueQNameNew extends AbderaTestCase {
+    private final QName qname;
+    
+    public TestSetAttributeValueQNameNew(Abdera abdera, QName qname) {
+        super(abdera);
+        this.qname = qname;
+        addTestParameter("qname", qname.toString());
+        addTestParameter("prefix", qname.getPrefix());
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        Element element = abdera.getFactory().newElement(new QName("test"));
+        element.setAttributeValue(qname, "value");
+        assertThat(element.getAttributeValue(qname)).isEqualTo("value");
+        List<QName> attrs = element.getAttributes();
+        assertThat(attrs).hasSize(1);
+        QName actualQName = attrs.get(0);
+        assertThat(actualQName).isEqualTo(qname);
+        assertThat(actualQName.getPrefix()).isEqualTo(qname.getPrefix());
+    }
+}

Propchange: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestSetAttributeValueQNameNew.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestSetAttributeValueQNameRemove.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestSetAttributeValueQNameRemove.java?rev=1703975&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestSetAttributeValueQNameRemove.java (added)
+++ webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestSetAttributeValueQNameRemove.java Sat Sep 19 10:24:26 2015
@@ -0,0 +1,43 @@
+/*
+ * 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.ts.fom.attribute;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Element;
+import org.apache.axiom.ts.fom.AbderaTestCase;
+
+public class TestSetAttributeValueQNameRemove extends AbderaTestCase {
+    public TestSetAttributeValueQNameRemove(Abdera abdera) {
+        super(abdera);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        Element element = abdera.getFactory().newElement(new QName("test"));
+        QName qname = new QName("urn:test", "attr", "p");
+        element.setAttributeValue(qname, "value");
+        assertThat(element.getAttributes()).containsExactly(qname);
+        element.setAttributeValue(qname, null);
+        assertThat(element.getAttributes()).isEmpty();
+    }
+}

Propchange: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/attribute/TestSetAttributeValueQNameRemove.java
------------------------------------------------------------------------------
    svn:eol-style = native