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 2010/05/27 02:09:18 UTC

svn commit: r948639 - in /tapestry/tapestry5/trunk: tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/CoercionTuple.java

Author: hlship
Date: Thu May 27 00:09:18 2010
New Revision: 948639

URL: http://svn.apache.org/viewvc?rev=948639&view=rev
Log:
Add a static create() method to CoercionTuple to make it easier to instantiate (without having to repeat all the generic types)

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/CoercionTuple.java

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=948639&r1=948638&r2=948639&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 Thu May 27 00:09:18 2010
@@ -938,17 +938,17 @@ public final class TapestryModule
      */
     public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration, Context context,
 
-            @Symbol(SymbolConstants.FILE_CHECK_INTERVAL)
-            @IntermediateType(TimeInterval.class)
-            long checkInterval,
+    @Symbol(SymbolConstants.FILE_CHECK_INTERVAL)
+    @IntermediateType(TimeInterval.class)
+    long checkInterval,
+
+    @Symbol(SymbolConstants.FILE_CHECK_UPDATE_TIMEOUT)
+    @IntermediateType(TimeInterval.class)
+    long updateTimeout,
 
-            @Symbol(SymbolConstants.FILE_CHECK_UPDATE_TIMEOUT)
-            @IntermediateType(TimeInterval.class)
-            long updateTimeout,
-
-            UpdateListenerHub updateListenerHub,
+    UpdateListenerHub updateListenerHub,
 
-            URLRewriter urlRewriter)
+    URLRewriter urlRewriter)
     {
         RequestFilter staticFilesFilter = new StaticFilesFilter(context);
 
@@ -1068,41 +1068,42 @@ public final class TapestryModule
     @Core
     final AssetSource assetSource)
     {
-        add(configuration, ComponentResources.class, PropertyOverrides.class,
+        configuration.add(CoercionTuple.create(ComponentResources.class, PropertyOverrides.class,
                 new Coercion<ComponentResources, PropertyOverrides>()
                 {
                     public PropertyOverrides coerce(ComponentResources input)
                     {
                         return new PropertyOverridesImpl(input);
                     }
-                });
+                }));
 
-        add(configuration, String.class, SelectModel.class, new Coercion<String, SelectModel>()
+        configuration.add(CoercionTuple.create(String.class, SelectModel.class, new Coercion<String, SelectModel>()
         {
             public SelectModel coerce(String input)
             {
                 return TapestryInternalUtils.toSelectModel(input);
             }
-        });
+        }));
 
-        add(configuration, Map.class, SelectModel.class, new Coercion<Map, SelectModel>()
+        configuration.add(CoercionTuple.create(Map.class, SelectModel.class, new Coercion<Map, SelectModel>()
         {
             @SuppressWarnings("unchecked")
             public SelectModel coerce(Map input)
             {
                 return TapestryInternalUtils.toSelectModel(input);
             }
-        });
+        }));
 
-        add(configuration, Collection.class, GridDataSource.class, new Coercion<Collection, GridDataSource>()
-        {
-            public GridDataSource coerce(Collection input)
-            {
-                return new CollectionGridDataSource(input);
-            }
-        });
+        configuration.add(CoercionTuple.create(Collection.class, GridDataSource.class,
+                new Coercion<Collection, GridDataSource>()
+                {
+                    public GridDataSource coerce(Collection input)
+                    {
+                        return new CollectionGridDataSource(input);
+                    }
+                }));
 
-        add(configuration, void.class, GridDataSource.class, new Coercion<Void, GridDataSource>()
+        configuration.add(CoercionTuple.create(void.class, GridDataSource.class, new Coercion<Void, GridDataSource>()
         {
             private final GridDataSource source = new NullDataSource();
 
@@ -1110,7 +1111,7 @@ public final class TapestryModule
             {
                 return source;
             }
-        });
+        }));
 
         add(configuration, GridPagerPosition.class);
         add(configuration, InsertPosition.class);
