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/12/02 00:59:12 UTC
[11/13] isis git commit: ISIS-961: removing duplication between
ActionLinkFactoryAbstract and ActionPanel (functionality moved to
ActionModel)
ISIS-961: removing duplication between ActionLinkFactoryAbstract and ActionPanel (functionality moved to ActionModel)
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/e5a2aded
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/e5a2aded
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/e5a2aded
Branch: refs/heads/master
Commit: e5a2adedc4c5c00a4e3882ff04d3b197377997bc
Parents: d231d20
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Mon Dec 1 23:25:41 2014 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Mon Dec 1 23:25:41 2014 +0000
----------------------------------------------------------------------
.../viewer/wicket/model/models/ActionModel.java | 41 ++++++++++++++++-
.../ui/components/actions/ActionPanel.java | 46 +-------------------
.../cssmenu/ActionLinkFactoryAbstract.java | 33 +-------------
3 files changed, 43 insertions(+), 77 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/e5a2aded/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java
index 3243340..05fb26c 100644
--- a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java
+++ b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java
@@ -521,7 +521,46 @@ public class ActionModel extends BookmarkableModel<ObjectAdapter> {
return bookmarkPolicy.value() == BookmarkPolicy.AS_ROOT && safeSemantics;
}
-
+ // //////////////////////////////////////
+
+ /**
+ * Executes the action, handling any {@link RecoverableException}s that
+ * might be encountered.
+ *
+ * <p>
+ * If an {@link RecoverableException} is encountered, then the application error will be
+ * {@link org.apache.isis.core.commons.authentication.MessageBroker#setApplicationError(String) set} so that a suitable message can be
+ * rendered higher up the call stack.
+ *
+ * <p>
+ * Any other types of exception will be ignored (to be picked up higher up in the callstack)
+ */
+ public ObjectAdapter executeHandlingApplicationExceptions() {
+ try {
+ final ObjectAdapter resultAdapter = this.getObject();
+ return resultAdapter;
+
+ } catch (RuntimeException ex) {
+
+ // see if is an application-defined exception
+ // if so, is converted to an application error,
+ // equivalent to calling DomainObjectContainer#raiseError(...)
+ final RecoverableException appEx = getApplicationExceptionIfAny(ex);
+ if (appEx != null) {
+ IsisContext.getMessageBroker().setApplicationError(appEx.getMessage());
+
+ // there's no need to set the abort cause on the transaction, it will have already been done
+ // (in IsisTransactionManager#executeWithinTransaction(...)).
+
+ return null;
+ }
+
+ // not handled, so propagate
+ throw ex;
+ }
+ }
+
+
// //////////////////////////////////////
public static RecoverableException getApplicationExceptionIfAny(Exception ex) {
http://git-wip-us.apache.org/repos/asf/isis/blob/e5a2aded/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionPanel.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionPanel.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionPanel.java
index 238840e..ad157b8 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionPanel.java
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionPanel.java
@@ -26,7 +26,6 @@ import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.Model;
-import org.apache.isis.applib.RecoverableException;
import org.apache.isis.applib.services.command.Command;
import org.apache.isis.applib.services.command.Command.Executor;
import org.apache.isis.applib.services.command.CommandContext;
@@ -243,7 +242,7 @@ public class ActionPanel extends PanelAbstract<ActionModel> implements ActionExe
// so we handle it here.
try {
// could be programmatic flushing, so must include in the try... finally
- final ObjectAdapter resultAdapter = executeActionHandlingApplicationExceptions();
+ final ObjectAdapter resultAdapter = getActionModel().executeHandlingApplicationExceptions();
// flush any queued changes, so concurrency or violation exceptions (if any)
// will be thrown here
@@ -322,49 +321,6 @@ public class ActionPanel extends PanelAbstract<ActionModel> implements ActionExe
}
}
- /**
- * Executes the action, handling any {@link RecoverableException}s that
- * might be encountered.
- *
- * <p>
- * If an {@link RecoverableException} is encountered, then the application error will be
- * {@link MessageBroker#setApplicationError(String) set} so that a suitable message can be
- * rendered higher up the call stack.
- *
- * <p>
- * Any other types of exception will be ignored (to be picked up higher up in the callstack)
- */
- private ObjectAdapter executeActionHandlingApplicationExceptions() {
- final ActionModel actionModel = getActionModel();
- try {
- ObjectAdapter resultAdapter = actionModel.getObject();
- return resultAdapter;
-
- } catch (RuntimeException ex) {
-
- // TODO: some duplication between this code and ActionLinkFactoryAbstract
-
- // see if is an application-defined exception
- // if so, is converted to an application error,
- // equivalent to calling DomainObjectContainer#raiseError(...)
- final RecoverableException appEx = ActionModel.getApplicationExceptionIfAny(ex);
- if (appEx != null) {
- getMessageBroker().setApplicationError(appEx.getMessage());
-
- // there's no need to set the abort cause on the transaction, it will have already been done
- // (in IsisTransactionManager#executeWithinTransaction(...)).
- return null;
- }
-
- // the ExceptionRecognizers stuff is done in the calling method (because may be triggered
- // by a flush to the object store (which in most cases won't have happened in the execute of
- // the action body)
-
- // not handled, so propagate
- throw ex;
- }
- }
-
///////////////////////////////////////////////////////
// Dependencies (from context)
http://git-wip-us.apache.org/repos/asf/isis/blob/e5a2aded/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/cssmenu/ActionLinkFactoryAbstract.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/cssmenu/ActionLinkFactoryAbstract.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/cssmenu/ActionLinkFactoryAbstract.java
index d5ab010..1142d14 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/cssmenu/ActionLinkFactoryAbstract.java
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/cssmenu/ActionLinkFactoryAbstract.java
@@ -32,11 +32,9 @@ import org.apache.wicket.markup.html.link.AbstractLink;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.util.visit.IVisit;
import org.apache.wicket.util.visit.IVisitor;
-import org.apache.isis.applib.RecoverableException;
import org.apache.isis.applib.annotation.ActionLayout;
import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
-import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.viewer.wicket.model.links.LinkAndLabel;
import org.apache.isis.viewer.wicket.model.models.ActionModel;
import org.apache.isis.viewer.wicket.model.models.ActionPrompt;
@@ -164,7 +162,7 @@ public abstract class ActionLinkFactoryAbstract implements ActionLinkFactory {
@Override
protected IRequestHandler getRequestHandler() {
- ObjectAdapter resultAdapter = executeActionHandlingApplicationExceptions(actionModel);
+ ObjectAdapter resultAdapter = actionModel.executeHandlingApplicationExceptions();
final Object value = resultAdapter.getObject();
return ActionModel.redirectHandler(value);
}
@@ -182,7 +180,7 @@ public abstract class ActionLinkFactoryAbstract implements ActionLinkFactory {
@Override
protected IRequestHandler getRequestHandler() {
- ObjectAdapter resultAdapter = executeActionHandlingApplicationExceptions(actionModel);
+ final ObjectAdapter resultAdapter = actionModel.executeHandlingApplicationExceptions();
final Object value = resultAdapter.getObject();
return ActionModel.downloadHandler(value);
}
@@ -204,33 +202,6 @@ public abstract class ActionLinkFactoryAbstract implements ActionLinkFactory {
(action.getReturnType().getCorrespondingClass() == org.apache.isis.applib.value.Blob.class ||
action.getReturnType().getCorrespondingClass() == org.apache.isis.applib.value.Clob.class);
}
-
- // adapted from similar code in ActionPanel :-(
- private static ObjectAdapter executeActionHandlingApplicationExceptions(final ActionModel actionModel) {
- try {
- return actionModel.getObject();
-
- } catch (RuntimeException ex) {
-
- // TODO: some duplication between this code and ActionPanel
-
- // see if is an application-defined exception
- // if so, is converted to an application error,
- // equivalent to calling DomainObjectContainer#raiseError(...)
- final RecoverableException appEx = ActionModel.getApplicationExceptionIfAny(ex);
- if (appEx != null) {
- IsisContext.getMessageBroker().setApplicationError(appEx.getMessage());
-
- // there's no need to set the abort cause on the transaction, it will have already been done
- // (in IsisTransactionManager#executeWithinTransaction(...)).
-
- return null;
- }
-
- // not handled, so propagate
- throw ex;
- }
- }
protected LinkAndLabel newLinkAndLabel(final ObjectAction objectAction, final AbstractLink link, final String disabledReasonIfAny) {