Author: drobiazko
Date: Thu Oct 22 19:05:58 2009
New Revision: 828818

URL: http://svn.apache.org/viewvc?rev=828818&view=rev
Log:
TAP5-889: Provide fluent API for order constraints of contributions

Added:
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderConstraint.java
   (with props)
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderConstraintBuilder.java
   (with props)
    
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/OrderConstraintBuilderTest.java
   (with props)
Modified:
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java

Added: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderConstraint.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderConstraint.java?rev=828818&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderConstraint.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderConstraint.java
 Thu Oct 22 19:05:58 2009
@@ -0,0 +1,72 @@
+// Copyright 2009 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.
+// You may obtain a copy of the License at
+//
+//     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,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package org.apache.tapestry5.ioc;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents an order constraints for {...@link OrderedConfiguration}.
+ * 
+ * @since 5.2.0.0
+ */
+public class OrderConstraint
+{
+    private static final String ALL = "*";
+    
+    private List<String> constraints = new ArrayList<String>();
+    
+    /**
+     * Adds an <i>after:id</i> constraint.
+     */
+    public OrderConstraint after(String id)
+    {
+        constraints.add("after:" + id);
+        
+        return this;
+    }
+    
+    /**
+     * Adds an <i>after:*</i> constraint.
+     */
+    public OrderConstraint afterAll()
+    {
+        return after(ALL);
+    }
+    /**
+     * Adds a <i>before:id</i> constraint.
+     */
+    public OrderConstraint before(String id)
+    {
+        constraints.add("before:" + id);
+        
+        return this;
+    }
+    
+    /**
+     * Adds a <i>before:*</i> constraint.
+     */
+    public OrderConstraint beforeAll()
+    {
+        return before(ALL);
+    }
+    
+    /**
+     * Returns all constraints as array of strings.
+     */
+    public String[] build()
+    {
+        return constraints.toArray(new String[]{});
+    }
+}

Propchange: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderConstraint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderConstraint.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderConstraintBuilder.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderConstraintBuilder.java?rev=828818&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderConstraintBuilder.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderConstraintBuilder.java
 Thu Oct 22 19:05:58 2009
@@ -0,0 +1,54 @@
+// Copyright 2009 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.
+// You may obtain a copy of the License at
+//
+//     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,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package org.apache.tapestry5.ioc;
+
+/**
+ * Constructs order constraints for {...@link OrderedConfiguration}.
+ * 
+ * @since 5.2.0.0
+ */
+public final class OrderConstraintBuilder
+{
+    /**
+     * Adds an <i>after:id</i> constraint.
+     */
+    public static OrderConstraint after(String id)
+    {
+        return new OrderConstraint().after(id);
+    }
+    
+    /**
+     * Adds an <i>after:*</i> constraint.
+     */
+    public static OrderConstraint afterAll()
+    {
+        return new OrderConstraint().afterAll();
+    }
+    
+    /**
+     * Adds a <i>before:id</i> constraint.
+     */
+    public static OrderConstraint before(String id)
+    {
+        return new OrderConstraint().before(id);
+    }
+    
+    /**
+     * Adds a <i>before:*</i> constraint.
+     */
+    public static OrderConstraint beforeAll()
+    {
+        return new OrderConstraint().beforeAll();
+    }
+}

Propchange: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderConstraintBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderConstraintBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java?rev=828818&r1=828817&r2=828818&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
 Thu Oct 22 19:05:58 2009
@@ -14,6 +14,9 @@
 
 package org.apache.tapestry5.ioc.services;
 
+import static org.apache.tapestry5.ioc.OrderConstraintBuilder.after;
+import static org.apache.tapestry5.ioc.OrderConstraintBuilder.before;
+
 import org.apache.tapestry5.IOCSymbols;
 import org.apache.tapestry5.ioc.*;
 import org.apache.tapestry5.ioc.annotations.*;
@@ -112,9 +115,9 @@
     {
         configuration.add("AnnotationBasedContributions", null);
 
-        configuration.addInstance("Value", ValueObjectProvider.class, 
"before:AnnotationBasedContributions");
-        configuration.addInstance("Symbol", SymbolObjectProvider.class, 
"before:AnnotationBasedContributions");
-        configuration.add("Autobuild", new AutobuildObjectProvider(), 
"before:AnnotationBasedContributions");
+        configuration.addInstance("Value", ValueObjectProvider.class, 
before("AnnotationBasedContributions").build());
+        configuration.addInstance("Symbol", SymbolObjectProvider.class, 
before("AnnotationBasedContributions").build());
+        configuration.add("Autobuild", new AutobuildObjectProvider(), 
before("AnnotationBasedContributions").build());
 
 
         ObjectProvider wrapper = new ObjectProvider()
@@ -125,7 +128,7 @@
             }
         };
 
-        configuration.add("ServiceOverride", wrapper, 
"after:AnnotationBasedContributions");
+        configuration.add("ServiceOverride", wrapper, 
after("AnnotationBasedContributions").build());
     }
 
     /**

Added: 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/OrderConstraintBuilderTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/OrderConstraintBuilderTest.java?rev=828818&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/OrderConstraintBuilderTest.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/OrderConstraintBuilderTest.java
 Thu Oct 22 19:05:58 2009
@@ -0,0 +1,68 @@
+// Copyright 2009 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.
+// You may obtain a copy of the License at
+//
+//     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,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package org.apache.tapestry5.ioc;
+
+import org.apache.tapestry5.ioc.test.IOCTestCase;
+import org.testng.annotations.Test;
+
+public class OrderConstraintBuilderTest extends IOCTestCase
+{
+    @Test
+    public void after()
+    {
+        String[] constraints = OrderConstraintBuilder.after("A").build();
+        
+        assertEquals(constraints.length, 1);
+        assertEquals(constraints[0], "after:A");
+    }
+
+    @Test
+    public void afterAll()
+    {
+        String[] constraints = OrderConstraintBuilder.afterAll().build();
+        
+        assertEquals(constraints.length, 1);
+        assertEquals(constraints[0], "after:*");
+    }
+
+    @Test
+    public void before()
+    {
+        String[] constraints = OrderConstraintBuilder.before("B").build();
+        
+        assertEquals(constraints.length, 1);
+        assertEquals(constraints[0], "before:B");
+    }
+
+    @Test
+    public void beforeAll()
+    {
+        String[] constraints = OrderConstraintBuilder.beforeAll().build();
+        
+        assertEquals(constraints.length, 1);
+        assertEquals(constraints[0], "before:*");
+    }
+    
+
+
+    @Test
+    public void combine()
+    {
+        String[] constraints = 
OrderConstraintBuilder.before("A").after("B").build();
+        
+        assertEquals(constraints.length, 2);
+        assertEquals(constraints[0], "before:A");
+        assertEquals(constraints[1], "after:B");
+    }
+}

Propchange: 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/OrderConstraintBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/OrderConstraintBuilderTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to