@@ -1118,24 +1119,24 @@ public final class TapestryModule
         add(configuration, LoopFormState.class);
         add(configuration, SubmitMode.class);
 
-        add(configuration, List.class, SelectModel.class, new Coercion<List, SelectModel>()
+        configuration.add(CoercionTuple.create(List.class, SelectModel.class, new Coercion<List, SelectModel>()
         {
             @SuppressWarnings("unchecked")
             public SelectModel coerce(List input)
             {
                 return TapestryInternalUtils.toSelectModel(input);
             }
-        });
+        }));
 
-        add(configuration, String.class, Pattern.class, new Coercion<String, Pattern>()
+        configuration.add(CoercionTuple.create(String.class, Pattern.class, new Coercion<String, Pattern>()
         {
             public Pattern coerce(String input)
             {
                 return Pattern.compile(input);
             }
-        });
+        }));
 
-        add(configuration, ComponentResourcesAware.class, ComponentResources.class,
+        configuration.add(CoercionTuple.create(ComponentResourcesAware.class, ComponentResources.class,
                 new Coercion<ComponentResourcesAware, ComponentResources>()
                 {
 
@@ -1143,57 +1144,59 @@ public final class TapestryModule
                     {
                         return input.getComponentResources();
                     }
-                });
+                }));
 
-        add(configuration, String.class, Renderable.class, new Coercion<String, Renderable>()
+        configuration.add(CoercionTuple.create(String.class, Renderable.class, new Coercion<String, Renderable>()
         {
             public Renderable coerce(String input)
             {
                 return new StringRenderable(input);
             }
-        });
+        }));
 
-        add(configuration, Renderable.class, Block.class, new Coercion<Renderable, Block>()
+        configuration.add(CoercionTuple.create(Renderable.class, Block.class, new Coercion<Renderable, Block>()
         {
             public Block coerce(Renderable input)
             {
                 return new RenderableAsBlock(input);
             }
-        });
+        }));
 
-        add(configuration, String.class, DateFormat.class, new Coercion<String, DateFormat>()
+        configuration.add(CoercionTuple.create(String.class, DateFormat.class, new Coercion<String, DateFormat>()
         {
             public DateFormat coerce(String input)
             {
                 return new SimpleDateFormat(input, threadLocale.getLocale());
             }
-        });
+        }));
 
-        add(configuration, String.class, Resource.class, new Coercion<String, Resource>()
+        configuration.add(CoercionTuple.create(String.class, Resource.class, new Coercion<String, Resource>()
         {
             public Resource coerce(String input)
             {
                 return assetSource.resourceForPath(input);
             }
-        });
+        }));
 
-        add(configuration, Renderable.class, RenderCommand.class, new Coercion<Renderable, RenderCommand>()
-        {
-            public RenderCommand coerce(final Renderable input)
-            {
-                return new RenderCommand()
+        configuration.add(CoercionTuple.create(Renderable.class, RenderCommand.class,
+                new Coercion<Renderable, RenderCommand>()
                 {
-                    public void render(MarkupWriter writer, RenderQueue queue)
+                    public RenderCommand coerce(final Renderable input)
                     {
-                        input.render(writer);
+                        return new RenderCommand()
+                        {
+                            public void render(MarkupWriter writer, RenderQueue queue)
+                            {
+                                input.render(writer);
+                            }
+                        };
                     }
-                };
-            }
-        });
+                }));
 
-        add(configuration, PrimaryKeyEncoder.class, ValueEncoder.class, new PrimaryKeyEncoder2ValueEncoder(coercer));
+        configuration.add(CoercionTuple.create(PrimaryKeyEncoder.class, ValueEncoder.class,
+                new PrimaryKeyEncoder2ValueEncoder(coercer)));
 
