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/04/14 00:24:14 UTC
svn commit: r1091962 - in
/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services:
LiteralPropertyConduit.java PropertyConduitDelegate.java
PropertyConduitSourceImpl.java
Author: hlship
Date: Wed Apr 13 22:24:14 2011
New Revision: 1091962
URL: http://svn.apache.org/viewvc?rev=1091962&view=rev
Log:
TAP5-853: Use a single, shared delegate for all PropertyConduit proxies
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/LiteralPropertyConduit.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitDelegate.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/LiteralPropertyConduit.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/LiteralPropertyConduit.java?rev=1091962&r1=1091961&r2=1091962&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/LiteralPropertyConduit.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/LiteralPropertyConduit.java Wed Apr 13 22:24:14 2011
@@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,6 +14,8 @@
package org.apache.tapestry5.internal.services;
+import java.lang.annotation.Annotation;
+
import org.apache.tapestry5.internal.InternalPropertyConduit;
import org.apache.tapestry5.ioc.AnnotationProvider;
import org.apache.tapestry5.ioc.services.TypeCoercer;
@@ -23,13 +25,22 @@ import org.apache.tapestry5.ioc.services
*/
public class LiteralPropertyConduit extends PropertyConduitDelegate implements InternalPropertyConduit
{
+ private final Class propertyType;
+
+ private final AnnotationProvider annotationProvider;
+
+ private final String description;
+
private final Object value;
- public LiteralPropertyConduit(Class propertyType, AnnotationProvider annotationProvider, String description,
- TypeCoercer typeCoercer,
- Object value)
+ public LiteralPropertyConduit(TypeCoercer typeCoercer, Class propertyType, AnnotationProvider annotationProvider,
+ String description, Object value)
{
- super(propertyType, null, annotationProvider, typeCoercer);
+ super(typeCoercer);
+
+ this.propertyType = propertyType;
+ this.annotationProvider = annotationProvider;
+ this.description = description;
this.value = value;
}
@@ -43,4 +54,26 @@ public class LiteralPropertyConduit exte
{
throw new RuntimeException(ServicesMessages.literalConduitNotUpdateable());
}
+
+ public Class getPropertyType()
+ {
+ return propertyType;
+ }
+
+ public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
+ {
+ return annotationProvider.getAnnotation(annotationClass);
+ }
+
+ public String getPropertyName()
+ {
+ return null;
+ }
+
+ @Override
+ public String toString()
+ {
+ return description;
+ }
+
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitDelegate.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitDelegate.java?rev=1091962&r1=1091961&r2=1091962&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitDelegate.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitDelegate.java Wed Apr 13 22:24:14 2011
@@ -29,42 +29,13 @@ import org.apache.tapestry5.ioc.services
@SuppressWarnings("all")
public class PropertyConduitDelegate
{
- private final Class propertyType;
-
- private final String propertyName;
-
- private final AnnotationProvider annotationProvider;
-
private final TypeCoercer typeCoercer;
- public PropertyConduitDelegate(Class propertyType, String propertyName, AnnotationProvider annotationProvider,
- TypeCoercer typeCoercer)
+ public PropertyConduitDelegate(TypeCoercer typeCoercer)
{
- assert propertyType != null;
- assert annotationProvider != null;
- assert typeCoercer != null;
-
- this.propertyType = propertyType;
- this.propertyName = propertyName;
- this.annotationProvider = annotationProvider;
this.typeCoercer = typeCoercer;
}
- public final <T extends Annotation> T getAnnotation(Class<T> annotationClass)
- {
- return annotationProvider.getAnnotation(annotationClass);
- }
-
- public final Class getPropertyType()
- {
- return propertyType;
- }
-
- public final String getPropertyName()
- {
- return propertyName;
- }
-
public final IntegerRange range(int from, int to)
{
return new IntegerRange(from, to);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java?rev=1091962&r1=1091961&r2=1091962&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java Wed Apr 13 22:24:14 2011
@@ -77,19 +77,23 @@ import org.apache.tapestry5.services.Pro
public class PropertyConduitSourceImpl implements PropertyConduitSource, InvalidationListener
{
- private static final MethodDescription GET = getMethodDescription(PropertyConduit.class, "get", Object.class);
+ static class ConduitMethods
+ {
+ private static final MethodDescription GET = getMethodDescription(PropertyConduit.class, "get", Object.class);
+
+ private static final MethodDescription SET = getMethodDescription(PropertyConduit.class, "set", Object.class,
+ Object.class);
- private static final MethodDescription SET = getMethodDescription(PropertyConduit.class, "set", Object.class,
- Object.class);
+ private static final MethodDescription GET_PROPERTY_TYPE = getMethodDescription(PropertyConduit.class,
+ "getPropertyType");
- private static final MethodDescription GET_ANNOTATION = getMethodDescription(AnnotationProvider.class,
- "getAnnotation", Class.class);
+ private static final MethodDescription GET_PROPERTY_NAME = getMethodDescription(InternalPropertyConduit.class,
+ "getPropertyName");
- private static final MethodDescription GET_PROPERTY_TYPE = getMethodDescription(PropertyConduit.class,
- "getPropertyType");
+ private static final MethodDescription GET_ANNOTATION = getMethodDescription(AnnotationProvider.class,
+ "getAnnotation", Class.class);
- private static final MethodDescription GET_PROPERTY_NAME = getMethodDescription(InternalPropertyConduit.class,
- "getPropertyName");
+ }
static class DelegateMethods
{
@@ -239,6 +243,8 @@ public class PropertyConduitSourceImpl i
private final PropertyConduit literalNull;
+ private final PropertyConduitDelegate sharedDelegate;
+
/**
* Encapsulates the process of building a PropertyConduit instance from an
* expression, as an {@link PlasticClassTransformer}.
@@ -274,30 +280,41 @@ public class PropertyConduitSourceImpl i
{
this.plasticClass = plasticClass;
- delegateField = plasticClass.introduceField(PropertyConduitDelegate.class, "delegate");
+ delegateField = plasticClass.introduceField(PropertyConduitDelegate.class, "delegate").inject(
+ sharedDelegate);
// Create the various methods; also determine the conduit's property type, property name and identify
// the annotation provider.
implementNavMethodAndAccessors();
- implementDelegateMethods();
+ implementOtherMethods();
plasticClass.addToString(String.format("PropertyConduit[%s %s]", rootType.getName(), expression));
}
- private void implementDelegateMethods()
+ private void implementOtherMethods()
{
- PropertyConduitDelegate delegate = new PropertyConduitDelegate(conduitPropertyType, conduitPropertyName,
- annotationProvider, typeCoercer);
+ PlasticField annotationProviderField = plasticClass.introduceField(AnnotationProvider.class,
+ "annotationProvider").inject(annotationProvider);
- delegateField.inject(delegate);
+ plasticClass.introduceMethod(ConduitMethods.GET_ANNOTATION).delegateTo(annotationProviderField);
- // TODO: These can easily be injected into the proxy, and not require delegate access.
+ plasticClass.introduceMethod(ConduitMethods.GET_PROPERTY_NAME, new InstructionBuilderCallback()
+ {
+ public void doBuild(InstructionBuilder builder)
+ {
+ builder.loadConstant(conduitPropertyName).returnResult();
+ }
+ });
+ plasticClass.introduceMethod(ConduitMethods.GET_PROPERTY_TYPE, new InstructionBuilderCallback()
+ {
+ public void doBuild(InstructionBuilder builder)
+ {
+ builder.loadTypeConstant(conduitPropertyType).returnResult();
+ }
+ });
- plasticClass.introduceMethod(GET_ANNOTATION).delegateTo(delegateField);
- plasticClass.introduceMethod(GET_PROPERTY_TYPE).delegateTo(delegateField);
- plasticClass.introduceMethod(GET_PROPERTY_NAME).delegateTo(delegateField);
}
/**
@@ -452,7 +469,7 @@ public class PropertyConduitSourceImpl i
conduitPropertyType = term.genericType;
annotationProvider = term.annotationProvider;
- plasticClass.introduceMethod(GET, new InstructionBuilderCallback()
+ plasticClass.introduceMethod(ConduitMethods.GET, new InstructionBuilderCallback()
{
public void doBuild(InstructionBuilder builder)
{
@@ -496,12 +513,13 @@ public class PropertyConduitSourceImpl i
return;
}
- implementNoOpMethod(SET, "Expression %s for class %s is read-only.", expression, rootType.getName());
+ implementNoOpMethod(ConduitMethods.SET, "Expression %s for class %s is read-only.", expression,
+ rootType.getName());
}
private void implementSetter(Type activeType, final Field field)
{
- plasticClass.introduceMethod(SET, new InstructionBuilderCallback()
+ plasticClass.introduceMethod(ConduitMethods.SET, new InstructionBuilderCallback()
{
public void doBuild(InstructionBuilder builder)
{
@@ -518,7 +536,7 @@ public class PropertyConduitSourceImpl i
private void implementSetter(Type activeType, final Method writeMethod)
{
- plasticClass.introduceMethod(SET, new InstructionBuilderCallback()
+ plasticClass.introduceMethod(ConduitMethods.SET, new InstructionBuilderCallback()
{
public void doBuild(InstructionBuilder builder)
{
@@ -550,12 +568,13 @@ public class PropertyConduitSourceImpl i
return;
}
- implementNoOpMethod(GET, "Expression %d for class %s is write-only.", expression, rootType.getName());
+ implementNoOpMethod(ConduitMethods.GET, "Expression %d for class %s is write-only.", expression,
+ rootType.getName());
}
private void implementGetter(final Type activeType, final Field field)
{
- plasticClass.introduceMethod(GET, new InstructionBuilderCallback()
+ plasticClass.introduceMethod(ConduitMethods.GET, new InstructionBuilderCallback()
{
public void doBuild(InstructionBuilder builder)
{
@@ -577,7 +596,7 @@ public class PropertyConduitSourceImpl i
private void implementGetter(final Type activeType, final Method readMethod)
{
- plasticClass.introduceMethod(GET, new InstructionBuilderCallback()
+ plasticClass.introduceMethod(ConduitMethods.GET, new InstructionBuilderCallback()
{
public void doBuild(InstructionBuilder builder)
{
@@ -598,7 +617,7 @@ public class PropertyConduitSourceImpl i
private void implementRangeOpGetter(final Tree rangeNode)
{
- plasticClass.introduceMethod(GET, new InstructionBuilderCallback()
+ plasticClass.introduceMethod(ConduitMethods.GET, new InstructionBuilderCallback()
{
public void doBuild(InstructionBuilder builder)
{
@@ -622,7 +641,7 @@ public class PropertyConduitSourceImpl i
// Implement get() as navigate, then do a method invocation based on node
// then, then pass (wrapped) result to delegate.invert()
- plasticClass.introduceMethod(GET, new InstructionBuilderCallback()
+ plasticClass.introduceMethod(ConduitMethods.GET, new InstructionBuilderCallback()
{
public void doBuild(InstructionBuilder builder)
{
@@ -752,7 +771,7 @@ public class PropertyConduitSourceImpl i
private void implementListGetter(final Tree listNode)
{
- plasticClass.introduceMethod(GET, new InstructionBuilderCallback()
+ plasticClass.introduceMethod(ConduitMethods.GET, new InstructionBuilderCallback()
{
public void doBuild(InstructionBuilder builder)
{
@@ -789,7 +808,8 @@ public class PropertyConduitSourceImpl i
private void implementNoOpSetter()
{
- implementNoOpMethod(SET, "Expression '%s' for class %s is read-only.", expression, rootType.getName());
+ implementNoOpMethod(ConduitMethods.SET, "Expression '%s' for class %s is read-only.", expression,
+ rootType.getName());
}
public void implementNoOpMethod(MethodDescription method, String format, Object... arguments)
@@ -1160,6 +1180,8 @@ public class PropertyConduitSourceImpl i
literalTrue = createLiteralConduit(Boolean.class, true);
literalFalse = createLiteralConduit(Boolean.class, false);
literalNull = createLiteralConduit(Void.class, null);
+
+ sharedDelegate = new PropertyConduitDelegate(typeCoercer);
}
public PropertyConduit create(Class rootClass, String expression)
@@ -1309,8 +1331,8 @@ public class PropertyConduitSourceImpl i
private <T> PropertyConduit createLiteralConduit(Class<T> type, T value)
{
- return new LiteralPropertyConduit(type, invariantAnnotationProvider, interner.format(
- "LiteralPropertyConduit[%s]", value), typeCoercer, value);
+ return new LiteralPropertyConduit(typeCoercer, type, invariantAnnotationProvider, interner.format(
+ "LiteralPropertyConduit[%s]", value), value);
}
private Tree parse(String expression)