tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r1150518 - in /tapestry/tapestry5/trunk: tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ tapestry-core/src/main/java/org/apache/tapestry5/services/ tap...
Date Sun, 24 Jul 2011 23:04:11 GMT
Author: hlship
Date: Sun Jul 24 23:04:09 2011
New Revision: 1150518

URL: http://svn.apache.org/viewvc?rev=1150518&view=rev
Log:
TAP5-1508: Rename ReadOnlyFieldValueConduit to ReadOnlyComponentFieldConduit
Recode BlockInjectionProvider to implement InjectionProvider2

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ReadOnlyComponentFieldConduit.java
      - copied, changed from r1150517, tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ReadOnlyFieldValueConduit.java
Removed:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ReadOnlyFieldValueConduit.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BlockInjectionProviderTest.java
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BlockInjectionProvider.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentResourcesInjectionProvider.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ApplicationStateWorker.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ComponentWorker.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectComponentWorker.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectContainerWorker.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectPageWorker.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/MixinWorker.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PersistenceContextWorker.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BlockInjectionProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BlockInjectionProvider.java?rev=1150518&r1=1150517&r2=1150518&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BlockInjectionProvider.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BlockInjectionProvider.java
Sun Jul 24 23:04:09 2011
@@ -17,18 +17,15 @@ package org.apache.tapestry5.internal.se
 import org.apache.tapestry5.Block;
 import org.apache.tapestry5.ComponentResources;
 import org.apache.tapestry5.annotations.Id;
-import org.apache.tapestry5.internal.transform.ReadOnlyFieldValueConduit;
+import org.apache.tapestry5.internal.transform.ReadOnlyComponentFieldConduit;
 import org.apache.tapestry5.ioc.ObjectLocator;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
-import org.apache.tapestry5.ioc.services.FieldValueConduit;
 import org.apache.tapestry5.model.MutableComponentModel;
-import org.apache.tapestry5.services.ClassTransformation;
-import org.apache.tapestry5.services.ComponentValueProvider;
-import org.apache.tapestry5.services.InjectionProvider;
-import org.apache.tapestry5.services.TransformConstants;
-import org.apache.tapestry5.services.TransformField;
-import org.apache.tapestry5.services.TransformMethod;
+import org.apache.tapestry5.plastic.FieldConduit;
+import org.apache.tapestry5.plastic.InstanceContext;
+import org.apache.tapestry5.plastic.PlasticField;
+import org.apache.tapestry5.services.transform.InjectionProvider2;
 
 /**
  * Identifies fields of type {@link Block} that have the {@link Inject} annotation and converts
them
@@ -40,56 +37,46 @@ import org.apache.tapestry5.services.Tra
  * Must be scheduled before {@link DefaultInjectionProvider} because it uses the same annotation,
Inject, with a
  * different interpretation.
  */
