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/02/03 23:54:49 UTC

git commit: ISIS-651: fixing NPE in ActionMemento and similar

Updated Branches:
  refs/heads/master 9032a866c -> 42bf756a0


ISIS-651: fixing NPE in ActionMemento and similar

Also: forcing invalidation of Isis ObjectSpec in EntityPage (else the UI is rendered w.r.t old Isis metadata)

Not exactly sure why either of these are problems.  For the latter, certainly, it seems that the IsisJRebelPlugin invalidates the
cache correctly, but it isn't picked up.  It would seem that the Wicket viewer is holding the ActionMemento, PropertyMemento and CollecitonMemento in-memory?

also:
- adding maxPermSize to launch config for simple app.


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

Branch: refs/heads/master
Commit: 42bf756a07370752def1dd1121b3ed49d5945893
Parents: 9032a86
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Mon Feb 3 22:39:28 2014 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Mon Feb 3 22:39:28 2014 +0000

----------------------------------------------------------------------
 .../wicket/model/mementos/ActionMemento.java    | 25 +++++++---
 .../model/mementos/ActionParameterMemento.java  | 21 ++++++--
 .../model/mementos/CollectionMemento.java       | 16 ++++--
 .../wicket/model/mementos/PropertyMemento.java  | 51 ++++++++++----------
 .../wicket/ui/pages/entity/EntityPage.java      | 15 +++++-
 .../launch/SimpleApp-PROTOTYPE-jrebel.launch    |  2 +-
 6 files changed, 88 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/42bf756a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/ActionMemento.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/ActionMemento.java b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/ActionMemento.java
index e27e2c0..509455c 100644
--- a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/ActionMemento.java
+++ b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/ActionMemento.java
@@ -25,6 +25,7 @@ import org.apache.isis.applib.annotation.ActionSemantics;
 import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager.ConcurrencyChecking;
 import org.apache.isis.core.metamodel.spec.ActionType;
 import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
 
 /**
@@ -42,17 +43,25 @@ public class ActionMemento implements Serializable {
     private transient ObjectAction action;
 
     public ActionMemento(final ObjectAction action) {
-        this(action.getOnType().getSpecId(), action.getType(), action.getIdentifier().toNameParmsIdentityString());
-        this.action = action;
+        this(action.getOnType().getSpecId(), action.getType(), action.getIdentifier().toNameParmsIdentityString(), action);
     }
 
     public ActionMemento(final ObjectSpecId owningType, final ActionType actionType, final String nameParmsId) {
-        this.owningType = owningType;
+        this(owningType, actionType, nameParmsId, actionFor(owningType, actionType, nameParmsId));
+    }
+
+    private ActionMemento(
+            final ObjectSpecId owningSpecId, 
+            final ActionType actionType, 
+            final String nameParmsId, 
+            final ObjectAction action) {
+        this.owningType = owningSpecId;
         this.actionType = actionType;
         this.nameParmsId = nameParmsId;
-        this.actionSemantics = getAction().getSemantics();
+        this.action = action;
+        this.actionSemantics = action.getSemantics();
     }
-
+    
     public ObjectSpecId getOwningType() {
         return owningType;
     }
@@ -71,10 +80,14 @@ public class ActionMemento implements Serializable {
 
     public ObjectAction getAction() {
         if (action == null) {
-            action = SpecUtils.getSpecificationFor(owningType).getObjectAction(this.actionType, nameParmsId);
+            action = actionFor(owningType, actionType, nameParmsId);
         }
         return action;
     }
 
+    private static ObjectAction actionFor(ObjectSpecId owningType, ActionType actionType, String nameParmsId) {
+        final ObjectSpecification objectSpec = SpecUtils.getSpecificationFor(owningType);
+        return objectSpec.getObjectAction(actionType, nameParmsId);
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/42bf756a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/ActionParameterMemento.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/ActionParameterMemento.java b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/ActionParameterMemento.java
index 0ede2f5..fd92b44 100644
--- a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/ActionParameterMemento.java
+++ b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/ActionParameterMemento.java
@@ -41,12 +41,19 @@ public class ActionParameterMemento implements Serializable {
     private transient ObjectActionParameter actionParameter;
 
     public ActionParameterMemento(final ActionMemento actionMemento, final int number) {
-        this.actionMemento = actionMemento;
-        this.number = number;
+        this(actionMemento, number, actionParameterFor(actionMemento, number));
     }
 
     public ActionParameterMemento(final ObjectActionParameter actionParameter) {
-        this(new ActionMemento(actionParameter.getAction()), actionParameter.getNumber());
+        this(new ActionMemento(actionParameter.getAction()), actionParameter.getNumber(), actionParameter);
+    }
+
+    private ActionParameterMemento(
+            final ActionMemento actionMemento, 
+            final int number, 
+            final ObjectActionParameter actionParameter) {
+        this.actionMemento = actionMemento;
+        this.number = number;
         this.actionParameter = actionParameter;
     }
 
@@ -60,12 +67,16 @@ public class ActionParameterMemento implements Serializable {
 
     public ObjectActionParameter getActionParameter() {
         if (actionParameter == null) {
-            final ObjectAction action = actionMemento.getAction();
-            this.actionParameter = action.getParameters().get(number);
+            this.actionParameter = actionParameterFor(actionMemento, number);
         }
         return actionParameter;
     }
 
+    private static ObjectActionParameter actionParameterFor(ActionMemento actionMemento, int number) {
+        final ObjectAction action = actionMemento.getAction();
+        return action.getParameters().get(number);
+    }
+
     /**
      * Convenience.
      */

