incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmatth...@apache.org
Subject svn commit: r1085483 - in /incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher: context/ view/edit/
Date Fri, 25 Mar 2011 17:33:59 GMT
Author: rmatthews
Date: Fri Mar 25 17:33:58 2011
New Revision: 1085483

URL: http://svn.apache.org/viewvc?rev=1085483&view=rev
Log:
Making us of the fixed memento to hold a transient object on the web page while it worked
on (ensuring state operation)

Removed:
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/HibernateOidObjectMapping.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/SerialOidObjectMapping.java
Modified:
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/DefaultOidObjectMapping.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/IndirectObjectMapping.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/ObjectMapping.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/RequestContext.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/EditObject.java

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/DefaultOidObjectMapping.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/DefaultOidObjectMapping.java?rev=1085483&r1=1085482&r2=1085483&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/DefaultOidObjectMapping.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/DefaultOidObjectMapping.java
Fri Mar 25 17:33:58 2011
@@ -20,8 +20,11 @@
 
 package org.apache.isis.viewer.scimpi.dispatcher.context;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -30,6 +33,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.commons.encoding.DataInputStreamExtended;
 import org.apache.isis.core.commons.encoding.DataOutputExtended;
 import org.apache.isis.core.commons.encoding.DataOutputStreamExtended;
 import org.apache.isis.core.commons.exceptions.IsisException;
@@ -39,6 +43,7 @@ import org.apache.isis.core.metamodel.ad
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification.CreationMode;
 import org.apache.isis.runtimes.dflt.runtime.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.memento.Memento;
 import org.apache.isis.runtimes.dflt.runtime.persistence.oidgenerator.simple.SerialOid;
 import org.apache.isis.viewer.scimpi.dispatcher.ScimpiException;
 import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext.Scope;
@@ -69,7 +74,7 @@ public class DefaultOidObjectMapping imp
 
     public void appendMappings(DebugBuilder request) {}
 
