tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r730611 - in /tapestry/tapestry5/trunk: tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ tapestry-ioc/src/site/apt/ tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ tapestry-spring/src/site/apt/
Date Thu, 01 Jan 2009 21:21:30 GMT
Author: hlship
Date: Thu Jan  1 13:21:29 2009
New Revision: 730611

URL: http://svn.apache.org/viewvc?rev=730611&view=rev
Log:
TAP5-429: Tapestry should throw an exception when a contribute method of a module class does
not match a known service

Added:
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/InvalidContributeDefModule.java
Modified:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/injection.apt
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
    tapestry/tapestry5/trunk/tapestry-spring/src/site/apt/index.apt

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=730611&r1=730610&r2=730611&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
Thu Jan  1 13:21:29 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 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.
@@ -173,12 +173,39 @@
         addBuiltin(PERTHREAD_MANAGER_SERVICE_ID, PerthreadManager.class, perthreadManager);
         addBuiltin(REGISTRY_SHUTDOWN_HUB_SERVICE_ID, RegistryShutdownHub.class, registryShutdownHub);
 
+        validateContributeDefs(moduleDefs);
+
         scoreboardAndTracker.startup();
 
         SerializationSupport.setProvider(this);
     }
 
     /**
+     * Validate that each module's ContributeDefs correspond to an actual service.
+     */
+    private void validateContributeDefs(Collection<ModuleDef> moduleDefs)
+    {
+        Set<ContributionDef> contributionDefs = CollectionFactory.newSet();
+
+        for (ModuleDef module : moduleDefs)
+        {
+            contributionDefs.addAll(module.getContributionDefs());
+        }
+
+        for (ContributionDef cd : contributionDefs)
+        {
+            String serviceId = cd.getServiceId();
+
+            if (!serviceIdToModule.containsKey(serviceId))
+            {
+                throw new IllegalArgumentException(
+                        String.format("Contibution %s is for service '%s', which does not
exist.",
+                                      cd, serviceId));
+            }
+        }
+    }
+
+    /**
      * It's not unreasonable for an eagerly-loaded service to decide to start a thread, at
which point we raise issues
      * about improper publishing of the Registry instance from the RegistryImpl constructor.
Moving eager loading of
      * services out to its own method should ensure thread safety.

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/injection.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/injection.apt?rev=730611&r1=730610&r2=730611&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/injection.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/injection.apt Thu Jan  1 13:21:29 2009
@@ -77,42 +77,32 @@
    if a resource can be injected.  When the Inject annotation is present, this step is skipped
(this is necessary
    when the object to be injected has a type that conflicts with a resource type, such as
String).
 
-   What resources are available depend on what kind of operation is occuring:
+   [org.slf4j.Logger]
+   The Logger of the service being constructed (or the logger of the Module class being instantiated).
 
-   * Autobuilt object: no special resources
+   [String]
+   The service id of the service being constructed.
 
-   * Contributor method:
+   [{{{../apidocs/org/apache/tapestry5/ioc/ObjectLocator.html}ObjectLocator}}]
+   For contribute methods, used to locate additional objects.
 
-     * The appropriate Configuration, OrderedConfiguration or MappedConfiguration instance.
+   [{{{../apidocs/org/apache/tapestry5/ioc/ServiceResources.html}ServiceResources}}]
+   For service builder methods, an extended version of ObjectLocator.
 
-     *  org.slf4j.Logger: Logger for the service, based on the class name of the module and
the service id
-    
-   * Service builder method:
+   [Class]
+   The service interface type.
 
-     * String: the service id
+   [{{{../apidocs/org/apache/tapestry5/ioc/OperationTracker.html}OperationTracker}}]
+   Used to track deeply nested operations so that errors can be reported sensibly.
 
-     * {{{../apidocs/org/apache/tapestry5/ioc/ObjectLocator.html}ObjectLocator}} or
-       {{{../apidocs/org/apache/tapestry5/ioc/ServiceResources.html}ServiceResources}}: Used
to lookup or autobuild additional objects;
-       the same object is passed for both types
+   [Object, or service interface type]
+   Passed to decorator methods.
 
-     *  org.slf4j.Logger: Logger for the service, based on the class name of the module and
the service id
+   [Collection, List, Map]
+   Assembled service configurations passed to service builder methods (or service class constructors).
 
-     * Class: Java class for the service's service interface
-
-     * Collection, List, Map: Combined service contributions
-
-     []
-
-   * Service Implementation Constructor: Same as service builder method.
-
-   * Service decorator method:  Same as service bulider method, without service contributions
(Collection, List, Map), plus:
-
-     Object or <Service Interface>: the delegate for the interceptor created by the
decorator method
-
-   []
-
-   In addition, {{{../apidocs/org/apache/tapestry5/ioc/OperationTracker.html}OperationTracker}}
is available
-   for injection via constructor, method or field.
+   [Configuration, OrderedConfiguration, MappedConfiguration]
+   Configuration passed to contribute methods, to build service configurations.
 
    If field type does not match any of the available resource types, or the Inject annotation
is present,
    logic continues to the next step.

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java?rev=730611&r1=730610&r2=730611&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
Thu Jan  1 13:21:29 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 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.
@@ -1065,4 +1065,23 @@
 
         assertEquals(g.getGreeting(), "Greetings from ServiceIdGreeter.");
     }
+
+    /**
+     * TAP5-429
+     */
+    @Test
+    public void contribute_to_unknown_service()
+    {
+        try
+        {
+            buildRegistry(InvalidContributeDefModule.class);
+            unreachable();
+        }
+        catch (IllegalArgumentException ex)
+        {
+            assertMessageContains(ex,
+                                  "Contibution org.apache.tapestry5.ioc.InvalidContributeDefModule.contributeDoesNotExist(Configuration)",
+                                  "is for service 'DoesNotExist', which does not exist.");
+        }
+    }
 }

Added: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/InvalidContributeDefModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/InvalidContributeDefModule.java?rev=730611&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/InvalidContributeDefModule.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/InvalidContributeDefModule.java
Thu Jan  1 13:21:29 2009
@@ -0,0 +1,26 @@
+// 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;
+
+public class InvalidContributeDefModule
+{
+    /**
+     * Its a contribute method, but to a service that does not exist.
+     */
+    public static void contributeDoesNotExist(Configuration<Object> configuration)
+    {
+
+    }
+}

Modified: tapestry/tapestry5/trunk/tapestry-spring/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/site/apt/index.apt?rev=730611&r1=730610&r2=730611&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/site/apt/index.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/site/apt/index.apt Thu Jan  1 13:21:29 2009
@@ -18,6 +18,9 @@
  <<Spring Beans are no longer exposed as services.>>
 
  You no longer create a ContextLoaderListener.
+
+ These changes represent an unfortunate backwards compatibility issue.
+ If necessary, you can still use tapestry-spring version 5.0.18 with the rest of Tapestry.
   
 Spring Version
 



Mime
View raw message