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 2017/09/19 22:06:46 UTC

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

ISIS-1726: generalizes the logic that searches for @PersistenceCapable entities, to also take into account meta-annotations.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/c1ed4c95
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/c1ed4c95
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/c1ed4c95

Branch: refs/heads/ISIS-1276-dn-5-1
Commit: c1ed4c957f0ac8a0839495c27b78a82eb22c89b2
Parents: 3b8652b
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Tue Sep 19 22:59:43 2017 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Tue Sep 19 23:05:22 2017 +0100

----------------------------------------------------------------------
 .../IsisComponentProvider.java                  | 37 +++++++++++++++-----
 1 file changed, 28 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/c1ed4c95/core/runtime/src/main/java/org/apache/isis/core/runtime/systemusinginstallers/IsisComponentProvider.java
----------------------------------------------------------------------
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 6616d68..6f599ed 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,17 +19,19 @@
 
 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 com.google.common.base.Function;
 import com.google.common.base.Joiner;
-import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
@@ -141,21 +143,20 @@ public abstract class IsisComponentProvider {
 
         final Reflections reflections = new Reflections(packages);
         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();
         mixinTypes.addAll(reflections.getTypesAnnotatedWith(Mixin.class));
         final Set<Class<?>> domainObjectTypes = reflections.getTypesAnnotatedWith(DomainObject.class);
         mixinTypes.addAll(
-                Lists.newArrayList(Iterables.filter(domainObjectTypes, new Predicate<Class<?>>() {
-                    @Override
-                    public boolean apply(@Nullable final Class<?> input) {
-                        if(input == null) { return false; }
-                        final DomainObject annotation = input.getAnnotation(DomainObject.class);
-                        return annotation.nature() == Nature.MIXIN;
+                domainObjectTypes.stream().filter(input -> {
+                    if (input == null) {
+                        return false;
                     }
-                }))
+                    final DomainObject annotation = input.getAnnotation(DomainObject.class);
+                    return annotation.nature() == Nature.MIXIN;
+                }).collect(Collectors.toList())
         );
 
         registry.setDomainServiceTypes(domainServiceTypes);
@@ -164,6 +165,24 @@ public abstract class IsisComponentProvider {
         registry.setMixinTypes(mixinTypes);
     }
 
+    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);