This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/main by this push:
new 4156192d457 CAUSEWAY-3883: no longer require DomainObjInvHandl. to
init w/ mixeeAdapter (refactor)
4156192d457 is described below
commit 4156192d45781fcbb318453c73703466d84f6491
Author: Andi Huber <[email protected]>
AuthorDate: Tue Jun 24 14:30:12 2025 +0200
CAUSEWAY-3883: no longer require DomainObjInvHandl. to init w/
mixeeAdapter (refactor)
---
.../applib/services/wrapper/WrappingObject.java | 28 +++++++++++++--
.../wrapper/WrapperFactoryDefault.java | 12 ++++---
.../handlers/DomainObjectInvocationHandler.java | 42 ++++++++++------------
.../wrapper/handlers/ProxyGenerator.java | 10 +++---
4 files changed, 54 insertions(+), 38 deletions(-)
diff --git
a/api/applib/src/main/java/org/apache/causeway/applib/services/wrapper/WrappingObject.java
b/api/applib/src/main/java/org/apache/causeway/applib/services/wrapper/WrappingObject.java
index e359df42488..0f447d8ce04 100644
---
a/api/applib/src/main/java/org/apache/causeway/applib/services/wrapper/WrappingObject.java
+++
b/api/applib/src/main/java/org/apache/causeway/applib/services/wrapper/WrappingObject.java
@@ -21,6 +21,8 @@
import java.lang.reflect.Modifier;
import java.util.List;
+import org.jspecify.annotations.Nullable;
+
import org.apache.causeway.applib.services.wrapper.control.SyncControl;
import
org.apache.causeway.commons.internal.proxy._ProxyFactoryService.AdditionalField;
import org.apache.causeway.commons.internal.reflection._Reflect;
@@ -47,12 +49,32 @@ public interface WrappingObject {
final static List<AdditionalField> ADDITIONAL_FIELDS = List.of(
new AdditionalField(ORIGIN_FIELD_NAME,
WrappingObject.Origin.class, Modifier.PROTECTED));
- record Origin(Object pojo, SyncControl syncControl, boolean isFallback) {
+ //TODO perhaps move to a module that sees ManagedObject
+ record Origin(
+ Object pojo,
+ /**
+ * The mixee adapted as a ManagedObject, used only if pojo is a
mixin.
+ */
+ @Nullable Object managedMixee,
+ SyncControl syncControl,
+ boolean isFallback) {
+ /**
+ * fallback, used for non-proxied target, with no execute (no verify
no rule checking).
+ */
public static Origin fallback(Object target) {
- return new Origin(target, SyncControl.control().withNoExecute(),
true);
+ return new Origin(target, null,
SyncControl.control().withNoExecute(), true);
+ }
+ /**
+ * fallback, used for non-proxied target as mixin, with no execute (no
verify no rule checking)
+ */
+ public static Origin fallbackMixin(Object target, Object managedMixee)
{
+ return new Origin(target, managedMixee,
SyncControl.control().withNoExecute(), true);
}
public Origin(Object pojo, SyncControl syncControl) {
- this(pojo, syncControl, false);
+ this(pojo, null, syncControl, false);
+ }
+ public Origin(Object pojo, Object managedMixee, SyncControl
syncControl) {
+ this(pojo, managedMixee, syncControl, false);
}
}
diff --git
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/WrapperFactoryDefault.java
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/WrapperFactoryDefault.java
index b4cf9ddc186..4ac9f090929 100644
---
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/WrapperFactoryDefault.java
+++
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/WrapperFactoryDefault.java
@@ -98,6 +98,7 @@
import org.apache.causeway.core.metamodel.spec.feature.MixedInMember;
import org.apache.causeway.core.metamodel.spec.feature.ObjectAction;
import org.apache.causeway.core.metamodel.spec.feature.OneToOneAssociation;
+import
org.apache.causeway.core.runtime.wrap.WrapperInvocationHandler.WrapperInvocation;
import
org.apache.causeway.core.runtimeservices.CausewayModuleCoreRuntimeServices;
import org.apache.causeway.core.runtimeservices.session.InteractionIdGenerator;
import
org.apache.causeway.core.runtimeservices.wrapper.dispatchers.InteractionEventDispatcher;
@@ -321,8 +322,8 @@ public <T, R> T asyncWrapMixin(
T mixin = factoryService.mixin(mixinClass, mixee);
- var mixeeAdapter = adaptAndGuardAgainstWrappingNotSupported(mixee);
- var mixinAdapter = adaptAndGuardAgainstWrappingNotSupported(mixin);
+ var managedMixee = adaptAndGuardAgainstWrappingNotSupported(mixee);
+ var managedMixin = adaptAndGuardAgainstWrappingNotSupported(mixin);
var mixinConstructor =
MixinConstructor.PUBLIC_SINGLE_ARG_RECEIVING_MIXEE
.getConstructorElseFail(mixinClass, mixee.getClass());
@@ -341,11 +342,12 @@ public <T, R> T asyncWrapMixin(
}
if (asyncControl.isCheckRules()) {
- var doih = proxyGenerator.handlerForMixin(mixeeAdapter,
mixinAdapter.objSpec());
- doih.invoke(mixin, method, args);
+ var doih =
proxyGenerator.handlerForMixin(managedMixin.objSpec());
+ var origin = WrappingObject.Origin.fallbackMixin(mixin,
managedMixee);
+ doih.invoke(new WrapperInvocation(origin, method, args));
}
- var actionAndTarget = memberAndTargetForMixin(resolvedMethod,
mixee, mixinAdapter);
+ var actionAndTarget = memberAndTargetForMixin(resolvedMethod,
mixee, managedMixin);
if (! actionAndTarget.isMemberFound()) {
return method.invoke(mixin, args);
}
diff --git
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/DomainObjectInvocationHandler.java
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/DomainObjectInvocationHandler.java
index 3580a6ea3a4..797c4ce0242 100644
---
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/DomainObjectInvocationHandler.java
+++
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/DomainObjectInvocationHandler.java
@@ -75,18 +75,14 @@ final class DomainObjectInvocationHandler
private final WrapperInvocationHandler.ClassMetaData classMetaData;
private final ProxyGenerator proxyGenerator;
- private final ManagedObject mixeeAdapter;
private final ObjectSpecification targetSpec;
DomainObjectInvocationHandler(
- final ManagedObject mixeeAdapter, // ignored if not handling a
mixin
final ObjectSpecification targetSpec,
final ProxyGenerator proxyGenerator) {
-
this.targetSpec = targetSpec;
this.classMetaData =
WrapperInvocationHandler.ClassMetaData.of(targetSpec.getCorrespondingClass());
this.proxyGenerator = proxyGenerator;
- this.mixeeAdapter = mixeeAdapter;
}
@Override
@@ -94,6 +90,7 @@ public Object invoke(WrapperInvocation wrapperInvocation)
throws Throwable {
final Object target = wrapperInvocation.origin().pojo();
final Method method = wrapperInvocation.method();
+ final ManagedObject managedMixee = (ManagedObject)
wrapperInvocation.origin().managedMixee();
if (classMetaData().isObjectMethod(method)
|| isEnhancedEntityMethod(method)) {
@@ -110,8 +107,7 @@ public Object invoke(WrapperInvocation wrapperInvocation)
throws Throwable {
return handleTitleMethod(wrapperInvocation, targetAdapter);
}
- final ObjectSpecification targetSpec = targetAdapter.objSpec();
- var resolvedMethod = _GenericResolver.resolveMethod(method,
targetSpec.getCorrespondingClass())
+ var resolvedMethod = _GenericResolver.resolveMethod(method,
targetAdapter.objSpec().getCorrespondingClass())
.orElseThrow();
if(!wrapperInvocation.origin().isFallback()) {
@@ -120,16 +116,14 @@ public Object invoke(WrapperInvocation wrapperInvocation)
throws Throwable {
}
// save method, through the proxy
if (classMetaData.isSaveMethod(method)) {
- return handleSaveMethod(wrapperInvocation, targetAdapter,
targetSpec);
+ return handleSaveMethod(wrapperInvocation, targetAdapter,
targetAdapter.objSpec());
}
}
- var objectMember = targetSpec.getMemberElseFail(resolvedMethod);
- var memberId = objectMember.getId();
-
+ var objectMember =
targetAdapter.objSpec().getMemberElseFail(resolvedMethod);
var intent = ImperativeFacet.getIntent(objectMember, resolvedMethod);
if(intent == Intent.CHECK_IF_HIDDEN || intent ==
Intent.CHECK_IF_DISABLED) {
- throw new UnsupportedOperationException(String.format("Cannot
invoke supporting method '%s'", memberId));
+ throw new UnsupportedOperationException(String.format("Cannot
invoke supporting method '%s'", objectMember.getId()));
}
if (intent == Intent.DEFAULTS || intent ==
Intent.CHOICES_OR_AUTOCOMPLETE) {
@@ -139,7 +133,7 @@ public Object invoke(WrapperInvocation wrapperInvocation)
throws Throwable {
if (objectMember.isOneToOneAssociation()) {
if (intent == Intent.CHECK_IF_VALID || intent ==
Intent.MODIFY_PROPERTY_SUPPORTING) {
- throw new UnsupportedOperationException(String.format("Cannot
invoke supporting method for '%s'; use only property accessor/mutator",
memberId));
+ throw new UnsupportedOperationException(String.format("Cannot
invoke supporting method for '%s'; use only property accessor/mutator",
objectMember.getId()));
}
final OneToOneAssociation otoa = (OneToOneAssociation)
objectMember;
@@ -155,48 +149,48 @@ public Object invoke(WrapperInvocation wrapperInvocation)
throws Throwable {
if (objectMember.isOneToManyAssociation()) {
if (intent == Intent.CHECK_IF_VALID) {
- throw new UnsupportedOperationException(String.format("Cannot
invoke supporting method '%s'; use only collection accessor/mutator",
memberId));
+ throw new UnsupportedOperationException(String.format("Cannot
invoke supporting method '%s'; use only collection accessor/mutator",
objectMember.getId()));
}
final OneToManyAssociation otma = (OneToManyAssociation)
objectMember;
if (intent == Intent.ACCESSOR) {
- return handleGetterMethodOnCollection(wrapperInvocation,
targetAdapter, otma, memberId);
+ return handleGetterMethodOnCollection(wrapperInvocation,
targetAdapter, otma, objectMember.getId());
}
}
if (objectMember instanceof ObjectAction) {
if (intent == Intent.CHECK_IF_VALID) {
- throw new UnsupportedOperationException(String.format("Cannot
invoke supporting method '%s'; use only the 'invoke' method", memberId));
+ throw new UnsupportedOperationException(String.format("Cannot
invoke supporting method '%s'; use only the 'invoke' method",
objectMember.getId()));
}
var objectAction = (ObjectAction) objectMember;
- if(targetSpec.isMixin()) {
- if (mixeeAdapter == null) {
+ if(targetAdapter.objSpec().isMixin()) {
+ if (managedMixee == null) {
throw _Exceptions.illegalState(
- "Missing the required mixeeAdapter for action
'%s'",
+ "Missing the required managedMixee for action
'%s'",
objectAction.getId());
}
- MmAssertionUtils.assertIsBookmarkSupported(mixeeAdapter);
+ MmAssertionUtils.assertIsBookmarkSupported(managedMixee);
- final ObjectMember mixinMember =
determineMixinMember(mixeeAdapter, objectAction);
+ final ObjectMember mixinMember =
determineMixinMember(managedMixee, objectAction);
if (mixinMember != null) {
if(mixinMember instanceof ObjectAction) {
- return handleActionMethod(wrapperInvocation,
mixeeAdapter, (ObjectAction)mixinMember);
+ return handleActionMethod(wrapperInvocation,
managedMixee, (ObjectAction)mixinMember);
}
if(mixinMember instanceof OneToOneAssociation) {
_Assert.assertEquals(0,
wrapperInvocation.args().length);
- return handleGetterMethodOnProperty(wrapperInvocation,
mixeeAdapter, (OneToOneAssociation)mixinMember);
+ return handleGetterMethodOnProperty(wrapperInvocation,
managedMixee, (OneToOneAssociation)mixinMember);
}
if(mixinMember instanceof OneToManyAssociation) {
_Assert.assertEquals(0,
wrapperInvocation.args().length);
- return
handleGetterMethodOnCollection(wrapperInvocation, mixeeAdapter,
(OneToManyAssociation)mixinMember, memberId);
+ return
handleGetterMethodOnCollection(wrapperInvocation, managedMixee,
(OneToManyAssociation)mixinMember, objectMember.getId());
}
} else {
throw _Exceptions.illegalState(String.format(
- "Could not locate mixin member for action '%s' on
spec '%s'", objectAction.getId(), targetSpec));
+ "Could not locate mixin member for action '%s' on
spec '%s'", objectAction.getId(), targetAdapter.objSpec()));
}
}
diff --git
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/ProxyGenerator.java
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/ProxyGenerator.java
index cd4f768f446..ed24161f121 100644
---
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/ProxyGenerator.java
+++
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/ProxyGenerator.java
@@ -48,12 +48,12 @@ public <T> T objectProxy(
public <T> T mixinProxy(
final T mixin,
- final ManagedObject mixeeAdapter,
+ final ManagedObject managedMixee,
final ObjectSpecification mixinSpec,
final SyncControl syncControl) {
- var invocationHandler = handlerForMixin(mixeeAdapter, mixinSpec);
- return instantiateProxy(invocationHandler, new
WrappingObject.Origin(mixin, syncControl));
+ var invocationHandler = handlerForMixin(mixinSpec);
+ return instantiateProxy(invocationHandler, new
WrappingObject.Origin(mixin, managedMixee, syncControl));
}
/**
@@ -118,14 +118,12 @@ private <T, P> P instantiatePluralProxy(final Class<T>
base, final PluralInvocat
public WrapperInvocationHandler handlerForRegular(ObjectSpecification
targetSpec) {
return new DomainObjectInvocationHandler(
- null, // mixeeAdapter ignored
targetSpec,
this);
}
- public WrapperInvocationHandler handlerForMixin(ManagedObject
mixeeAdapter, ObjectSpecification mixinSpec) {
+ public WrapperInvocationHandler handlerForMixin(ObjectSpecification
mixinSpec) {
return new DomainObjectInvocationHandler(
- mixeeAdapter,
mixinSpec,
this);
}