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 2022/09/04 04:01:51 UTC
[isis] branch master updated: ISIS-3202: unrelated: adds ProperMixinAsReturnType as a design draft
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 251a05c3df ISIS-3202: unrelated: adds ProperMixinAsReturnType as a design draft
251a05c3df is described below
commit 251a05c3dfc06cc630e977367b82bfbff180025e
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sun Sep 4 06:01:44 2022 +0200
ISIS-3202: unrelated: adds ProperMixinAsReturnType as a design draft
---
.../java/org/apache/isis/applib/value/Clob.java | 9 ++
.../domainmodel/MetaModelRegressionTest.java | 5 +-
.../model/good/ProperMixinAsReturnType.java | 104 +++++++++++++++++++++
3 files changed, 114 insertions(+), 4 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/isis/applib/value/Clob.java b/api/applib/src/main/java/org/apache/isis/applib/value/Clob.java
index 78642986b1..9b28921213 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/value/Clob.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/value/Clob.java
@@ -19,6 +19,7 @@
package org.apache.isis.applib.value;
import java.io.IOException;
+import java.io.StringWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@@ -36,6 +37,7 @@ import org.apache.isis.applib.jaxb.PrimitiveJaxbAdapters;
import org.apache.isis.commons.internal.base._Strings;
import lombok.NonNull;
+import lombok.SneakyThrows;
import lombok.val;
/**
@@ -171,6 +173,13 @@ public final class Clob implements NamedWithMimeType {
}
}
+ @SneakyThrows
+ public String asString() {
+ val sw = new StringWriter();
+ writeCharsTo(sw);
+ return sw.toString();
+ }
+
// -- OBJECT CONTRACT
@Override
diff --git a/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/MetaModelRegressionTest.java b/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/MetaModelRegressionTest.java
index 388e18b56d..745f5e9482 100644
--- a/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/MetaModelRegressionTest.java
+++ b/regressiontests/stable-domainmodel/src/test/java/org/apache/isis/testdomain/domainmodel/MetaModelRegressionTest.java
@@ -19,7 +19,6 @@
package org.apache.isis.testdomain.domainmodel;
import java.io.IOException;
-import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.util.List;
@@ -92,9 +91,7 @@ class MetaModelRegressionTest {
private static String asXml(final Blob zip) throws IOException {
val clob = zip.unZip(CommonMimeType.XML).toClob(StandardCharsets.UTF_8);
- val sw = new StringWriter();
- clob.writeCharsTo(sw);
- return sw.toString();
+ return clob.asString();
}
private Options options() {
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/good/ProperMixinAsReturnType.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/good/ProperMixinAsReturnType.java
new file mode 100644
index 0000000000..90dc4f7eb2
--- /dev/null
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/good/ProperMixinAsReturnType.java
@@ -0,0 +1,104 @@
+/*
+ * 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 java.time.LocalDate;
+import java.util.Random;
+
+import javax.inject.Inject;
+
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.Domain;
+import org.apache.isis.applib.annotation.DomainObject;
+import org.apache.isis.applib.annotation.MemberSupport;
+import org.apache.isis.applib.annotation.Nature;
+import org.apache.isis.applib.annotation.Parameter;
+import org.apache.isis.applib.annotation.Property;
+import org.apache.isis.applib.services.factory.FactoryService;
+import org.apache.isis.testdomain.model.interaction.InteractionDemoItem;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * A draft:
+ * <p>
+ * Without any addition to existing programming model annotations, I could think
+ * of adding a new feature, that is to allow for actions to return mixin
+ * instances. In this example you see an action updateDemoItemGeneric that
+ * randomly chooses between 2 different mixed in actions, which to return: its
+ * either updateDemoItemName or updateDemoItemDate both mixins implementing the
+ * 'I am a mixin' marker interface DemoItemUpdateMixin. The meta-model figures
+ * out on type inspection (compile time types that is) which types are mixin
+ * types. Hence the marker interface.
+ * <p>
+ * instead of having to define a marker interface yourself, the framework could
+ * just provide one out of the box for this use-case. Something along those
+ * lines: interface MixinAsReturnType {} with special semantics, that is, those
+ * stay hidden in the UI and are only considered as action return types.
+ *
+ * @see "https://the-asf.slack.com/archives/CFC42LWBV/p1662261916803059?thread_ts=1661485836.027909&cid=CFC42LWBV"
+ */
+@Domain.Exclude// just a draft
+//@Named("testdomain.ProperMixinAsReturnType")
+//@DomainObject(nature = Nature.VIEW_MODEL)
+public class ProperMixinAsReturnType {
+
+ @Inject
+ FactoryService factoryService;
+
+ @Property
+ @Getter
+ @Setter
+ private InteractionDemoItem demoItem;
+
+ @Action
+ public MixinAsReturnType updateDemoItemGeneric() {
+ return new Random().nextBoolean()
+ ? factoryService.mixin(ProperMixinAsReturnType.updateDemoItemName.class, this)
+ : factoryService.mixin(ProperMixinAsReturnType.updateDemoItemDate.class, this);
+ }
+
+ // -- MIXINS
+
+ @DomainObject(nature = Nature.MIXIN)
+ interface MixinAsReturnType {
+ }
+
+ @Action
+ public class updateDemoItemName implements MixinAsReturnType {
+
+ @MemberSupport
+ public ProperMixinAsReturnType act(@Parameter final String newName) {
+ demoItem.setName(newName);
+ return ProperMixinAsReturnType.this;
+ }
+ }
+
+ @Action
+ public class updateDemoItemDate implements MixinAsReturnType {
+
+ @MemberSupport
+ public ProperMixinAsReturnType act(@Parameter final LocalDate newDate) {
+ demoItem.setDate(newDate);
+ return ProperMixinAsReturnType.this;
+ }
+ }
+
+}