You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2018/01/05 10:24:38 UTC

[isis] 10/12: ISIS-1726: generalizes the logic that searches for @PersistenceCapable entities, to also take into account meta-annotations.

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

danhaywood pushed a commit to branch dev/2.0.0-M2
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 40410e77d4774396a63eb5ca3128a64fd4954f2a
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Sep 19 22:59:43 2017 +0100

    ISIS-1726: generalizes the logic that searches for @PersistenceCapable entities, to also take into account meta-annotations.
---
 .../IsisComponentProvider.java                     | 35 ++++++++++++++++++----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisComponentProvider.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisComponentProvider.java
index 890e831..f7ba2b1 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisComponentProvider.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisComponentProvider.java
@@ -19,14 +19,17 @@
 
 package org.apache.isis.core.runtime.systemusinginstallers;
 
+import java.lang.annotation.Annotation;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import javax.annotation.Nullable;
 import javax.jdo.annotations.PersistenceCapable;
+import javax.ws.rs.HEAD;
 
 import com.google.common.base.Function;
 import com.google.common.base.Joiner;
@@ -142,7 +145,7 @@ public abstract class IsisComponentProvider {
         final Reflections reflections = new Reflections(moduleAndFrameworkPackages);
 
         final Set<Class<?>> domainServiceTypes = reflections.getTypesAnnotatedWith(DomainService.class);
-        final Set<Class<?>> persistenceCapableTypes = reflections.getTypesAnnotatedWith(PersistenceCapable.class);
+        final Set<Class<?>> persistenceCapableTypes = findPersistenceCapableTypes(reflections);
         final Set<Class<? extends FixtureScript>> fixtureScriptTypes = reflections.getSubTypesOf(FixtureScript.class);
 
         final Set<Class<?>> mixinTypes = Sets.newHashSet();
@@ -150,9 +153,13 @@ public abstract class IsisComponentProvider {
 
         final Set<Class<?>> domainObjectTypes = reflections.getTypesAnnotatedWith(DomainObject.class);
         mixinTypes.addAll(
-                domainObjectTypes.stream()
-                        .filter(input -> input.getAnnotation(DomainObject.class).nature() == Nature.MIXIN)
-                        .collect(Collectors.toList())
+                domainObjectTypes.stream().filter(input -> {
+                    if (input == null) {
+                        return false;
+                    }
+                    final DomainObject annotation = input.getAnnotation(DomainObject.class);
+                    return annotation.nature() == Nature.MIXIN;
+                }).collect(Collectors.toList())
         );
 
         // add in any explicitly registered services...
@@ -192,12 +199,30 @@ public abstract class IsisComponentProvider {
     }
     static private boolean containedWithin(final List<String> packagesWithDotSuffix, final String className) {
         for (String packageWithDotSuffix : packagesWithDotSuffix) {
-            if(className.startsWith(packageWithDotSuffix)) {
+            if (className.startsWith(packageWithDotSuffix)) {
                 return true;
             }
         }
         return false;
     }
+    private Set<Class<?>> findPersistenceCapableTypes(final Reflections reflections) {
+
+        Set<Class<?>> pcSet = Sets.newLinkedHashSet();
+
+        Set<Class<?>> persistenceCapables = reflections.getTypesAnnotatedWith(PersistenceCapable.class);
+        persistenceCapables.stream()
+                .filter(x -> !x.isAnnotation())
+                .forEach(pcSet::add);
+
+        Stream<Class<? extends Annotation>> pcMetaAnnotStream =
+                (Stream)persistenceCapables.stream().filter(x -> x.isAnnotation());
+        pcMetaAnnotStream.map(metaAnnot -> reflections.getTypesAnnotatedWith(metaAnnot).stream())
+                .flatMap(x -> x)
+                .filter(x -> !x.isAnnotation())
+                .forEach(pcSet::add);
+
+        return pcSet;
+    }
 
     private void specifyServicesAndRegisteredEntitiesUsing(final AppManifest appManifest) {
         final Iterable<String> packageNames = modulePackageNamesFrom(appManifest);

-- 
To stop receiving notification emails like this one, please contact
"commits@isis.apache.org" <co...@isis.apache.org>.