You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2014/05/10 08:27:59 UTC

git commit: ISIS-550: minor refactoring of InvocationResult

Repository: isis
Updated Branches:
  refs/heads/ISIS-550 cfcb20183 -> c1a259667


ISIS-550: minor refactoring of InvocationResult

- make nested static class
- use factory methods to avoid boolean in method signature.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/c1a25966
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/c1a25966
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/c1a25966

Branch: refs/heads/ISIS-550
Commit: c1a259667282c21654435bcae22ee39f8e8bbefb
Parents: cfcb201
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Sat May 10 07:24:04 2014 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Sat May 10 07:24:04 2014 +0100

----------------------------------------------------------------------
 .../invoke/ActionInvocationFacetViaMethod.java  | 55 ++++++++++++++------
 .../PostsActionInvokedEventFacetViaMethod.java  |  4 +-
 2 files changed, 40 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/c1a25966/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/ActionInvocationFacetViaMethod.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/ActionInvocationFacetViaMethod.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/ActionInvocationFacetViaMethod.java
index c8f81d3..4f9dfbf 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/ActionInvocationFacetViaMethod.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/ActionInvocationFacetViaMethod.java
@@ -122,27 +122,48 @@ public class ActionInvocationFacetViaMethod extends ActionInvocationFacetAbstrac
     
     	// Can return null both because the action finally was not invoked 
     	// or because it returned null.
-    	return internalInvoke(owningAction, targetAdapter, arguments).getResult();
+    	return internalInvoke(owningAction, targetAdapter, arguments).getAdapter();
     	
     }
-    
-    public class InvocationResult {
-    	
-    	private final Boolean wasInvoked;
-    	private final ObjectAdapter result;
+
+    /**
+     * Introduced to disambiguate the meaning of <tt>null</tt> as a return value of
+     * {@link ActionInvocationFacetViaMethod#invoke(ObjectAdapter, ObjectAdapter[])}
+     */
+    public static class InvocationResult {
+
+        public static InvocationResult forActionThatReturned(final ObjectAdapter resultAdapter) {
+            return new InvocationResult(true, resultAdapter);
+        }
+
+        public static InvocationResult forActionNotInvoked() {
+            return new InvocationResult(false, null);
+        }
+
+    	private final boolean whetherInvoked;
+    	private final ObjectAdapter adapter;
     	
-    	public InvocationResult(Boolean invoked, ObjectAdapter result) {
-    		this.wasInvoked = invoked;
-    		this.result = result;
+    	private InvocationResult(final boolean whetherInvoked, final ObjectAdapter result) {
+    		this.whetherInvoked = whetherInvoked;
+    		this.adapter = result;
     	}
 
-		public Boolean getWasInvoked() {
-			return wasInvoked;
+		public boolean getWhetherInvoked() {
+			return whetherInvoked;
 		}
 
-		public ObjectAdapter getResult() {
-			return result;
+		/**
+		 * Returns the result, or null if either the action invocation returned null or 
+		 * if the action was never invoked in the first place.
+		 * 
+		 * <p>
+		 * Use {@link #getWhetherInvoked()} to distinguish between these two cases.
+		 */
+		public ObjectAdapter getAdapter() {
+			return adapter;
 		}
+
+
     	
     }
     
@@ -226,7 +247,7 @@ public class ActionInvocationFacetViaMethod extends ActionInvocationFacetAbstrac
                 if(commandService.persistIfPossible(command)) {
                     // force persistence, then return the command itself.
                     final ObjectAdapter resultAdapter = getAdapterManager().adapterFor(command);
-                    return new InvocationResult(true, resultAdapter);
+                    return InvocationResult.forActionThatReturned(resultAdapter);
                 } else {
                     throw new IsisException(
                             "Unable to schedule action '"
@@ -247,7 +268,7 @@ public class ActionInvocationFacetViaMethod extends ActionInvocationFacetAbstrac
                     LOG.debug(" action result " + result);
                 }
                 if (result == null) {
-                	return new InvocationResult(true, null);
+                	return InvocationResult.forActionThatReturned(null);
                 }
 
                 final ObjectAdapter resultAdapter = getAdapterManager().adapterFor(result);
@@ -269,7 +290,7 @@ public class ActionInvocationFacetViaMethod extends ActionInvocationFacetAbstrac
                             ? new CurrentInvocation(targetAdapter, getIdentified(), arguments, resultAdapter, command)
                             :null);
                 
-                return new InvocationResult(true, resultAdapter);
+                return InvocationResult.forActionThatReturned(resultAdapter);
             }
 
         } catch (final IllegalArgumentException e) {
@@ -292,7 +313,7 @@ public class ActionInvocationFacetViaMethod extends ActionInvocationFacetAbstrac
             ThrowableExtensions.throwWithinIsisException(e, "Exception executing " + method);
             
             // Action was not invoked (an Exception was thrown)
-            return new InvocationResult(false, null);
+            return InvocationResult.forActionNotInvoked();
         } catch (final IllegalAccessException e) {
             throw new ReflectiveActionException("Illegal access of " + method, e);
         }

http://git-wip-us.apache.org/repos/asf/isis/blob/c1a25966/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/PostsActionInvokedEventFacetViaMethod.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/PostsActionInvokedEventFacetViaMethod.java b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/PostsActionInvokedEventFacetViaMethod.java
index 7e22b78..16f2fb7 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/PostsActionInvokedEventFacetViaMethod.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/progmodel/facets/actions/invoke/event/PostsActionInvokedEventFacetViaMethod.java
@@ -69,12 +69,12 @@ public class PostsActionInvokedEventFacetViaMethod extends ActionInvocationFacet
     	final InvocationResult invocationResult = this.internalInvoke(owningAction, targetAdapter, arguments);
     	
     	// Perhaps the Action was not properly invoked (i.e. an exception was raised).
-    	if (invocationResult.getWasInvoked()) {
+    	if (invocationResult.getWhetherInvoked()) {
     		// If invoked, then send the ActionInvokedEvent to the EventBus.
     		postEvent(owningAction, targetAdapter, arguments);
     	}
     	
-    	return invocationResult.getResult();
+    	return invocationResult.getAdapter();
     	
     }