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 2019/10/05 21:51:14 UTC
[isis] branch v2 updated: ISIS-2158: non-invasive preparations for
ISIS-1998
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/v2 by this push:
new f3e03a1 ISIS-2158: non-invasive preparations for ISIS-1998
f3e03a1 is described below
commit f3e03a1d390e6ffbbbd424e87600f062f0253db0
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sat Oct 5 23:50:58 2019 +0200
ISIS-2158: non-invasive preparations for ISIS-1998
adding tests first (test driven development) before actually modifying
the programming model ...
1. facet processing tests
2. smoketests to test whether the generated meta-model is as expected
---
.../org/apache/isis/applib/annotation/Action.java | 2 +-
.../apache/isis/commons/internal/base/_With.java | 30 ++++-
.../isis/commons/internal/reflection/_Reflect.java | 19 ++-
.../facets/object/mixin/MixinIntendedAs.java | 123 ++++++++++++++++++
.../object/mixin/MixinIntendedAsActionTest.java | 141 +++++++++++++++++++++
.../facets/object/grid/GridFacetFactory.java | 6 +-
.../javalang/IteratorFilteringFacetFactory.java | 4 +-
.../mixin/MetaModelValidatorForMixinTypes.java | 21 +--
.../metamodel/facets/object/mixin/MixinFacet.java | 28 ++--
.../facets/object/mixin/MixinFacetAbstract.java | 64 ++++++----
.../mixin/MixinFacetForDomainObjectAnnotation.java | 19 +--
.../object/mixin/MixinFacetForMixinAnnotation.java | 4 +-
.../mixin/MixinFacetForMixinAnnotationFactory.java | 24 ++--
.../method/NavigableParentFacetMethodFactory.java | 66 ----------
...arameterChoicesFacetFromParentedCollection.java | 10 +-
.../specloader/specimpl/ObjectActionMixedIn.java | 2 +-
.../facets/AbstractFacetFactoryJUnit4TestCase.java | 3 +-
.../NavigableParentFacetMethodFactoryTest.java | 70 ----------
.../adapterfactory/pojo/PojoAdapterTest.java | 1 -
.../transaction/PojoAdapterBuilder.java | 2 +-
.../runtime/system/ObjectMemberAbstractTest.java | 21 ++-
.../runtime/persistence/adapter/PojoAdapter.java | 16 +--
.../model/good/ProperActionSupport_action.java | 44 +++++++
.../model/good/ProperActionSupport_mixin.java | 45 +++++++
.../DomainModelTest_usingGoodDomain.java | 10 ++
25 files changed, 532 insertions(+), 243 deletions(-)
diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/Action.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/Action.java
index 9cabe5f..4ae8645 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/annotation/Action.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/Action.java
@@ -38,7 +38,7 @@ import org.apache.isis.applib.value.Clob;
* Domain semantics for domain object collection.
*/
@Inherited
-@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
+@Target({ ElementType.METHOD, ElementType.TYPE, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface Action {
diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_With.java b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_With.java
index f30fbf4..fa5fffb 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_With.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_With.java
@@ -22,14 +22,18 @@ package org.apache.isis.commons.internal.base;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Optional;
import java.util.TreeMap;
import java.util.TreeSet;
+import java.util.concurrent.Callable;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import javax.annotation.Nullable;
+import lombok.val;
+
/**
* <h1>- internal use only -</h1>
* <p>
@@ -305,7 +309,31 @@ public final class _With<T> {
return create(StringBuilder::new, initializer);
}
+ // -- EXCEPTION SWALLOW IDIOMS
+
+ /**
+ * Returns Optional of the callable's result after invocation. Any exception during
+ * invocation will result in an empty Optional.
+ */
+ public static <T> Optional<T> tryCall(Callable<T> callable) {
+ try {
+ val result = callable.call();
+ return Optional.ofNullable(result);
+ } catch (Exception e) {
+ return Optional.empty();
+ }
+ }
-
+ /**
+ * Returns the callable's result after invocation. Any exception during
+ * invocation will result in the defaultValue being returned instead.
+ */
+ public static <T> T tryOrDefault(Callable<T> callable, T defaultValue) {
+ try {
+ return callable.call();
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
}
diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Reflect.java b/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Reflect.java
index 289a90c..258fb50 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Reflect.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_Reflect.java
@@ -19,6 +19,9 @@
package org.apache.isis.commons.internal.reflection;
+import static org.apache.isis.commons.internal.base._NullSafe.stream;
+import static org.apache.isis.commons.internal.base._With.requires;
+
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
@@ -44,8 +47,7 @@ import org.springframework.core.annotation.AnnotationUtils;
import org.apache.isis.commons.internal.base._Strings;
import org.apache.isis.commons.internal.collections._Arrays;
-import static org.apache.isis.commons.internal.base._NullSafe.stream;
-import static org.apache.isis.commons.internal.base._With.requires;
+import lombok.val;
/**
* <h1>- internal use only -</h1>
@@ -392,6 +394,19 @@ public final class _Reflect {
}
return null;
}
+
+ // -- COMMON CONSTRUCTOR IDIOMS
+
+ public static boolean hasPublic1ArgConstructor(Class<?> cls) {
+ val constructors = cls.getConstructors();
+ for (val constructor : constructors) {
+ if(constructor.getParameterCount()==1 &&
+ Modifier.isPublic(constructor.getModifiers())) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/core/detached-tests/src/test/java/org/apache/isis/metamodel/facets/object/mixin/MixinIntendedAs.java b/core/detached-tests/src/test/java/org/apache/isis/metamodel/facets/object/mixin/MixinIntendedAs.java
new file mode 100644
index 0000000..26839e8
--- /dev/null
+++ b/core/detached-tests/src/test/java/org/apache/isis/metamodel/facets/object/mixin/MixinIntendedAs.java
@@ -0,0 +1,123 @@
+/*
+ * 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.isis.metamodel.facets.object.mixin;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.applib.Identifier;
+import org.apache.isis.commons.internal.environment.IsisSystemEnvironment;
+import org.apache.isis.config.IsisConfiguration;
+import org.apache.isis.metamodel.MetaModelContext;
+import org.apache.isis.metamodel.facetapi.FacetHolder;
+import org.apache.isis.metamodel.facetapi.FeatureType;
+import org.apache.isis.metamodel.facetapi.MethodRemover;
+import org.apache.isis.metamodel.facets.AbstractFacetFactoryTest;
+import org.apache.isis.metamodel.facets.FacetFactory;
+import org.apache.isis.metamodel.facets.FacetedMethodParameter;
+import org.apache.isis.metamodel.facets.MethodRemoverConstants;
+import org.apache.isis.metamodel.metamodelvalidator.dflt.MetaModelValidatorDefault;
+import org.apache.isis.metamodel.progmodel.ProgrammingModelAbstract;
+import org.apache.isis.metamodel.progmodels.dflt.ProgrammingModelFacetsJava8;
+import org.apache.isis.metamodel.specloader.SpecificationLoaderDefault;
+
+import lombok.val;
+
+abstract class MixinIntendedAs {
+
+ protected ProgrammingModelFacetsJava8 programmingModel;
+
+ protected void setUp() throws Exception {
+
+ programmingModel = new ProgrammingModelFacetsJava8(
+ ProgrammingModelAbstract.DeprecatedPolicy.IGNORE);
+ programmingModel.init();
+
+ // PRODUCTION
+
+ MetaModelContext.preset(MetaModelContext.builder()
+ .specificationLoader(SpecificationLoaderDefault.getInstance(
+ new IsisConfiguration(),
+ new IsisSystemEnvironment(),
+ new ProgrammingModelFacetsJava8(ProgrammingModelAbstract.DeprecatedPolicy.HONOUR),
+ new MetaModelValidatorDefault()))
+// .serviceInjector(mockServiceInjector)
+// .serviceRegistry(mockServiceRegistry)
+ .build());
+
+ MetaModelContext.current().getSpecificationLoader().init();
+
+ }
+
+ protected void tearDown() {
+ programmingModel = null;
+ }
+
+ protected void newContext(
+ final Class<?> cls,
+ final Method method,
+ final int paramNum,
+ final MethodRemover methodRemover) {
+
+ }
+
+ protected FacetHolder runTypeContextOn(Class<?> type) {
+
+ val facetHolder = new AbstractFacetFactoryTest.IdentifiedHolderImpl(
+ Identifier.classIdentifier(type));
+
+ val processClassContext =
+ new FacetFactory.ProcessClassContext(
+ type,
+ MethodRemoverConstants.NOOP,
+ facetHolder);
+
+ programmingModel.getList().stream()
+ .filter(facetFactory->!facetFactory.getClass().getSimpleName().startsWith("Grid"))
+ .peek(facetFactory->System.out.println("### " + facetFactory.getClass().getName()))
+ .forEach(facetFactory->facetFactory.process(processClassContext));
+
+ return facetHolder;
+ }
+
+ protected FacetedMethodParameter runScalarParameterContextOn(Method actionMethod, int paramIndex) {
+
+ val owningType = actionMethod.getDeclaringClass();
+ val parameterType = actionMethod.getParameterTypes()[paramIndex];
+
+ val facetedMethodParameter = new FacetedMethodParameter(
+ FeatureType.ACTION_PARAMETER_SCALAR,
+ owningType,
+ actionMethod,
+ parameterType);
+
+ val processParameterContext =
+ new FacetFactory.ProcessParameterContext(
+ owningType,
+ actionMethod,
+ paramIndex,
+ MethodRemoverConstants.NOOP,
+ facetedMethodParameter);
+
+ programmingModel.getList()
+ .forEach(facetFactory->facetFactory.processParams(processParameterContext));
+
+ return facetedMethodParameter;
+ }
+
+}
diff --git a/core/detached-tests/src/test/java/org/apache/isis/metamodel/facets/object/mixin/MixinIntendedAsActionTest.java b/core/detached-tests/src/test/java/org/apache/isis/metamodel/facets/object/mixin/MixinIntendedAsActionTest.java
new file mode 100644
index 0000000..0b246cf
--- /dev/null
+++ b/core/detached-tests/src/test/java/org/apache/isis/metamodel/facets/object/mixin/MixinIntendedAsActionTest.java
@@ -0,0 +1,141 @@
+/*
+ * 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.isis.metamodel.facets.object.mixin;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.springframework.util.ReflectionUtils;
+
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.DomainObject;
+import org.apache.isis.applib.annotation.Mixin;
+import org.apache.isis.metamodel.MetaModelContext;
+import org.apache.isis.metamodel.adapter.oid.Oid;
+import org.apache.isis.metamodel.facets.all.named.NamedFacet;
+import org.apache.isis.metamodel.facets.object.mixin.MixinFacet.Policy;
+import org.apache.isis.metamodel.spec.ManagedObject;
+import org.apache.isis.metamodel.spec.ObjectSpecId;
+import org.apache.isis.metamodel.specloader.specimpl.IntrospectionState;
+import org.apache.isis.runtime.persistence.adapter.PojoAdapter;
+
+import lombok.Data;
+import lombok.RequiredArgsConstructor;
+import lombok.val;
+
+@SuppressWarnings("unused")
+class MixinIntendedAsActionTest extends MixinIntendedAs {
+
+ @BeforeEach
+ void beforeEach() throws Exception {
+ super.setUp();
+ }
+
+ @AfterEach
+ void afterEach() throws Exception {
+ super.tearDown();
+ }
+
+ // the non holder
+ @DomainObject
+ static class NoCustomer {
+
+ }
+
+ // the (shared) holder
+ @DomainObject @Data
+ static class Customer {
+ String name;
+ }
+
+ // ------------------------------
+ // -- classic mix-in declaration
+ // ------------------------------
+
+ @Mixin @RequiredArgsConstructor
+ static class Customer_mixin {
+
+ private final Customer holder;
+
+ @Action
+ public void $$(String newName) { holder.setName(newName); }
+ }
+
+ @Test
+ void classicMixin_shouldHaveProperFacet() {
+
+ val mixinFacet = super.runTypeContextOn(Customer_mixin.class)
+ .getFacet(MixinFacet.class);
+
+ // proper predicates
+ assertNotNull(mixinFacet);
+ assertTrue(mixinFacet.isMixinFor(Customer.class));
+ assertFalse(mixinFacet.isMixinFor(NoCustomer.class));
+
+ // proper instantiation
+ val holderPojo = new Customer();
+ val mixinPojo = mixinFacet.instantiate(holderPojo);
+ ((Customer_mixin)mixinPojo).$$("hello");
+ assertEquals("hello", holderPojo.getName());
+
+ }
+
+ // ------------------------------------------
+ // -- advanced mix-in declaration ... @Action
+ // ------------------------------------------
+
+ @Action @RequiredArgsConstructor
+ static class Customer_action {
+
+ private final Customer holder;
+
+ @Action // <-- TODO optional?
+ public void $$(String newName) { holder.setName(newName); }
+ }
+
+ @Test @Disabled("under construction")
+ void actionMixin_shouldHaveProperFacet() {
+
+ val mixinFacet = super.runTypeContextOn(Customer_action.class)
+ .getFacet(MixinFacet.class);
+
+ // proper predicates
+ assertNotNull(mixinFacet);
+ assertTrue(mixinFacet.isMixinFor(Customer.class));
+ assertFalse(mixinFacet.isMixinFor(NoCustomer.class));
+
+ // proper instantiation
+ val holderPojo = new Customer();
+ val mixinPojo = mixinFacet.instantiate(holderPojo);
+ ((Customer_action)mixinPojo).$$("hello");
+ assertEquals("hello", holderPojo.getName());
+ }
+
+
+
+
+}
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/grid/GridFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/grid/GridFacetFactory.java
index 2a92ded..03018ca 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/grid/GridFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/grid/GridFacetFactory.java
@@ -32,13 +32,15 @@ public class GridFacetFactory extends FacetFactoryAbstract {
@Override
public void process(final ProcessClassContext processClassContext) {
+ if(gridService.get()==null) {
+ return;
+ }
val facetHolder = processClassContext.getFacetHolder();
-
FacetUtil.addFacet(GridFacetDefault.create(facetHolder, gridService.get()));
}
private final _Lazy<GridService> gridService = _Lazy.threadSafe(()->
- getServiceRegistry().lookupServiceElseFail(GridService.class));
+ getServiceRegistry().lookupService(GridService.class).orElse(null));
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/ignore/javalang/IteratorFilteringFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/ignore/javalang/IteratorFilteringFacetFactory.java
index c9fb5eb..8dc9921 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/ignore/javalang/IteratorFilteringFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/ignore/javalang/IteratorFilteringFacetFactory.java
@@ -41,8 +41,8 @@ public class IteratorFilteringFacetFactory extends FacetFactoryAbstract implemen
}
@Override
- public void process(final ProcessClassContext processClassContaxt) {
- processClassContaxt.removeMethod(MethodScope.OBJECT, "iterator", java.util.Iterator.class, new Class[] {});
+ public void process(final ProcessClassContext processClassContext) {
+ processClassContext.removeMethod(MethodScope.OBJECT, "iterator", java.util.Iterator.class, new Class[] {});
}
@Override
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MetaModelValidatorForMixinTypes.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MetaModelValidatorForMixinTypes.java
index 55fed7a..1f3deac 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MetaModelValidatorForMixinTypes.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MetaModelValidatorForMixinTypes.java
@@ -18,10 +18,8 @@
*/
package org.apache.isis.metamodel.facets.object.mixin;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Modifier;
-
import org.apache.isis.applib.Identifier;
+import org.apache.isis.commons.internal.reflection._Reflect;
import org.apache.isis.metamodel.specloader.validator.MetaModelValidatorForValidationFailures;
public class MetaModelValidatorForMixinTypes extends MetaModelValidatorForValidationFailures {
@@ -33,26 +31,19 @@ public class MetaModelValidatorForMixinTypes extends MetaModelValidatorForValida
}
public boolean ensureMixinType(final Class<?> candidateMixinType) {
- boolean mixinType = has1ArgConstructor(candidateMixinType);
- if (mixinType) {
+
+ if (_Reflect.hasPublic1ArgConstructor(candidateMixinType)) {
return true;
}
+
addFailure(
Identifier.classIdentifier(candidateMixinType),
"%s: annotated with %s annotation but does not have a public 1-arg constructor",
candidateMixinType.getName(),
annotation);
+
return false;
}
- private static boolean has1ArgConstructor(final Class<?> cls) {
- final Constructor<?>[] constructors = cls.getConstructors();
- for (final Constructor<?> constructor : constructors) {
- final Class<?>[] parameterTypes = constructor.getParameterTypes();
- if (parameterTypes.length == 1 && Modifier.isPublic(constructor.getModifiers())) {
- return true;
- }
- }
- return false;
- }
+
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacet.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacet.java
index 034ea31..1649b4d 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacet.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacet.java
@@ -19,17 +19,28 @@
package org.apache.isis.metamodel.facets.object.mixin;
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.Collection;
import org.apache.isis.applib.annotation.DomainObject;
+import org.apache.isis.applib.annotation.Mixin;
import org.apache.isis.applib.annotation.Nature;
+import org.apache.isis.applib.annotation.Property;
import org.apache.isis.metamodel.adapter.ObjectAdapter;
import org.apache.isis.metamodel.facets.SingleValueFacet;
+import org.apache.isis.metamodel.spec.ManagedObject;
import org.apache.isis.metamodel.spec.ObjectSpecification;
/**
- * Applies to {@link ObjectSpecification}s of classes that can act as a mix-in, namely that they are annotated
- * appropriately (eg {@link org.apache.isis.applib.annotation.Mixin} or {@link DomainObject} with
- * {@link DomainObject#nature()} of {@link Nature#MIXIN}) and which have a 1-arg constructor accepting an object
- * (being the object this is a mix-in for).
+ * Applies to {@link ObjectSpecification}s of classes that can act as a mix-in.
+ * <p>
+ * Mix-ins are annotated e.g. {@link Mixin} or {@link DomainObject} with
+ * {@link DomainObject#nature()} of {@link Nature#MIXIN}) and have a public 1-arg
+ * constructor accepting an object (the mix-in's <i>holder</i>), being the object
+ * this is a mix-in for.
+ * <p>
+ * Since 2.0 there are additional annotations, that when declared on a type, make
+ * the type recognized as a mix-in. These are {@link Action}, {@link Property} and
+ * {@link Collection}.
*/
public interface MixinFacet extends SingleValueFacet<String> {
@@ -41,14 +52,15 @@ public interface MixinFacet extends SingleValueFacet<String> {
}
/**
- * Returns the (adapter of the) domain object that a mixin adapter contains.
+ * Returns the (adapter of the) domain object that is the <i>holder</i> of the
+ * given mix-in adapter.
*/
- ObjectAdapter mixedIn(ObjectAdapter mixinAdapter, final Policy policy);
+ ObjectAdapter mixedIn(ManagedObject mixinAdapter, Policy policy);
/**
- * Returns the mixin around the provided domain object
+ * Returns the mix-in around the provided domain object (<i>holder</i>)
*/
- Object instantiate(Object domainPojo);
+ Object instantiate(Object holderPojo);
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetAbstract.java
index 09d3baa..d3bfb11 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetAbstract.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetAbstract.java
@@ -19,8 +19,9 @@
package org.apache.isis.metamodel.facets.object.mixin;
+import static org.apache.isis.commons.internal.base._With.tryOrDefault;
+
import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
@@ -28,11 +29,16 @@ import org.apache.isis.metamodel.adapter.ObjectAdapter;
import org.apache.isis.metamodel.facetapi.Facet;
import org.apache.isis.metamodel.facetapi.FacetHolder;
import org.apache.isis.metamodel.facets.SingleValueFacetAbstract;
+import org.apache.isis.metamodel.spec.ManagedObject;
+
+import lombok.val;
-public abstract class MixinFacetAbstract extends SingleValueFacetAbstract<String> implements MixinFacet {
+public abstract class MixinFacetAbstract
+extends SingleValueFacetAbstract<String> implements MixinFacet {
private final Class<?> mixinType;
private final Class<?> constructorType;
+ private final Constructor<?> constructor;
public static Class<? extends Facet> type() {
return MixinFacet.class;
@@ -47,6 +53,7 @@ public abstract class MixinFacetAbstract extends SingleValueFacetAbstract<String
super(type(), value, holder);
this.mixinType = mixinType;
this.constructorType = constructorType;
+ this.constructor = tryOrDefault(()->mixinType.getConstructor(constructorType), null);
}
@Override
@@ -59,21 +66,20 @@ public abstract class MixinFacetAbstract extends SingleValueFacetAbstract<String
@Override
public Object instantiate(final Object domainPojo) {
+ if(constructor == null) {
+ return null; // invalid mix-in declaration; ought we to fail-fast?
+ }
if(domainPojo == null) {
return null;
}
- if(!constructorType.isAssignableFrom(domainPojo.getClass())) {
+ if(!isMixinFor(domainPojo.getClass())) {
// shouldn't happen; ought we to fail-fast instead?
return null;
}
try {
- final Constructor<?> constructor = mixinType.getConstructor(constructorType);
- final Object mixinPojo = constructor.newInstance(domainPojo);
+ val mixinPojo = constructor.newInstance(domainPojo);
getServiceInjector().injectServicesInto(mixinPojo);
return mixinPojo;
- } catch (NoSuchMethodException e) {
- // shouldn't happen; ought we to fail-fast instead?
- return null;
} catch (InvocationTargetException e) {
// shouldn't happen; ought we to fail-fast instead?
return null;
@@ -87,21 +93,35 @@ public abstract class MixinFacetAbstract extends SingleValueFacetAbstract<String
}
@Override
- public ObjectAdapter mixedIn(ObjectAdapter mixinAdapter, final Policy policy) {
-
- final Object mixin = mixinAdapter.getPojo();
+ public ObjectAdapter mixedIn(ManagedObject mixinAdapter, Policy policy) {
+ val mixinPojo = mixinAdapter.getPojo();
+ val holderPojo = holderPojoFor(mixinPojo, policy);
+ return holderPojo!=null
+ ? getObjectAdapterProvider().adapterFor(holderPojo)
+ : null;
+ }
- final Field[] declaredFields = mixinType.getDeclaredFields();
- for (final Field declaredField : declaredFields) {
- if(declaredField.getType().isAssignableFrom(constructorType)) {
- declaredField.setAccessible(true);
+ @Override
+ public void appendAttributesTo(final Map<String, Object> attributeMap) {
+ super.appendAttributesTo(attributeMap);
+ attributeMap.put("mixinType", mixinType);
+ attributeMap.put("constructorType", constructorType);
+ }
+
+ // -- HELPER
+
+ private Object holderPojoFor(Object mixinPojo, Policy policy) {
+ val mixinFields = mixinType.getDeclaredFields();
+ for (val mixinField : mixinFields) {
+ if(mixinField.getType().isAssignableFrom(constructorType)) {
+ mixinField.setAccessible(true);
try {
- Object o = declaredField.get(mixin);
- return getObjectAdapterProvider().adapterFor(o);
+ val holderPojo = mixinField.get(mixinPojo);
+ return holderPojo;
} catch (IllegalAccessException e) {
if(policy == Policy.FAIL_FAST) {
throw new RuntimeException(
- "Unable to access " + declaredField + " for " + getTitleService().titleOf(mixin));
+ "Unable to access " + mixinField + " for " + getTitleService().titleOf(mixinPojo));
}
// otherwise continue to next possible field.
}
@@ -109,16 +129,10 @@ public abstract class MixinFacetAbstract extends SingleValueFacetAbstract<String
}
if(policy == Policy.FAIL_FAST) {
throw new RuntimeException(
- "Could not find the \"mixed-in\" domain object within " + getTitleService().titleOf(mixin)
+ "Could not find the \"mixed-in\" domain object within " + getTitleService().titleOf(mixinPojo)
+ " (tried to guess by looking at all private fields and matching one against the constructor parameter)");
}
// else just...
return null;
}
-
- @Override public void appendAttributesTo(final Map<String, Object> attributeMap) {
- super.appendAttributesTo(attributeMap);
- attributeMap.put("mixinType", mixinType);
- attributeMap.put("constructorType", constructorType);
- }
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetForDomainObjectAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetForDomainObjectAnnotation.java
index f9e83fb..331b653 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetForDomainObjectAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetForDomainObjectAnnotation.java
@@ -19,7 +19,6 @@
package org.apache.isis.metamodel.facets.object.mixin;
-import java.lang.reflect.Constructor;
import java.util.Optional;
import org.apache.isis.applib.annotation.DomainObject;
@@ -28,6 +27,8 @@ import org.apache.isis.applib.services.inject.ServiceInjector;
import org.apache.isis.metamodel.facetapi.Facet;
import org.apache.isis.metamodel.facetapi.FacetHolder;
+import lombok.val;
+
public class MixinFacetForDomainObjectAnnotation extends MixinFacetAbstract {
public static Class<? extends Facet> type() {
@@ -52,16 +53,18 @@ public class MixinFacetForDomainObjectAnnotation extends MixinFacetAbstract {
return domainObjectIfAny
.filter(domainObject -> domainObject.nature() == Nature.MIXIN)
.map(domainObject -> {
- final Constructor<?>[] constructors = candidateMixinType.getConstructors();
- for (Constructor<?> constructor : constructors) {
- final Class<?>[] constructorTypes = constructor.getParameterTypes();
- if(constructorTypes.length != 1) {
+ val constructors = candidateMixinType.getConstructors();
+ for (val constructor : constructors) {
+ if(constructor.getParameterCount() != 1) {
continue;
}
- final Class<?> constructorType = constructorTypes[0];
+ val constructorTypes = constructor.getParameterTypes();
+ val constructorType = constructorTypes[0];
return new MixinFacetForDomainObjectAnnotation(
- candidateMixinType, domainObject.mixinMethod(), constructorType, facetHolder
- );
+ candidateMixinType,
+ domainObject.mixinMethod(),
+ constructorType,
+ facetHolder);
}
// else
return null;
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetForMixinAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetForMixinAnnotation.java
index 0f6682b..c12ae82 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetForMixinAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetForMixinAnnotation.java
@@ -42,8 +42,10 @@ public class MixinFacetForMixinAnnotation extends MixinFacetAbstract {
}
public static MixinFacet create(
- final Class<?> candidateMixinType, final FacetHolder facetHolder,
+ final Class<?> candidateMixinType,
+ final FacetHolder facetHolder,
final ServiceInjector servicesInjector) {
+
final Mixin mixin = candidateMixinType.getAnnotation(Mixin.class);
if(mixin == null) {
return null;
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetForMixinAnnotationFactory.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetForMixinAnnotationFactory.java
index 43cf6c3..d0671c4 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetForMixinAnnotationFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/mixin/MixinFacetForMixinAnnotationFactory.java
@@ -20,15 +20,18 @@
package org.apache.isis.metamodel.facets.object.mixin;
import org.apache.isis.applib.annotation.Mixin;
-import org.apache.isis.metamodel.facetapi.FacetHolder;
import org.apache.isis.metamodel.facetapi.FeatureType;
import org.apache.isis.metamodel.facetapi.MetaModelValidatorRefiner;
import org.apache.isis.metamodel.facets.FacetFactoryAbstract;
import org.apache.isis.metamodel.specloader.validator.MetaModelValidatorComposite;
-public class MixinFacetForMixinAnnotationFactory extends FacetFactoryAbstract implements MetaModelValidatorRefiner {
+import lombok.val;
- private final MetaModelValidatorForMixinTypes mixinTypeValidator = new MetaModelValidatorForMixinTypes("@Mixin");
+public class MixinFacetForMixinAnnotationFactory
+extends FacetFactoryAbstract implements MetaModelValidatorRefiner {
+
+ private final MetaModelValidatorForMixinTypes mixinTypeValidator =
+ new MetaModelValidatorForMixinTypes("@Mixin");
public MixinFacetForMixinAnnotationFactory() {
super(FeatureType.OBJECTS_ONLY);
@@ -37,20 +40,19 @@ public class MixinFacetForMixinAnnotationFactory extends FacetFactoryAbstract im
@Override
public void process(final ProcessClassContext processClassContext) {
- final Class<?> candidateMixinType = processClassContext.getCls();
-
- final Mixin mixinAnnotation = candidateMixinType.getAnnotation(Mixin.class);
- if(mixinAnnotation == null) {
+ val mixinIfAny = processClassContext.synthesizeOnType(Mixin.class);
+ if(!mixinIfAny.isPresent()) {
return;
}
+ val candidateMixinType = processClassContext.getCls();
if (!mixinTypeValidator.ensureMixinType(candidateMixinType)) {
return;
}
- final FacetHolder facetHolder = processClassContext.getFacetHolder();
-
- final MixinFacet mixinFacet = MixinFacetForMixinAnnotation.create(candidateMixinType, facetHolder,
- getServiceInjector());
+ val facetHolder = processClassContext.getFacetHolder();
+
+ val mixinFacet = MixinFacetForMixinAnnotation
+ .create(candidateMixinType, facetHolder, getServiceInjector());
facetHolder.addFacet(mixinFacet);
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/navparent/method/NavigableParentFacetMethodFactory.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/navparent/method/NavigableParentFacetMethodFactory.java
deleted file mode 100644
index 8dd7f52..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/object/navparent/method/NavigableParentFacetMethodFactory.java
+++ /dev/null
@@ -1,66 +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.isis.metamodel.facets.object.navparent.method;
-
-import java.lang.reflect.Method;
-
-import org.apache.isis.metamodel.facetapi.FacetHolder;
-import org.apache.isis.metamodel.facetapi.FacetUtil;
-import org.apache.isis.metamodel.facetapi.FeatureType;
-import org.apache.isis.metamodel.facets.MethodFinderUtils;
-import org.apache.isis.metamodel.facets.MethodPrefixBasedFacetFactoryAbstract;
-import org.apache.isis.metamodel.methodutils.MethodScope;
-
-/**
- *
- * @since 2.0
- *
- * @deprecated according to proposed spec, <a href="https://issues.apache.org/jira/browse/ISIS-1816">ISIS-1816</a>
- * let's not introduce new 'keywords'.
- */
-@Deprecated
-public class NavigableParentFacetMethodFactory extends MethodPrefixBasedFacetFactoryAbstract {
-
- private static final String NAVIGABLE_PARENT_PREFIX = "parent";
-
- private static final String[] PREFIXES = { NAVIGABLE_PARENT_PREFIX, };
-
- public NavigableParentFacetMethodFactory() {
- super(FeatureType.OBJECTS_ONLY, OrphanValidation.VALIDATE, PREFIXES);
- }
-
- @Override
- public void process(final ProcessClassContext processClassContext) {
- final Class<?> cls = processClassContext.getCls();
- final FacetHolder facetHolder = processClassContext.getFacetHolder();
-
- final Method method =
- MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, NAVIGABLE_PARENT_PREFIX, Object.class, NO_PARAMETERS_TYPES);
- if (method == null) {
- return;
- }
- processClassContext.removeMethod(method);
- try {
- FacetUtil.addFacet(new NavigableParentFacetMethod(method, facetHolder));
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
-}
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/postprocessors/param/ActionParameterChoicesFacetFromParentedCollection.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/postprocessors/param/ActionParameterChoicesFacetFromParentedCollection.java
index 9d74f31..2ac21d8 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/postprocessors/param/ActionParameterChoicesFacetFromParentedCollection.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/postprocessors/param/ActionParameterChoicesFacetFromParentedCollection.java
@@ -30,6 +30,8 @@ import org.apache.isis.metamodel.facets.object.mixin.MixinFacet;
import org.apache.isis.metamodel.facets.param.choices.ActionParameterChoicesFacetAbstract;
import org.apache.isis.metamodel.spec.feature.OneToManyAssociation;
+import lombok.val;
+
public class ActionParameterChoicesFacetFromParentedCollection extends ActionParameterChoicesFacetAbstract {
private final OneToManyAssociation otma;
@@ -54,10 +56,11 @@ public class ActionParameterChoicesFacetFromParentedCollection extends ActionPar
}
/**
- * in the case of a mixin action, the target passed to the facet is actually the mixin itself, not the mixee.
+ * in the case of a mixin action, the target passed to the facet is actually the mixin itself,
+ * not the mixee.
*/
private ObjectAdapter determineParentAdapter(final ObjectAdapter target) {
- final MixinFacet mixinFacet = target.getSpecification().getFacet(MixinFacet.class);
+ val mixinFacet = target.getSpecification().getFacet(MixinFacet.class);
ObjectAdapter mixedInTarget = null;
if(mixinFacet != null) {
mixedInTarget = mixinFacet.mixedIn(target, MixinFacet.Policy.FAIL_FAST);
@@ -65,7 +68,8 @@ public class ActionParameterChoicesFacetFromParentedCollection extends ActionPar
return mixedInTarget != null ? mixedInTarget : target;
}
- @Override public void appendAttributesTo(final Map<String, Object> attributeMap) {
+ @Override
+ public void appendAttributesTo(final Map<String, Object> attributeMap) {
super.appendAttributesTo(attributeMap);
attributeMap.put("oneToManyAssociation", otma);
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/specloader/specimpl/ObjectActionMixedIn.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/specloader/specimpl/ObjectActionMixedIn.java
index def43a6..5123df8 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/specloader/specimpl/ObjectActionMixedIn.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/specloader/specimpl/ObjectActionMixedIn.java
@@ -148,7 +148,7 @@ public class ObjectActionMixedIn extends ObjectActionDefault implements MixedInM
(ObjectActionParameterAbstract) mixinActionParameters.get(paramNum);
final TypedHolder paramPeer = paramPeers.get(paramNum);
- final ObjectSpecification specification = getSpecificationLoader().loadSpecification(paramPeer.getType());
+ getSpecificationLoader().loadSpecification(paramPeer.getType());
final ObjectActionParameterMixedIn mixedInParameter =
mixinParameter.getPeer().getFeatureType() == FeatureType.ACTION_PARAMETER_SCALAR
diff --git a/core/metamodel/src/test/java/org/apache/isis/metamodel/facets/AbstractFacetFactoryJUnit4TestCase.java b/core/metamodel/src/test/java/org/apache/isis/metamodel/facets/AbstractFacetFactoryJUnit4TestCase.java
index e9bbd5b..9ef2513 100644
--- a/core/metamodel/src/test/java/org/apache/isis/metamodel/facets/AbstractFacetFactoryJUnit4TestCase.java
+++ b/core/metamodel/src/test/java/org/apache/isis/metamodel/facets/AbstractFacetFactoryJUnit4TestCase.java
@@ -130,8 +130,7 @@ public abstract class AbstractFacetFactoryJUnit4TestCase {
facetHolder = new AbstractFacetFactoryTest.IdentifiedHolderImpl(Identifier.propertyOrCollectionIdentifier(Customer.class, "firstName"));
facetedMethod = FacetedMethod.createForProperty(AbstractFacetFactoryTest.Customer.class, "firstName");
- facetedMethodParameter = new FacetedMethodParameter(FeatureType.ACTION_PARAMETER_SCALAR, facetedMethod.getOwningType(), facetedMethod.getMethod(), String.class
- );
+ facetedMethodParameter = new FacetedMethodParameter(FeatureType.ACTION_PARAMETER_SCALAR, facetedMethod.getOwningType(), facetedMethod.getMethod(), String.class);
}
@After
diff --git a/core/metamodel/src/test/java/org/apache/isis/metamodel/facets/object/navparent/NavigableParentFacetMethodFactoryTest.java b/core/metamodel/src/test/java/org/apache/isis/metamodel/facets/object/navparent/NavigableParentFacetMethodFactoryTest.java
deleted file mode 100644
index 585a3c4..0000000
--- a/core/metamodel/src/test/java/org/apache/isis/metamodel/facets/object/navparent/NavigableParentFacetMethodFactoryTest.java
+++ /dev/null
@@ -1,70 +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.isis.metamodel.facets.object.navparent;
-
-import java.lang.reflect.Method;
-
-import org.apache.isis.metamodel.facetapi.Facet;
-import org.apache.isis.metamodel.facets.AbstractFacetFactoryTest;
-import org.apache.isis.metamodel.facets.FacetFactory.ProcessClassContext;
-import org.apache.isis.metamodel.facets.object.navparent.method.NavigableParentFacetMethod;
-import org.apache.isis.metamodel.facets.object.navparent.method.NavigableParentFacetMethodFactory;
-
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.Assert.assertThat;
-
-public class NavigableParentFacetMethodFactoryTest extends AbstractFacetFactoryTest {
-
- private NavigableParentFacetMethodFactory facetFactory;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- facetFactory = new NavigableParentFacetMethodFactory();
- }
-
- @Override
- protected void tearDown() throws Exception {
- facetFactory = null;
- super.tearDown();
- }
-
- public void testNavigableParentMethodPickedUpOnClassAndMethodRemoved() {
- class Customer {
- @SuppressWarnings("unused")
- public Object parent() {
- return null;
- }
- }
- final Method navigableParentMethod = findMethod(Customer.class, "parent");
-
- facetFactory.process(new ProcessClassContext(Customer.class, methodRemover, facetedMethod));
-
- final Facet facet = facetedMethod.getFacet(NavigableParentFacet.class);
- assertThat(facet, is(notNullValue()));
- assertThat(facet, is(instanceOf(NavigableParentFacetMethod.class)));
-
- assertTrue(methodRemover.getRemovedMethodMethodCalls().contains(navigableParentMethod));
- }
-
-}
diff --git a/core/plugins/jdo/datanucleus-5/src/test/java/org/apache/isis/runtime/persistence/adapterfactory/pojo/PojoAdapterTest.java b/core/plugins/jdo/datanucleus-5/src/test/java/org/apache/isis/runtime/persistence/adapterfactory/pojo/PojoAdapterTest.java
index a93f3a2..78302ac 100644
--- a/core/plugins/jdo/datanucleus-5/src/test/java/org/apache/isis/runtime/persistence/adapterfactory/pojo/PojoAdapterTest.java
+++ b/core/plugins/jdo/datanucleus-5/src/test/java/org/apache/isis/runtime/persistence/adapterfactory/pojo/PojoAdapterTest.java
@@ -67,7 +67,6 @@ public class PojoAdapterTest {
adapter = PojoAdapter.of(
domainObject,
Factory.persistentOf(ObjectSpecId.of("CUS"), "1"),
- mockAuthenticationSession,
mockSpecificationLoader,
mockPersistenceSession);
diff --git a/core/plugins/jdo/datanucleus-5/src/test/java/org/apache/isis/runtime/persistence/objectstore/transaction/PojoAdapterBuilder.java b/core/plugins/jdo/datanucleus-5/src/test/java/org/apache/isis/runtime/persistence/objectstore/transaction/PojoAdapterBuilder.java
index 11b1b5e..9cdd687 100644
--- a/core/plugins/jdo/datanucleus-5/src/test/java/org/apache/isis/runtime/persistence/objectstore/transaction/PojoAdapterBuilder.java
+++ b/core/plugins/jdo/datanucleus-5/src/test/java/org/apache/isis/runtime/persistence/objectstore/transaction/PojoAdapterBuilder.java
@@ -192,7 +192,7 @@ public class PojoAdapterBuilder {
public PojoAdapter build() {
final RootOid rootOid = persistence.createOid(objectSpecId, identifier);
final Oid oid = type.oidFor(rootOid, objectSpecId, aggregatedId);
- final PojoAdapter pojoAdapter = PojoAdapter.of(pojo, oid, authenticationSession,
+ final PojoAdapter pojoAdapter = PojoAdapter.of(pojo, oid,
specificationLoader, persistenceSession);
if(persistence == Persistence.PERSISTENT && version != null) {
pojoAdapter.setVersion(version);
diff --git a/core/plugins/jdo/datanucleus-5/src/test/java/org/apache/isis/runtime/system/ObjectMemberAbstractTest.java b/core/plugins/jdo/datanucleus-5/src/test/java/org/apache/isis/runtime/system/ObjectMemberAbstractTest.java
index d6105b0..79c0ca7 100644
--- a/core/plugins/jdo/datanucleus-5/src/test/java/org/apache/isis/runtime/system/ObjectMemberAbstractTest.java
+++ b/core/plugins/jdo/datanucleus-5/src/test/java/org/apache/isis/runtime/system/ObjectMemberAbstractTest.java
@@ -19,6 +19,15 @@
package org.apache.isis.runtime.system;
+import static org.hamcrest.Matchers.emptyString;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
import org.datanucleus.enhancement.Persistable;
import org.jmock.Expectations;
import org.jmock.auto.Mock;
@@ -60,15 +69,6 @@ import org.apache.isis.security.authentication.AuthenticationSessionProvider;
import org.apache.isis.unittestsupport.jmocking.JUnitRuleMockery2;
import org.apache.isis.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.isEmptyString;
-import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
public class ObjectMemberAbstractTest {
@Rule
@@ -112,7 +112,6 @@ public class ObjectMemberAbstractTest {
persistentAdapter = PojoAdapter.of(
mockPersistable,
Factory.persistentOf(ObjectSpecId.of("CUS"), "1"),
- mockAuthenticationSession,
mockSpecificationLoader,
null);
@@ -146,7 +145,7 @@ public class ObjectMemberAbstractTest {
@Test
public void testToString() throws Exception {
testMember.addFacet(new NamedFacetAbstract("", true, testMember) {});
- assertThat(testMember.toString(), not(isEmptyString()));
+ assertThat(testMember.toString(), not(is(emptyString())));
}
@Test
diff --git a/core/runtime/src/main/java/org/apache/isis/runtime/persistence/adapter/PojoAdapter.java b/core/runtime/src/main/java/org/apache/isis/runtime/persistence/adapter/PojoAdapter.java
index 1f5f26a..1d81b66 100644
--- a/core/runtime/src/main/java/org/apache/isis/runtime/persistence/adapter/PojoAdapter.java
+++ b/core/runtime/src/main/java/org/apache/isis/runtime/persistence/adapter/PojoAdapter.java
@@ -19,6 +19,8 @@
package org.apache.isis.runtime.persistence.adapter;
+import static org.apache.isis.commons.internal.base._With.requires;
+
import java.io.Serializable;
import java.util.Objects;
import java.util.UUID;
@@ -36,17 +38,11 @@ import org.apache.isis.metamodel.spec.ObjectSpecification;
import org.apache.isis.metamodel.specloader.SpecificationLoader;
import org.apache.isis.runtime.system.persistence.PersistenceSession;
import org.apache.isis.runtime.system.session.IsisSession;
-import org.apache.isis.security.authentication.AuthenticationSession;
-
-import static org.apache.isis.commons.internal.base._With.requires;
import lombok.val;
-import lombok.extern.log4j.Log4j2;
-@Log4j2
public final class PojoAdapter implements ObjectAdapter {
- private final AuthenticationSession authenticationSession;
private final SpecificationLoader specificationLoader;
private final PersistenceSession persistenceSession;
@@ -78,32 +74,28 @@ public final class PojoAdapter implements ObjectAdapter {
final IsisSession isisSession,
final PersistenceSession persistenceSession) {
- val authenticationSession = isisSession.getAuthenticationSession();
val specificationLoader = isisSession.getSpecificationLoader();
- return new PojoAdapter(pojo, oid, authenticationSession, specificationLoader, persistenceSession);
+ return new PojoAdapter(pojo, oid, specificationLoader, persistenceSession);
}
public static PojoAdapter of(
final Object pojo,
final Oid oid,
- final AuthenticationSession authenticationSession,
final SpecificationLoader specificationLoader,
final PersistenceSession persistenceSession) {
- return new PojoAdapter(pojo, oid, authenticationSession, specificationLoader, persistenceSession);
+ return new PojoAdapter(pojo, oid, specificationLoader, persistenceSession);
}
private PojoAdapter(
final Object pojo,
final Oid oid,
- final AuthenticationSession authenticationSession,
final SpecificationLoader specificationLoader,
final PersistenceSession persistenceSession) {
Objects.requireNonNull(pojo);
this.specificationLoader = specificationLoader;
- this.authenticationSession = authenticationSession;
this.persistenceSession = persistenceSession;
if (pojo instanceof ObjectAdapter) {
diff --git a/examples/smoketests/src/main/java/org/apache/isis/testdomain/model/good/ProperActionSupport_action.java b/examples/smoketests/src/main/java/org/apache/isis/testdomain/model/good/ProperActionSupport_action.java
new file mode 100644
index 0000000..42a66b4
--- /dev/null
+++ b/examples/smoketests/src/main/java/org/apache/isis/testdomain/model/good/ProperActionSupport_action.java
@@ -0,0 +1,44 @@
+/*
+ * 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.isis.testdomain.model.good;
+
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.Model;
+
+import lombok.RequiredArgsConstructor;
+
+@Action @RequiredArgsConstructor
+public class ProperActionSupport_action {
+
+ private final ProperActionSupport holder;
+
+ // proper mix-in action
+ @Action
+ public ProperActionSupport $$() {
+ return holder;
+ }
+
+ // proper support
+ @Model
+ public boolean hide$$() {
+ return false;
+ }
+
+
+}
diff --git a/examples/smoketests/src/main/java/org/apache/isis/testdomain/model/good/ProperActionSupport_mixin.java b/examples/smoketests/src/main/java/org/apache/isis/testdomain/model/good/ProperActionSupport_mixin.java
new file mode 100644
index 0000000..8ef9564
--- /dev/null
+++ b/examples/smoketests/src/main/java/org/apache/isis/testdomain/model/good/ProperActionSupport_mixin.java
@@ -0,0 +1,45 @@
+/*
+ * 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.isis.testdomain.model.good;
+
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.Mixin;
+import org.apache.isis.applib.annotation.Model;
+
+import lombok.RequiredArgsConstructor;
+
+@Mixin @RequiredArgsConstructor
+public class ProperActionSupport_mixin {
+
+ private final ProperActionSupport holder;
+
+ // proper mix-in action
+ @Action
+ public ProperActionSupport $$() {
+ return holder;
+ }
+
+ // proper support
+ @Model
+ public boolean hide$$() {
+ return false;
+ }
+
+
+}
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingGoodDomain.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingGoodDomain.java
index 7370815..01050c2 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingGoodDomain.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/domainmodel/DomainModelTest_usingGoodDomain.java
@@ -18,15 +18,20 @@
*/
package org.apache.isis.testdomain.domainmodel;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.apache.isis.config.IsisPresets;
import org.apache.isis.integtestsupport.validate.ValidateDomainModel;
+import org.apache.isis.metamodel.MetaModelContext;
+import org.apache.isis.metamodel.specloader.specimpl.IntrospectionState;
import org.apache.isis.testdomain.Smoketest;
import org.apache.isis.testdomain.conf.Configuration_headless;
import org.apache.isis.testdomain.model.good.Configuration_usingValidDomain;
+import org.apache.isis.testdomain.model.good.ProperActionSupport;
import lombok.val;
@@ -75,6 +80,11 @@ class DomainModelTest_usingGoodDomain {
val validateDomainModel = new ValidateDomainModel();
validateDomainModel.run(); // should not throw
+ // check whether mix-ins are picked up as they should
+ val specLoader = MetaModelContext.current().getSpecificationLoader();
+ val holderSpec = specLoader.loadSpecification(ProperActionSupport.class, IntrospectionState.TYPE_AND_MEMBERS_INTROSPECTED);
+ val oa = holderSpec.getObjectAction("mixin"); // proper mix-in support
+ assertNotNull(oa);
}