You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/03/15 09:38:44 UTC

[isis] branch master updated: ISIS-1906 removing @Parent from applib

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 9d02350  ISIS-1906 removing @Parent from applib
9d02350 is described below

commit 9d02350540abdac94f07dd5ed1f13e6bb2fe621d
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Mar 15 10:38:38 2018 +0100

    ISIS-1906 removing @Parent from applib
    
    introduces new logic, handling
    @PropertyLayout(navigable=Navigable.PARENT) as a replacement for @Parent
---
 .../apache/isis/applib/annotation/Navigable.java   | 44 ++++++++++++++++++++++
 .../org/apache/isis/applib/annotation/Parent.java  | 34 -----------------
 .../isis/applib/annotation/PropertyLayout.java     |  2 +
 .../isis/core/metamodel/facets/Annotations.java    | 10 ++++-
 .../NavigableParentAnnotationFacetFactory.java     | 39 +++++++++++--------
 .../annotation/NavigableParentTestSamples.java     |  5 ++-
 6 files changed, 80 insertions(+), 54 deletions(-)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/Navigable.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/Navigable.java
new file mode 100644
index 0000000..76d599b
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/Navigable.java
@@ -0,0 +1,44 @@
+/*
+ *  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.isis.applib.annotation;
+
+/**
+ * 
+ * Tells the framework which method or field to use in order to construct a navigable chain of
+ * parent domain object instances. The Navigable.PARENT 'flag' can only be used once per class declaration. 
+ * 
+ * @since 2.0.0
+ *
+ */
+public enum Navigable {
+
+    
+	NOT_SPECIFIED,
+	
+	IGNORE,
+	
+	PARENT,
+	
+	;
+	
+    public boolean isParent() {
+        return this == PARENT;
+    }
+
+}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/Parent.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/Parent.java
deleted file mode 100644
index 6e4a7d8..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/annotation/Parent.java
+++ /dev/null
@@ -1,34 +0,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.
- */
-package org.apache.isis.applib.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Tells the framework which method or field to use in order to construct a navigable chain of
- * parent domain object instances. This annotation can only be used once per class declaration. 
- * 
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.FIELD, ElementType.METHOD})
-public @interface Parent {
-}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/PropertyLayout.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/PropertyLayout.java
index ec21f5f..a4939c3 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/annotation/PropertyLayout.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/PropertyLayout.java
@@ -70,6 +70,8 @@ public @interface PropertyLayout {
      * A flag indicating whether the value of {@linkplain #named()} should be HTML escaped or not.
      */
     boolean namedEscaped() default true;
+    
+    Navigable navigable() default Navigable.NOT_SPECIFIED;
 
     /**
      * How the properties of this domain object are be edited, either {@link PromptStyle#DIALOG dialog} or {@link PromptStyle#INLINE inline}.
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/Annotations.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/Annotations.java
index 381df00..972f06e 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/Annotations.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/Annotations.java
@@ -383,6 +383,7 @@ public final class Annotations  {
      * In this hierarchy traversal, implemented interfaces are not processed.      
      * @param cls
      * @param annotationClass
+     * @param filter
      * @return list of {@link Evaluator} that wraps each annotated member found on the class where 
      * the search stopped, or an empty list if no such {@code annotationClass} annotation found.
      * 
@@ -390,10 +391,15 @@ public final class Annotations  {
      */
     public static <T extends Annotation> List<Evaluator<T>> firstEvaluatorsInHierarchyHaving(
             final Class<?> cls,
-            final Class<T> annotationClass) {
+            final Class<T> annotationClass,
+            final Predicate<Evaluator<T>> filter) {
     	
     	 final List<Evaluator<T>> evaluators = Lists.newArrayList();
-    	 visitEvaluatorsWhile(cls, annotationClass, __->evaluators.isEmpty(), evaluators::add);
+    	 visitEvaluatorsWhile(cls, annotationClass, __->evaluators.isEmpty(), evaluator->{
+    		 if(filter.test(evaluator)) {
+    			 evaluators.add(evaluator);
+    		 }
+    	 });
          
          return evaluators;
     }
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/navparent/annotation/NavigableParentAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/navparent/annotation/NavigableParentAnnotationFacetFactory.java
index 5035d53..c929ab5 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/navparent/annotation/NavigableParentAnnotationFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/navparent/annotation/NavigableParentAnnotationFacetFactory.java
@@ -22,7 +22,7 @@ package org.apache.isis.core.metamodel.facets.object.navparent.annotation;
 import java.lang.reflect.Method;
 import java.util.List;
 
-import org.apache.isis.applib.annotation.Parent;
+import org.apache.isis.applib.annotation.PropertyLayout;
 import org.apache.isis.applib.internal.base._NullSafe;
 import org.apache.isis.core.commons.config.IsisConfiguration;
 import org.apache.isis.core.metamodel.facetapi.FacetHolder;
@@ -59,11 +59,13 @@ public class NavigableParentAnnotationFacetFactory extends FacetFactoryAbstract
 
         // Starting from the current domain-object class, we search down the object 
         // inheritance hierarchy (super class, super super class, ...), until we find 
-        // the first class that has a @Parent annotation. That's the one we use to 
+        // the first class that has a @PropertyLayout(navigable=Navigable.PARENT) annotation. 
+        // That's the one we use to 
         // resolve the current domain-object's navigable parent. 
         
-        final List<Annotations.Evaluator<Parent>> evaluators = 
-        		Annotations.firstEvaluatorsInHierarchyHaving(cls, Parent.class);
+        final List<Annotations.Evaluator<PropertyLayout>> evaluators = 
+        		Annotations.firstEvaluatorsInHierarchyHaving(cls, PropertyLayout.class, 
+        				NavigableParentAnnotationFacetFactory::isNavigaleParentFlagSet);
         
         if (_NullSafe.isEmpty(evaluators)) {
             return; // no parent resolvable
@@ -72,17 +74,17 @@ public class NavigableParentAnnotationFacetFactory extends FacetFactoryAbstract
         	throw new RuntimeException("unable to determine navigable parent due to ambiguity");
         }
         
-        final Annotations.Evaluator<Parent> parentEvaluator = evaluators.get(0);
+        final Annotations.Evaluator<PropertyLayout> parentEvaluator = evaluators.get(0);
         
         final Method method;
 
         // find method that provides the parent ...
         if(parentEvaluator instanceof Annotations.MethodEvaluator) {
         	// we have a @Parent annotated method
-        	method = ((Annotations.MethodEvaluator<Parent>) parentEvaluator).getMethod();
+        	method = ((Annotations.MethodEvaluator<PropertyLayout>) parentEvaluator).getMethod();
         } else if(parentEvaluator instanceof Annotations.FieldEvaluator) {
         	// we have a @Parent annotated field (useful if one uses lombok's @Getter on a field)
-        	method = ((Annotations.FieldEvaluator<Parent>) parentEvaluator).getGetter(cls).orElse(null);
+        	method = ((Annotations.FieldEvaluator<PropertyLayout>) parentEvaluator).getGetter(cls).orElse(null);
         	if(method==null)
         		return; // code should not be reached, since case should be handled by meta-data validation 
         	
@@ -96,6 +98,10 @@ public class NavigableParentAnnotationFacetFactory extends FacetFactoryAbstract
 			e.printStackTrace();
 		}
     }
+    
+    private static boolean isNavigaleParentFlagSet(Annotations.Evaluator<PropertyLayout> evaluator){
+    	return evaluator.getAnnotation().navigable().isParent();
+    }
 
 
     /**
@@ -110,8 +116,9 @@ public class NavigableParentAnnotationFacetFactory extends FacetFactoryAbstract
             public boolean visit(ObjectSpecification objectSpec, ValidationFailures validationFailures) {
                 final Class<?> cls = objectSpec.getCorrespondingClass();
                 
-                final List<Annotations.Evaluator<Parent>> evaluators = 
-                		Annotations.firstEvaluatorsInHierarchyHaving(cls, Parent.class);
+                final List<Annotations.Evaluator<PropertyLayout>> evaluators = 
+                		Annotations.firstEvaluatorsInHierarchyHaving(cls, PropertyLayout.class, 
+                				NavigableParentAnnotationFacetFactory::isNavigaleParentFlagSet);
                 
                 if (_NullSafe.isEmpty(evaluators)) {
                 	return true; // no conflict, continue validation processing
@@ -119,29 +126,29 @@ public class NavigableParentAnnotationFacetFactory extends FacetFactoryAbstract
                 	
                 	validationFailures.add(
                             "%s: conflict for determining a strategy for retrieval of (navigable) parent for class, "
-                            + "contains multiple annotations '@%s', while at most one is allowed.",
+                            + "contains multiple annotations '@%s' having navigable=PARENT, while at most one is allowed.",
                             objectSpec.getIdentifier().getClassName(),
-                            Parent.class.getName());
+                            PropertyLayout.class.getName());
                 	
                 	return true; // continue validation processing
                 } 
                 
-                final Annotations.Evaluator<Parent> parentEvaluator = evaluators.get(0);
+                final Annotations.Evaluator<PropertyLayout> parentEvaluator = evaluators.get(0);
                 
                 if(parentEvaluator instanceof Annotations.FieldEvaluator) {
                 	// we have a @Parent annotated field (useful if one uses lombok's @Getter on a field)
                 	
-                	final Annotations.FieldEvaluator<Parent> fieldEvaluator = 
-                			(Annotations.FieldEvaluator<Parent>) parentEvaluator;
+                	final Annotations.FieldEvaluator<PropertyLayout> fieldEvaluator = 
+                			(Annotations.FieldEvaluator<PropertyLayout>) parentEvaluator;
                 	
                 	if(!fieldEvaluator.getGetter(cls).isPresent()) {
                 		
 	            		validationFailures.add(
 	                            "%s: unable to determine a strategy for retrieval of (navigable) parent for class, "
-	                            + "field '%s' annotated with '@%s' does not provide a getter.",
+	                            + "field '%s' annotated with '@%s' having navigable=PARENT does not provide a getter.",
 	                            objectSpec.getIdentifier().getClassName(),
 	                            fieldEvaluator.getField().getName(),
-	                            Parent.class.getName());
+	                            PropertyLayout.class.getName());
                 	}
                 	
                 }
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/navparent/annotation/NavigableParentTestSamples.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/navparent/annotation/NavigableParentTestSamples.java
index 4326b72..2cab87a 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/navparent/annotation/NavigableParentTestSamples.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/object/navparent/annotation/NavigableParentTestSamples.java
@@ -1,6 +1,7 @@
 package org.apache.isis.core.metamodel.facets.object.navparent.annotation;
 
-import org.apache.isis.applib.annotation.Parent;
+import org.apache.isis.applib.annotation.Navigable;
+import org.apache.isis.applib.annotation.PropertyLayout;
 
 class NavigableParentTestSamples {
 
@@ -24,7 +25,7 @@ class NavigableParentTestSamples {
 			return "A";
 		}
 
-		@Parent
+		@PropertyLayout(navigable=Navigable.PARENT)
 		public Object root() {
 			return myParent;
 		}

-- 
To stop receiving notification emails like this one, please contact
ahuber@apache.org.