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/20 21:14:24 UTC

svn commit: r1148905 - in /tapestry/tapestry5/trunk/tapestry-ioc/src: main/java/org/apache/tapestry5/ioc/ main/java/org/apache/tapestry5/ioc/internal/ test/java/org/apache/tapestry5/ioc/ test/java/org/apache/tapestry5/ioc/internal/

Author: hlship
Date: Wed Jul 20 19:14:21 2011
New Revision: 1148905

URL: http://svn.apache.org/viewvc?rev=1148905&view=rev
Log:
TAP5-1565: OrderedConfiguration should have methods to make it easy to add elements in sequential order

Modified:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FredModule.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java?rev=1148905&r1=1148904&r2=1148905&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java Wed Jul 20 19:14:21 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2008, 2009, 2010 The Apache Software Foundation
+// Copyright 2006, 2008, 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.
@@ -26,7 +26,10 @@ package org.apache.tapestry5.ioc;
  * </ul>
  * <p/>
  * The service defines the <em>type</em> of contribution, in terms of a base class or service interface. Contributions
- * must be compatible with the type.
+ * must be compatible with the type, or be {@linkplain org.apache.tapestry5.ioc.services.TypeCoercer coercable} to the type.
+ *
+ * @see org.apache.tapestry5.ioc.annotations.Contribute
+ * @see org.apache.tapestry5.ioc.annotations.UsesConfiguration
  */
 public interface OrderedConfiguration<T>
 {
@@ -34,25 +37,23 @@ public interface OrderedConfiguration<T>
      * Adds an ordered object to a service's contribution. Each object has an id (which must be unique). Optionally,
      * pre-requisites (a list of ids that must precede this object) and post-requisites (ids that must follow) can be
      * provided.
-     * 
-     * @param id
-     *            a unique id for the object; the id will be fully qualified with the contributing module's id
-     * @param constraints
-     *            used to order the object relative to other contributed objects
-     * @parm object to add to the service's configuration
+     * <p/>
+     * <p>If no constraints are supplied, then an implicit constraint is supplied: after the previously
+     * contributed id <em>within the same contribution method</em>.
+     *
+     * @param id          a unique id for the object; the id will be fully qualified with the contributing module's id
+     * @param constraints used to order the object relative to other contributed objects
+     * @param object      to add to the service's configuration
      */
     void add(String id, T object, String... constraints);
 
     /**
      * Overrides a normally contributed object. Each override must match a single normally contributed object.
-     * 
-     * @param id
-     *            identifies object to override
-     * @param object
-     *            overriding object (may be null)
-     * @param constraints
-     *            contrains for the overridden object, replacing constraints for the original object (even if
-     *            omitted, in which case the override object will have no orderring contraints)
+     *
+     * @param id          identifies object to override
+     * @param object      overriding object (may be null)
+     * @param constraints constraints for the overridden object, replacing constraints for the original object (even if
+     *                    omitted, in which case the override object will have no ordering constraints)
      * @since 5.1.0.0
      */
     void override(String id, T object, String... constraints);
@@ -61,28 +62,22 @@ public interface OrderedConfiguration<T>
      * Adds an ordered object by instantiating (with dependencies) the indicated class. When the configuration type is
      * an interface and the class to be contributed is a local file,
      * then a reloadable proxy for the class will be created and contributed.
-     * 
-     * @param id
-     *            of contribution (used for ordering)
-     * @param clazz
-     *            class to instantiate
-     * @param constraints
-     *            used to order the object relative to other contributed objects
+     *
+     * @param id          of contribution (used for ordering)
+     * @param clazz       class to instantiate
+     * @param constraints used to order the object relative to other contributed objects
      * @since 5.1.0.0
      */
     void addInstance(String id, Class<? extends T> clazz, String... constraints);
 
     /**
      * Instantiates an object and adds it as an override. When the configuration type is an interface and the class to
-     * be contributed is a local file,
-     * then a reloadable proxy for the class will be created and contributed.
-     * 
-     * @param id
-     *            of object to override
-     * @param clazz
-     *            to instantiate
-     * @param constraints
-     *            override contraints
+     * be contributed is a local file, then a reloadable proxy for the class will be created and contributed.
+     *
+     * @param id          of object to override
+     * @param clazz       to instantiate
+     * @param constraints constraints for the overridden object, replacing constraints for the original object (even if
+     *                    omitted, in which case the override object will have no ordering constraints)
      * @since 5.1.0.0
      */
     void overrideInstance(String id, Class<? extends T> clazz, String... constraints);

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java?rev=1148905&r1=1148904&r2=1148905&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java Wed Jul 20 19:14:21 2011
@@ -655,7 +655,7 @@ public class RegistryImpl implements Reg
         for (final ContributionDef def : contributions)
         {
             final OrderedConfiguration<T> validating = new ValidatingOrderedConfigurationWrapper<T>(valueType,
-                    resources, typeCoercerProxy, orderer, overrides, def, serviceId);
+                    resources, typeCoercerProxy, orderer, overrides, def);
 
             String description = IOCMessages.invokingMethod(def);
 

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java?rev=1148905&r1=1148904&r2=1148905&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java Wed Jul 20 19:14:21 2011
@@ -14,18 +14,18 @@
 
 package org.apache.tapestry5.ioc.internal;
 
-import java.util.Map;
-
 import org.apache.tapestry5.ioc.ObjectLocator;
 import org.apache.tapestry5.ioc.OrderedConfiguration;
 import org.apache.tapestry5.ioc.def.ContributionDef;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.ioc.internal.util.Orderer;
 
+import java.util.Map;
+
 /**
  * Wraps a {@link java.util.List} as a {@link org.apache.tapestry5.ioc.OrderedConfiguration}, implementing validation of
  * values provided to an {@link org.apache.tapestry5.ioc.OrderedConfiguration}.
- * 
+ *
  * @param <T>
  */
 public class ValidatingOrderedConfigurationWrapper<T> extends AbstractConfigurationImpl<T> implements
@@ -35,17 +35,18 @@ public class ValidatingOrderedConfigurat
 
     private final Orderer<T> orderer;
 
-    private final String serviceId;
-
     private final Class<T> expectedType;
 
     private final Map<String, OrderedConfigurationOverride<T>> overrides;
 
     private final ContributionDef contribDef;
 
+    // Used to supply a default ordering constraint when none is supplied.
+    private String priorId;
+
     public ValidatingOrderedConfigurationWrapper(Class<T> expectedType, ObjectLocator locator,
-            TypeCoercerProxy typeCoercer, Orderer<T> orderer, Map<String, OrderedConfigurationOverride<T>> overrides,
-            ContributionDef contribDef, String serviceId)
+                                                 TypeCoercerProxy typeCoercer, Orderer<T> orderer, Map<String, OrderedConfigurationOverride<T>> overrides,
+                                                 ContributionDef contribDef)
     {
         super(expectedType, locator);
         this.typeCoercer = typeCoercer;
@@ -53,7 +54,6 @@ public class ValidatingOrderedConfigurat
         this.orderer = orderer;
         this.overrides = overrides;
         this.contribDef = contribDef;
-        this.serviceId = serviceId;
         this.expectedType = expectedType;
     }
 
