You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by ah...@apache.org on 2024/11/13 10:06:27 UTC

(causeway) 02/02: CAUSEWAY-2297: rethinking BeanSort

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

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

commit 6422e1b0dadedebf8be6bacdfc81bc3283f2c60f
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Nov 13 11:06:21 2024 +0100

    CAUSEWAY-2297: rethinking BeanSort
---
 .../causeway/applib/annotation/Programmatic.java   |   2 +-
 .../applib/services/metamodel/BeanSort.java        | 165 ++++++++++++---------
 commons/src/main/java/module-info.java             |   1 -
 .../commons/internal/annotations/BeanInternal.java |  47 ------
 .../commons/internal/reflection/_ClassCache.java   |  55 ++++---
 .../beans/CausewayBeanFactoryPostProcessor.java    |  14 ++
 .../config/beans/CausewayBeanTypeClassifier.java   |  50 ++++---
 .../config/beans/CausewayBeanTypeRegistry.java     |  16 +-
 .../core/metamodel/context/MetaModelContext.java   |   4 +-
 .../metamodel/objectmanager/ObjectManager.java     |   4 +-
 10 files changed, 189 insertions(+), 169 deletions(-)

diff --git a/api/applib/src/main/java/org/apache/causeway/applib/annotation/Programmatic.java b/api/applib/src/main/java/org/apache/causeway/applib/annotation/Programmatic.java
index 81d3bd633c8..2c175cb01d3 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/annotation/Programmatic.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/annotation/Programmatic.java
@@ -26,7 +26,7 @@ import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
 /**
- * Indicates that an property, collection or action is to be called
+ * Indicates that a property, collection or action is to be called
  * programmatically and should be ignored from the metamodel.
  *
  * <p>
diff --git a/api/applib/src/main/java/org/apache/causeway/applib/services/metamodel/BeanSort.java b/api/applib/src/main/java/org/apache/causeway/applib/services/metamodel/BeanSort.java
index 21959d10f9f..4709285caa3 100644
--- a/api/applib/src/main/java/org/apache/causeway/applib/services/metamodel/BeanSort.java
+++ b/api/applib/src/main/java/org/apache/causeway/applib/services/metamodel/BeanSort.java
@@ -18,9 +18,14 @@
  */
 package org.apache.causeway.applib.services.metamodel;
 
+import javax.imageio.spi.ServiceRegistry;
+
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Profile;
 
 import org.apache.causeway.applib.annotation.Programmatic;
+import org.apache.causeway.applib.services.factory.FactoryService;
 
 /**
  * Top level object classification.
@@ -34,7 +39,7 @@ public enum BeanSort {
      * Includes classes annotated with {@code @DomainObject}, when *not* associated
      * with a persistence layer. <p>  see also {@link #ENTITY}
      */
-    VIEW_MODEL,
+    VIEW_MODEL(new BeanPolicy(BeanPolicy.INTROSPECTION | BeanPolicy.WRAPPING)),
     /**
      * Persistable object, associated with a persistence layer/context.
      * <p>
@@ -42,110 +47,134 @@ public enum BeanSort {
      * with a persistence layer. <p>  see also {@link #VIEW_MODEL}
      *
      */
-    ENTITY,
+    ENTITY(new BeanPolicy(BeanPolicy.INTROSPECTION | BeanPolicy.WRAPPING)),
     /**
      * Injectable object, associated with a lifecycle context
      * (application-scoped, request-scoped, ...).
      * <p>
+     * In other words: Indicates that the class is a Spring managed bean,
+     * which IS also contributing to the UI or WEB API. Hence needs introspection.
+     * <p>
+     * The {@link ServiceRegistry} must be aware.
+     * <p>
      * to be introspected: YES
      */
-    MANAGED_BEAN_CONTRIBUTING,
+    MANAGED_BEAN_CONTRIBUTING(new BeanPolicy(BeanPolicy.INTROSPECTION | BeanPolicy.INJECTABLE | BeanPolicy.WRAPPING)),
     /**
      * Injectable object, associated with a lifecycle context
      * (application-scoped, request-scoped, ...).
      * <p>
+     * In other words: Indicates that the class is a Spring managed bean,
+     * which is NOT contributing to the UI or WEB API. Hence not introspected.
+     * <p>
+     * The {@link ServiceRegistry} must be aware regardless.
+     * <p>
+     * This is also the fallback {@link BeanSort} for beans originating from {@link Bean} annotated factory methods,
+     * when the bean class itself declares no annotations.
+     * <p>
      * to be introspected: NO
      */
