You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2011/07/24 17:17:53 UTC

svn commit: r1150401 - in /tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5: internal/transform/SessionAttributeWorker.java services/TapestryModule.java

Author: hlship
Date: Sun Jul 24 15:17:52 2011
New Revision: 1150401

URL: http://svn.apache.org/viewvc?rev=1150401&view=rev
Log:
TAP5-1508: Record SessionAttributeWorker to CCTW2

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/SessionAttributeWorker.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/SessionAttributeWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/SessionAttributeWorker.java?rev=1150401&r1=1150400&r2=1150401&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/SessionAttributeWorker.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/SessionAttributeWorker.java Sun Jul 24 15:17:52 2011
@@ -1,4 +1,4 @@
-// Copyright 2009, 2010 The Apache Software Foundation
+// Copyright 2009, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -15,23 +15,25 @@
 package org.apache.tapestry5.internal.transform;
 
 import org.apache.tapestry5.annotations.SessionAttribute;
-import org.apache.tapestry5.ioc.services.FieldValueConduit;
 import org.apache.tapestry5.model.MutableComponentModel;
-import org.apache.tapestry5.services.ClassTransformation;
-import org.apache.tapestry5.services.ComponentClassTransformWorker;
+import org.apache.tapestry5.plastic.FieldConduit;
+import org.apache.tapestry5.plastic.InstanceContext;
+import org.apache.tapestry5.plastic.PlasticClass;
+import org.apache.tapestry5.plastic.PlasticField;
 import org.apache.tapestry5.services.Request;
 import org.apache.tapestry5.services.Session;
-import org.apache.tapestry5.services.TransformField;
+import org.apache.tapestry5.services.transform.ComponentClassTransformWorker2;
+import org.apache.tapestry5.services.transform.TransformationSupport;
 
 /**
  * Looks for the {@link SessionAttribute} annotation and converts read and write access on such
  * fields into calls to the {@link Session#getAttribute(String)} and {@link Session#setAttribute(String, Object)}.
  */
-public class SessionAttributeWorker implements ComponentClassTransformWorker
+public class SessionAttributeWorker implements ComponentClassTransformWorker2
 {
     private final Request request;
 
-    private class SessionKeyConduit implements FieldValueConduit
+    private class SessionKeyConduit implements FieldConduit<Object>
     {
         private final String key;
 
@@ -40,20 +42,26 @@ public class SessionAttributeWorker impl
             this.key = key;
         }
 
-        private Session getSession()
+        public Object get(Object instance, InstanceContext context)
         {
-            return request.getSession(true);
+            Session session = getSession();
+
+            if (session == null)
+            {
+                return null;
+            }
+
+            return session.getAttribute(key);
         }
 
-        public Object get()
+        public void set(Object instance, InstanceContext context, Object newValue)
         {
-            // TODO: caching, and not creating the session unnecessarily
-            return getSession().getAttribute(key);
+            request.getSession(true).setAttribute(key, newValue);
         }
 
-        public void set(Object newValue)
+        private Session getSession()
         {
-            getSession().setAttribute(key, newValue);
+            return request.getSession(false);
         }
     }
 
@@ -62,15 +70,16 @@ public class SessionAttributeWorker impl
         this.request = request;
     }
 
-    public void transform(ClassTransformation transformation, MutableComponentModel model)
+
+    public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model)
     {
-        for (TransformField field : transformation.matchFieldsWithAnnotation(SessionAttribute.class))
+        for (PlasticField field : plasticClass.getFieldsWithAnnotation(SessionAttribute.class))
         {
             convertFieldToSessionAccess(field);
         }
     }
 
-    private void convertFieldToSessionAccess(TransformField field)
+    private void convertFieldToSessionAccess(PlasticField field)
     {
         SessionAttribute annotation = field.getAnnotation(SessionAttribute.class);
 
@@ -78,10 +87,10 @@ public class SessionAttributeWorker impl
 
         String key = determineSessionKey(field, annotation.value());
 
-        field.replaceAccess(new SessionKeyConduit(key));
+        field.setConduit(new SessionKeyConduit(key));
     }
 
-    private String determineSessionKey(TransformField field, String value)
+    private String determineSessionKey(PlasticField field, String value)
     {
         return value.equals("") ? field.getName() : value;
     }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=1150401&r1=1150400&r2=1150401&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java Sun Jul 24 15:17:52 2011
@@ -540,6 +540,8 @@ public final class TapestryModule
      * <dd>Converts fields that reference application state objects</dd>
      * <dt>Persist</dt>
      * <dd>Allows fields to store their their value persistently between requests via {@link Persist}</dd>
+     * <dt>SessionAttribute</dt>
+     * <dd>Support for the {@link SessionAttribute}</dd>
      * </dl>
      */
     @Contribute(ComponentClassTransformWorker2.class)
@@ -607,6 +609,7 @@ public final class TapestryModule
 
         configuration.addInstance("Persist", PersistWorker.class);
 
+        configuration.addInstance("SessionAttribute", SessionAttributeWorker.class);
 
         // This one is always last. Any additional private fields that aren't
         // annotated will
@@ -635,8 +638,6 @@ public final class TapestryModule
 
         configuration.addInstance("Log", LogWorker.class);
 
-        configuration.addInstance("SessionAttribute", SessionAttributeWorker.class);
-
         configuration.addInstance("HeartbeatDeferred", HeartbeatDeferredWorker.class, "after:RenderPhase");
     }