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 2020/09/01 10:29:22 UTC
[isis] 02/02: ISIS-2332: fix spec-loader to consult
bean-type-registry for BeanSort
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
commit 798a24bce8ba48f16f9de5590a65fb8743f1d9ec
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Sep 1 12:28:56 2020 +0200
ISIS-2332: fix spec-loader to consult bean-type-registry for BeanSort
---
.../core/config/beans/IsisBeanTypeRegistry.java | 9 +++-
.../specloader/SpecificationLoaderDefault.java | 62 +++++++++-------------
.../specimpl/ObjectSpecificationAbstract.java | 31 -----------
3 files changed, 34 insertions(+), 68 deletions(-)
diff --git a/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeRegistry.java b/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeRegistry.java
index bbc12e8..2d1ba6b 100644
--- a/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeRegistry.java
+++ b/core/config/src/main/java/org/apache/isis/core/config/beans/IsisBeanTypeRegistry.java
@@ -82,7 +82,6 @@ public final class IsisBeanTypeRegistry implements IsisComponentScanInterceptor,
@Override
public void close() {
-
managedBeanNamesByType.clear();
introspectableTypes.clear();
allCategorySets.forEach(Set::clear);
@@ -104,6 +103,12 @@ public final class IsisBeanTypeRegistry implements IsisComponentScanInterceptor,
return defensiveCopy;
}
+
+ public BeanSort lookupBeanSortByIntrospectableType(Class<?> type) {
+ synchronized (introspectableTypes) {
+ return introspectableTypes.getOrDefault(type, BeanSort.UNKNOWN);
+ }
+ }
public void veto(Class<?> type) {
vetoedTypes.add(type);
@@ -319,5 +324,7 @@ public final class IsisBeanTypeRegistry implements IsisComponentScanInterceptor,
return null;
}
+
+
}
\ No newline at end of file
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationLoaderDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationLoaderDefault.java
index b46a3b2..479ada0 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationLoaderDefault.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/SpecificationLoaderDefault.java
@@ -25,6 +25,7 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
+import java.util.function.Function;
import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
@@ -209,7 +210,7 @@ public class SpecificationLoaderDefault implements SpecificationLoader {
facetProcessor.init();
postProcessor.init();
- val typeRegistry = isisBeanTypeRegistryHolder.getIsisBeanTypeRegistry();
+ val typeRegistry = getIsisBeanTypeRegistry();
val knownSpecs = _Lists.<ObjectSpecification>newArrayList();
@@ -365,18 +366,18 @@ public class SpecificationLoaderDefault implements SpecificationLoader {
return true;
}
-
- //TODO[ISIS-2332] when the cache is cleared, sort information get's lost
- //instead better integrate the isis bean type registry with the spec loading
@Nullable
- private ObjectSpecification primeSpecification(
+ private ObjectSpecification loadSpecification(
final @Nullable Class<?> type,
- final @NonNull BeanSort sort) {
-
+ final Function<Class<?>, BeanSort> beanClassifier,
+ final IntrospectionState upTo) {
+
if(type==null) {
return null;
}
+ requires(upTo, "upTo");
+
val substitute = classSubstitutorRegistry.getSubstitution(type);
if (substitute.isNeverIntrospect()) {
return null; // never inspect
@@ -390,46 +391,31 @@ public class SpecificationLoaderDefault implements SpecificationLoader {
// we try not to block on long running code ... 'spec.introspectUpTo(upTo);'
synchronized (cache) {
- cachedSpec = cache.computeIfAbsent(typeName, __->createSpecification(substitutedType, sort));
+ cachedSpec = cache.computeIfAbsent(typeName, __->
+ createSpecification(substitutedType, beanClassifier.apply(type)));
}
- cachedSpec.introspectUpTo(IntrospectionState.NOT_INTROSPECTED);
+ cachedSpec.introspectUpTo(upTo);
return cachedSpec;
+ }
+
+ @Nullable
+ private ObjectSpecification primeSpecification(
+ final @Nullable Class<?> type,
+ final @NonNull BeanSort sort) {
+ return loadSpecification(type, __->sort, IntrospectionState.NOT_INTROSPECTED);
}
-
+
@Override @Nullable
public ObjectSpecification loadSpecification(
final @Nullable Class<?> type,
final IntrospectionState upTo) {
- if(type==null) {
- return null;
- }
-
- requires(upTo, "upTo");
-
- val substitute = classSubstitutorRegistry.getSubstitution(type);
- if (substitute.isNeverIntrospect()) {
- return null; // never inspect
- }
-
- val substitutedType = substitute.apply(type);
-
- val typeName = substitutedType.getName();
-
- final ObjectSpecification cachedSpec;
-
- // we try not to block on long running code ... 'spec.introspectUpTo(upTo);'
- synchronized (cache) {
- cachedSpec = cache.computeIfAbsent(typeName, __->createSpecification(substitutedType, BeanSort.UNKNOWN));
- }
-
- cachedSpec.introspectUpTo(upTo);
-
- return cachedSpec;
+ return loadSpecification(
+ type, __->getIsisBeanTypeRegistry().lookupBeanSortByIntrospectableType(type), upTo);
}
@Override
@@ -509,6 +495,10 @@ public class SpecificationLoaderDefault implements SpecificationLoader {
// -- HELPER
+ private IsisBeanTypeRegistry getIsisBeanTypeRegistry() {
+ return isisBeanTypeRegistryHolder.getIsisBeanTypeRegistry();
+ }
+
private void guardAgainstMetamodelLockedAfterFullIntrospection(final Class<?> cls) {
if(isMetamodelFullyIntrospected()
&& isisConfiguration.getCore().getMetaModel().getIntrospector().isLockAfterFullIntrospection()) {
@@ -550,7 +540,7 @@ public class SpecificationLoaderDefault implements SpecificationLoader {
// ... and create the specs
- val typeRegistry = isisBeanTypeRegistryHolder.getIsisBeanTypeRegistry();
+ val typeRegistry = getIsisBeanTypeRegistry();
val managedBeanNameIfAny = typeRegistry.getManagedBeanNameForType(cls);
val objectSpec = new ObjectSpecificationDefault(
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectSpecificationAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectSpecificationAbstract.java
index 74609ea..0ef31b0 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectSpecificationAbstract.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/specimpl/ObjectSpecificationAbstract.java
@@ -56,10 +56,8 @@ import org.apache.isis.core.metamodel.facets.all.describedas.DescribedAsFacet;
import org.apache.isis.core.metamodel.facets.all.help.HelpFacet;
import org.apache.isis.core.metamodel.facets.all.hide.HiddenFacet;
import org.apache.isis.core.metamodel.facets.all.named.NamedFacet;
-import org.apache.isis.core.metamodel.facets.collections.CollectionFacet;
import org.apache.isis.core.metamodel.facets.members.cssclass.CssClassFacet;
import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
-import org.apache.isis.core.metamodel.facets.object.entity.EntityFacet;
import org.apache.isis.core.metamodel.facets.object.icon.IconFacet;
import org.apache.isis.core.metamodel.facets.object.immutable.ImmutableFacet;
import org.apache.isis.core.metamodel.facets.object.mixin.MixinFacet;
@@ -69,8 +67,6 @@ import org.apache.isis.core.metamodel.facets.object.parented.ParentedCollectionF
import org.apache.isis.core.metamodel.facets.object.parseable.ParseableFacet;
import org.apache.isis.core.metamodel.facets.object.plural.PluralFacet;
import org.apache.isis.core.metamodel.facets.object.title.TitleFacet;
-import org.apache.isis.core.metamodel.facets.object.value.ValueFacet;
-import org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet;
import org.apache.isis.core.metamodel.interactions.InteractionContext;
import org.apache.isis.core.metamodel.interactions.InteractionUtils;
import org.apache.isis.core.metamodel.interactions.ObjectTitleContext;
@@ -964,31 +960,4 @@ implements ObjectSpecification {
.getIsisBeanTypeRegistry();
}
- //TODO just make 'sort' a field of ObjectSpecification
- protected BeanSort sortOf(ObjectSpecification spec) {
-
- if(isManagedBean()) { // <-- not a facet, because we get this information earlier (during class scanning)
- return BeanSort.MANAGED_BEAN_CONTRIBUTING;
- }
- if(containsFacet(ValueFacet.class)) {
- return BeanSort.VALUE;
- }
- if(containsFacet(ViewModelFacet.class)) {
- return BeanSort.VIEW_MODEL;
- }
- if(containsFacet(MixinFacet.class)) {
- return BeanSort.MIXIN;
- }
- if(containsFacet(CollectionFacet.class)) {
- return BeanSort.COLLECTION;
- }
- if(containsFacet(EntityFacet.class)) {
- return BeanSort.ENTITY;
- }
-
- return BeanSort.UNKNOWN;
- }
-
-
-
}