You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2007/05/13 20:01:01 UTC

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

Author: hlship
Date: Sun May 13 11:01:00 2007
New Revision: 537622

URL: http://svn.apache.org/viewvc?view=rev&rev=537622
Log:
TAPESTRY-1434: Service builder methods do not allow services to be defined in terms of non-interface class, even though ServiceBinder does

Added:
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/ConcreteServiceBuilderModule.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/BuilderMethodModule.java
Modified:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImpl.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImpl.java?view=diff&rev=537622&r1=537621&r2=537622
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImpl.java Sun May 13 11:01:00 2007
@@ -281,8 +281,7 @@
 
         // If the method name was just "build()", then work from the return type.
 
-        if (serviceId.equals(""))
-            serviceId = InternalUtils.lastTerm(method.getReturnType().getName());
+        if (serviceId.equals("")) serviceId = method.getReturnType().getSimpleName();
 
         // Any number of parameters is fine, we'll adapt. Eventually we have to check
         // that we can satisfy the parameters requested. Thrown exceptions of the method
@@ -291,7 +290,7 @@
 
         Class returnType = method.getReturnType();
 
-        if (!returnType.isInterface())
+        if (returnType.isPrimitive() || returnType.isArray())
         {
             _log.warn(buildMethodWrongReturnType(method), null);
             return;

Added: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/ConcreteServiceBuilderModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/ConcreteServiceBuilderModule.java?view=auto&rev=537622
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/ConcreteServiceBuilderModule.java (added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/ConcreteServiceBuilderModule.java Sun May 13 11:01:00 2007
@@ -0,0 +1,24 @@
+// Copyright 2007 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.tapestry.ioc;
+
+public class ConcreteServiceBuilderModule
+{
+    /** Of course, this is silly to do now that there is {@link ServiceBinder}. */
+    public StringHolderImpl buildStringHolder()
+    {
+        return new StringHolderImpl();
+    }
+}

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java?view=diff&rev=537622&r1=537621&r2=537622
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java Sun May 13 11:01:00 2007
@@ -545,7 +545,22 @@
                     ex.getMessage(),
                     "Service interface java.lang.Runnable is matched by 2 services: Barney, Fred.  Automatic dependency resolution requires that exactly one service implement the interface.");
         }
+    }
 
+    @Test
+    public void service_build_method_return_type_not_interface()
+    {
+        Registry r = buildRegistry(ConcreteServiceBuilderModule.class);
+
+        StringHolder holder = r.getService(StringHolder.class);
+
+        // No interface means no proxy.
+
+        assertTrue(holder instanceof StringHolderImpl);
+
+        // But the implementation is cached
+
+        assertSame(r.getService(StringHolder.class), holder);
     }
 
     @Test

Added: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/BuilderMethodModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/BuilderMethodModule.java?view=auto&rev=537622
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/BuilderMethodModule.java (added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/BuilderMethodModule.java Sun May 13 11:01:00 2007
@@ -0,0 +1,23 @@
+// Copyright 2007 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.tapestry.ioc.internal;
+
+public class BuilderMethodModule
+{
+    public String[] buildStringArray()
+    {
+        return null;
+    }
+}

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImplTest.java?view=diff&rev=537622&r1=537621&r2=537622
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImplTest.java Sun May 13 11:01:00 2007
@@ -182,6 +182,24 @@
     }
 
     @Test
+    public void builder_method_returns_array() throws Exception
+    {
+        Method m = BuilderMethodModule.class.getMethod("buildStringArray");
+
+        Log log = mockLog();
+
+        log.warn(IOCMessages.buildMethodWrongReturnType(m), null);
+
+        replay();
+
+        ModuleDef md = new DefaultModuleDefImpl(BuilderMethodModule.class, log, null);
+
+        assertTrue(md.getServiceIds().isEmpty());
+
+        verify();
+    }
+
+    @Test
     public void decorator_method_returns_void() throws Exception
     {
         invalidDecoratorMethod(VoidDecoratorMethodModule.class, "decorateVoid");