-    MANAGED_BEAN_NOT_CONTRIBUTING,
+    MANAGED_BEAN_NOT_CONTRIBUTING(new BeanPolicy(BeanPolicy.INJECTABLE | BeanPolicy.WRAPPING)),
     /**
      * Object associated with an <i>entity</i>, <i>viewmodel</i> or <i>domain-service</i>
      * to act as contributer of a single <i>domain-action</i> or
      * <i>domain-property</i> or <i>domain-collection</i>.
      */
-    MIXIN,
+    MIXIN(new BeanPolicy(BeanPolicy.INTROSPECTION | BeanPolicy.WRAPPING)),
     /**
      * Immutable, serializable object.
+     * Values (including enums) my have object support methods, hence needs introspection.
      */
-    VALUE,
+    VALUE(new BeanPolicy(BeanPolicy.INTROSPECTION)),
     /**
      * Container of objects.
      */
-    COLLECTION,
+    COLLECTION(new BeanPolicy(0)),
     /**
-     * A non concrete type, that is a placeholder for a its concrete implementer.
+     * A non concrete type, that is a placeholder for a concrete implementer.
+     * <p>
+     * E.g. action return types or collection element types could be interfaces or abstract types
+     * (as discovered by reflection during introspection)
      */
-    ABSTRACT,
+    ABSTRACT(new BeanPolicy(BeanPolicy.INTROSPECTION)),
+    /**
+     * Type must NOT be added to the meta-model, eg. by means of
+     * {@link org.apache.causeway.applib.annotation.Domain.Exclude} or {@link Programmatic}.
+     * Consequently the specification-loader should skip introspection of those types.
+     * <p>
+     * In other words: Indicates that the class is some bean,
+     * which is NOT contributing to the UI or WEB API, and
+     * also NOT managed by Spring.
+     * <p>
+     * {@link ServiceRegistry} will NOT be aware.
+     * <p>
+     * {@link FactoryService#create(Class)} will nevertheless support
+     * those programmatic beans. They may have injection points that need resolving.
+     */
+    PROGRAMMATIC(new BeanPolicy(BeanPolicy.WRAPPING)),
     /**
      * Type must not be added to the meta-model, eg. by means of
-     * {@link org.apache.causeway.applib.annotation.Domain.Exclude}, {@link Profile} or {@link Programmatic}
+     * {@link javax.enterprise.inject.Vetoed} or {@link Profile}.
+     * Consequently the specification-loader should skip introspection of those types.
+     * If discovered by Spring during class-path scanning, we remove the corresponding {@link BeanDefinition}.
+     * <p>
+     * {@link ServiceRegistry} must not be aware of those types.
+     * <p>
+     * {@link FactoryService#getOrCreate(Class)} must fail for those types.
      */
