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

danhaywood 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 39d04f5  ISIS-2025: adds wrapTry for WrapperFactory
39d04f5 is described below

commit 39d04f51a90d07f6d34b791dfcf039e6f86f2b13
Author: danhaywood <d...@haywood-associates.co.uk>
AuthorDate: Sat Oct 27 13:59:23 2018 +0100

    ISIS-2025: adds wrapTry for WrapperFactory
---
 .../applib/services/wrapper/WrapperFactory.java    | 33 +++++++++---
 .../isis/core/wrapper/WrapperFactoryDefault.java   |  5 ++
 .../handlers/DomainObjectInvocationHandler.java    | 63 +++++++++++++++++++---
 3 files changed, 88 insertions(+), 13 deletions(-)

diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/services/wrapper/WrapperFactory.java
 
b/core/applib/src/main/java/org/apache/isis/applib/services/wrapper/WrapperFactory.java
index b153931..2bd8a21 100644
--- 
a/core/applib/src/main/java/org/apache/isis/applib/services/wrapper/WrapperFactory.java
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/services/wrapper/WrapperFactory.java
@@ -77,22 +77,28 @@ public interface WrapperFactory {
         /**
          * Validate all business rules and then execute.
          */
-        EXECUTE(true,true), 
+        EXECUTE(true,true,true),
+        /**
+         * Validate all business rules and then execute, but don't throw 
exception if fails.
+         */
+        TRY(true,true,false),
         /**
          * Skip all business rules and then execute.
          */
-        SKIP_RULES(false, true), 
+        SKIP_RULES(false, true, false),
         /**
          * Validate all business rules but do not execute.
          */
-        NO_EXECUTE(true, false);
+        NO_EXECUTE(true, false, true);
         
         private final boolean enforceRules;
         private final boolean execute;
+        private final boolean failFast;
 
-        private ExecutionMode(final boolean enforceRules, final boolean 
execute) {
+        private ExecutionMode(final boolean enforceRules, final boolean 
execute, final boolean failFast) {
             this.enforceRules = enforceRules;
             this.execute = execute;
+            this.failFast = failFast;
         }
 
         public boolean shouldEnforceRules() {
@@ -101,6 +107,9 @@ public interface WrapperFactory {
         public boolean shouldExecute() {
             return execute;
         }
+        public boolean shouldFailFast() {
+            return failFast;
+        }
     }
 
     WrapperFactory NOOP = new WrapperFactory(){
@@ -111,11 +120,16 @@ public interface WrapperFactory {
         }
 
         @Override
-        public <T> T wrapNoExecute(T domainObject) {
+        public <T> T wrapTry(T domainObject) {
             return domainObject;
         }
         
         @Override
+        public <T> T wrapNoExecute(T domainObject) {
+            return domainObject;
+        }
+
+        @Override
         public <T> T wrapSkipRules(T domainObject) {
             return domainObject;
         }
@@ -166,12 +180,19 @@ public interface WrapperFactory {
     <T> T wrap(T domainObject);
 
     /**
+     * Convenience method for {@link #wrap(Object, ExecutionMode)} with {@link 
ExecutionMode#TRY},
+     * to make this feature more discoverable.
+     */
+    @Programmatic
+    <T> T wrapTry(T domainObject);
+    
+    /**
      * Convenience method for {@link #wrap(Object, ExecutionMode)} with {@link 
ExecutionMode#NO_EXECUTE},
      * to make this feature more discoverable.
      */
     @Programmatic
     <T> T wrapNoExecute(T domainObject);
-    
+
     /**
      * Convenience method for {@link #wrap(Object, ExecutionMode)} with {@link 
ExecutionMode#SKIP_RULES},
      * to make this feature more discoverable.
diff --git 
a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/WrapperFactoryDefault.java
 
b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/WrapperFactoryDefault.java
index 7390b5e..3d83d23 100644
--- 
a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/WrapperFactoryDefault.java
+++ 
b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/WrapperFactoryDefault.java
@@ -226,6 +226,11 @@ public class WrapperFactoryDefault implements 
WrapperFactory {
     }
 
     @Override
+    public <T> T wrapTry(final T domainObject) {
+        return wrap(domainObject, ExecutionMode.TRY);
+    }
+
+    @Override
     public <T> T wrapNoExecute(final T domainObject) {
         return wrap(domainObject, ExecutionMode.NO_EXECUTE);
     }
diff --git 
a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/handlers/DomainObjectInvocationHandler.java
 
b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/handlers/DomainObjectInvocationHandler.java
index 766fe01..c628799 100644
--- 
a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/handlers/DomainObjectInvocationHandler.java
+++ 
b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/handlers/DomainObjectInvocationHandler.java
@@ -401,7 +401,15 @@ public class DomainObjectInvocationHandler<T> extends 
DelegatingInvocationHandle
 
         if (getExecutionMode().shouldExecute()) {
             if (targetAdapter.isTransient()) {
-                getPersistenceSessionService().makePersistent(targetAdapter);
+                if(getExecutionMode().shouldFailFast()) {
+                    
getPersistenceSessionService().makePersistent(targetAdapter);
+                } else {
+                    try {
+                        
getPersistenceSessionService().makePersistent(targetAdapter);
+                    } catch(Exception ignore) {
+                        // ignore
+                    }
+                }
             }
         }
         return null;
@@ -466,7 +474,16 @@ public class DomainObjectInvocationHandler<T> extends 
DelegatingInvocationHandle
         }
 
         if (getExecutionMode().shouldExecute()) {
-            property.set(targetAdapter, argumentAdapter, 
getInteractionInitiatedBy());
+            if(getExecutionMode().shouldFailFast()) {
+                property.set(targetAdapter, argumentAdapter, 
getInteractionInitiatedBy());
+            } else {
+                try {
+                    property.set(targetAdapter, argumentAdapter, 
getInteractionInitiatedBy());
+                } catch(Exception ignore) {
+                    // ignore
+                }
+            }
+
         }
 
         return null;
@@ -567,7 +584,15 @@ public class DomainObjectInvocationHandler<T> extends 
DelegatingInvocationHandle
         }
 
         if (getExecutionMode().shouldExecute()) {
-            otma.addElement(targetAdapter, argumentNO, 
getInteractionInitiatedBy());
+            if(getExecutionMode().shouldFailFast()) {
+                otma.addElement(targetAdapter, argumentNO, 
getInteractionInitiatedBy());
+            } else {
+                try {
+                    otma.addElement(targetAdapter, argumentNO, 
getInteractionInitiatedBy());
+                } catch(Exception ignore) {
+                    // ignore
+                }
+            }
         }
 
         return null;
@@ -607,7 +632,15 @@ public class DomainObjectInvocationHandler<T> extends 
DelegatingInvocationHandle
         }
 
         if (getExecutionMode().shouldExecute()) {
-            collection.removeElement(targetAdapter, argumentAdapter, 
getInteractionInitiatedBy());
+            if(getExecutionMode().shouldFailFast()) {
+                collection.removeElement(targetAdapter, argumentAdapter, 
getInteractionInitiatedBy());
+            } else {
+                try {
+                    collection.removeElement(targetAdapter, argumentAdapter, 
getInteractionInitiatedBy());
+                } catch(Exception ignore) {
+                    // ignore
+                }
+            }
         }
 
         return null;
@@ -668,9 +701,25 @@ public class DomainObjectInvocationHandler<T> extends 
DelegatingInvocationHandle
 
             final ObjectAdapter mixedInAdapter = null; // if a mixin action, 
then it will automatically fill in.
 
-            final ObjectAdapter returnedAdapter = objectAction.execute(
-                    targetAdapter, mixedInAdapter, argAdapters,
-                    interactionInitiatedBy);
+
+            ObjectAdapter returnedAdapter;
+
+            if(getExecutionMode().shouldFailFast()) {
+                returnedAdapter = objectAction.execute(
+                        targetAdapter, mixedInAdapter, argAdapters,
+                        interactionInitiatedBy);
+            } else {
+                try {
+                    returnedAdapter = objectAction.execute(
+                            targetAdapter, mixedInAdapter, argAdapters,
+                            interactionInitiatedBy);
+                } catch(Exception ignore) {
+                    // ignore
+                    returnedAdapter = null;
+                }
+
+            }
+
 
             return ObjectAdapter.Util.unwrap(returnedAdapter);
         }

Reply via email to