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/26 14:16:10 UTC
svn commit: r1705436 - 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 26 12:16:10 2015
New Revision: 1705436
URL: http://svn.apache.org/viewvc?rev=1705436&view=rev
Log:
Eliminate duplicate code.
Added:
webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/Categorizable.java (with props)
webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/CategorizableMixin.aj (with props)
webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/entry/TestAddCategoryFromCategories.java (with props)
webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/org/apache/axiom/ts/fom/entry/categories.xml (with props)
Modified:
webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/AbderaEntry.java
webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/AbderaSource.java
webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/CategoryContainerMixin.aj
webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMSource.java
webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/FOMTestSuiteBuilder.java
Modified: webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/AbderaEntry.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/AbderaEntry.java?rev=1705436&r1=1705435&r2=1705436&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/AbderaEntry.java (original)
+++ webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/AbderaEntry.java Sat Sep 26 12:16:10 2015
@@ -20,6 +20,6 @@ package org.apache.axiom.fom;
import org.apache.abdera.model.Entry;
-public interface AbderaEntry extends Entry, AbderaExtensibleElement, CategoryContainer {
+public interface AbderaEntry extends Entry, AbderaExtensibleElement, Categorizable {
}
Modified: webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/AbderaSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/AbderaSource.java?rev=1705436&r1=1705435&r2=1705436&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/AbderaSource.java (original)
+++ webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/AbderaSource.java Sat Sep 26 12:16:10 2015
@@ -20,6 +20,6 @@ package org.apache.axiom.fom;
import org.apache.abdera.model.Source;
-public interface AbderaSource extends Source, AbderaExtensibleElement, CategoryContainer {
+public interface AbderaSource extends Source, AbderaExtensibleElement, Categorizable {
}
Added: webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/Categorizable.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/Categorizable.java?rev=1705436&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/Categorizable.java (added)
+++ webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/Categorizable.java Sat Sep 26 12:16:10 2015
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+public interface Categorizable extends CategoryContainer {
+
+}
Propchange: webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/Categorizable.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/CategorizableMixin.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/CategorizableMixin.aj?rev=1705436&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/CategorizableMixin.aj (added)
+++ webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/CategorizableMixin.aj Sat Sep 26 12:16:10 2015
@@ -0,0 +1,40 @@
+/*
+ * 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.abdera.model.Categories;
+import org.apache.abdera.model.Category;
+import org.apache.abdera.model.Element;
+
+public aspect CategorizableMixin {
+ public final void Categorizable.internalAddCategory(Category category) {
+ Element el = category.getParentElement();
+ if (el != null && el instanceof Categories) {
+ Categories cats = category.getParentElement();
+ category = (Category)category.clone();
+ try {
+ if (category.getScheme() == null && cats.getScheme() != null)
+ category.setScheme(cats.getScheme().toString());
+ } catch (Exception e) {
+ // Do nothing, shouldn't happen
+ }
+ }
+ coreAppendChild((AbderaCategory)category, false);
+ }
+}
Propchange: webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/CategorizableMixin.aj
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/CategoryContainerMixin.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/CategoryContainerMixin.aj?rev=1705436&r1=1705435&r2=1705436&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/CategoryContainerMixin.aj (original)
+++ webservices/axiom/trunk/aspects/fom-aspects/src/main/java/org/apache/axiom/fom/CategoryContainerMixin.aj Sat Sep 26 12:16:10 2015
@@ -25,7 +25,6 @@ import org.apache.abdera.util.Constants;
import org.apache.axiom.core.Axis;
import org.apache.axiom.core.ElementMatcher;
-// TODO: also handle addCategory(Category) here
public aspect CategoryContainerMixin {
private static final ElementMatcher<AbderaCategory> CATEGORY_BY_SCHEME = new ElementMatcher<AbderaCategory>() {
public boolean matches(AbderaCategory element, String namespaceURI, String name) {
Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java?rev=1705436&r1=1705435&r2=1705436&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java (original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java Sat Sep 26 12:16:10 2015
@@ -30,7 +30,6 @@ import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.i18n.iri.IRISyntaxException;
import org.apache.abdera.i18n.text.io.InputStreamDataSource;
import org.apache.abdera.model.AtomDate;
-import org.apache.abdera.model.Categories;
import org.apache.abdera.model.Category;
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Content.Type;
@@ -81,18 +80,7 @@ public class FOMEntry extends FOMExtensi
}
public Entry addCategory(Category category) {
- Element el = category.getParentElement();
- if (el != null && el instanceof Categories) {
- Categories cats = category.getParentElement();
- category = (Category)category.clone();
- try {
- if (category.getScheme() == null && cats.getScheme() != null)
- category.setScheme(cats.getScheme().toString());
- } catch (Exception e) {
- // Do nothing, shouldn't happen
- }
- }
- addChild((OMElement)category);
+ internalAddCategory(category);
return this;
}
Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMSource.java?rev=1705436&r1=1705435&r2=1705436&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMSource.java (original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMSource.java Sat Sep 26 12:16:10 2015
@@ -24,12 +24,10 @@ import java.util.List;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.i18n.iri.IRIHelper;
import org.apache.abdera.model.AtomDate;
-import org.apache.abdera.model.Categories;
import org.apache.abdera.model.Category;
import org.apache.abdera.model.Collection;
import org.apache.abdera.model.DateTime;
import org.apache.abdera.model.Div;
-import org.apache.abdera.model.Element;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Generator;
import org.apache.abdera.model.IRIElement;
@@ -72,18 +70,7 @@ public class FOMSource extends FOMExtens
}
public <T extends Source> T addCategory(Category category) {
- Element el = category.getParentElement();
- if (el != null && el instanceof Categories) {
- Categories cats = category.getParentElement();
- category = (Category)category.clone();
- try {
- if (category.getScheme() == null && cats.getScheme() != null)
- category.setScheme(cats.getScheme().toString());
- } catch (Exception e) {
- // Do nothing, shouldn't happen
- }
- }
- addChild((OMElement)category);
+ internalAddCategory(category);
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=1705436&r1=1705435&r2=1705436&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 26 12:16:10 2015
@@ -41,6 +41,7 @@ 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.TestAddCategoryFromCategories(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/TestAddCategoryFromCategories.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/entry/TestAddCategoryFromCategories.java?rev=1705436&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/entry/TestAddCategoryFromCategories.java (added)
+++ webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/entry/TestAddCategoryFromCategories.java Sat Sep 26 12:16:10 2015
@@ -0,0 +1,51 @@
+/*
+ * 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 org.apache.abdera.Abdera;
+import org.apache.abdera.model.Categories;
+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 TestAddCategoryFromCategories extends AbderaTestCase {
+ public TestAddCategoryFromCategories(Abdera abdera) {
+ super(abdera);
+ }
+
+ @Override
+ protected void runTest() throws Throwable {
+ Document<Categories> document = abdera.getParser().parse(
+ TestAddCategoryFromCategories.class.getResourceAsStream("categories.xml"));
+ Categories categories = document.getRoot();
+ Entry entry = abdera.getFactory().newEntry();
+ Category orgCategory = categories.getCategories().get(0);
+ entry.addCategory(orgCategory);
+ Category category = entry.getCategories().get(0);
+ assertThat(category).isNotSameAs(orgCategory);
+ // Assert that the original Category has not been removed from the Categories instance
+ assertThat(categories.getCategories().get(0)).isSameAs(orgCategory);
+ assertThat(category.getTerm()).isEqualTo(orgCategory.getTerm());
+ // The scheme is inherited from the app:categories element
+ assertThat(category.getScheme()).isEqualTo(categories.getScheme());
+ }
+}
Propchange: webservices/axiom/trunk/testing/fom-testsuite/src/main/java/org/apache/axiom/ts/fom/entry/TestAddCategoryFromCategories.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=1705436&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 Sat Sep 26 12:16:10 2015
@@ -0,0 +1,27 @@
+<?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.
+ -->
+<app:categories
+ xmlns:app="http://www.w3.org/2007/app"
+ xmlns:atom="http://www.w3.org/2005/Atom"
+ fixed="yes" scheme="http://example.com/cats/big3">
+ <atom:category term="animal" />
+ <atom:category term="vegetable" />
+ <atom:category term="mineral" />
+</app:categories>
Propchange: webservices/axiom/trunk/testing/fom-testsuite/src/main/resources/org/apache/axiom/ts/fom/entry/categories.xml
------------------------------------------------------------------------------
svn:eol-style = native