http://git-wip-us.apache.org/repos/asf/isis/blob/42bf756a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/CollectionMemento.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/CollectionMemento.java b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/CollectionMemento.java
index e7e8986..6d2a0b2 100644
--- a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/CollectionMemento.java
+++ b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/CollectionMemento.java
@@ -44,12 +44,16 @@ public class CollectionMemento implements Serializable {
     private transient OneToManyAssociation collection;
 
     public CollectionMemento(final ObjectSpecId owningType, final String id) {
-        this.owningType = owningType;
-        this.id = id;
+        this(owningType, id, collectionFor(owningType, id));
     }
 
     public CollectionMemento(final OneToManyAssociation collection) {
-        this(owningSpecFor(collection).getSpecId(), collection.getIdentifier().toNameIdentityString());
+        this(owningSpecFor(collection).getSpecId(), collection.getIdentifier().toNameIdentityString(), collection);
+    }
+
+    private CollectionMemento(final ObjectSpecId owningType, final String id, final OneToManyAssociation collection) {
+        this.owningType = owningType;
+        this.id = id;
         this.collection = collection;
     }
 
@@ -74,9 +78,13 @@ public class CollectionMemento implements Serializable {
 
     public OneToManyAssociation getCollection() {
         if (collection == null) {
-            collection = (OneToManyAssociation) SpecUtils.getSpecificationFor(owningType).getAssociation(id);
+            collection = collectionFor(owningType, id);
         }
         return collection;
     }
 
+    private static OneToManyAssociation collectionFor(ObjectSpecId owningType, String id) {
+        return (OneToManyAssociation) SpecUtils.getSpecificationFor(owningType).getAssociation(id);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/42bf756a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/PropertyMemento.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/PropertyMemento.java b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/PropertyMemento.java
index 0b3751c..6504be6 100644
--- a/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/PropertyMemento.java
+++ b/component/viewer/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/mementos/PropertyMemento.java
@@ -35,41 +35,37 @@ public class PropertyMemento implements Serializable {
         return IsisContext.getSpecificationLoader().loadSpecification(association.getIdentifier().toClassIdentityString());
     }
 
-    private final ObjectSpecId owningType;
+    private final ObjectSpecId owningSpecId;
     private final String identifier;
+    private final ObjectSpecId specId;
 
-    /**
-     * Lazily loaded as required.
-     */
-    private ObjectSpecId type;
-
-    private transient OneToOneAssociation property;
+//    private transient OneToOneAssociation property;
 
-    public PropertyMemento(final ObjectSpecId owningType, final String name) {
-        this(owningType, name, null);
+    public PropertyMemento(final ObjectSpecId owningType, final String identifier) {
+        this(owningType, identifier, null);
     }
 
-    public PropertyMemento(final ObjectSpecId owningType, final String name, final ObjectSpecId type) {
-        this.owningType = owningType;
-        this.identifier = name;
-        this.type = type;
+    public PropertyMemento(final ObjectSpecId owningType, final String identifier, final ObjectSpecId type) {
+        this(owningType, identifier, type, propertyFor(owningType, identifier));
     }
 
     public PropertyMemento(final OneToOneAssociation property) {
-        this(owningSpecFor(property).getSpecId(), property.getIdentifier().toNameIdentityString(), property.getSpecification().getSpecId());
-        this.property = property;
+        this(owningSpecFor(property).getSpecId(), property.getIdentifier().toNameIdentityString(), property.getSpecification().getSpecId(), property);
+    }
+    
+    private PropertyMemento(final ObjectSpecId owningSpecId, final String name, final ObjectSpecId specId, final OneToOneAssociation property) {
+        this.owningSpecId = owningSpecId;
+        this.identifier = name;
+        this.specId = specId;
+//        this.property = property;
     }
 
     public ObjectSpecId getOwningType() {
-        return owningType;
+        return owningSpecId;
     }
 
     public ObjectSpecId getType() {
-        if (type == null) {
-            // lazy load if need be
-            type = getProperty().getSpecification().getSpecId();
-        }
-        return type;
+        return specId;
     }
 
     public String getIdentifier() {
@@ -77,10 +73,15 @@ public class PropertyMemento implements Serializable {
     }
 
     public OneToOneAssociation getProperty() {
-        if (property == null) {
-            property = (OneToOneAssociation) SpecUtils.getSpecificationFor(owningType).getAssociation(identifier);
-        }
-        return property;
+//        if (property == null) {
+//            property = propertyFor(owningSpecId, identifier);
+//        }
+//        return property;
+        return propertyFor(owningSpecId, identifier);
+    }
+
+    private static OneToOneAssociation propertyFor(ObjectSpecId owningType, String identifier) {
+        return (OneToOneAssociation) SpecUtils.getSpecificationFor(owningType).getAssociation(identifier);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/isis/blob/42bf756a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/entity/EntityPage.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/entity/EntityPage.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/entity/EntityPage.java
index 2ffe5df..fc12a21 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/entity/EntityPage.java
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/entity/EntityPage.java
@@ -27,6 +27,8 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager.ConcurrencyChecking;
 import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException;
+import org.apache.isis.core.runtime.system.DeploymentType;
+import org.apache.isis.core.runtime.system.context.IsisContext;
 import org.apache.isis.viewer.wicket.model.hints.UiHintsBroadcastEvent;
 import org.apache.isis.viewer.wicket.model.models.EntityModel;
 import org.apache.isis.viewer.wicket.ui.ComponentType;
@@ -44,7 +46,6 @@ public class EntityPage extends PageAbstract {
     
     private final EntityModel model;
 
-
     /**
      * Called reflectively, in support of 
      * {@link BookmarkablePageLink bookmarkable} links.
@@ -77,6 +78,14 @@ public class EntityPage extends PageAbstract {
 
     private EntityPage(PageParameters pageParameters, EntityModel entityModel, String titleString) {
         super(pageParameters, ApplicationActions.INCLUDE, titleString, ComponentType.ENTITY);
+
+        // this is a work-around for JRebel integration...
+        // ... even though the IsisJRebelPlugin calls invalidateCache, it seems that there is 
+        // some caching elsewhere in the Wicket viewer meaning that stale metadata is referenced.
+        // doing an additional call here seems to be sufficient, though not exactly sure why... :-(
+        if(!getDeploymentType().isProduction()) {
+            getSpecificationLoader().invalidateCacheFor(entityModel.getObject().getObject());
+        }
         
         this.model = entityModel;
         addChildComponents(themeDiv, model);
@@ -107,4 +116,8 @@ public class EntityPage extends PageAbstract {
         super.onBeforeRender();
     }
 
+    private DeploymentType getDeploymentType() {
+        return IsisContext.getDeploymentType();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/42bf756a/example/application/simple_wicket_restful_jdo/webapp/ide/eclipse/launch/SimpleApp-PROTOTYPE-jrebel.launch
----------------------------------------------------------------------
diff --git a/example/application/simple_wicket_restful_jdo/webapp/ide/eclipse/launch/SimpleApp-PROTOTYPE-jrebel.launch b/example/application/simple_wicket_restful_jdo/webapp/ide/eclipse/launch/SimpleApp-PROTOTYPE-jrebel.launch
index 5fb0838..c496303 100644
--- a/example/application/simple_wicket_restful_jdo/webapp/ide/eclipse/launch/SimpleApp-PROTOTYPE-jrebel.launch
+++ b/example/application/simple_wicket_restful_jdo/webapp/ide/eclipse/launch/SimpleApp-PROTOTYPE-jrebel.launch
@@ -27,5 +27,5 @@
 <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--port 8080 --type PROTOTYPE"/>
 <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="simple_wicket_restful_jdo-webapp"/>
 <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
-<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="${jrebel_args} -Drebel.log=false -Drebel.plugins=c:/github/danhaywood/isis-jrebel-plugin/target/danhaywood-isis-jrebel-plugin-1.0.0-SNAPSHOT.jar -Disis-jrebel-plugin.packagePrefix=dom.simple -Disis-jrebel-plugin.loggingLevel=warn"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="${jrebel_args} -Drebel.log=false -Drebel.plugins=c:/github/danhaywood/isis-jrebel-plugin/target/danhaywood-isis-jrebel-plugin-1.0.0-SNAPSHOT.jar -Disis-jrebel-plugin.packagePrefix=dom.simple -Disis-jrebel-plugin.loggingLevel=warn -XX:MaxPermSize=128m"/>
 </launchConfiguration>