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/25 00:07:25 UTC

svn commit: r1705175 - 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/util/ testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/ testing/...

Author: veithen
Date: Thu Sep 24 22:07:24 2015
New Revision: 1705175

URL: http://svn.apache.org/viewvc?rev=1705175&view=rev
Log:
Rewrite FOMHelper.getCategories using the core model API.

Added:
    webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/FOMExceptionTranslator.java   (with props)
    webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/entry/
    webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/entry/TestGetCategoriesByScheme.java   (with props)
    webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/
    webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/org/
    webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/org/apache/
    webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/org/apache/axiom/
    webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/org/apache/axiom/ts/
    webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/org/apache/axiom/ts/fom/
    webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/org/apache/axiom/ts/fom/entry/
    webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/org/apache/axiom/ts/fom/entry/categories.xml   (with props)
Modified:
    webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/util/FOMHelper.java
    webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/util/FOMList.java
    webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/FOMTestSuiteBuilder.java

Added: webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/FOMExceptionTranslator.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/FOMExceptionTranslator.java?rev=1705175&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/FOMExceptionTranslator.java (added)
+++ webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/FOMExceptionTranslator.java Thu Sep 24 22:07:24 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.fom;
+
+import org.apache.axiom.core.CoreModelException;
+import org.apache.axiom.core.ExceptionTranslator;
+
+public final class FOMExceptionTranslator implements ExceptionTranslator {
+    public static final FOMExceptionTranslator INSTANCE = new FOMExceptionTranslator();
+    
+    private FOMExceptionTranslator() {}
+
+    public RuntimeException toUncheckedException(CoreModelException ex) {
+        return new RuntimeException(ex);
+    }
+}

