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 2008/09/17 12:30:59 UTC
svn commit: r696229 - in /tapestry/tapestry5/branches/5.1-dev: src/site/apt/
tapestry-core/src/main/java/org/apache/tapestry5/services/
tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/
tapestry-ioc/src/main/java/org/apache/tapestry5/ioc...
Author: hlship
Date: Wed Sep 17 03:30:57 2008
New Revision: 696229
URL: http://svn.apache.org/viewvc?rev=696229&view=rev
Log:
TAPESTRY-2678: Configuration interface should support contributing a class (which is autobuilt) in addition to an instance
Added:
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributeByClassModule.java
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/UppercaseStringTransformer.java
Modified:
tapestry/tapestry5/branches/5.1-dev/src/site/apt/index.apt
tapestry/tapestry5/branches/5.1-dev/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentEventRequestFilter.java
tapestry/tapestry5/branches/5.1-dev/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
tapestry/tapestry5/branches/5.1-dev/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Configuration.java
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/MappedConfiguration.java
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapper.java
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingMappedConfigurationWrapper.java
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/site/apt/configuration.apt
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperTest.java
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingMappedConfigurationWrapperTest.java
tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java
Modified: tapestry/tapestry5/branches/5.1-dev/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/src/site/apt/index.apt?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/src/site/apt/index.apt (original)
+++ tapestry/tapestry5/branches/5.1-dev/src/site/apt/index.apt Wed Sep 17 03:30:57 2008
@@ -86,6 +86,9 @@
New And Of Note
+ * IoC Service contributions may now be made in terms of classes (that are automatically instantiated) as well as
+ instances.
+
* Tapestry now bundles Prototype version 1.6.0.2.
* New methods have been added to
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentEventRequestFilter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentEventRequestFilter.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentEventRequestFilter.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentEventRequestFilter.java Wed Sep 17 03:30:57 2008
@@ -19,9 +19,7 @@
/**
* Filter interface for {@link ComponentEventRequestHandler}.
*
- * @see org.apache.tapestry5.services.TapestryModule#contributeComponentEventRequestHandler(org.apache.tapestry5.ioc.OrderedConfiguration,
- * org.apache.tapestry5.internal.services.RequestSecurityManager, ComponentEventRequestHandler,
- * org.apache.tapestry5.ioc.ObjectLocator)
+ * @see TapestryModule#contributeComponentEventRequestHandler(org.apache.tapestry5.ioc.OrderedConfiguration, org.apache.tapestry5.internal.services.RequestSecurityManager, ComponentEventRequestHandler)
*/
public interface ComponentEventRequestFilter
{
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java Wed Sep 17 03:30:57 2008
@@ -195,6 +195,7 @@
binder.bind(BindingFactory.class, AssetBindingFactory.class).withId("AssetBindingFactory");
binder.bind(BindingFactory.class, NullFieldStrategyBindingFactory.class).withId(
"NullFieldStrategyBindingFactory");
+ binder.bind(ApplicationStatePersistenceStrategy.class, SessionApplicationStatePersistenceStrategy.class).withId("SessionApplicationStatePersistenceStrategy");
}
// ========================================================================
@@ -330,7 +331,7 @@
// only have a single annotation, the order doesn't matter so much, as long as
// UnclaimedField is last.
- configuration.add("Cached", locator.autobuild(CachedWorker.class));
+ configuration.addInstance("Cached", CachedWorker.class);
configuration.add("Meta", new MetaWorker());
@@ -343,7 +344,7 @@
configuration.add("Mixin", new MixinWorker(resolver));
configuration.add("OnEvent", new OnEventWorker());
configuration.add("SupportsInformalParameters", new SupportsInformalParametersWorker());
- configuration.add("InjectPage", locator.autobuild(InjectPageWorker.class));
+ configuration.addInstance("InjectPage", InjectPageWorker.class);
configuration.add("InjectContainer", new InjectContainerWorker());
configuration.add("InjectComponent", new InjectComponentWorker());
configuration.add("RenderCommand", new RenderCommandWorker());
@@ -351,7 +352,7 @@
// Default values for parameters are often some form of injection, so make sure
// that Parameter fields are processed after injections.
- configuration.add("Parameter", locator.autobuild(ParameterWorker.class), "after:Inject*");
+ configuration.addInstance("Parameter", ParameterWorker.class, "after:Inject*");
// Workers for the component rendering state machine methods; this is in typical
// execution order.
@@ -378,9 +379,9 @@
configuration.add("Retain", new RetainWorker());
configuration.add("Persist", new PersistWorker());
- configuration.add("IncludeStylesheet", locator.autobuild(IncludeStylesheetWorker.class), "after:SetupRender");
- configuration.add("IncludeJavaScriptLibrary", locator.autobuild(IncludeJavaScriptLibraryWorker.class),
- "after:SetupRender");
+ configuration.addInstance("IncludeStylesheet", IncludeStylesheetWorker.class, "after:SetupRender");
+ configuration.addInstance("IncludeJavaScriptLibrary", IncludeJavaScriptLibraryWorker.class,
+ "after:SetupRender");
configuration.add("InvokePostRenderCleanupOnResources", new InvokePostRenderCleanupOnResourcesWorker());
@@ -389,11 +390,10 @@
configuration.add("Property", new PropertyWorker());
// These must come after Property, since they actually delete fields that may still have the annotation
- configuration.add("ApplicationState", locator.autobuild(ApplicationStateWorker.class),
- "after:Property");
- configuration.add("Environment", locator.autobuild(EnvironmentalWorker.class), "after:Property");
+ configuration.addInstance("ApplicationState", ApplicationStateWorker.class, "after:Property");
+ configuration.addInstance("Environment", EnvironmentalWorker.class, "after:Property");
- configuration.add("Log", locator.autobuild(LogWorker.class));
+ configuration.addInstance("Log", LogWorker.class);
// This one is always last. Any additional private fields that aren't annotated will
// be converted to clear out at the end of the request.
@@ -599,9 +599,7 @@
LocalizationSetter localizationSetter,
- final EndOfRequestListenerHub endOfRequestListenerHub,
-
- ObjectLocator locator)
+ final EndOfRequestListenerHub endOfRequestListenerHub)
{
RequestFilter staticFilesFilter = new StaticFilesFilter(context);
@@ -635,7 +633,7 @@
configuration.add("StaticFiles", staticFilesFilter);
- configuration.add("ErrorFilter", locator.autobuild(RequestErrorFilter.class));
+ configuration.addInstance("ErrorFilter", RequestErrorFilter.class);
configuration.add("StoreIntoGlobals", storeIntoGlobals, "after:StaticFiles", "before:ErrorFilter");
@@ -1284,11 +1282,6 @@
configuration.add("session", sessionStategy);
}
- public ApplicationStatePersistenceStrategy buildSessionApplicationStatePersistenceStrategy(ObjectLocator locator)
- {
- return locator.autobuild(SessionApplicationStatePersistenceStrategy.class);
- }
-
public void contributeAssetSource(MappedConfiguration<String, AssetFactory> configuration,
@ContextProvider AssetFactory contextAssetFactory,
@@ -1356,12 +1349,12 @@
*/
public void contributeAjaxComponentEventResultProcessor(
- MappedConfiguration<Class, ComponentEventResultProcessor> configuration, ObjectLocator locator)
+ MappedConfiguration<Class, ComponentEventResultProcessor> configuration)
{
- configuration.add(RenderCommand.class, locator.autobuild(RenderCommandComponentEventResultProcessor.class));
- configuration.add(Component.class, locator.autobuild(AjaxComponentInstanceEventResultProcessor.class));
- configuration.add(JSONObject.class, locator.autobuild(JSONObjectEventResultProcessor.class));
- configuration.add(JSONArray.class, locator.autobuild(JSONArrayEventResultProcessor.class));
+ configuration.addInstance(RenderCommand.class, RenderCommandComponentEventResultProcessor.class);
+ configuration.addInstance(Component.class, AjaxComponentInstanceEventResultProcessor.class);
+ configuration.addInstance(JSONObject.class, JSONObjectEventResultProcessor.class);
+ configuration.addInstance(JSONArray.class, JSONArrayEventResultProcessor.class);
configuration.add(StreamResponse.class, new StreamResponseResultProcessor(response));
}
@@ -1373,28 +1366,22 @@
* PageRenderRequestHandler}</dd> <dt>ComponentEvent</dt> <dd>Identifies the {@link ComponentEventRequestParameters}
* and forwards onto the {@link ComponentEventRequestHandler}</dd> </dl>
*/
- public void contributeMasterDispatcher(OrderedConfiguration<Dispatcher> configuration,
- ObjectLocator locator)
+ public void contributeMasterDispatcher(OrderedConfiguration<Dispatcher> configuration)
{
// Looks for the root path and renders the start page. This is maintained for compatibility
// with earlier versions of Tapestry 5, it is recommended that an Index page be used instead.
- configuration.add("RootPath",
- locator.autobuild(RootPathDispatcher.class),
- "before:Asset");
+ configuration.addInstance("RootPath", RootPathDispatcher.class, "before:Asset");
// This goes first because an asset to be streamed may have an file extension, such as
// ".html", that will confuse the later dispatchers.
- configuration.add("Asset",
- locator.autobuild(AssetDispatcher.class), "before:ComponentEvent");
+ configuration.addInstance("Asset", AssetDispatcher.class, "before:ComponentEvent");
- configuration.add("ComponentEvent", locator.autobuild(ComponentEventDispatcher.class),
- "before:PageRender");
+ configuration.addInstance("ComponentEvent", ComponentEventDispatcher.class, "before:PageRender");
- configuration.add("PageRender",
- locator.autobuild(PageRenderDispatcher.class));
+ configuration.addInstance("PageRender", PageRenderDispatcher.class);
}
/**
@@ -1407,9 +1394,7 @@
@InjectService("LocationRenderer")
ObjectRenderer locationRenderer,
- final TypeCoercer typeCoercer,
-
- ObjectLocator locator)
+ final TypeCoercer typeCoercer)
{
configuration.add(Object.class, new ObjectRenderer()
{
@@ -1419,7 +1404,7 @@
}
});
- configuration.add(Request.class, locator.autobuild(RequestRenderer.class));
+ configuration.addInstance(Request.class, RequestRenderer.class);
configuration.add(Location.class, locationRenderer);
@@ -1435,10 +1420,10 @@
configuration.add(ClassTransformation.class, preformatted);
- configuration.add(List.class, locator.autobuild(ListRenderer.class));
- configuration.add(Object[].class, locator.autobuild(ObjectArrayRenderer.class));
- configuration.add(ComponentResources.class, locator.autobuild(ComponentResourcesRenderer.class));
- configuration.add(EventContext.class, locator.autobuild(EventContextRenderer.class));
+ configuration.addInstance(List.class, ListRenderer.class);
+ configuration.addInstance(Object[].class, ObjectArrayRenderer.class);
+ configuration.addInstance(ComponentResources.class, ComponentResourcesRenderer.class);
+ configuration.addInstance(EventContext.class, EventContextRenderer.class);
}
@@ -1705,10 +1690,9 @@
* Contributes {@link ValueEncoderFactory}s for types: <ul> <li>Object <li>String <li>Enum </ul>
*/
@SuppressWarnings("unchecked")
- public static void contributeValueEncoderSource(MappedConfiguration<Class, ValueEncoderFactory> configuration,
- ObjectLocator locator)
+ public static void contributeValueEncoderSource(MappedConfiguration<Class, ValueEncoderFactory> configuration)
{
- configuration.add(Object.class, locator.autobuild(TypeCoercedValueEncoderFactory.class));
+ configuration.addInstance(Object.class, TypeCoercedValueEncoderFactory.class);
configuration.add(String.class, GenericValueEncoderFactory.create(new StringValueEncoder()));
configuration.add(Enum.class, new EnumValueEncoderFactory());
}
@@ -2042,8 +2026,8 @@
*/
public void contributeComponentEventRequestHandler(OrderedConfiguration<ComponentEventRequestFilter> configuration,
final RequestSecurityManager requestSecurityManager,
- @Ajax ComponentEventRequestHandler ajaxHandler,
- ObjectLocator locator)
+ @Ajax ComponentEventRequestHandler ajaxHandler
+ )
{
ComponentEventRequestFilter secureFilter = new ComponentEventRequestFilter()
{
@@ -2058,7 +2042,7 @@
configuration.add("Ajax", new AjaxFilter(request, ajaxHandler));
- configuration.add("ImmediateRender", locator.autobuild(ImmediateActionRenderResponseFilter.class));
+ configuration.addInstance("ImmediateRender", ImmediateActionRenderResponseFilter.class);
configuration.add("Secure", secureFilter, "before:Ajax");
}
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java Wed Sep 17 03:30:57 2008
@@ -134,12 +134,10 @@
*/
public static void contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer> config,
- HibernateConfigurer defaultHibernateConfigurer,
-
- ObjectLocator locator)
+ HibernateConfigurer defaultHibernateConfigurer)
{
config.add("Default", defaultHibernateConfigurer);
- config.add("PackageName", locator.autobuild(PackageNameHibernateConfigurer.class));
+ config.addInstance("PackageName", PackageNameHibernateConfigurer.class);
}
/**
@@ -184,10 +182,9 @@
* Session}</dd> </dl>
*/
public static void contributePersistentFieldManager(
- MappedConfiguration<String, PersistentFieldStrategy> configuration,
- ObjectLocator locator)
+ MappedConfiguration<String, PersistentFieldStrategy> configuration)
{
- configuration.add("entity", locator.autobuild(EntityPersistentFieldStrategy.class));
+ configuration.addInstance("entity", EntityPersistentFieldStrategy.class);
}
/**
@@ -195,11 +192,10 @@
* annotation.
*/
public static void contributeComponentClassTransformWorker(
- OrderedConfiguration<ComponentClassTransformWorker> configuration,
- ObjectLocator locator)
+ OrderedConfiguration<ComponentClassTransformWorker> configuration)
{
// If logging is enabled, we want logging to be the first advice, wrapping around the commit advice.
- configuration.add("CommitAfter", locator.autobuild(CommitAfterWorker.class), "after:Log");
+ configuration.addInstance("CommitAfter", CommitAfterWorker.class, "after:Log");
}
}
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Configuration.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Configuration.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Configuration.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Configuration.java Wed Sep 17 03:30:57 2008
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2008 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.
@@ -35,4 +35,13 @@
* @param object to add to the service's configuration
*/
void add(T object);
+
+ /**
+ * Automatically instantiates an instance of the class, with dependencies injeted, and adds it to the
+ * configuration.
+ *
+ * @param clazz what class to instantiate
+ * @since 5.1
+ */
+ void addInstance(Class<? extends T> clazz);
}
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/MappedConfiguration.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/MappedConfiguration.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/MappedConfiguration.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/MappedConfiguration.java Wed Sep 17 03:30:57 2008
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2008 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.
@@ -35,6 +35,14 @@
* @param value to contribute
* @throws IllegalArgumentException if key is not unique
*/
-
void add(K key, V value);
+
+ /**
+ * Adds a keyed object as an instantiated instance (with dependencies injected) of a class.
+ *
+ * @param key unique id for the value
+ * @param clazz class to instantiate and contribute
+ * @since 5.1
+ */
+ void addInstance(K key, Class<? extends V> clazz);
}
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java Wed Sep 17 03:30:57 2008
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2008 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.
@@ -37,4 +37,14 @@
* @parm object to add to the service's configuration
*/
void add(String id, T object, String... constraints);
+
+ /**
+ * Adds an ordered object by instantiating (with dependencies) the indicated class.
+ *
+ * @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
+ */
+ void addInstance(String id, Class<? extends T> clazz, String... constraints);
}
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java Wed Sep 17 03:30:57 2008
@@ -322,4 +322,9 @@
{
return MESSAGES.format("no-convention-service-implementation-found", clazz.getName(), clazz.getName());
}
+
+ static String wrongContributionClass(Class clazz, String serviceId, Class expectedType)
+ {
+ return MESSAGES.format("wrong-contribution-class", clazz.getName(), serviceId, expectedType.getName());
+ }
}
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java Wed Sep 17 03:30:57 2008
@@ -94,22 +94,6 @@
private final Set<ServiceDef> allServiceDefs = CollectionFactory.newSet();
-
- public static final class OrderedConfigurationToOrdererAdaptor<T> implements OrderedConfiguration<T>
- {
- private final Orderer<T> orderer;
-
- public OrderedConfigurationToOrdererAdaptor(Orderer<T> orderer)
- {
- this.orderer = orderer;
- }
-
- public void add(String id, T object, String... constraints)
- {
- orderer.add(id, object, constraints);
- }
- }
-
/**
* Constructs the registry from a set of module definitions and other resources.
*
@@ -174,7 +158,6 @@
for (Class marker : serviceDef.getMarkers())
InternalUtils.addToMapList(markerToServiceDef, marker, serviceDef);
-
}
moduleToServiceDefs.put(module, moduleServiceDefs);
@@ -343,16 +326,8 @@
final Collection<T> result = CollectionFactory.newList();
- Configuration<T> configuration = new Configuration<T>()
- {
- public void add(T object)
- {
- result.add(object);
- }
- };
-
for (Module m : moduleToServiceDefs.keySet())
- addToUnorderedConfiguration(configuration, objectType, serviceDef, m);
+ addToUnorderedConfiguration(result, objectType, serviceDef, m);
return result;
}
@@ -365,12 +340,10 @@
String serviceId = serviceDef.getServiceId();
Logger logger = getServiceLogger(serviceId);
- final Orderer<T> orderer = new Orderer<T>(logger);
-
- OrderedConfiguration<T> configuration = new OrderedConfigurationToOrdererAdaptor<T>(orderer);
+ Orderer<T> orderer = new Orderer<T>(logger);
for (Module m : moduleToServiceDefs.keySet())
- addToOrderedConfiguration(configuration, objectType, serviceDef, m);
+ addToOrderedConfiguration(orderer, objectType, serviceDef, m);
// An ugly hack ... perhaps we should introduce a new builtin service so that this can be
// accomplished in the normal way?
@@ -385,7 +358,7 @@
}
};
- configuration.add("ServiceByMarker", (T) contribution);
+ orderer.add("ServiceByMarker", (T) contribution);
}
return orderer.getOrdered();
@@ -395,21 +368,13 @@
{
lock.check();
- // When the key type is String, then a case insensitive map is used for both cases.
+ // When the key type is String, then a case insensitive map is used.
final Map<K, V> result = newConfigurationMap(keyType);
Map<K, ContributionDef> keyToContribution = newConfigurationMap(keyType);
- MappedConfiguration<K, V> configuration = new MappedConfiguration<K, V>()
- {
- public void add(K key, V value)
- {
- result.put(key, value);
- }
- };
-
for (Module m : moduleToServiceDefs.keySet())
- addToMappedConfiguration(configuration, keyToContribution, keyType, objectType, serviceDef, m);
+ addToMappedConfiguration(result, keyToContribution, keyType, objectType, serviceDef, m);
return result;
}
@@ -427,7 +392,7 @@
return CollectionFactory.newMap();
}
- private <K, V> void addToMappedConfiguration(MappedConfiguration<K, V> configuration,
+ private <K, V> void addToMappedConfiguration(final Map<K, V> map,
Map<K, ContributionDef> keyToContribution, Class<K> keyClass,
Class<V> valueType, ServiceDef serviceDef, Module module)
{
@@ -440,7 +405,22 @@
boolean debug = logger.isDebugEnabled();
- ObjectLocator locator = new ServiceResourcesImpl(this, module, serviceDef, classFactory, logger);
+ final ObjectLocator locator = new ServiceResourcesImpl(this, module, serviceDef, classFactory, logger);
+
+ MappedConfiguration<K, V> configuration = new MappedConfiguration<K, V>()
+ {
+ public void add(K key, V value)
+ {
+ map.put(key, value);
+ }
+
+ public void addInstance(K key, Class<? extends V> clazz)
+ {
+ // Because of the number of checks in VMCW, we let the VMCW instantiate the instance
+ // and run checks. This code is, effectively, unreachable.
+ throw new RuntimeException("Should not be invoked directly.");
+ }
+ };
for (ContributionDef def : contributions)
{
@@ -448,16 +428,16 @@
logger, keyClass,
valueType,
keyToContribution,
- configuration);
+ configuration, locator);
if (debug) logger.debug(IOCMessages.invokingMethod(def));
def.contribute(module, locator, validating);
}
-
}
- private <T> void addToUnorderedConfiguration(Configuration<T> configuration, Class<T> valueType,
+ private <T> void addToUnorderedConfiguration(final Collection<T> collection,
+ Class<T> valueType,
ServiceDef serviceDef, Module module)
{
String serviceId = serviceDef.getServiceId();
@@ -469,7 +449,22 @@
boolean debug = logger.isDebugEnabled();
- ObjectLocator locator = new ServiceResourcesImpl(this, module, serviceDef, classFactory, logger);
+ final ObjectLocator locator = new ServiceResourcesImpl(this, module, serviceDef, classFactory, logger);
+
+ Configuration<T> configuration = new Configuration<T>()
+ {
+ public void add(T object)
+ {
+ collection.add(object);
+ }
+
+ public void addInstance(Class<? extends T> clazz)
+ {
+ T object = locator.autobuild(clazz);
+
+ add(object);
+ }
+ };
for (ContributionDef def : contributions)
{
@@ -482,7 +477,8 @@
}
}
- private <T> void addToOrderedConfiguration(OrderedConfiguration<T> configuration, Class<T> valueType,
+ private <T> void addToOrderedConfiguration(final Orderer<T> orderer,
+ Class<T> valueType,
ServiceDef serviceDef, Module module)
{
String serviceId = serviceDef.getServiceId();
@@ -493,7 +489,22 @@
Logger logger = getServiceLogger(serviceId);
boolean debug = logger.isDebugEnabled();
- ObjectLocator locator = new ServiceResourcesImpl(this, module, serviceDef, classFactory, logger);
+ final ObjectLocator locator = new ServiceResourcesImpl(this, module, serviceDef, classFactory, logger);
+
+ OrderedConfiguration<T> configuration = new OrderedConfiguration<T>()
+ {
+ public void add(String id, T object, String... constraints)
+ {
+ orderer.add(id, object, constraints);
+ }
+
+ public void addInstance(String id, Class<? extends T> clazz, String... constraints)
+ {
+ T object = locator.autobuild(clazz);
+
+ add(id, object, constraints);
+ }
+ };
for (ContributionDef def : contributions)
{
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapper.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapper.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapper.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapper.java Wed Sep 17 03:30:57 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -16,6 +16,7 @@
import org.apache.tapestry5.ioc.Configuration;
import org.apache.tapestry5.ioc.def.ContributionDef;
+import org.apache.tapestry5.ioc.internal.util.Defense;
import org.slf4j.Logger;
/**
@@ -68,4 +69,13 @@
delegate.add(object);
}
+ public void addInstance(Class<? extends T> clazz)
+ {
+ Defense.notNull(clazz, "clazz");
+
+ if (!expectedType.isAssignableFrom(clazz))
+ throw new IllegalArgumentException(IOCMessages.wrongContributionClass(clazz, serviceId, expectedType));
+
+ delegate.addInstance(clazz);
+ }
}
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingMappedConfigurationWrapper.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingMappedConfigurationWrapper.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingMappedConfigurationWrapper.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingMappedConfigurationWrapper.java Wed Sep 17 03:30:57 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -15,6 +15,7 @@
package org.apache.tapestry5.ioc.internal;
import org.apache.tapestry5.ioc.MappedConfiguration;
+import org.apache.tapestry5.ioc.ObjectLocator;
import org.apache.tapestry5.ioc.def.ContributionDef;
import org.slf4j.Logger;
@@ -46,10 +47,12 @@
private final MappedConfiguration<K, V> delegate;
+ private final ObjectLocator locator;
+
public ValidatingMappedConfigurationWrapper(String serviceId, ContributionDef contributionDef,
Logger logger, Class<K> expectedKeyType, Class<V> expectedValueType,
Map<K, ContributionDef> keyToContributor,
- MappedConfiguration<K, V> delegate)
+ MappedConfiguration<K, V> delegate, ObjectLocator locator)
{
this.serviceId = serviceId;
this.contributionDef = contributionDef;
@@ -58,6 +61,7 @@
this.expectedValueType = expectedValueType;
this.keyToContributor = keyToContributor;
this.delegate = delegate;
+ this.locator = locator;
}
public void add(K key, V value)
@@ -68,19 +72,20 @@
return;
}
- if (value == null)
+ if (!expectedKeyType.isInstance(key))
{
- logger.warn(IOCMessages.contributionWasNull(serviceId, contributionDef));
+ logger.warn(IOCMessages.contributionWrongKeyType(serviceId, contributionDef, key
+ .getClass(), expectedKeyType));
return;
}
- if (!expectedKeyType.isInstance(key))
+ if (value == null)
{
- logger.warn(IOCMessages.contributionWrongKeyType(serviceId, contributionDef, key
- .getClass(), expectedKeyType));
+ logger.warn(IOCMessages.contributionWasNull(serviceId, contributionDef));
return;
}
+
if (!expectedValueType.isInstance(value))
{
logger.warn(IOCMessages.contributionWrongValueType(serviceId, contributionDef, value
@@ -107,4 +112,10 @@
keyToContributor.put(key, contributionDef);
}
+ public void addInstance(K key, Class<? extends V> clazz)
+ {
+ V value = locator.autobuild(clazz);
+
+ add(key, value);
+ }
}
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java Wed Sep 17 03:30:57 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -16,6 +16,7 @@
import org.apache.tapestry5.ioc.OrderedConfiguration;
import org.apache.tapestry5.ioc.def.ContributionDef;
+import org.apache.tapestry5.ioc.internal.util.Defense;
import org.slf4j.Logger;
/**
@@ -53,6 +54,16 @@
delegate.add(id, validVersionOf(object), constraints);
}
+ public void addInstance(String id, Class<? extends T> clazz, String... constraints)
+ {
+ Defense.notNull(clazz, "clazz");
+
+ if (!expectedType.isAssignableFrom(clazz))
+ throw new IllegalArgumentException(IOCMessages.wrongContributionClass(clazz, serviceId, expectedType));
+
+ delegate.addInstance(id, clazz, constraints);
+ }
+
private T validVersionOf(T object)
{
if (object == null || expectedType.isInstance(object)) return object;
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java Wed Sep 17 03:30:57 2008
@@ -77,10 +77,9 @@
/**
* Contributes the "perthread" scope.
*/
- public void contributeServiceLifecycleSource(MappedConfiguration<String, ServiceLifecycle> configuration,
- ObjectLocator locator)
+ public void contributeServiceLifecycleSource(MappedConfiguration<String, ServiceLifecycle> configuration)
{
- configuration.add(PERTHREAD_SCOPE, locator.autobuild(PerThreadServiceLifecycle.class));
+ configuration.addInstance(PERTHREAD_SCOPE, PerThreadServiceLifecycle.class);
}
/**
@@ -88,12 +87,10 @@
* <p/>
* Contributes "Value", which injects values (not services) triggered by the {@link Value} annotation.
*/
- public static void contributeMasterObjectProvider(OrderedConfiguration<ObjectProvider> configuration,
-
- ObjectLocator locator)
+ public static void contributeMasterObjectProvider(OrderedConfiguration<ObjectProvider> configuration)
{
- configuration.add("Value", locator.autobuild(ValueObjectProvider.class));
- configuration.add("Symbol", locator.autobuild(SymbolObjectProvider.class));
+ configuration.addInstance("Value", ValueObjectProvider.class);
+ configuration.addInstance("Symbol", SymbolObjectProvider.class);
}
/**
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties Wed Sep 17 03:30:57 2008
@@ -84,3 +84,4 @@
unexpected-service-proxy-provider=Unexpected service proxy provider when clearing the provider. This may indicate that you have multiple IoC Registries.
no-proxy-provider=Service token for service '%s' can not be converted back into a proxy because no proxy provider has been registered. This may indicate that an IoC Registry has not been started yet.
no-convention-service-implementation-found=No service implements the interface %s. Please provide the implementation %sImpl or bind the service interface to a service implementation.
+wrong-contribution-class=Unable to contribute instance of class %s to service '%s' as it is not assignable to expected contribution type %s.
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/site/apt/configuration.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/site/apt/configuration.apt?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/site/apt/configuration.apt (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/site/apt/configuration.apt Wed Sep 17 03:30:57 2008
@@ -227,7 +227,12 @@
{{{apidocs/org/apache/tapestry5/ioc/util/CaseInsensitiveMap.html}CaseInsensitiveMap}}
will be automatically used (and passed to the service builder method), to help ensure that {{{case.html}case insensitivity}}
is automatic and pervasive.
-
+
+Injecting Classes
+
+ All three configuration interfaces have a second method, addInstance(). This method takes a class, not an instance.
+ The class is instantiated and contributed. If the constructor for the class takes dependencies, those are injected as well.
+
Injecting Resources
In addition to injecting services into a contributor method (via
Added: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributeByClassModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributeByClassModule.java?rev=696229&view=auto
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributeByClassModule.java (added)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributeByClassModule.java Wed Sep 17 03:30:57 2008
@@ -0,0 +1,73 @@
+// Copyright 2008 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.services.ChainBuilder;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+public class ContributeByClassModule
+{
+ public static StringTransformer buildMasterStringTransformer(final Collection<StringTransformer> configuration)
+ {
+ return new StringTransformer()
+ {
+ public String transform(String input)
+ {
+ String current = input;
+
+ for (StringTransformer t : configuration)
+ {
+ current = t.transform(current);
+ }
+ return current;
+ }
+ };
+ }
+
+ public static StringTransformer buildStringTransformerChain(final List<StringTransformer> configuration,
+ ChainBuilder builder)
+ {
+ return builder.build(StringTransformer.class, configuration);
+ }
+
+ public static void contributeMasterStringTransformer(Configuration<StringTransformer> configuration)
+ {
+ configuration.addInstance(UppercaseStringTransformer.class);
+ }
+
+ public static void contributeStringTransformerChain(final OrderedConfiguration<StringTransformer> configuration)
+ {
+ configuration.addInstance("Default", UppercaseStringTransformer.class);
+ }
+
+ public static StringTransformer buildMappedStringTransformer(final Map<String, StringTransformer> configuration)
+ {
+ return new StringTransformer()
+ {
+ public String transform(String input)
+ {
+ return configuration.get("Default").transform(input);
+ }
+ };
+ }
+
+ public static void contributeMappedStringTransformer(MappedConfiguration<String, StringTransformer> configuration)
+ {
+ configuration.addInstance("Default", UppercaseStringTransformer.class);
+ }
+}
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java Wed Sep 17 03:30:57 2008
@@ -914,4 +914,40 @@
r.shutdown();
}
+
+ @Test
+ public void unordered_configuration_contribute_by_class()
+ {
+ Registry r = buildRegistry(ContributeByClassModule.class);
+
+ StringTransformer st = r.getService("MasterStringTransformer", StringTransformer.class);
+
+ assertEquals(st.transform("Tapestry"), "TAPESTRY");
+
+ r.shutdown();
+ }
+
+ @Test
+ public void ordered_configuration_contribute_by_class()
+ {
+ Registry r = buildRegistry(ContributeByClassModule.class);
+
+ StringTransformer st = r.getService("StringTransformerChain", StringTransformer.class);
+
+ assertEquals(st.transform("Tapestry"), "TAPESTRY");
+
+ r.shutdown();
+ }
+
+ @Test
+ public void mapped_configuration_contribute_by_class()
+ {
+ Registry r = buildRegistry(ContributeByClassModule.class);
+
+ StringTransformer st = r.getService("MappedStringTransformer", StringTransformer.class);
+
+ assertEquals(st.transform("Tapestry"), "TAPESTRY");
+
+ r.shutdown();
+ }
}
Added: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/UppercaseStringTransformer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/UppercaseStringTransformer.java?rev=696229&view=auto
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/UppercaseStringTransformer.java (added)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/UppercaseStringTransformer.java Wed Sep 17 03:30:57 2008
@@ -0,0 +1,23 @@
+// Copyright 2008 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 UppercaseStringTransformer implements StringTransformer
+{
+ public String transform(String input)
+ {
+ return input.toUpperCase();
+ }
+}
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperTest.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperTest.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingConfigurationWrapperTest.java Wed Sep 17 03:30:57 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -19,6 +19,9 @@
import org.slf4j.Logger;
import org.testng.annotations.Test;
+import java.util.HashMap;
+import java.util.Map;
+
public class ValidatingConfigurationWrapperTest extends IOCInternalTestCase
{
@SuppressWarnings("unchecked")
@@ -42,6 +45,26 @@
verify();
}
+ @SuppressWarnings({"unchecked"})
+ @Test
+ public void valid_class_contribution()
+ {
+ ContributionDef def = mockContributionDef();
+ Logger logger = mockLogger();
+ Configuration configuration = mockConfiguration();
+
+ configuration.addInstance(HashMap.class);
+
+ replay();
+
+ Configuration wrapper = new ValidatingConfigurationWrapper("foo.Bar", logger,
+ Map.class, def, configuration);
+
+ wrapper.addInstance(HashMap.class);
+
+ verify();
+ }
+
@SuppressWarnings("unchecked")
@Test
public void null_contribution()
@@ -85,6 +108,35 @@
verify();
}
+ @Test
+ public void wrong_class_contributed()
+ {
+ Logger logger = mockLogger();
+ Configuration configuration = mockConfiguration();
+ ContributionDef def = new ContributionDefImpl("Bar", findMethod("contributeWrongType"),
+ getClassFactory());
+
+ replay();
+
+ Configuration wrapper = new ValidatingConfigurationWrapper("Bar", logger, Runnable.class,
+ def, configuration);
+
+ try
+ {
+ wrapper.addInstance(this.getClass());
+ unreachable();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ assertMessageContains(ex,
+ "Unable to contribute instance of class org.apache.tapestry5.ioc.internal.ValidatingConfigurationWrapperTest",
+ "to service 'Bar'",
+ "as it is not assignable to expected contribution type java.lang.Runnable");
+ }
+
+ verify();
+ }
+
// Just a placeholder to give the errors something to report about
public void contributeUnorderedNull()
@@ -96,5 +148,4 @@
{
}
-
}
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingMappedConfigurationWrapperTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingMappedConfigurationWrapperTest.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingMappedConfigurationWrapperTest.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingMappedConfigurationWrapperTest.java Wed Sep 17 03:30:57 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -15,6 +15,7 @@
package org.apache.tapestry5.ioc.internal;
import org.apache.tapestry5.ioc.MappedConfiguration;
+import org.apache.tapestry5.ioc.ObjectLocator;
import org.apache.tapestry5.ioc.def.ContributionDef;
import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newMap;
import org.slf4j.Logger;
@@ -34,6 +35,7 @@
Logger logger = mockLogger();
Map<Class, ContributionDef> keyToContribution = newMap();
MappedConfiguration<Class, Runnable> delegate = mockMappedConfiguration();
+ ObjectLocator locator = mockObjectLocator();
Class key = Integer.class;
Runnable value = mockRunnable();
@@ -43,7 +45,7 @@
replay();
MappedConfiguration<Class, Runnable> wrapper = new ValidatingMappedConfigurationWrapper<Class, Runnable>(
- SERVICE_ID, def, logger, Class.class, Runnable.class, keyToContribution, delegate);
+ SERVICE_ID, def, logger, Class.class, Runnable.class, keyToContribution, delegate, locator);
wrapper.add(key, value);
@@ -59,6 +61,7 @@
ContributionDef def2 = newContributionDef("contributionPlaceholder2");
Logger logger = mockLogger();
Map<Class, ContributionDef> keyToContribution = newMap();
+ ObjectLocator locator = mockObjectLocator();
keyToContribution.put(Integer.class, def1);
@@ -72,7 +75,7 @@
replay();
MappedConfiguration<Class, Runnable> wrapper = new ValidatingMappedConfigurationWrapper<Class, Runnable>(
- SERVICE_ID, def2, logger, Class.class, Runnable.class, keyToContribution, delegate);
+ SERVICE_ID, def2, logger, Class.class, Runnable.class, keyToContribution, delegate, locator);
wrapper.add(key, value);
@@ -89,13 +92,14 @@
Map<Class, ContributionDef> keyToContribution = newMap();
MappedConfiguration<Class, Runnable> delegate = mockMappedConfiguration();
Runnable value = mockRunnable();
+ ObjectLocator locator = mockObjectLocator();
logger.warn(IOCMessages.contributionKeyWasNull(SERVICE_ID, def));
replay();
MappedConfiguration<Class, Runnable> wrapper = new ValidatingMappedConfigurationWrapper<Class, Runnable>(
- SERVICE_ID, def, logger, Class.class, Runnable.class, keyToContribution, delegate);
+ SERVICE_ID, def, logger, Class.class, Runnable.class, keyToContribution, delegate, locator);
wrapper.add(null, value);
@@ -111,6 +115,7 @@
Map<?, ContributionDef> keyToContribution = newMap();
MappedConfiguration delegate = mockMappedConfiguration();
Runnable value = mockRunnable();
+ ObjectLocator locator = mockObjectLocator();
logger.warn(IOCMessages
.contributionWrongKeyType(SERVICE_ID, def, String.class, Class.class));
@@ -119,7 +124,7 @@
MappedConfiguration wrapper = new ValidatingMappedConfigurationWrapper(SERVICE_ID, def,
logger, Class.class, Runnable.class,
- keyToContribution, delegate);
+ keyToContribution, delegate, locator);
wrapper.add("java.util.List", value);
@@ -134,6 +139,7 @@
Logger logger = mockLogger();
Map<?, ContributionDef> keyToContribution = newMap();
MappedConfiguration delegate = mockMappedConfiguration();
+ ObjectLocator locator = mockObjectLocator();
logger.warn(IOCMessages.contributionWrongValueType(
SERVICE_ID,
@@ -145,7 +151,7 @@
MappedConfiguration wrapper = new ValidatingMappedConfigurationWrapper(SERVICE_ID, def,
logger, Class.class, Runnable.class,
- keyToContribution, delegate);
+ keyToContribution, delegate, locator);
wrapper.add(List.class, "do something");
@@ -159,13 +165,14 @@
Logger logger = mockLogger();
Map<Class, ContributionDef> keyToContribution = newMap();
MappedConfiguration<Class, Runnable> delegate = mockMappedConfiguration();
-
+ ObjectLocator locator = mockObjectLocator();
+
logger.warn(IOCMessages.contributionWasNull(SERVICE_ID, def));
replay();
MappedConfiguration<Class, Runnable> wrapper = new ValidatingMappedConfigurationWrapper<Class, Runnable>(
- SERVICE_ID, def, logger, Class.class, Runnable.class, keyToContribution, delegate);
+ SERVICE_ID, def, logger, Class.class, Runnable.class, keyToContribution, delegate, locator);
wrapper.add(Integer.class, null);
Modified: tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java?rev=696229&r1=696228&r2=696229&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java (original)
+++ tapestry/tapestry5/branches/5.1-dev/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java Wed Sep 17 03:30:57 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -20,6 +20,9 @@
import org.testng.annotations.Test;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
public class ValidatingOrderedConfigurationWrapperTest extends IOCInternalTestCase
{
@@ -44,6 +47,53 @@
}
@Test
+ public void contribute_valid_class()
+ {
+ ContributionDef def = mockContributionDef();
+ Logger logger = mockLogger();
+ OrderedConfiguration<Map> configuration = mockOrderedConfiguration();
+
+ configuration.addInstance("id", HashMap.class, "after:pre", "before:post");
+
+ replay();
+
+ OrderedConfiguration<Map> wrapper = new ValidatingOrderedConfigurationWrapper<Map>(
+ "Service", def, logger, Map.class, configuration);
+
+ wrapper.addInstance("id", HashMap.class, "after:pre", "before:post");
+
+ verify();
+ }
+
+ @Test
+ public void contribute_invalid_class()
+ {
+ ContributionDef def = mockContributionDef();
+ Logger logger = mockLogger();
+ OrderedConfiguration<Object> configuration = mockOrderedConfiguration();
+
+ replay();
+
+ OrderedConfiguration<Object> wrapper = new ValidatingOrderedConfigurationWrapper<Object>(
+ "Service", def, logger, Map.class, configuration);
+
+ try
+ {
+ wrapper.addInstance("id", ArrayList.class, "after:pre", "before:post");
+ unreachable();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ assertMessageContains(ex,
+ "Unable to contribute instance of class java.util.ArrayList",
+ "to service 'Service'",
+ "as it is not assignable to expected contribution type java.util.Map.");
+ }
+
+ verify();
+ }
+
+ @Test
public void valid_type_short_form()
{
ContributionDef def = mockContributionDef();