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 207c7a89281 CAUSEWAY-3883: flattens WrapperInvocationHandler hierarchy
(refactor)
207c7a89281 is described below
commit 207c7a8928106deb1210fceb0447dfb2efb668b7
Author: Andi Huber <[email protected]>
AuthorDate: Mon Jun 16 19:21:10 2025 +0200
CAUSEWAY-3883: flattens WrapperInvocationHandler hierarchy (refactor)
---
.../handlers/CollectionInvocationHandler.java | 45 ----------------------
.../handlers/DomainObjectInvocationHandler.java | 18 +++------
.../wrapper/handlers/MapInvocationHandler.java | 44 ---------------------
...rAbstract.java => PluralInvocationHandler.java} | 40 +++++++++++++++++--
.../wrapper/handlers/ProxyGenerator.java | 12 +++---
5 files changed, 48 insertions(+), 111 deletions(-)
diff --git
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/CollectionInvocationHandler.java
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/CollectionInvocationHandler.java
deleted file mode 100644
index bc4c97d1051..00000000000
---
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/CollectionInvocationHandler.java
+++ /dev/null
@@ -1,45 +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.core.runtimeservices.wrapper.handlers;
-
-import java.util.Collection;
-
-import org.apache.causeway.commons.internal.assertions._Assert;
-import org.apache.causeway.commons.semantics.CollectionSemantics;
-import org.apache.causeway.core.metamodel.spec.feature.OneToManyAssociation;
-
-class CollectionInvocationHandler<T, C extends Collection<?>>
-extends PluralInvocationHandlerAbstract<T, C> {
-
- public CollectionInvocationHandler(
- final C collectionToBeProxied,
- final DomainObjectInvocationHandler<T> handler,
- final OneToManyAssociation otma) {
-
- super(collectionToBeProxied, handler, otma,
- CollectionSemantics
- .valueOfElseFail(collectionToBeProxied.getClass()));
-
-
_Assert.assertTrue(Collection.class.isAssignableFrom(collectionToBeProxied.getClass()),
- ()->String.format("Cannot use %s for type %s, these are not
compatible.",
- this.getClass().getName(),
- collectionToBeProxied.getClass()));
- }
-
-}
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 93286ad3987..6ca432e4feb 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
@@ -57,7 +57,6 @@
import org.apache.causeway.core.metamodel.object.MmAssertionUtils;
import org.apache.causeway.core.metamodel.object.MmEntityUtils;
import org.apache.causeway.core.metamodel.object.MmUnwrapUtils;
-import org.apache.causeway.core.metamodel.objectmanager.ObjectManager;
import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
import org.apache.causeway.core.metamodel.spec.feature.MixedIn;
import org.apache.causeway.core.metamodel.spec.feature.MixedInMember;
@@ -78,7 +77,7 @@
* @param <T> type of delegate
*/
@Log4j2
-public class DomainObjectInvocationHandler<T>
+public final class DomainObjectInvocationHandler<T>
implements WrapperInvocationHandler {
@Getter(onMethod_ = {@Override}) @Accessors(fluent=true)
@@ -140,8 +139,7 @@ public DomainObjectInvocationHandler(
nsme);
}
- entityFacet = targetAdapter.objSpec().entityFacet().orElse(null);
-
+ this.entityFacet = targetAdapter.objSpec().entityFacet().orElse(null);
this.mixeeAdapter = mixeeAdapter;
}
@@ -160,7 +158,7 @@ public Object invoke(final Object proxyObjectUnused, final
Method method, final
return context().invoke(method, args);
}
- final ManagedObject targetAdapter =
getObjectManager().adapt(context().delegate());
+ final ManagedObject targetAdapter =
mmc.getObjectManager().adapt(context().delegate());
if(!targetAdapter.specialization().isMixin()) {
MmAssertionUtils.assertIsBookmarkSupported(targetAdapter);
@@ -371,7 +369,7 @@ private Object handleSetterMethodOnProperty(
checkUsability(targetAdapter, property);
});
- var argumentAdapter = getObjectManager().adapt(singleArg);
+ var argumentAdapter = property.getObjectManager().adapt(singleArg);
runValidationTask(()->{
var interactionResult = property.isAssociationValid(
@@ -459,7 +457,7 @@ private Object handleActionMethod(
final ObjectAction objectAction) {
var head = objectAction.interactionHead(targetAdapter);
- var objectManager = getObjectManager();
+ var objectManager = objectAction.getObjectManager();
// adapt argument pojos to managed objects
var argAdapters =
objectAction.getParameterTypes().map(IndexedFunction.zeroBased((paramIndex,
paramSpec)->{
@@ -631,10 +629,4 @@ private void zeroArgsElseThrow(final Object[] args, final
String name) {
}
}
- // -- DEPENDENCIES
-
- private ObjectManager getObjectManager() {
- return mmc.getObjectManager();
- }
-
}
diff --git
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/MapInvocationHandler.java
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/MapInvocationHandler.java
deleted file mode 100644
index d73a953b0bf..00000000000
---
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/MapInvocationHandler.java
+++ /dev/null
@@ -1,44 +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.core.runtimeservices.wrapper.handlers;
-
-import java.util.Map;
-
-import org.apache.causeway.commons.internal.assertions._Assert;
-import org.apache.causeway.commons.semantics.CollectionSemantics;
-import org.apache.causeway.core.metamodel.spec.feature.OneToManyAssociation;
-
-class MapInvocationHandler<T, M extends Map<?,?>>
-extends PluralInvocationHandlerAbstract<T, M> {
-
- public MapInvocationHandler(
- final M mapToBeProxied,
- final DomainObjectInvocationHandler<T> handler,
- final OneToManyAssociation otma) {
-
- super(mapToBeProxied, handler, otma,
- CollectionSemantics.MAP);
-
-
_Assert.assertTrue(Map.class.isAssignableFrom(mapToBeProxied.getClass()),
- ()->String.format("Cannot use %s for type %s, these are not
compatible.",
- this.getClass().getName(),
- mapToBeProxied.getClass()));
- }
-
-}
diff --git
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/PluralInvocationHandlerAbstract.java
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/PluralInvocationHandler.java
similarity index 68%
rename from
core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/PluralInvocationHandlerAbstract.java
rename to
core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/PluralInvocationHandler.java
index 718a4d20566..17fd445fef6 100644
---
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/PluralInvocationHandlerAbstract.java
+++
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/PluralInvocationHandler.java
@@ -23,6 +23,7 @@
import java.util.Map;
import
org.apache.causeway.applib.services.wrapper.events.CollectionMethodEvent;
+import org.apache.causeway.commons.internal.assertions._Assert;
import org.apache.causeway.commons.semantics.CollectionSemantics;
import org.apache.causeway.core.metamodel.spec.feature.OneToManyAssociation;
import org.apache.causeway.core.runtime.wrap.WrapperInvocationHandler;
@@ -36,16 +37,49 @@
* @param <T> Domain Object type
* @param <P> non-scalar type (eg. {@link Collection} or {@link Map}) to be
proxied
*/
-abstract class PluralInvocationHandlerAbstract<T, P>
+final class PluralInvocationHandler<T, P>
implements WrapperInvocationHandler {
+ // -- FACTORIES
+
+ static <T, C extends Collection<?>> PluralInvocationHandler<T, C>
forCollection(
+ final C collectionToBeProxied,
+ final DomainObjectInvocationHandler<T> handler,
+ final OneToManyAssociation otma) {
+
+
_Assert.assertTrue(Collection.class.isAssignableFrom(collectionToBeProxied.getClass()),
+ ()->String.format("Cannot use %s for type %s, these are not
compatible.",
+ PluralInvocationHandler.class.getName() +
".forCollection(..)",
+ collectionToBeProxied.getClass()));
+
+ return new PluralInvocationHandler<>(collectionToBeProxied, handler,
otma,
+ CollectionSemantics
+ .valueOfElseFail(collectionToBeProxied.getClass()));
+ }
+
+ static <T, M extends Map<?,?>> PluralInvocationHandler<T, M> forMap(
+ final M mapToBeProxied,
+ final DomainObjectInvocationHandler<T> handler,
+ final OneToManyAssociation otma) {
+
+
_Assert.assertTrue(Map.class.isAssignableFrom(mapToBeProxied.getClass()),
+ ()->String.format("Cannot use %s for type %s, these are not
compatible.",
+ PluralInvocationHandler.class.getName() + ".forMap(..)",
+ mapToBeProxied.getClass()));
+
+ return new PluralInvocationHandler<>(mapToBeProxied, handler, otma,
+ CollectionSemantics.MAP);
+ }
+
+ // -- CONSTRUCTION
+
@Getter(onMethod_ = {@Override}) @Accessors(fluent=true)
private final WrapperInvocationHandler.Context context;
private final OneToManyAssociation oneToManyAssociation;
private final CollectionSemantics collectionSemantics;
-
- protected PluralInvocationHandlerAbstract(
+
+ protected PluralInvocationHandler(
final P collectionOrMapToBeProxied,
final DomainObjectInvocationHandler<T> handler,
final OneToManyAssociation otma,
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 24aa3be43d7..dda662c6503 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
@@ -78,12 +78,12 @@ public <T, E> Collection<E> collectionProxy(
final DomainObjectInvocationHandler<T> handler,
final OneToManyAssociation otma) {
- var collectionInvocationHandler = new CollectionInvocationHandler<T,
Collection<E>>(
- collectionToBeProxied, handler, otma);
+ var collectionInvocationHandler = PluralInvocationHandler
+ .forCollection(collectionToBeProxied, handler, otma);
var proxyBase = CollectionSemantics
- .valueOfElseFail(collectionToBeProxied.getClass())
- .getContainerType();
+ .valueOfElseFail(collectionToBeProxied.getClass())
+ .getContainerType();
return instantiateProxy(_Casts.uncheckedCast(proxyBase),
collectionInvocationHandler);
}
@@ -97,8 +97,8 @@ public <T, P, Q> Map<P, Q> mapProxy(
final DomainObjectInvocationHandler<T> handler,
final OneToManyAssociation otma) {
- var mapInvocationHandler = new MapInvocationHandler<T, Map<P, Q>>(
- collectionToBeProxied, handler, otma);
+ var mapInvocationHandler = PluralInvocationHandler
+ .forMap(collectionToBeProxied, handler, otma);
var proxyBase = Map.class;