-public class BlockInjectionProvider implements InjectionProvider
+public class BlockInjectionProvider implements InjectionProvider2
 {
+    private static final String BLOCK_TYPE_NAME = Block.class.getName();
 
-    public boolean provideInjection(final String fieldName, Class fieldType, ObjectLocator
locator,
-            ClassTransformation transformation, MutableComponentModel componentModel)
+    public boolean provideInjection(PlasticField field, ObjectLocator locator, MutableComponentModel
componentModel)
     {
-        if (!fieldType.equals(Block.class))
+        if (!field.getTypeName().equals(BLOCK_TYPE_NAME))
+        {
             return false;
-
-        TransformField field = transformation.getField(fieldName);
+        }
 
         Id annotation = field.getAnnotation(Id.class);
 
-        String blockId = getBlockId(fieldName, annotation);
+        String blockId = getBlockId(field.getName(), annotation);
 
-        ComponentValueProvider<FieldValueConduit> provider = cxreateProvider(fieldName,
blockId);
+        FieldConduit<Object> conduit = createConduit(field, blockId);
 
-        field.replaceAccess(provider);
+        field.setConduit(conduit);
 
         return true; // claim the field
     }
 
-    private ComponentValueProvider<FieldValueConduit> cxreateProvider(final String
fieldName, final String blockId)
+    private FieldConduit<Object> createConduit(PlasticField field, final String blockId)
     {
-        return new ComponentValueProvider<FieldValueConduit>()
+        final String className = field.getPlasticClass().getClassName();
+        final String fieldName = field.getName();
+
+        return new ReadOnlyComponentFieldConduit(className, fieldName)
         {
-            public FieldValueConduit get(final ComponentResources resources)
+            public Object get(Object instance, InstanceContext context)
             {
-                return new FieldValueConduit()
-                {
-                    public Object get()
-                    {
-                        return resources.getBlock(blockId);
-                    }
-
-                    public void set(Object newValue)
-                    {
-                        String componentClassName = resources.getComponentModel().getComponentClassName();
-                        throw new RuntimeException(String.format("Field %s.%s is read only.",
componentClassName, fieldName));
-                    }
-                };
+                ComponentResources resources = context.get(ComponentResources.class);
+
+                return resources.getBlock(blockId);
             }
         };
     }
 
     private String getBlockId(String fieldName, Id annotation)
     {
-        if (annotation != null)
-            return annotation.value();
-
-        return InternalUtils.stripMemberName(fieldName);
+        return annotation != null ? annotation.value() : InternalUtils.stripMemberName(fieldName);
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentResourcesInjectionProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentResourcesInjectionProvider.java?rev=1150518&r1=1150517&r2=1150518&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentResourcesInjectionProvider.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentResourcesInjectionProvider.java
Sun Jul 24 23:04:09 2011
@@ -15,7 +15,6 @@
 package org.apache.tapestry5.internal.services;
 
 import org.apache.tapestry5.ComponentResources;
-import org.apache.tapestry5.internal.transform.ReadOnlyFieldValueConduit;
 import org.apache.tapestry5.ioc.ObjectLocator;
 import org.apache.tapestry5.ioc.services.FieldValueConduit;
 import org.apache.tapestry5.model.MutableComponentModel;

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ApplicationStateWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ApplicationStateWorker.java?rev=1150518&r1=1150517&r2=1150518&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ApplicationStateWorker.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ApplicationStateWorker.java
Sun Jul 24 23:04:09 2011
@@ -95,7 +95,7 @@ public class ApplicationStateWorker impl
 
             final String fieldName = existsField.getName();
 
-            existsField.setConduit(new ReadOnlyFieldValueConduit(className, fieldName)
+            existsField.setConduit(new ReadOnlyComponentFieldConduit(className, fieldName)
             {
                 public Object get(Object instance, InstanceContext context)
                 {

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ComponentWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ComponentWorker.java?rev=1150518&r1=1150517&r2=1150518&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ComponentWorker.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ComponentWorker.java
Sun Jul 24 23:04:09 2011
@@ -105,7 +105,7 @@ public class ComponentWorker implements 
             {
                 final ComponentResources resources = context.get(ComponentResources.class);
 
-                return new ReadOnlyFieldValueConduit(resources, fieldName)
+                return new ReadOnlyComponentFieldConduit(resources, fieldName)
                 {
                     public Object get(Object instance, InstanceContext context)
                     {

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectComponentWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectComponentWorker.java?rev=1150518&r1=1150517&r2=1150518&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectComponentWorker.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectComponentWorker.java
Sun Jul 24 23:04:09 2011
@@ -32,7 +32,7 @@ import org.apache.tapestry5.services.tra
  */
 public class InjectComponentWorker implements ComponentClassTransformWorker2
 {
-    private final class InjectedComponentFieldValueConduit extends ReadOnlyFieldValueConduit
+    private final class InjectedComponentFieldValueConduit extends ReadOnlyComponentFieldConduit
     {
         private final ComponentResources resources;
         private final String fieldName, componentId, type;

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectContainerWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectContainerWorker.java?rev=1150518&r1=1150517&r2=1150518&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectContainerWorker.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectContainerWorker.java
Sun Jul 24 23:04:09 2011
@@ -70,7 +70,7 @@ public class InjectContainerWorker imple
                 final Class fieldType = cache.forName(fieldTypeName);
                 final ComponentResources resources = context.get(ComponentResources.class);
 
-                return new ReadOnlyFieldValueConduit(resources, fieldName)
+                return new ReadOnlyComponentFieldConduit(resources, fieldName)
                 {
                     public Object get(Object instance, InstanceContext context)
                     {

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectPageWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectPageWorker.java?rev=1150518&r1=1150517&r2=1150518&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectPageWorker.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/InjectPageWorker.java
Sun Jul 24 23:04:09 2011
@@ -34,7 +34,7 @@ import org.apache.tapestry5.services.tra
  */
 public class InjectPageWorker implements ComponentClassTransformWorker2
 {
-    private final class InjectedPageConduit extends ReadOnlyFieldValueConduit
+    private final class InjectedPageConduit extends ReadOnlyComponentFieldConduit
     {
         private final String injectedPageName;
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/MixinWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/MixinWorker.java?rev=1150518&r1=1150517&r2=1150518&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/MixinWorker.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/MixinWorker.java
Sun Jul 24 23:04:09 2011
@@ -85,7 +85,7 @@ public class MixinWorker implements Comp
                 ComponentResources resources = context.get(ComponentResources.class);
                 final InternalComponentResources icr = (InternalComponentResources) resources;
 
-                return new ReadOnlyFieldValueConduit(resources, fieldName)
+                return new ReadOnlyComponentFieldConduit(resources, fieldName)
                 {
                     public Object get(Object instance, InstanceContext context)
                     {

Copied: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ReadOnlyComponentFieldConduit.java
(from r1150517, tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ReadOnlyFieldValueConduit.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ReadOnlyComponentFieldConduit.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ReadOnlyComponentFieldConduit.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ReadOnlyFieldValueConduit.java&r1=1150517&r2=1150518&rev=1150518&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ReadOnlyFieldValueConduit.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ReadOnlyComponentFieldConduit.java
Sun Jul 24 23:04:09 2011
@@ -24,21 +24,21 @@ import org.apache.tapestry5.plastic.Inst
  *
  * @since 5.2.0
  */
-public abstract class ReadOnlyFieldValueConduit implements FieldConduit<Object>
+public abstract class ReadOnlyComponentFieldConduit implements FieldConduit<Object>
 {
     private final String qualifiedFieldName;
 
-    public ReadOnlyFieldValueConduit(String qualifiedFieldName)
+    public ReadOnlyComponentFieldConduit(String qualifiedFieldName)
     {
         this.qualifiedFieldName = qualifiedFieldName;
     }
 
-    public ReadOnlyFieldValueConduit(String className, String fieldName)
+    public ReadOnlyComponentFieldConduit(String className, String fieldName)
     {
         this(String.format("%s.%s", className, fieldName));
     }
 
-    public ReadOnlyFieldValueConduit(ComponentResources resources, String fieldName)
+    public ReadOnlyComponentFieldConduit(ComponentResources resources, String fieldName)
     {
         this(resources.getComponentModel().getComponentClassName(), fieldName);
     }

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=1150518&r1=1150517&r2=1150518&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 23:04:09 2011
@@ -746,12 +746,15 @@ public final class TapestryModule
     /**
      * <dl>
      * <dt>Named</dt> <dd>Handles fields with the {@link javax.inject.Named}
annotation</dd>
+     * <dt>Block</dt>
+     * <dd>injects fields of type {@link Block}</dd>
      * </dl>
      */
     @Contribute(InjectionProvider2.class)
     public static void provideStandardInjectionProviders(OrderedConfiguration<InjectionProvider2>
configuration)
     {
         configuration.addInstance("Named", InjectNamedProvider.class, "before:Default");
+        configuration.add("Block", new BlockInjectionProvider(), "before:Default");
     }
 
     /**
@@ -759,8 +762,6 @@ public final class TapestryModule
      * <dl>
      * <dt>Default</dt>
      * <dd>based on {@link MasterObjectProvider}</dd>
-     * <dt>Block</dt>
-     * <dd>injects fields of type Block</dd>
      * <dt>ComponentResources</dt>
      * <dd>give component access to its resources</dd>
      * <dt>CommonResources</dt>
@@ -795,7 +796,6 @@ public final class TapestryModule
 
         configuration.add("Asset", new AssetInjectionProvider(symbolSource, assetSource),
"before:Default");
 
-        configuration.add("Block", new BlockInjectionProvider(), "before:Default");
 
         // This needs to be the last one, since it matches against services
         // and might blow up if there is no match.

Modified: tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PersistenceContextWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PersistenceContextWorker.java?rev=1150518&r1=1150517&r2=1150518&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PersistenceContextWorker.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PersistenceContextWorker.java
Sun Jul 24 23:04:09 2011
@@ -14,7 +14,7 @@
 
 package org.apache.tapestry5.internal.jpa;
 
-import org.apache.tapestry5.internal.transform.ReadOnlyFieldValueConduit;
+import org.apache.tapestry5.internal.transform.ReadOnlyComponentFieldConduit;
 import org.apache.tapestry5.jpa.EntityManagerManager;
 import org.apache.tapestry5.model.MutableComponentModel;
 import org.apache.tapestry5.plastic.InstanceContext;
@@ -43,7 +43,7 @@ public class PersistenceContextWorker im
 
             field.claim(annotation);
 
-            field.setConduit(new ReadOnlyFieldValueConduit(plasticClass.getClassName(), field.getName())
+            field.setConduit(new ReadOnlyComponentFieldConduit(plasticClass.getClassName(),
field.getName())
             {
                 public Object get(Object instance, InstanceContext context)
                 {



Mime
View raw message