@@ -61,7 +61,18 @@ public class ValidatingOrderedConfigurat
     {
         T coerced = object == null ? null : typeCoercer.coerce(object, expectedType);
 
+        // https://issues.apache.org/jira/browse/TAP5-1565
+        // Order each added contribution after the previously added contribution
+        // (in the same method) if no other constraint is supplied.
+        if (constraints.length == 0 && priorId != null)
+        {
+            // Ugly: reassigning parameters is yuck.
+            constraints = new String[]{"after:" + priorId};
+        }
+
         orderer.add(id, coerced, constraints);
+
+        priorId = id;
     }
 
     public void override(String id, T object, String... constraints)

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FredModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FredModule.java?rev=1148905&r1=1148904&r2=1148905&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FredModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FredModule.java Wed Jul 20 19:14:21 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2009 The Apache Software Foundation
+// Copyright 2006, 2007, 2009, 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.
@@ -93,10 +93,8 @@ public class FredModule
 
     public void contributeOrderedNames(OrderedConfiguration<String> configuration)
     {
-        // Order "FRED" after "BARNEY"
-
-        configuration.add("fred", "FRED", "after:barney");
         configuration.add("barney", "BARNEY");
+        configuration.add("fred", "FRED");
     }
 
     public void contributeUnorderedNames(Configuration<String> configuration)

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java?rev=1148905&r1=1148904&r2=1148905&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java Wed Jul 20 19:14:21 2011
@@ -46,7 +46,7 @@ public class ValidatingOrderedConfigurat
         replay();
 
         OrderedConfiguration<Runnable> wrapper = new ValidatingOrderedConfigurationWrapper<Runnable>(Runnable.class,
-                null, tc, orderer, null, null, "Service");
+                null, tc, orderer, null, null);
 
         wrapper.add("id", contribution, "after:pre", "before:post");
 
@@ -76,7 +76,7 @@ public class ValidatingOrderedConfigurat
         replay();
 
         OrderedConfiguration<Map> wrapper = new ValidatingOrderedConfigurationWrapper<Map>(Map.class, locator, tc,
-                orderer, null, null, "Service");
+                orderer, null, null);
 
         wrapper.addInstance("id", HashMap.class, "after:pre", "before:post");
 
@@ -94,7 +94,7 @@ public class ValidatingOrderedConfigurat
         replay();
 
         OrderedConfiguration<Runnable> wrapper = new ValidatingOrderedConfigurationWrapper<Runnable>(Runnable.class,
-                null, null, orderer, null, null, "Service");
+                null, null, orderer, null, null);
 
         wrapper.add("id", null);