Propchange: webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/FOMExceptionTranslator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/util/FOMHelper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/util/FOMHelper.java?rev=1705175&r1=1705174&r2=1705175&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/util/FOMHelper.java (original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/util/FOMHelper.java Thu Sep 24 22:07:24 2015
@@ -25,14 +25,28 @@ import org.apache.abdera.model.Category;
 import org.apache.abdera.model.Element;
 import org.apache.abdera.model.Link;
 import org.apache.abdera.util.Constants;
+import org.apache.axiom.core.Axis;
+import org.apache.axiom.core.ElementMatcher;
+import org.apache.axiom.fom.AbderaCategory;
+import org.apache.axiom.fom.AbderaElement;
+import org.apache.axiom.fom.FOMExceptionTranslator;
+import org.apache.axiom.fom.Policies;
 import org.apache.axiom.util.UIDGenerator;
 
 @SuppressWarnings("unchecked")
 public class FOMHelper implements Constants {
+    private static final ElementMatcher<AbderaCategory> CATEGORY_BY_SCHEME = new ElementMatcher<AbderaCategory>() {
+        public boolean matches(AbderaCategory element, String namespaceURI, String name) {
+            String scheme = element.getAttributeValue(SCHEME);
+            return scheme != null && scheme.equals(name);
+        }
+    };
 
-    public static List<Category> getCategories(Element element, String scheme) {
-        Iterator i = new FOMElementIterator(element, Category.class, SCHEME, scheme, null);
-        return new FOMList<Category>(i);
+    public static List<Category> getCategories(AbderaElement element, String scheme) {
+        // TODO: we should probably set detachPolicy to null
+        return new FOMList<Category>(element.coreGetElements(
+                Axis.CHILDREN, AbderaCategory.class, CATEGORY_BY_SCHEME, null, scheme,
+                FOMExceptionTranslator.INSTANCE, Policies.DETACH_POLICY));
     }
 
     public static List<Link> getLinks(Element element, String rel) {

Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/util/FOMList.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/util/FOMList.java?rev=1705175&r1=1705174&r2=1705175&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/util/FOMList.java (original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/util/FOMList.java Thu Sep 24 22:07:24 2015
@@ -33,13 +33,12 @@ import java.util.ListIterator;
  * caller. This gives us a hybrid approach. We create an internal iterator, then create a List from that, the iterator
  * is consumed as the list is used. The List itself is unmodifiable.
  */
-@SuppressWarnings("unchecked")
 public class FOMList<T> extends java.util.AbstractCollection<T> implements List<T> {
 
-    private final Iterator<T> i;
+    private final Iterator<? extends T> i;
     private final List<T> buffer = new ArrayList<T>();
 
-    public FOMList(Iterator<T> i) {
+    public FOMList(Iterator<? extends T> i) {
         this.i = i;
     }
 
@@ -93,11 +92,11 @@ public class FOMList<T> extends java.uti
         throw new UnsupportedOperationException();
     }
 
-    public boolean addAll(Collection c) {
+    public boolean addAll(Collection<? extends T> c) {
         throw new UnsupportedOperationException();
     }
 
-    public boolean addAll(int index, Collection c) {
+    public boolean addAll(int index, Collection<? extends T> c) {
         throw new UnsupportedOperationException();
     }
 
@@ -110,7 +109,7 @@ public class FOMList<T> extends java.uti
         return buffer.contains(o);
     }
 
-    public boolean containsAll(Collection c) {
+    public boolean containsAll(Collection<?> c) {
         for (Object o : c)
             if (contains(o))
                 return true;
@@ -148,11 +147,11 @@ public class FOMList<T> extends java.uti
         throw new UnsupportedOperationException();
     }
 
-    public boolean removeAll(Collection c) {
+    public boolean removeAll(Collection<?> c) {
         throw new UnsupportedOperationException();
     }
 
-    public boolean retainAll(Collection c) {
+    public boolean retainAll(Collection<?> c) {
         throw new UnsupportedOperationException();
     }
 
@@ -170,21 +169,21 @@ public class FOMList<T> extends java.uti
         return buffer.toArray();
     }
 
-    public Object[] toArray(Object[] a) {
+    public <U> U[] toArray(U[] a) {
         buffer(-1);
         return buffer.toArray(a);
     }
 
     private class BufferIterator<M> implements ListIterator<M> {
 
-        private FOMList set = null;
+        private FOMList<M> set = null;
         private int counter = 0;
 
-        BufferIterator(FOMList set) {
+        BufferIterator(FOMList<M> set) {
             this.set = set;
         }
 
-        BufferIterator(FOMList set, int index) {
+        BufferIterator(FOMList<M> set, int index) {
             this.set = set;
             this.counter = index;
         }

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=1705175&r1=1705174&r2=1705175&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 Thu Sep 24 22:07:24 2015
@@ -41,5 +41,6 @@ public class FOMTestSuiteBuilder extends
         addTest(new org.apache.axiom.ts.fom.collection.TestSetAcceptRemove(abdera));
         addTest(new org.apache.axiom.ts.fom.control.TestIsDraft(abdera));
         addTest(new org.apache.axiom.ts.fom.control.TestSetUnsetDraft(abdera));
+        addTest(new org.apache.axiom.ts.fom.entry.TestGetCategoriesByScheme(abdera));
     }
 }

Added: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/entry/TestGetCategoriesByScheme.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/entry/TestGetCategoriesByScheme.java?rev=1705175&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/entry/TestGetCategoriesByScheme.java (added)
+++ webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/entry/TestGetCategoriesByScheme.java Thu Sep 24 22:07:24 2015
@@ -0,0 +1,45 @@
+/*
+ * 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.entry;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.util.List;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Category;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.axiom.ts.fom.AbderaTestCase;
+
+public class TestGetCategoriesByScheme extends AbderaTestCase {
+    public TestGetCategoriesByScheme(Abdera abdera) {
+        super(abdera);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        Document<Entry> document = abdera.getParser().parse(
+                TestGetCategoriesByScheme.class.getResourceAsStream("categories.xml"));
+        List<Category> categories = document.getRoot().getCategories("http://www.example.org/");
+        assertThat(categories).hasSize(2);
+        assertThat(categories.get(0).getTerm()).isEqualTo("term1");
+        assertThat(categories.get(1).getTerm()).isEqualTo("term2");
+    }
+}

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

Added: webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/org/apache/axiom/ts/fom/entry/categories.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/org/apache/axiom/ts/fom/entry/categories.xml?rev=1705175&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/org/apache/axiom/ts/fom/entry/categories.xml (added)
+++ webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/org/apache/axiom/ts/fom/entry/categories.xml Thu Sep 24 22:07:24 2015
@@ -0,0 +1,26 @@
+<?xml version="1.0" ?>
+<!--
+  ~ 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.
+  -->
+<entry xmlns="http://www.w3.org/2005/Atom">
+  <id>urn:uuid:1225c695-dead-cafe-babe-80da344efa6a</id>
+  <category scheme="http://www.example.org/" term="term1"/>
+  <category term="other"/>
+  <category scheme="http://www.example.org/" term="term2"/>
+  <category scheme="urn:test" term="test"/>
+</entry>

Propchange: webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/org/apache/axiom/ts/fom/entry/categories.xml
------------------------------------------------------------------------------
    svn:eol-style = native