-    public void clear(Scope scope) {
+    public void clear() {
         requestTransients.clear();
         
         List<String> remove = new ArrayList<String>();
@@ -88,6 +93,22 @@ public class DefaultOidObjectMapping imp
         sessionTransients.clear();
     }
 
+    public String encodedObject(ObjectAdapter object) {
+         Memento memento = new Memento(object);
+        
+        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        final DataOutputStreamExtended outputImpl = new DataOutputStreamExtended(baos);
+        try {
+            // TODO record the OID for the this object so it can be re-reference without
being rewriting the data
+            memento.encodedData(outputImpl);
+            final byte[] byteArray = baos.toByteArray();
+            String data = new String(byteArray);
+            return "D" + mapObject(object, Scope.INTERACTION) + "|" + URLEncoder.encode(data,
"UTF-8");
+        } catch (IOException e) {
+            throw new IsisException("Failed to write object", e);
+        }
+    }
+    
     public String mapObject(ObjectAdapter inObject, Scope scope) {
         // TODO need to ensure that transient objects are remapped each time so that any
changes are added to
         // session data
@@ -123,6 +144,8 @@ public class DefaultOidObjectMapping imp
             String id = (isTransient ? "T" : "P") + object.getSpecification().getFullIdentifier()
+ "@" + encodedOid;
             LOG.debug("encoded " + oid + " as " + id + " ~ " + encodedOid);
             if (isTransient) {
+                
+                 // TODO if Transient/Interaction then return state; other store state in
session an return OID string 
                 TransientObjectMapping mapping = new TransientObjectMapping((ObjectAdapter)
inObject);
                 if (scope == Scope.REQUEST) {
                     requestTransients.put(id, mapping);
@@ -138,6 +161,28 @@ public class DefaultOidObjectMapping imp
         }
     }
 
+    public ObjectAdapter decodeObject(String data) {
+        byte[] oidBytes;
+        try {
+            int x = data.indexOf('|');
+            String id = data.substring(0, x);
+            String objectData = data.substring(x + 1);
+            String state = URLDecoder.decode(objectData, "UTF-8");
+            
+            ObjectAdapter object = mappedObject(id);
+            Memento memento = new Memento(object);
+            
+            oidBytes = state.getBytes();
+            final ByteArrayInputStream bais = new ByteArrayInputStream(oidBytes);
+            final DataInputStreamExtended inputImpl = new DataInputStreamExtended(bais);
+            memento.restore(inputImpl);
+            memento.recreateObject();
+            return object;
+        } catch (IOException ex) {
+            throw new IsisException("Failed to read object", ex);
+        }
+    }
+    
     public ObjectAdapter mappedObject(String id) {
         char type = id.charAt(0);
         if ((type == 'T')) {

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/IndirectObjectMapping.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/IndirectObjectMapping.java?rev=1085483&r1=1085482&r2=1085483&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/IndirectObjectMapping.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/IndirectObjectMapping.java
Fri Mar 25 17:33:58 2011
@@ -27,6 +27,7 @@ import java.util.Map;
 import java.util.TreeSet;
 
 import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext.Scope;
 
@@ -72,8 +73,8 @@ public class IndirectObjectMapping imple
         }
     }
 
-    public void clear(Scope scope) {
-        scopedMappings.get(scope).clear();
+    public void clear() {
+        scopedMappings.get(Scope.REQUEST).clear();
     }
 
     public void unmapObject(ObjectAdapter object, Scope scope) {
@@ -181,4 +182,12 @@ public class IndirectObjectMapping imple
         appendMappings(debug, Scope.REQUEST);
     }
 
+    public ObjectAdapter decodeObject(String substring) {
+        throw new NotYetImplementedException();
+    }
+
+    public String encodedObject(ObjectAdapter object) {
+        throw new NotYetImplementedException();
+    }
+
 }

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/ObjectMapping.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/ObjectMapping.java?rev=1085483&r1=1085482&r2=1085483&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/ObjectMapping.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/ObjectMapping.java
Fri Mar 25 17:33:58 2011
@@ -31,8 +31,7 @@ public interface ObjectMapping {
 
     void reloadIdentityMap();
 
-    // TODO this is only useed to clear REQUEST mappings, so change name and remove parameter
to reflect that
-    void clear(Scope scope);
+    void clear();
 
     void unmapObject(ObjectAdapter object, Scope scope);
 
@@ -40,8 +39,14 @@ public interface ObjectMapping {
 
     ObjectAdapter mappedObject(String id);
 
+    ObjectAdapter decodeObject(String substring);
+
     String mapObject(ObjectAdapter obj, Scope scope);
 
+    String encodedObject(ObjectAdapter object);
+
     void append(DebugBuilder debug);
 
+
+
 }

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/RequestContext.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/RequestContext.java?rev=1085483&r1=1085482&r2=1085483&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/RequestContext.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/context/RequestContext.java
Fri Mar 25 17:33:58 2011
@@ -163,11 +163,9 @@ public abstract class RequestContext {
     }
 
     public String mapObject(ObjectAdapter object, String scopeName, Scope defaultScope) {
-       // if (!object.getSpecification().containsFacet(EncodeableFacet.class)) {
         Scope scope = scopeName == null ? defaultScope : scope(scopeName);
         LOG.debug("mapping " + object + " " + scope);
         return objectMapping.mapObject(object, scope);
-     //   }
     }
 
     private ObjectAdapter mappedObject(String id) {
@@ -178,6 +176,10 @@ public abstract class RequestContext {
             id = RESULT;
         }
 
+        if (id.startsWith("D")) {
+            return objectMapping.decodeObject(id.substring(1));
+        }
+        
         String[] idParts = id.split("@");
         if (idParts.length == 2) {
             ObjectAdapter mappedObject = objectMapping.mappedObject(id);
@@ -496,7 +498,7 @@ public abstract class RequestContext {
     // //////////////////////////////
     public void endRequest() throws IOException {
         getWriter().close();
-        objectMapping.clear(Scope.REQUEST);
+        objectMapping.clear();
         variables.get(Scope.REQUEST).clear();
         variables.get(Scope.INTERACTION).clear();
     }
@@ -679,10 +681,12 @@ public abstract class RequestContext {
     // //////////////////////////////////////////////////////////////////
 
     public String mapObject(ObjectAdapter object, Scope scope) {
-        if (object.getOid() != null) {
-            return objectMapping.mapObject(object, scope);
-        } else if (object.getResolveState().isValue()) {
+        if (object.getResolveState().isValue()) {
             return object.titleString();
+        } else if (scope == Scope.INTERACTION && object.isTransient()) {
+            return objectMapping.encodedObject(object);
+        } else if (object.getOid() != null) {
+            return objectMapping.mapObject(object, scope);
         } else {
             collection = object;
             return "collection";

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/EditObject.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/EditObject.java?rev=1085483&r1=1085482&r2=1085483&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/EditObject.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/EditObject.java
Fri Mar 25 17:33:58 2011
@@ -105,9 +105,9 @@ public class EditObject extends Abstract
         request.processUtilCloseTag();
         
         AuthenticationSession session = IsisContext.getAuthenticationSession();
-        List<ObjectAssociation> fields = specification.getAssociations(ObjectAssociationFilters.dynamicallyVisible(session,
object));
-        fields = containedBlock.includedFields(fields);
-        InputField[] formFields = createFields(fields);
+        List<ObjectAssociation> viewFields = specification.getAssociations(ObjectAssociationFilters.dynamicallyVisible(session,
object));
+        viewFields = containedBlock.includedFields(viewFields);
+        InputField[] formFields = createFields(viewFields);
         
         initializeFields(context, object, formFields, entryState, !hideNonEditableFields);
         setDefaults(context, object, formFields, entryState, showIcon);
@@ -133,21 +133,28 @@ public class EditObject extends Abstract
 
         if (object.isTransient()) {
             // restore transient details
-            List<ObjectAssociation> fields2 = object.getSpecification().getAssociations();
-            for (int i = 0; i < fields2.size(); i++) {
-                ObjectAssociation field = fields2.get(i);
-                if (!fields.contains(field)) {
+            List<ObjectAssociation> objectFields = object.getSpecification().getAssociations();
+            for (int i = 0; i < objectFields.size(); i++) {
+                ObjectAssociation field = objectFields.get(i);
+                ObjectAdapter fieldValue = field.get(object);
+                if (!viewFields.contains(field)) {
                     String fieldId = field.getId();
-                    String value = getValue(context, field.get(object)); 
+                    String value = getValue(context, fieldValue); 
                     hiddenFields.add(new HiddenInputField(fieldId, value));
                 }
+                
+                if (fieldValue != null && fieldValue.isTransient()) {
+                    String fieldId = field.getId();
+                    String data = context.mapObject(fieldValue, Scope.REQUEST);
+                    hiddenFields.add(new HiddenInputField(fieldId, data));
+                }
             }
         } else {
             // ensure all booleans are included so the pass back TRUE if set. 
             List<ObjectAssociation> fields2 = object.getSpecification().getAssociations();
             for (int i = 0; i < fields2.size(); i++) {
                 ObjectAssociation field = fields2.get(i);
-                if (!fields.contains(field) && field.getSpecification().containsFacet(BooleanValueFacet.class))
{
+                if (!viewFields.contains(field) && field.getSpecification().containsFacet(BooleanValueFacet.class))
{
                     String fieldId = field.getId();
                     String value = getValue(context, field.get(object)); 
                     hiddenFields.add(new HiddenInputField(fieldId, value));
@@ -307,7 +314,7 @@ public class EditObject extends Abstract
     }
 
     private String getValue(RequestContext context, ObjectAdapter field) {
-        if (field == null) {
+        if (field == null || field.isTransient()) {
             return "";
         }
         ObjectSpecification specification = field.getSpecification();



Mime
View raw message