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

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

commit ecf938944dbf1f55bd89a6b8d6be9416f09a4233
Author: Dan Haywood <d...@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.
---
 .../isis/applib/internal/reflection/_Reflect.java  |  9 ++++--
 .../internal/reflection/_Reflect_Discovery.java    | 24 +++++++++++++++-
 .../IsisComponentProvider.java                     | 33 ++++++++++++++--------
 3 files changed, 51 insertions(+), 15 deletions(-)

diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/internal/reflection/_Reflect.java
 
b/core/applib/src/main/java/org/apache/isis/applib/internal/reflection/_Reflect.java
index 589cf31..e0b213d 100644
--- 
a/core/applib/src/main/java/org/apache/isis/applib/internal/reflection/_Reflect.java
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/internal/reflection/_Reflect.java
@@ -23,10 +23,11 @@ import java.lang.annotation.Annotation;
 import java.util.List;
 import java.util.Set;
 
-import org.apache.isis.applib.internal.context._Context;
 import org.reflections.scanners.SubTypesScanner;
 import org.reflections.util.ClasspathHelper;
 
+import org.apache.isis.applib.internal.context._Context;
+
 /**
  * <h1>- internal use only -</h1>
  * <p>
@@ -54,6 +55,9 @@ public final class _Reflect {
                
                //TODO missing java-doc
                public <T> Set<Class<? extends T>> getSubTypesOf(Class<T> type);
+
+               public Set<Class<?>> findPersistenceCapableTypes();
+
        }
 
        //TODO missing java-doc
@@ -79,5 +83,6 @@ public final class _Reflect {
                                new SubTypesScanner(false)
                );
        }
-       
+
+
 }
diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/internal/reflection/_Reflect_Discovery.java
 
b/core/applib/src/main/java/org/apache/isis/applib/internal/reflection/_Reflect_Discovery.java
index 9059e05..5db08e5 100644
--- 
a/core/applib/src/main/java/org/apache/isis/applib/internal/reflection/_Reflect_Discovery.java
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/internal/reflection/_Reflect_Discovery.java
@@ -8,11 +8,15 @@ import java.util.Set;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import javax.jdo.annotations.PersistenceCapable;
 import javax.validation.constraints.NotNull;
 
+import com.google.common.collect.Sets;
+
+import org.reflections.Reflections;
+
 import org.apache.isis.applib.internal.base._NullSafe;
 import org.apache.isis.applib.internal.reflection._Reflect.Discovery;
-import org.reflections.Reflections;
 
 /**
  * 
@@ -80,6 +84,24 @@ class _Reflect_Discovery implements _Reflect.Discovery {
                                .filter(_NullSafe::isPresent);
        }
 
+       public Set<Class<?>> findPersistenceCapableTypes() {
+
+               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;
+       }
 
        
 }
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 70c0acb..471b547 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,26 @@
 
 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;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
+import org.reflections.Reflections;
 
 import org.apache.isis.applib.AppManifest;
 import org.apache.isis.applib.annotation.DomainObject;
@@ -58,13 +70,6 @@ import 
org.apache.isis.objectstore.jdo.service.RegisterEntities;
 import org.apache.isis.progmodels.dflt.JavaReflectorHelper;
 import org.apache.isis.progmodels.dflt.ProgrammingModelFacetsJava5;
 
-import com.google.common.base.Function;
-import com.google.common.base.Joiner;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
 /**
  * 
  */
@@ -138,7 +143,7 @@ public abstract class IsisComponentProvider {
         final Discovery discovery = 
_Reflect.discover(moduleAndFrameworkPackages);
 
         final Set<Class<?>> domainServiceTypes = 
discovery.getTypesAnnotatedWith(DomainService.class);
-        final Set<Class<?>> persistenceCapableTypes = 
discovery.getTypesAnnotatedWith(PersistenceCapable.class);
+        final Set<Class<?>> persistenceCapableTypes = 
discovery.findPersistenceCapableTypes();
         final Set<Class<? extends FixtureScript>> fixtureScriptTypes = 
discovery.getSubTypesOf(FixtureScript.class);
 
         final Set<Class<?>> mixinTypes = Sets.newHashSet();
@@ -146,9 +151,13 @@ public abstract class IsisComponentProvider {
 
         final Set<Class<?>> domainObjectTypes = 
discovery.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())
         );
         
         
@@ -190,7 +199,7 @@ 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;
             }
         }

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

Reply via email to