-        add(configuration, Date.class, Calendar.class, new Coercion<Date, Calendar>()
+        configuration.add(CoercionTuple.create(Date.class, Calendar.class, new Coercion<Date, Calendar>()
         {
             public Calendar coerce(Date input)
             {
@@ -1201,12 +1204,12 @@ public final class TapestryModule
                 calendar.setTime(input);
                 return calendar;
             }
-        });
+        }));
     }
 
     private static <T extends Enum> void add(Configuration<CoercionTuple> configuration, Class<T> enumType)
     {
-        add(configuration, String.class, enumType, StringToEnumCoercion.create(enumType));
+        configuration.add(CoercionTuple.create(String.class, enumType, StringToEnumCoercion.create(enumType)));
     }
 
     /**
@@ -1224,14 +1227,6 @@ public final class TapestryModule
         configuration.addInstance("Messages", MessagesConstraintGenerator.class);
     }
 
-    private static <S, T> void add(Configuration<CoercionTuple> configuration, Class<S> sourceType,
-            Class<T> targetType, Coercion<S, T> coercion)
-    {
-        CoercionTuple<S, T> tuple = new CoercionTuple<S, T>(sourceType, targetType, coercion);
-
-        configuration.add(tuple);
-    }
-
     private static void add(OrderedConfiguration<ComponentClassTransformWorker> configuration,
             Class<? extends Annotation> annotationClass, TransformMethodSignature lifecycleMethodSignature,
             String methodAlias)

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/CoercionTuple.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/CoercionTuple.java?rev=948639&r1=948638&r2=948639&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/CoercionTuple.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/CoercionTuple.java Thu May 27 00:09:18 2010
@@ -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,
@@ -18,13 +18,16 @@ import static org.apache.tapestry5.ioc.i
 
 /**
  * An immutable object that represents a mapping from one type to another. This is also the contribution type when
- * building the {@link org.apache.tapestry5.ioc.services.TypeCoercer} service. Wraps a {@link
- * org.apache.tapestry5.ioc.services.Coercion} object that performs the work with additional properties that describe
+ * building the {@link org.apache.tapestry5.ioc.services.TypeCoercer} service. Wraps a
+ * {@link org.apache.tapestry5.ioc.services.Coercion} object that performs the work with additional properties that
+ * describe
  * the input and output types of the coercion, needed when searching for an appropriate coercion (or sequence of
  * coercions).
- *
- * @param <S> source (input) type
- * @param <T> target (output) type
+ * 
+ * @param <S>
+ *            source (input) type
+ * @param <T>
+ *            target (output) type
  */
 public final class CoercionTuple<S, T>
 {
@@ -60,7 +63,8 @@ public final class CoercionTuple<S, T>
 
     private String convert(Class type)
     {
-        if (void.class.equals(type)) return "null";
+        if (void.class.equals(type))
+            return "null";
 
         String name = ClassFabUtils.toJavaClassName(type);
 
@@ -83,15 +87,28 @@ public final class CoercionTuple<S, T>
     }
 
     /**
+     * Convenience constructor to help with generics.
+     * 
+     * @since 5.2.0
+     */
+    public static <S, T> CoercionTuple<S, T> create(Class<S> sourceType, Class<T> targetType, Coercion<S, T> coercion)
+    {
+        return new CoercionTuple<S, T>(sourceType, targetType, coercion);
+    }
+
+    /**
      * Internal-use constructor.
-     *
-     * @param sourceType the source (or input) type of the coercion
-     * @param targetType the target (or output) type of the coercion
-     * @param coercion   the object that performs the coercion
-     * @param wrap       if true, the coercion is wrapped to provide a useful toString()
+     * 
+     * @param sourceType
+     *            the source (or input) type of the coercion
+     * @param targetType
+     *            the target (or output) type of the coercion
+     * @param coercion
+     *            the object that performs the coercion
+     * @param wrap
+     *            if true, the coercion is wrapped to provide a useful toString()
      */
-    public CoercionTuple(Class<S> sourceType, Class<T> targetType, Coercion<S, T> coercion,
-                         boolean wrap)
+    public CoercionTuple(Class<S> sourceType, Class<T> targetType, Coercion<S, T> coercion, boolean wrap)
     {
         notNull(sourceType, "sourceType");
         notNull(targetType, "targetType");