-    VETOED,
-    UNKNOWN;
-
-    // -- SIMPLE PREDICATES
-
-    public boolean isManagedBeanContributing() {
-        return this == MANAGED_BEAN_CONTRIBUTING;
-    }
-
-    public boolean isManagedBeanNotContributing() {
-        return this == MANAGED_BEAN_NOT_CONTRIBUTING;
-    }
-
-    public boolean isManagedBeanAny() {
-        return this == MANAGED_BEAN_CONTRIBUTING
-                || this == MANAGED_BEAN_NOT_CONTRIBUTING;
+    @SuppressWarnings("javadoc")
+    VETOED(new BeanPolicy(0)),
+    UNKNOWN(new BeanPolicy(0));
+
+    public record BeanPolicy(int flags) {
+        final static int INTROSPECTION = 0x01;
+        final static int INJECTABLE = 0x02;
+        final static int WRAPPING = 0x04;
+        /**
+         * Enables meta-model introspection.
+         * Potentially contributes to the UI or Web API.
+         */
+        boolean isIntrospectionAllowed() { return (flags & INTROSPECTION) !=0; }
+        /**
+         * Contributes actions, members and/or object support to the UI or Web API.
+         */
+        boolean contributesToUiOrWebApi() { return isIntrospectionAllowed(); } // seems to be just a synonym
+        boolean isInjectable() { return (flags & INJECTABLE) !=0; }
+        boolean isWrappingSupported() { return (flags & WRAPPING) !=0; }
     }
 
-    public boolean isMixin() {
-        return this == MIXIN;
-    }
+    // -- POLICY
 
-    public boolean isViewModel() {
-        return this == VIEW_MODEL;
-    }
+    private final BeanPolicy policy;
+    private BeanSort(final BeanPolicy policy) { this.policy = policy;}
 
-    public boolean isValue() {
-        return this == VALUE;
-    }
+    // -- PREDICATES
 
-    public boolean isCollection() {
-        return this == COLLECTION;
-    }
+    public boolean isManagedBeanContributing() { return this == MANAGED_BEAN_CONTRIBUTING; }
+    public boolean isManagedBeanNotContributing() { return this == MANAGED_BEAN_NOT_CONTRIBUTING; }
+    public boolean isMixin() { return this == MIXIN; }
+    public boolean isViewModel() { return this == VIEW_MODEL; }
+    public boolean isValue() { return this == VALUE; }
+    public boolean isCollection() { return this == COLLECTION; }
+    public boolean isEntity() { return this == ENTITY; }
+    public boolean isAbstract() { return this == ABSTRACT; }
+    public boolean isProgrammatic() { return this == PROGRAMMATIC; }
+    public boolean isVetoed() { return this == VETOED; }
+    public boolean isUnknown() { return this == UNKNOWN; }
 
-    public boolean isEntity() {
-        return this == ENTITY;
-    }
+    // -- DEPRECATED
 
-    public boolean isAbstract() {
-        return this == ABSTRACT;
+    @Deprecated public boolean isToBeIntrospected() { return policy.isIntrospectionAllowed(); }
+    @Deprecated public boolean isWrappingSupported() {
+        return policy.isWrappingSupported();
+        //return isMixin() || isViewModel() || isEntity() || isInjectable();
     }
-
-    public boolean isVetoed() {
-        return this == VETOED;
+    @Deprecated public boolean isManagedBeanAny() {
+        return policy.isInjectable();
     }
-
-    public boolean isUnknown() {
-        return this == UNKNOWN;
-    }
-
-    // -- HIGHER LEVEL PREDICATES
-
-    public boolean isToBeIntrospected() {
-
-        if(isVetoed()
-                || isUnknown()
-                || isCollection()
-                || this == MANAGED_BEAN_NOT_CONTRIBUTING) {
-            return false;
-        }
-
-        return true;
-    }
-
-    public boolean isWrappingSupported() {
-        return isMixin() || isViewModel() || isEntity() || isManagedBeanAny();
+    @Deprecated public boolean isInjectable() {
+        return this == MANAGED_BEAN_CONTRIBUTING
+                || this == MANAGED_BEAN_NOT_CONTRIBUTING;
     }
 
-    // ...
 }
diff --git a/commons/src/main/java/module-info.java b/commons/src/main/java/module-info.java
index d5b114ad131..88e426e4f8f 100644
--- a/commons/src/main/java/module-info.java
+++ b/commons/src/main/java/module-info.java
@@ -29,7 +29,6 @@ module org.apache.causeway.commons {
     exports org.apache.causeway.commons.tabular;
     // internals exported as well
     exports org.apache.causeway.commons.internal;
-    exports org.apache.causeway.commons.internal.annotations;
     exports org.apache.causeway.commons.internal.assertions;
     exports org.apache.causeway.commons.internal.base;
     exports org.apache.causeway.commons.internal.binding;
diff --git a/commons/src/main/java/org/apache/causeway/commons/internal/annotations/BeanInternal.java b/commons/src/main/java/org/apache/causeway/commons/internal/annotations/BeanInternal.java
deleted file mode 100644
index ca7e453477e..00000000000
--- a/commons/src/main/java/org/apache/causeway/commons/internal/annotations/BeanInternal.java
+++ /dev/null
@@ -1,47 +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.causeway.commons.internal.annotations;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.stereotype.Component;
-
-/**
- * Indicates that the class is a Spring managed bean, 
- * intended for framework internal use.
- * <p>
- * The specification-loader should skip introspection of those types. 
- * However, those types are considered to be injectable. 
- * Hence the service registry should be aware of those.
- * <p>
- * {@link BeanInternal} intentionally is NOT meta annotated with {@link Component}, 
- * to specifically allow for the light weight use case 
- * of instances being generated by {@link Bean} annotated factory methods.
- */
-@Inherited
-@Target({ ElementType.TYPE })
-@Retention(RetentionPolicy.RUNTIME)
-public @interface BeanInternal {
-
-}
diff --git a/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_ClassCache.java b/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_ClassCache.java
index d5caeba430c..137ee7349d9 100644
--- a/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_ClassCache.java
+++ b/commons/src/main/java/org/apache/causeway/commons/internal/reflection/_ClassCache.java
@@ -38,7 +38,6 @@ import jakarta.inject.Named;
 import jakarta.xml.bind.annotation.XmlRootElement;
 
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
 import org.springframework.core.annotation.MergedAnnotations;
 import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
 import org.springframework.lang.Nullable;
@@ -46,7 +45,6 @@ import org.springframework.lang.Nullable;
 import org.apache.causeway.commons.collections.Can;
 import org.apache.causeway.commons.functional.Try;
 import org.apache.causeway.commons.internal._Constants;
-import org.apache.causeway.commons.internal.annotations.BeanInternal;
 import org.apache.causeway.commons.internal.assertions._Assert;
 import org.apache.causeway.commons.internal.base._Casts;
 import org.apache.causeway.commons.internal.base._Lazy;
@@ -60,6 +58,8 @@ import org.apache.causeway.commons.internal.reflection._GenericResolver.Resolved
 import org.apache.causeway.commons.semantics.AccessorSemantics;
 
 import lombok.AccessLevel;
+import lombok.Builder;
+import lombok.NonNull;
 import lombok.RequiredArgsConstructor;
 import lombok.SneakyThrows;
 
@@ -81,6 +81,24 @@ import lombok.SneakyThrows;
 @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
 public final class _ClassCache implements AutoCloseable {
 
+    @Builder(builderMethodName = "builderPlain")
+    public record Options(
+            @Nullable ClassLoader classLoader,
+            @NonNull Can<Class<? extends Annotation>> annotationsVetoingIntrospection) {
+        public static OptionsBuilder builder() {
+            return builderPlain()
+                    .classLoader(_Context.getDefaultClassLoader())
+                    .annotationsVetoingIntrospection(Can.empty());
+        }
+        public void install() {
+            _Context.put(_ClassCache.Options.class, this, true);
+        }
+        static Options fallback() { return builder().build(); }
+        static Options getInstance() {
+            return _Context.computeIfAbsent(Options.class, Options::fallback);
+        }
+    }
+
     public enum Attribute {
         /**
          * Corresponds to the bean name of Spring managed beans.
@@ -93,17 +111,17 @@ public final class _ClassCache implements AutoCloseable {
     }
 
     public static _ClassCache getInstance() {
-        return _Context.computeIfAbsent(_ClassCache.class, ()->new _ClassCache(_Context.getDefaultClassLoader()));
+        return _Context.computeIfAbsent(_ClassCache.class, ()->new _ClassCache(Options.getInstance()));
     }
 
     /**
      * JUnit support.
      */
     public static void invalidate() {
-        _Context.put(_ClassCache.class, new _ClassCache(_Context.getDefaultClassLoader()), true);
+        _Context.put(_ClassCache.class, new _ClassCache(Options.getInstance()), true);
     }
 
-    private final @Nullable ClassLoader classLoader;
+    private final Options options;
 
     public void add(final Class<?> type) {
         classModel(type);
@@ -261,11 +279,19 @@ public final class _ClassCache implements AutoCloseable {
             MergedAnnotations mergedAnnotations,
             /** explicit name if any */
             @Nullable String named,
+            /**
+             * if true, type is NOT contributing to the UI or WEB API,
+             * consequently will NOT introspect
+             */
+            boolean hasIntrospectionVetoingSemantics,
             Map<Attribute, String> attributeMap) {
 
-        static ClassModelHead create(final Class<?> type) {
+        static ClassModelHead create(final Class<?> type, final Options options) {
             var mergedAnnotations = MergedAnnotations.from(type, SearchStrategy.TYPE_HIERARCHY);
-            return new ClassModelHead(mergedAnnotations, _ClassCacheUtil.inferName(type, mergedAnnotations),
+            return new ClassModelHead(mergedAnnotations,
+                    _ClassCacheUtil.inferName(type, mergedAnnotations),
+                    options.annotationsVetoingIntrospection()
+                        .anyMatch(annotationType->mergedAnnotations.get(annotationType).isPresent()),
                     new ConcurrentHashMap<>());
         }
 
@@ -281,14 +307,6 @@ public final class _ClassCache implements AutoCloseable {
             return mergedAnnotations.get(annotationType).isPresent();
         }
 
-        /**
-         * whether type is annotated with {@link BeanInternal} or {@link Configuration}
-         */
-        public boolean hasInternalBeanSemantics() {
-            return hasAnnotation(BeanInternal.class)
-                    || hasAnnotation(Configuration.class);
-        }
-
         /**
          * whether type is annotated with {@link XmlRootElement}
          */
@@ -329,7 +347,8 @@ public final class _ClassCache implements AutoCloseable {
                 Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
 
         private static ClassModelBody create(final Class<?> type, final ClassModelHead head) {
-            if(head.hasInternalBeanSemantics()) return EMPTY; //skip further inspection
+
+            if(head.hasIntrospectionVetoingSemantics) return EMPTY; //skip further inspection
 
             var body = new ClassModelBody(Can.ofArray(type.getDeclaredFields()));
 
@@ -457,7 +476,7 @@ public final class _ClassCache implements AutoCloseable {
      */
     @SuppressWarnings({ "unchecked", "rawtypes" })
     private Class<?> reloadType(final Class<?> _type) {
-        return Optional.ofNullable(classLoader)
+        return Optional.ofNullable(options.classLoader())
                 .filter(cl->!_type.isPrimitive())
                 .filter(cl->!_Reflect.isJavaApiClass(_type))
                 .filter(cl->!cl.equals(_type.getClassLoader()))
@@ -469,7 +488,7 @@ public final class _ClassCache implements AutoCloseable {
 
     private ClassModel inspectType(final Class<?> _type) {
         final Class<?> type = reloadType(_type);
-        var head = ClassModelHead.create(type);
+        var head = ClassModelHead.create(type, options);
         return new ClassModel(head, _Lazy.threadSafe(()->ClassModelBody.create(type, head)));
     }
 
diff --git a/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanFactoryPostProcessor.java b/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanFactoryPostProcessor.java
index d31888f7152..b39dddcc912 100644
--- a/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanFactoryPostProcessor.java
+++ b/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanFactoryPostProcessor.java
@@ -33,12 +33,15 @@ import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Import;
 import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Repository;
 
 import org.apache.causeway.applib.annotation.DomainObject;
 import org.apache.causeway.applib.annotation.DomainService;
+import org.apache.causeway.applib.annotation.Programmatic;
 import org.apache.causeway.commons.collections.Can;
 import org.apache.causeway.commons.internal.base._NullSafe;
 import org.apache.causeway.commons.internal.base._Timing;
+import org.apache.causeway.commons.internal.reflection._ClassCache;
 import org.apache.causeway.core.config.CausewayModuleCoreConfig;
 import org.apache.causeway.core.config.beans.aoppatch.AopPatch;
 
@@ -72,6 +75,7 @@ implements
     @Override
     public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
         this.causewayBeanTypeClassifier = new CausewayBeanTypeClassifier(applicationContext);
+        installClassCashOptions();
     }
 
     @Override
@@ -115,4 +119,14 @@ implements
         return new CausewayBeanTypeRegistry(componentScanResult);
     }
 
+    private void installClassCashOptions() {
+        _ClassCache.Options.builder()
+            .annotationsVetoingIntrospection(Can.of(
+                    Programmatic.class,
+                    Configuration.class,
+                    Repository.class))
+            .build()
+            .install();
+    }
+
 }
diff --git a/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanTypeClassifier.java b/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanTypeClassifier.java
index 35ec8ae6e05..05c4835c90f 100644
--- a/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanTypeClassifier.java
+++ b/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanTypeClassifier.java
@@ -31,10 +31,10 @@ import org.springframework.util.ClassUtils;
 
 import org.apache.causeway.applib.annotation.DomainObject;
 import org.apache.causeway.applib.annotation.DomainService;
+import org.apache.causeway.applib.annotation.Programmatic;
 import org.apache.causeway.applib.id.LogicalType;
 import org.apache.causeway.applib.services.metamodel.BeanSort;
 import org.apache.causeway.commons.collections.Can;
-import org.apache.causeway.commons.internal.annotations.BeanInternal;
 import org.apache.causeway.commons.internal.reflection._Annotations;
 import org.apache.causeway.commons.internal.reflection._ClassCache;
 import org.apache.causeway.commons.semantics.CollectionSemantics;
@@ -44,35 +44,35 @@ import org.apache.causeway.core.config.progmodel.ProgrammingModelConstants.TypeE
 
 import lombok.NonNull;
 
-@BeanInternal
+@Programmatic
 public record CausewayBeanTypeClassifier(
         @NonNull Can<String> activeProfiles,
         @NonNull _ClassCache classCache) {
-    
+
     // -- CONSTRUCTION
-    
+
     CausewayBeanTypeClassifier(final ApplicationContext applicationContext) {
         this(Can.ofArray(applicationContext.getEnvironment().getActiveProfiles()));
     }
-    
-    CausewayBeanTypeClassifier(Can<String> activeProfiles) {
+
+    CausewayBeanTypeClassifier(final Can<String> activeProfiles) {
         this(activeProfiles, _ClassCache.getInstance());
     }
 
     // -- CLASSIFY
-    
+
     /**
-     * Classify {@link LogicalType} as detected and named by either Causeway or Spring. 
+     * Classify {@link LogicalType} as detected and named by either Causeway or Spring.
      * <p>
      * Typically Causeway we will use a different fallback naming strategy for 'unnamed' types,
-     * that is, it uses the fully qualified class name.  
-     *  
-     * @param logicalType with name as either forced by Causeway or suggested by Spring 
+     * that is, it uses the fully qualified class name.
+     *
+     * @param logicalType with name as either forced by Causeway or suggested by Spring
      */
     public CausewayBeanMetaData classify(@NonNull final LogicalType logicalType, final DiscoveredBy discoveredBy) {
-        
+
         var type = logicalType.correspondingClass();
-        
+
         Supplier<LogicalType> named = ()->discoveredBy.isSpring()
             ? LogicalType.infer(type) // use only if discovered by Spring but NOT managed by Spring
             : logicalType; // name is already inferred, when discovered by Causeway
@@ -98,6 +98,8 @@ public record CausewayBeanTypeClassifier(
             return CausewayBeanMetaData.unspecified(discoveredBy, BeanSort.ABSTRACT, named.get());
         }
 
+        var typeHead = classCache().head(type);
+
         // handle vetoing ...
         if(TypeExcludeMarker.anyMatchOn(type)) {
             return CausewayBeanMetaData.notManaged(discoveredBy, BeanSort.VETOED, named.get()); // reject
@@ -115,17 +117,21 @@ public record CausewayBeanTypeClassifier(
         if(org.apache.causeway.applib.ViewModel.class.isAssignableFrom(type)) {
             return CausewayBeanMetaData.causewayManaged(discoveredBy, BeanSort.VIEW_MODEL, named.get());
         }
-        
-        var typeHead = classCache().head(type);
-        
+
         // value types
         if(typeHead.hasAnnotation(org.apache.causeway.applib.annotation.Value.class)) {
             return CausewayBeanMetaData.notManaged(discoveredBy, BeanSort.VALUE, named.get());
         }
-        
-        // internal bean types
-        if(typeHead.hasInternalBeanSemantics()) {
-            return CausewayBeanMetaData.springManaged(discoveredBy, BeanSort.MANAGED_BEAN_NOT_CONTRIBUTING, logicalType);
+
+        // types not to be introspected by causeway
+        if(typeHead.hasIntrospectionVetoingSemantics()) {
+            return switch (discoveredBy) {
+                case SPRING ->
+                    // only when discovered by Spring is also injectable
+                    CausewayBeanMetaData.springManaged(discoveredBy, BeanSort.MANAGED_BEAN_NOT_CONTRIBUTING, logicalType);
+                case CAUSEWAY ->
+                    CausewayBeanMetaData.notManaged(discoveredBy, BeanSort.PROGRAMMATIC, logicalType);
+            };
         }
 
         // domain service
@@ -139,8 +145,8 @@ public record CausewayBeanTypeClassifier(
         }
         if(typeHead.hasAnnotation(Entity.class)) {
             return CausewayBeanMetaData.entity(discoveredBy, PersistenceStack.JPA, named.get());
-        }  
-        
+        }
+
         // domain object
         var aDomainObject = typeHead.annotation(DomainObject.class).orElse(null);
         if(aDomainObject!=null) {
diff --git a/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanTypeRegistry.java b/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanTypeRegistry.java
index 651c091dd6c..db963dfc7ee 100644
--- a/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanTypeRegistry.java
+++ b/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanTypeRegistry.java
@@ -25,8 +25,8 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Stream;
 
+import org.apache.causeway.applib.annotation.Programmatic;
 import org.apache.causeway.commons.collections.Can;
-import org.apache.causeway.commons.internal.annotations.BeanInternal;
 import org.apache.causeway.core.config.beans.CausewayBeanMetaData.PersistenceStack;
 
 import lombok.NonNull;
@@ -34,7 +34,7 @@ import lombok.NonNull;
 /**
  * Holds discovered domain types grouped by bean-sort.
  */
-@BeanInternal
+@Programmatic
 public class CausewayBeanTypeRegistry {
 
     /**
@@ -59,7 +59,7 @@ public class CausewayBeanTypeRegistry {
         introspectableTypes.forEach(typeMeta->{
 
             var cls = typeMeta.getCorrespondingClass();
-            
+
             introspectableTypesByClass.put(typeMeta.getCorrespondingClass(), typeMeta);
 
             switch (typeMeta.beanSort()) {
@@ -89,9 +89,9 @@ public class CausewayBeanTypeRegistry {
             }
         });
     }
-    
+
     // -- SIZE
-    
+
     public int managedBeansContributingCount() { return managedBeansContributing.size(); }
     public int entityTypeCount() { return entityTypes.size(); }
     public int viewmodelTypeCount() { return viewmodelTypes.size(); }
@@ -106,7 +106,7 @@ public class CausewayBeanTypeRegistry {
     public Stream<Class<?>> streamViewmodelTypes() { return viewmodelTypes.keySet().stream(); }
     public Stream<Class<?>> streamMixinTypes() { return mixinTypes.keySet().stream(); }
     public Stream<Class<?>> streamValueTypes() { return valueTypes.keySet().stream(); }
-    
+
     // -- AS SET
 
     public Set<Class<?>> entityTypeSet() { return Collections.unmodifiableSet(entityTypes.keySet()); }
@@ -122,8 +122,8 @@ public class CausewayBeanTypeRegistry {
         return Optional.ofNullable(managedBeansContributing.get(type))
                 .map(CausewayBeanMetaData::getBeanName);
     }
-    
-    public boolean containsManagedBeansContributing(@NonNull Class<?> type) {
+
+    public boolean containsManagedBeansContributing(@NonNull final Class<?> type) {
         return managedBeansContributing.containsKey(type);
     }
 
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/context/MetaModelContext.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/context/MetaModelContext.java
index cacd91b0e46..4e338fe7772 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/context/MetaModelContext.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/context/MetaModelContext.java
@@ -23,15 +23,15 @@ import java.util.concurrent.atomic.AtomicReference;
 
 import org.springframework.lang.Nullable;
 
+import org.apache.causeway.applib.annotation.Programmatic;
 import org.apache.causeway.applib.services.i18n.TranslationService;
-import org.apache.causeway.commons.internal.annotations.BeanInternal;
 import org.apache.causeway.commons.internal.assertions._Assert;
 import org.apache.causeway.commons.internal.exceptions._Exceptions;
 
 /**
  * @since 2.0
  */
-@BeanInternal
+@Programmatic
 public abstract class MetaModelContext implements HasMetaModelContext {
 
     @Override
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/objectmanager/ObjectManager.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/objectmanager/ObjectManager.java
index 1037ded3c12..f7bc02587cc 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/objectmanager/ObjectManager.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/objectmanager/ObjectManager.java
@@ -25,12 +25,12 @@ import jakarta.inject.Named;
 
 import org.springframework.lang.Nullable;
 
+import org.apache.causeway.applib.annotation.Programmatic;
 import org.apache.causeway.applib.exceptions.unrecoverable.BookmarkNotFoundException;
 import org.apache.causeway.applib.query.Query;
 import org.apache.causeway.applib.services.bookmark.Bookmark;
 import org.apache.causeway.commons.collections.Can;
 import org.apache.causeway.commons.handler.ChainOfResponsibility;
-import org.apache.causeway.commons.internal.annotations.BeanInternal;
 import org.apache.causeway.commons.internal.assertions._Assert;
 import org.apache.causeway.commons.internal.base._NullSafe;
 import org.apache.causeway.commons.internal.exceptions._Exceptions;
@@ -58,7 +58,7 @@ import lombok.NonNull;
  *
  * @since 2.0
  */
-@BeanInternal
+@Programmatic
 @Named(CausewayModuleCoreMetamodel.NAMESPACE + ".ObjectManager")
 public record ObjectManager(
         MetaModelContext mmc,