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/04/24 03:58:52 UTC
svn commit: r531674 [1/2] - in /tapestry/tapestry5:
tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/
tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/
tapestry-core/trunk/src/main/java/org/apache/tapestry/serv...
Author: hlship
Date: Mon Apr 23 18:58:49 2007
New Revision: 531674
URL: http://svn.apache.org/viewvc?view=rev&rev=531674
Log:
TAPESTRY-1387: Extended autobuilding into ObjectLocator and ServiceResources, such that the primary way a service implementation has its dependencies injected is via its constructor, even when a service builder method is present.
Renamed ServiceLocator to ObjectLocator, reflecting the fact that most of what it does is obtain objects (that may or may not be services).
Added:
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ObjectLocator.java
- copied, changed from r529445, tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceLocator.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ObjectLocatorImpl.java
- copied, changed from r529445, tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceLocatorImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/DuplicateServiceTypeModule.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/FailInConstructorRunnable.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/Greeter.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/GreeterModule.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/ServiceBuilderAutobuilderModule.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/UnbuildableRunnable.java
Removed:
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceLocator.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceLocatorImpl.java
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AliasImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetInjectionProvider.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetObjectProvider.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CommonResourcesInjectionProvider.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentResourcesInjectionProvider.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectResourcesWorker.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectWorker.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/InjectionProvider.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AliasImplTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetInjectionProviderTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetObjectProviderTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectResourcesWorkerTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectWorkerTest.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ObjectProvider.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/Registry.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBuilderResources.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceResources.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ContributionDef.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ContributionDefImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCInternalTestCase.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCMessages.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/InternalRegistry.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ModuleImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryWrapper.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceBinderImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceResourcesImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/JustInTimeObjectCreator.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/PerThreadServiceLifecycle.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ServiceMessages.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ValueObjectProvider.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/util/InternalUtils.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/util/OneShotLock.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/services/TapestryIOCModule.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/resources/org/apache/tapestry/ioc/internal/IOCStrings.properties
tapestry/tapestry5/tapestry-ioc/trunk/src/main/resources/org/apache/tapestry/ioc/internal/services/ServiceStrings.properties
tapestry/tapestry5/tapestry-ioc/trunk/src/site/apt/configuration.apt
tapestry/tapestry5/tapestry-ioc/trunk/src/site/apt/module.apt
tapestry/tapestry5/tapestry-ioc/trunk/src/site/apt/service.apt
tapestry/tapestry5/tapestry-ioc/trunk/src/test/conf/testng.xml
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ContributionDefImplTest.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ModuleImplTest.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ThreadLocaleImplTest.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ValueObjectProviderTest.java
tapestry/tapestry5/tapestry-project/trunk/src/site/apt/index.apt
tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringObjectProvider.java
tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/apache/tapestry/spring/SpringObjectProviderTest.java
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AliasImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AliasImpl.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AliasImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AliasImpl.java Mon Apr 23 18:58:49 2007
@@ -21,7 +21,7 @@
import org.apache.tapestry.ioc.AnnotationProvider;
import org.apache.tapestry.ioc.ObjectProvider;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.ioc.internal.util.OneShotLock;
import org.apache.tapestry.services.Alias;
import org.apache.tapestry.services.AliasManager;
@@ -74,7 +74,7 @@
}
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider,
- ServiceLocator locator)
+ ObjectLocator locator)
{
if (!_initialized) throw new RuntimeException(ServicesMessages.aliasModeNotSet());
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetInjectionProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetInjectionProvider.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetInjectionProvider.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetInjectionProvider.java Mon Apr 23 18:58:49 2007
@@ -17,7 +17,7 @@
import static java.lang.String.format;
import org.apache.tapestry.annotations.Path;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.ioc.services.SymbolSource;
import org.apache.tapestry.model.MutableComponentModel;
import org.apache.tapestry.services.AssetSource;
@@ -40,7 +40,7 @@
_assetSource = assetSource;
}
- public boolean provideInjection(String fieldName, String fieldType, ServiceLocator locator,
+ public boolean provideInjection(String fieldName, String fieldType, ObjectLocator locator,
ClassTransformation transformation, MutableComponentModel componentModel)
{
Path path = transformation.getFieldAnnotation(fieldName, Path.class);
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetObjectProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetObjectProvider.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetObjectProvider.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetObjectProvider.java Mon Apr 23 18:58:49 2007
@@ -19,7 +19,7 @@
import org.apache.tapestry.ioc.AnnotationProvider;
import org.apache.tapestry.ioc.ObjectProvider;
import org.apache.tapestry.ioc.Resource;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.ioc.services.SymbolSource;
import org.apache.tapestry.ioc.services.TypeCoercer;
@@ -64,7 +64,7 @@
* not used
*/
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider,
- ServiceLocator locator)
+ ObjectLocator locator)
{
Path path = annotationProvider.getAnnotation(Path.class);
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CommonResourcesInjectionProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CommonResourcesInjectionProvider.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CommonResourcesInjectionProvider.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CommonResourcesInjectionProvider.java Mon Apr 23 18:58:49 2007
@@ -21,7 +21,7 @@
import org.apache.commons.logging.Log;
import org.apache.tapestry.ioc.Messages;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.model.MutableComponentModel;
import org.apache.tapestry.services.ClassTransformation;
import org.apache.tapestry.services.InjectionProvider;
@@ -46,7 +46,7 @@
_configuration.put(fieldType.getName(), methodName);
}
- public boolean provideInjection(String fieldName, String fieldType, ServiceLocator locator,
+ public boolean provideInjection(String fieldName, String fieldType, ObjectLocator locator,
ClassTransformation transformation, MutableComponentModel componentModel)
{
String implementationMethodName = _configuration.get(fieldType);
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentResourcesInjectionProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentResourcesInjectionProvider.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentResourcesInjectionProvider.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentResourcesInjectionProvider.java Mon Apr 23 18:58:49 2007
@@ -17,7 +17,7 @@
import static java.lang.String.format;
import org.apache.tapestry.ComponentResources;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.model.MutableComponentModel;
import org.apache.tapestry.services.ClassTransformation;
import org.apache.tapestry.services.InjectionProvider;
@@ -29,7 +29,7 @@
{
private static final String COMPONENT_RESOURCES_CLASS_NAME = ComponentResources.class.getName();
- public boolean provideInjection(String fieldName, String fieldType, ServiceLocator locator,
+ public boolean provideInjection(String fieldName, String fieldType, ObjectLocator locator,
ClassTransformation transformation, MutableComponentModel componentModel)
{
if (fieldType.equals(COMPONENT_RESOURCES_CLASS_NAME))
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectResourcesWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectResourcesWorker.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectResourcesWorker.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectResourcesWorker.java Mon Apr 23 18:58:49 2007
@@ -15,7 +15,7 @@
package org.apache.tapestry.internal.services;
import org.apache.tapestry.annotations.Inject;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.model.MutableComponentModel;
import org.apache.tapestry.services.ClassTransformation;
import org.apache.tapestry.services.ComponentClassTransformWorker;
@@ -31,13 +31,13 @@
*/
public class InjectResourcesWorker implements ComponentClassTransformWorker
{
- private final ServiceLocator _locator;
+ private final ObjectLocator _locator;
// Really, a chain of command
private final InjectionProvider _injectionProvider;
- public InjectResourcesWorker(final ServiceLocator locator,
+ public InjectResourcesWorker(final ObjectLocator locator,
final InjectionProvider injectionProvider)
{
_locator = locator;
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectWorker.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectWorker.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectWorker.java Mon Apr 23 18:58:49 2007
@@ -19,7 +19,7 @@
import org.apache.tapestry.annotations.Inject;
import org.apache.tapestry.ioc.AnnotationProvider;
import org.apache.tapestry.ioc.ObjectProvider;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.model.MutableComponentModel;
import org.apache.tapestry.services.ClassTransformation;
import org.apache.tapestry.services.ComponentClassTransformWorker;
@@ -36,9 +36,9 @@
{
private final ObjectProvider _objectProvider;
- private final ServiceLocator _locator;
+ private final ObjectLocator _locator;
- public InjectWorker(ObjectProvider objectProvider, ServiceLocator locator)
+ public InjectWorker(ObjectProvider objectProvider, ObjectLocator locator)
{
_objectProvider = objectProvider;
_locator = locator;
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java Mon Apr 23 18:58:49 2007
@@ -35,12 +35,12 @@
import org.apache.tapestry.internal.util.IntegerRange;
import org.apache.tapestry.ioc.Configuration;
import org.apache.tapestry.ioc.Location;
-import org.apache.tapestry.ioc.LogSource;
import org.apache.tapestry.ioc.MappedConfiguration;
import org.apache.tapestry.ioc.ObjectProvider;
import org.apache.tapestry.ioc.OrderedConfiguration;
import org.apache.tapestry.ioc.ServiceBinder;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
+import org.apache.tapestry.ioc.ServiceResources;
import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.ioc.annotations.Scope;
import org.apache.tapestry.ioc.annotations.Value;
@@ -57,14 +57,11 @@
import org.apache.tapestry.services.ApplicationInitializerFilter;
import org.apache.tapestry.services.AssetFactory;
import org.apache.tapestry.services.BindingFactory;
-import org.apache.tapestry.services.BindingSource;
import org.apache.tapestry.services.ClasspathAssetAliasManager;
import org.apache.tapestry.services.ComponentClassResolver;
-import org.apache.tapestry.services.ComponentClassTransformWorker;
import org.apache.tapestry.services.ComponentMessagesSource;
import org.apache.tapestry.services.Context;
import org.apache.tapestry.services.ObjectRenderer;
-import org.apache.tapestry.services.PersistentFieldManager;
import org.apache.tapestry.services.PropertyConduitSource;
import org.apache.tapestry.services.Request;
import org.apache.tapestry.services.RequestExceptionHandler;
@@ -95,7 +92,7 @@
}
public static void contributeAlias(Configuration<AliasContribution> configuration,
- ServiceLocator locator)
+ ObjectLocator locator)
{
add(
configuration,
@@ -106,7 +103,7 @@
}
@SuppressWarnings("unchecked")
- private static void add(Configuration<AliasContribution> configuration, ServiceLocator locator,
+ private static void add(Configuration<AliasContribution> configuration, ObjectLocator locator,
Class... serviceInterfaces)
{
for (Class serviceInterface : serviceInterfaces)
@@ -181,8 +178,6 @@
private final RequestGlobals _requestGlobals;
- private final LinkFactory _linkFactory;
-
private final ContextPathSource _contextPathSource;
public InternalModule(@InjectService("ComponentInstantiatorSource")
@@ -210,9 +205,6 @@
@InjectService("ContextPathSource")
ContextPathSource contextPathSource,
- @InjectService("LinkFactory")
- LinkFactory linkFactory,
-
@InjectService("ThreadLocale")
ThreadLocale threadLocale,
@@ -228,7 +220,6 @@
_response = response;
_threadLocale = threadLocale;
_requestGlobals = requestGlobals;
- _linkFactory = linkFactory;
_contextPathSource = contextPathSource;
}
@@ -256,13 +247,10 @@
return source;
}
- public ComponentClassTransformer build(@InjectService("ComponentClassTransformWorker")
- ComponentClassTransformWorker workerChain,
-
- LogSource logSource)
+ public ComponentClassTransformer buildComponentClassTransformer(ServiceResources resources)
{
- ComponentClassTransformerImpl transformer = new ComponentClassTransformerImpl(workerChain,
- logSource);
+ ComponentClassTransformerImpl transformer = resources
+ .autobuild(ComponentClassTransformerImpl.class);
_componentInstantiatorSource.addInvalidationListener(transformer);
@@ -289,11 +277,9 @@
return service;
}
- public PageLoader build(PageElementFactory pageElementFactory, BindingSource bindingSource,
- PersistentFieldManager persistentFieldManager)
+ public PageLoader buildPageLoader(ServiceResources resources)
{
- PageLoaderImpl service = new PageLoaderImpl(_componentTemplateSource, pageElementFactory,
- bindingSource, _linkFactory, persistentFieldManager);
+ PageLoaderImpl service = resources.autobuild(PageLoaderImpl.class);
// Recieve invalidations when the class loader is discarded (due to a component class
// change). The notification is forwarded to the page loader's listeners.
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java Mon Apr 23 18:58:49 2007
@@ -68,8 +68,8 @@
import org.apache.tapestry.model.EmbeddedComponentModel;
import org.apache.tapestry.runtime.Component;
import org.apache.tapestry.runtime.RenderQueue;
-import org.apache.tapestry.services.ComponentClassResolver;
import org.apache.tapestry.services.Alias;
+import org.apache.tapestry.services.ComponentClassResolver;
import org.apache.tapestry.services.Request;
import org.apache.tapestry.services.TapestryModule;
import org.apache.tapestry.test.TapestryTestCase;
@@ -126,6 +126,11 @@
public final <T> T getService(String serviceId, Class<T> serviceInterface)
{
return _registry.getService(serviceId, serviceInterface);
+ }
+
+ public final <T> T autobuild(Class<T> clazz)
+ {
+ return _registry.autobuild(clazz);
}
public final void shutdown()
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/InjectionProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/InjectionProvider.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/InjectionProvider.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/InjectionProvider.java Mon Apr 23 18:58:49 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 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.
@@ -14,7 +14,7 @@
package org.apache.tapestry.services;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.model.MutableComponentModel;
/**
@@ -47,6 +47,6 @@
* @return true if an injection has been made (terminates the command chain), false to continue
* down the chain
*/
- boolean provideInjection(String fieldName, String fieldType, ServiceLocator locator,
+ boolean provideInjection(String fieldName, String fieldType, ObjectLocator locator,
ClassTransformation transformation, MutableComponentModel componentModel);
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java Mon Apr 23 18:58:49 2007
@@ -77,7 +77,6 @@
import org.apache.tapestry.internal.services.AssetSourceImpl;
import org.apache.tapestry.internal.services.BeanModelSourceImpl;
import org.apache.tapestry.internal.services.BindingSourceImpl;
-import org.apache.tapestry.internal.services.ClassNameLocator;
import org.apache.tapestry.internal.services.ClasspathAssetAliasManagerImpl;
import org.apache.tapestry.internal.services.CommonResourcesInjectionProvider;
import org.apache.tapestry.internal.services.ComponentActionDispatcher;
@@ -161,7 +160,8 @@
import org.apache.tapestry.ioc.ObjectProvider;
import org.apache.tapestry.ioc.OrderedConfiguration;
import org.apache.tapestry.ioc.ServiceBinder;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
+import org.apache.tapestry.ioc.ServiceResources;
import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.ioc.annotations.SubModule;
import org.apache.tapestry.ioc.annotations.Value;
@@ -176,7 +176,6 @@
import org.apache.tapestry.ioc.services.StrategyBuilder;
import org.apache.tapestry.ioc.services.SymbolSource;
import org.apache.tapestry.ioc.services.ThreadLocale;
-import org.apache.tapestry.ioc.services.TypeCoercer;
import org.apache.tapestry.ioc.util.StrategyRegistry;
import org.apache.tapestry.runtime.Component;
import org.apache.tapestry.runtime.RenderCommand;
@@ -219,6 +218,7 @@
binder.bind(ValidationConstraintGenerator.class, ValidationConstraintGeneratorImpl.class);
binder.bind(EnvironmentalShadowBuilder.class, EnvironmentalShadowBuilderImpl.class);
binder.bind(ComponentSource.class, ComponentSourceImpl.class);
+ binder.bind(BeanModelSource.class, BeanModelSourceImpl.class);
}
public static MarkupWriterFactory build(@InjectService("ComponentInvocationMap")
@@ -248,8 +248,8 @@
/**
* A few of the built in services overlap in terms of service interface so we make contributions
- * to the Alias service to disambiguate. This ensures that a bare @{@link Inject} will chose
- * the correct value without being further qualified.
+ * to the Alias service to disambiguate. This ensures that a bare parameter (without an
+ * InjectService annotation) will chose the correct value without being further qualified.
* <ul>
* <li>{@link ComponentEventResultProcessor}: the master ComponentEventResultProcessor service
* (rather than one of the other services that exist to handle a specific type of result)</li>
@@ -257,25 +257,26 @@
* other services that renders a specific type of object)</li>
* <li>{@link ClassFactory}: the <em>ComponentClassFactory</em> (which will be recreated if
* the component class loader is recreated, on a change to a component class)
+ * <li>{@link DataTypeAnalyzer}: the <em>DefaultDataTypeAnalyzer</em> service
* </ul>
- * @param configuration
- * @param locator
- * @param componentClassFactory
*/
public static void contributeAlias(Configuration<AliasContribution> configuration,
- ServiceLocator locator,
+ ObjectLocator locator,
@InjectService("ComponentClassFactory")
- ClassFactory componentClassFactory)
+ ClassFactory componentClassFactory,
+
+ @InjectService("DefaultDataTypeAnalyzer")
+ DataTypeAnalyzer dataTypeAnalyzer)
{
add(configuration, locator, ComponentEventResultProcessor.class, ObjectRenderer.class);
configuration.add(AliasContribution.create(ClassFactory.class, componentClassFactory));
-
+ configuration.add(AliasContribution.create(DataTypeAnalyzer.class, dataTypeAnalyzer));
}
@SuppressWarnings("unchecked")
- private static void add(Configuration<AliasContribution> configuration, ServiceLocator locator,
+ private static void add(Configuration<AliasContribution> configuration, ObjectLocator locator,
Class... serviceInterfaces)
{
for (Class serviceInterface : serviceInterfaces)
@@ -369,7 +370,7 @@
public static void contributeComponentClassTransformWorker(
OrderedConfiguration<ComponentClassTransformWorker> configuration,
- ServiceLocator locator,
+ ObjectLocator locator,
@InjectService("MasterObjectProvider")
ObjectProvider objectProvider,
@@ -584,7 +585,7 @@
ObjectProvider wrapper = new ObjectProvider()
{
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider,
- ServiceLocator locator)
+ ObjectLocator locator)
{
return alias.getObjectProvider().provide(objectType, annotationProvider, locator);
}
@@ -822,8 +823,6 @@
private final PropertyAccess _propertyAccess;
- private final PropertyConduitSource _propertyConduitSource;
-
private final ClassFactory _componentClassFactory;
public TapestryModule(@InjectService("PipelineBuilder")
@@ -859,8 +858,6 @@
@InjectService("LinkFactory")
LinkFactory linkFactory,
- PropertyConduitSource propertyConduitSource,
-
PropertyAccess propertyAccess,
@InjectService("ComponentClassFactory")
@@ -879,7 +876,6 @@
_componentInstantiatorSource = componentInstantiatorSource;
_linkFactory = linkFactory;
_propertyAccess = propertyAccess;
- _propertyConduitSource = propertyConduitSource;
_componentClassFactory = componentClassFactory;
}
@@ -889,12 +885,9 @@
return _shadowBuilder.build(globals, "context", Context.class);
}
- public ComponentClassResolver build(Collection<LibraryMapping> configuration,
- @InjectService("ClassNameLocator")
- ClassNameLocator classNameLocator)
+ public ComponentClassResolver buildComponentClassResolver(ServiceResources resources)
{
- ComponentClassResolverImpl service = new ComponentClassResolverImpl(
- _componentInstantiatorSource, classNameLocator, configuration);
+ ComponentClassResolverImpl service = resources.autobuild(ComponentClassResolverImpl.class);
// Allow the resolver to clean its cache when the source is invalidated
@@ -923,11 +916,9 @@
return service;
}
- public MetaDataLocator build(ComponentClassResolver componentClassResolver,
-
- Map<String, String> configuration)
+ public MetaDataLocator buildMetaDataLocator(ServiceResources resources)
{
- MetaDataLocatorImpl service = new MetaDataLocatorImpl(componentClassResolver, configuration);
+ MetaDataLocatorImpl service = resources.autobuild(MetaDataLocatorImpl.class);
_componentInstantiatorSource.addInvalidationListener(service);
@@ -1107,18 +1098,19 @@
* entirely pased on the property type, working against its own configuration (mapping property
* type class to data type).
*/
- public DataTypeAnalyzer buildDefaultDataTypeAnalyzer(Map<Class, String> configuration)
+ public DataTypeAnalyzer buildDefaultDataTypeAnalyzer(ServiceResources resources)
{
- DefaultDataTypeAnalyzer service = new DefaultDataTypeAnalyzer(configuration);
+ DefaultDataTypeAnalyzer service = resources.autobuild(DefaultDataTypeAnalyzer.class);
_componentInstantiatorSource.addInvalidationListener(service);
return service;
}
- public TranslatorDefaultSource build(Map<Class, Translator> configuration)
+ public TranslatorDefaultSource buildTranslatorDefaultSource(ServiceResources resources)
{
- TranslatorDefaultSourceImpl service = new TranslatorDefaultSourceImpl(configuration);
+ TranslatorDefaultSourceImpl service = resources
+ .autobuild(TranslatorDefaultSourceImpl.class);
_componentInstantiatorSource.addInvalidationListener(service);
@@ -1135,21 +1127,20 @@
return _strategyBuilder.build(registry);
}
- /**
- * The configuration of the model source is a mapping from type to string. The types are
- * property types and the values, the strings, represent different type of editors.
- */
- public BeanModelSource build(TypeCoercer typeCoercer,
-
- @InjectService("DataTypeAnalyzer")
- DataTypeAnalyzer analyzer)
- {
- return new BeanModelSourceImpl(typeCoercer, _propertyAccess, _propertyConduitSource,
- _componentClassFactory, analyzer);
- }
+ // /**
+ // * The configuration of the model source is a mapping from type to string. The types are
+ // * property types and the values, the strings, represent different type of editors.
+ // */
+ // public BeanModelSource build(TypeCoercer typeCoercer,
+ //
+ // @InjectService("DataTypeAnalyzer")
+ // DataTypeAnalyzer analyzer)
+ // {
+ // return new BeanModelSourceImpl(typeCoercer, _propertyAccess, _propertyConduitSource,
+ // _componentClassFactory, analyzer);
+ // }
- public ComponentMessagesSource build(@InjectService("UpdateListenerHub")
- UpdateListenerHub updateListenerHub)
+ public static ComponentMessagesSource build(UpdateListenerHub updateListenerHub)
{
ComponentMessagesSourceImpl service = new ComponentMessagesSourceImpl();
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java Mon Apr 23 18:58:49 2007
@@ -59,7 +59,7 @@
import org.apache.tapestry.ioc.Location;
import org.apache.tapestry.ioc.Messages;
import org.apache.tapestry.ioc.Resource;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.ioc.test.IOCTestCase;
import org.apache.tapestry.model.ComponentModel;
import org.apache.tapestry.model.MutableComponentModel;
@@ -856,7 +856,7 @@
}
protected final void train_provideInjection(InjectionProvider provider, String fieldName,
- String fieldType, ServiceLocator locator, ClassTransformation transformation,
+ String fieldType, ObjectLocator locator, ClassTransformation transformation,
MutableComponentModel model, boolean result)
{
expect(provider.provideInjection(fieldName, fieldType, locator, transformation, model))
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AliasImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AliasImplTest.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AliasImplTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AliasImplTest.java Mon Apr 23 18:58:49 2007
@@ -22,7 +22,7 @@
import org.apache.tapestry.internal.test.InternalBaseTestCase;
import org.apache.tapestry.ioc.AnnotationProvider;
import org.apache.tapestry.ioc.ObjectProvider;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.services.Alias;
import org.apache.tapestry.services.AliasManager;
import org.testng.annotations.Test;
@@ -36,7 +36,7 @@
{
AliasManager manager = newAliasManager();
AliasManager overridesManager = newAliasManager();
- ServiceLocator locator = mockServiceLocator();
+ ObjectLocator locator = mockObjectLocator();
AnnotationProvider annotationProvider = mockAnnotationProvider();
replay();
@@ -75,7 +75,7 @@
AliasManager overridesManager = newAliasManager();
AnnotationProvider annotationProvider = mockAnnotationProvider();
- ServiceLocator locator = mockServiceLocator();
+ ObjectLocator locator = mockObjectLocator();
Runnable r = mockRunnable();
Map<Class, Object> configuration = newMap();
@@ -115,7 +115,7 @@
AliasManager overridesManager = newAliasManager();
AnnotationProvider annotationProvider = mockAnnotationProvider();
- ServiceLocator locator = mockServiceLocator();
+ ObjectLocator locator = mockObjectLocator();
Runnable r = mockRunnable();
Runnable override = mockRunnable();
@@ -153,7 +153,7 @@
AliasManager overridesManager = newAliasManager();
AnnotationProvider annotationProvider = mockAnnotationProvider();
- ServiceLocator locator = mockServiceLocator();
+ ObjectLocator locator = mockObjectLocator();
train_getAliasesForMode(manager, mode, _emptyMap);
train_getAliasesForMode(overridesManager, mode, _emptyMap);
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetInjectionProviderTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetInjectionProviderTest.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetInjectionProviderTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetInjectionProviderTest.java Mon Apr 23 18:58:49 2007
@@ -16,7 +16,7 @@
import org.apache.tapestry.annotations.Path;
import org.apache.tapestry.internal.test.InternalBaseTestCase;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.ioc.services.SymbolSource;
import org.apache.tapestry.model.MutableComponentModel;
import org.apache.tapestry.services.AssetSource;
@@ -31,7 +31,7 @@
{
SymbolSource symbolSource = mockSymbolSource();
AssetSource assetSource = mockAssetSource();
- ServiceLocator locator = mockServiceLocator();
+ ObjectLocator locator = mockObjectLocator();
ClassTransformation ct = mockClassTransformation();
MutableComponentModel model = mockMutableComponentModel();
@@ -54,7 +54,7 @@
{
SymbolSource symbolSource = mockSymbolSource();
AssetSource assetSource = mockAssetSource();
- ServiceLocator locator = mockServiceLocator();
+ ObjectLocator locator = mockObjectLocator();
ClassTransformation ct = mockClassTransformation();
MutableComponentModel model = mockMutableComponentModel();
Path annotation = mockPath();
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetObjectProviderTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetObjectProviderTest.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetObjectProviderTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetObjectProviderTest.java Mon Apr 23 18:58:49 2007
@@ -19,7 +19,7 @@
import org.apache.tapestry.internal.test.InternalBaseTestCase;
import org.apache.tapestry.ioc.AnnotationProvider;
import org.apache.tapestry.ioc.ObjectProvider;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.ioc.services.SymbolSource;
import org.apache.tapestry.ioc.services.TypeCoercer;
import org.apache.tapestry.services.AssetSource;
@@ -32,7 +32,7 @@
public void no_path_annotation()
{
AssetSource source = mockAssetSource();
- ServiceLocator locator = mockServiceLocator();
+ ObjectLocator locator = mockObjectLocator();
AnnotationProvider annotationProvider = mockAnnotationProvider();
TypeCoercer typeCoercer = mockTypeCoercer();
SymbolSource symbolSource = mockSymbolSource();
@@ -52,7 +52,7 @@
public void normal_conversion()
{
AssetSource source = mockAssetSource();
- ServiceLocator locator = mockServiceLocator();
+ ObjectLocator locator = mockObjectLocator();
Asset asset = mockAsset();
String path = "${foo}";
String expanded = "foo/bar/baz.gif";
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectResourcesWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectResourcesWorkerTest.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectResourcesWorkerTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectResourcesWorkerTest.java Mon Apr 23 18:58:49 2007
@@ -16,7 +16,7 @@
import org.apache.tapestry.annotations.Inject;
import org.apache.tapestry.internal.test.InternalBaseTestCase;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.model.MutableComponentModel;
import org.apache.tapestry.services.ClassTransformation;
import org.apache.tapestry.services.ComponentClassTransformWorker;
@@ -31,7 +31,7 @@
@Test
public void anonymous_injection()
{
- ServiceLocator locator = mockServiceLocator();
+ ObjectLocator locator = mockObjectLocator();
InjectionProvider ip = newMock(InjectionProvider.class);
Inject annotation = newMock(Inject.class);
ClassTransformation ct = mockClassTransformation();
@@ -58,7 +58,7 @@
@Test
public void anonymous_injection_not_provided()
{
- ServiceLocator locator = mockServiceLocator();
+ ObjectLocator locator = mockObjectLocator();
InjectionProvider ip = newMock(InjectionProvider.class);
Inject annotation = newMock(Inject.class);
ClassTransformation ct = mockClassTransformation();
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectWorkerTest.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectWorkerTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectWorkerTest.java Mon Apr 23 18:58:49 2007
@@ -21,7 +21,7 @@
import org.apache.tapestry.internal.test.InternalBaseTestCase;
import org.apache.tapestry.ioc.AnnotationProvider;
import org.apache.tapestry.ioc.ObjectProvider;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.model.MutableComponentModel;
import org.apache.tapestry.services.ClassTransformation;
import org.apache.tapestry.services.Request;
@@ -35,7 +35,7 @@
public void annotation_has_value()
{
ObjectProvider provider = mockObjectProvider();
- ServiceLocator locator = mockServiceLocator();
+ ObjectLocator locator = mockObjectLocator();
Inject annotation = newMock(Inject.class);
ClassTransformation ct = mockClassTransformation();
MutableComponentModel model = mockMutableComponentModel();
@@ -67,7 +67,7 @@
public void provide_object_fails()
{
ObjectProvider provider = mockObjectProvider();
- ServiceLocator locator = mockServiceLocator();
+ ObjectLocator locator = mockObjectLocator();
Inject annotation = newMock(Inject.class);
ClassTransformation ct = mockClassTransformation();
MutableComponentModel model = mockMutableComponentModel();
Copied: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ObjectLocator.java (from r529445, tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceLocator.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ObjectLocator.java?view=diff&rev=531674&p1=tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceLocator.java&r1=529445&p2=tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ObjectLocator.java&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceLocator.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ObjectLocator.java Mon Apr 23 18:58:49 2007
@@ -16,11 +16,12 @@
/**
* Defines an object which can provide access to services defined within a
- * {@link org.apache.tapestry.ioc.Registry}. Services are accessed via service id, or (when
- * appropriate) by just service interface. The Registry itself implements this interface, as does
+ * {@link org.apache.tapestry.ioc.Registry}, or to objects or object instances available by other
+ * means. Services are accessed via service id, or (when appropriate) by just service interface. The
+ * Registry itself implements this interface, as does
* {@link org.apache.tapestry.ioc.ServiceResources}.
*/
-public interface ServiceLocator
+public interface ObjectLocator
{
/**
@@ -72,4 +73,16 @@
*/
<T> T getObject(Class<T> objectType, AnnotationProvider annotationProvider);
+ /**
+ * Autobuilds a class by finding the public constructor with the most parameters. Services and
+ * resources will be injected into the parameters of the constructor.
+ *
+ * @param <T>
+ * @param clazz
+ * the type of object to instantiate
+ * @return the instantiated instance
+ * @throws RuntimeException
+ * if the autobuild fails
+ */
+ <T> T autobuild(Class<T> clazz);
}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ObjectProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ObjectProvider.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ObjectProvider.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ObjectProvider.java Mon Apr 23 18:58:49 2007
@@ -25,7 +25,7 @@
* In many cases, an object provider searches for additional annotations on the element (usually a
* parameter, or perhaps a field) for which a value is required.
* <p>
- * A default ObjectProvider uses {@link ServiceLocator#getService(Class)}.
+ * A default ObjectProvider uses {@link ObjectLocator#getService(Class)}.
*/
public interface ObjectProvider
{
@@ -49,5 +49,5 @@
* if the expression can not be evaluated, or the type of object identified is not
* assignable to the type specified by the objectType parameter
*/
- <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ServiceLocator locator);
+ <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator);
}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/Registry.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/Registry.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/Registry.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/Registry.java Mon Apr 23 18:58:49 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 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.
@@ -17,7 +17,7 @@
/**
* Public access to the IoC service registry.
*/
-public interface Registry extends ServiceLocator
+public interface Registry extends ObjectLocator
{
/**
* Invoked at the end of a request to discard any thread-specific information accumulated during
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBuilderResources.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBuilderResources.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBuilderResources.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBuilderResources.java Mon Apr 23 18:58:49 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 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.
@@ -12,24 +12,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry.ioc;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Extends {@link org.apache.tapestry.ioc.ServiceResources} with additional methods needed only by
- * the service builder method, related to accessing a service's configuration. Services may have a
- * <em>single</em> configuration in one of three flavors: unordered, ordered or mapped.
- *
- *
- */
-public interface ServiceBuilderResources extends ServiceResources, ModuleBuilderSource
-{
- <T> Collection<T> getUnorderedConfiguration(Class<T> valueType);
-
- <T> List<T> getOrderedConfiguration(Class<T> valueType);
-
- <K, V> Map<K, V> getMappedConfiguration(Class<K> keyType, Class<V> valueType);
-}
+package org.apache.tapestry.ioc;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Extends {@link org.apache.tapestry.ioc.ServiceResources} with additional methods needed only by
+ * the service builder method, related to accessing a service's configuration. Services may have a
+ * <em>single</em> configuration in one of three flavors: unordered, ordered or mapped.
+ */
+public interface ServiceBuilderResources extends ServiceResources, ModuleBuilderSource
+{
+ <T> Collection<T> getUnorderedConfiguration(Class<T> valueType);
+
+ <T> List<T> getOrderedConfiguration(Class<T> valueType);
+
+ <K, V> Map<K, V> getMappedConfiguration(Class<K> keyType, Class<V> valueType);
+}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceResources.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceResources.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceResources.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceResources.java Mon Apr 23 18:58:49 2007
@@ -19,9 +19,9 @@
/**
* Contains resources that may be provided to a service when it initializes, which includes other
* services defined in the registry. ServiceResources provides access to other services (it extends
- * {@link org.apache.tapestry.ioc.ServiceLocator}).
+ * {@link org.apache.tapestry.ioc.ObjectLocator}).
*/
-public interface ServiceResources extends ServiceLocator
+public interface ServiceResources extends ObjectLocator
{
/** Returns the fully qualified id of the service. */
String getServiceId();
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ContributionDef.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ContributionDef.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ContributionDef.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ContributionDef.java Mon Apr 23 18:58:49 2007
@@ -18,7 +18,7 @@
import org.apache.tapestry.ioc.MappedConfiguration;
import org.apache.tapestry.ioc.ModuleBuilderSource;
import org.apache.tapestry.ioc.OrderedConfiguration;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
/**
* Contribution to a service configuration.
@@ -45,7 +45,7 @@
* encapsulate all related error checks (such as passing of nulls or inappropriate
* classes).
*/
- void contribute(ModuleBuilderSource moduleBuilderSource, ServiceLocator locator,
+ void contribute(ModuleBuilderSource moduleBuilderSource, ObjectLocator locator,
Configuration configuration);
/**
@@ -61,7 +61,7 @@
* encapsulate all related error checks (such as passing of nulls or inappropriate
* classes).
*/
- void contribute(ModuleBuilderSource moduleBuilderSource, ServiceLocator locator,
+ void contribute(ModuleBuilderSource moduleBuilderSource, ObjectLocator locator,
OrderedConfiguration configuration);
/**
@@ -77,6 +77,6 @@
* encapsulate all related error checks (such as passing of null keys or values or
* inappropriate classes, or duplicate keys).
*/
- void contribute(ModuleBuilderSource moduleBuilderSource, ServiceLocator locator,
+ void contribute(ModuleBuilderSource moduleBuilderSource, ObjectLocator locator,
MappedConfiguration configuration);
}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ContributionDefImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ContributionDefImpl.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ContributionDefImpl.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ContributionDefImpl.java Mon Apr 23 18:58:49 2007
@@ -24,7 +24,7 @@
import org.apache.tapestry.ioc.MappedConfiguration;
import org.apache.tapestry.ioc.ModuleBuilderSource;
import org.apache.tapestry.ioc.OrderedConfiguration;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.ioc.def.ContributionDef;
import org.apache.tapestry.ioc.internal.util.InternalUtils;
import org.apache.tapestry.ioc.services.ClassFactory;
@@ -55,25 +55,25 @@
return _serviceId;
}
- public void contribute(ModuleBuilderSource moduleBuilderSource, ServiceLocator locator,
+ public void contribute(ModuleBuilderSource moduleBuilderSource, ObjectLocator locator,
Configuration configuration)
{
invokeMethod(moduleBuilderSource, locator, Configuration.class, configuration);
}
- public void contribute(ModuleBuilderSource moduleBuilderSource, ServiceLocator locator,
+ public void contribute(ModuleBuilderSource moduleBuilderSource, ObjectLocator locator,
OrderedConfiguration configuration)
{
invokeMethod(moduleBuilderSource, locator, OrderedConfiguration.class, configuration);
}
- public void contribute(ModuleBuilderSource moduleBuilderSource, ServiceLocator locator,
+ public void contribute(ModuleBuilderSource moduleBuilderSource, ObjectLocator locator,
MappedConfiguration configuration)
{
invokeMethod(moduleBuilderSource, locator, MappedConfiguration.class, configuration);
}
- private <T> void invokeMethod(ModuleBuilderSource source, ServiceLocator locator,
+ private <T> void invokeMethod(ModuleBuilderSource source, ObjectLocator locator,
Class<T> parameterType, T parameterValue)
{
Map<Class, Object> parameterDefaults = newMap();
@@ -83,7 +83,7 @@
// type, then we'll see an error putting together the parameter.
parameterDefaults.put(parameterType, parameterValue);
- parameterDefaults.put(ServiceLocator.class, locator);
+ parameterDefaults.put(ObjectLocator.class, locator);
Throwable fail = null;
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCInternalTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCInternalTestCase.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCInternalTestCase.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCInternalTestCase.java Mon Apr 23 18:58:49 2007
@@ -63,6 +63,11 @@
return _registry.getService(serviceId, serviceInterface);
}
+ public final <T> T autobuild(Class<T> clazz)
+ {
+ return _registry.autobuild(clazz);
+ }
+
@BeforeSuite
public final void setup_registry()
{
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCMessages.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCMessages.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCMessages.java Mon Apr 23 18:58:49 2007
@@ -294,4 +294,14 @@
{
return MESSAGES.format("error-in-bind-method", methodId, cause);
}
+
+ static String noAutobuildConstructor(Class clazz)
+ {
+ return MESSAGES.format("no-autobuild-constructor", clazz.getName());
+ }
+
+ static String autobuildConstructorError(String constructorDescription, Throwable cause)
+ {
+ return MESSAGES.format("autobuild-constructor-error", constructorDescription, cause);
+ }
}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/InternalRegistry.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/InternalRegistry.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/InternalRegistry.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/InternalRegistry.java Mon Apr 23 18:58:49 2007
@@ -24,7 +24,7 @@
import org.apache.tapestry.ioc.Registry;
import org.apache.tapestry.ioc.ServiceDecorator;
import org.apache.tapestry.ioc.ServiceLifecycle;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.ioc.def.ServiceDef;
import org.apache.tapestry.ioc.services.ClassFab;
import org.apache.tapestry.ioc.services.RegistryShutdownHub;
@@ -148,10 +148,10 @@
* value is to be obtained
* @param locator
* identifies what services are visible in the context
- * @see ObjectProvider#provide(Class, AnnotationProvider, ServiceLocator)
+ * @see ObjectProvider#provide(Class, AnnotationProvider, ObjectLocator)
*/
<T> T getObject(Class<T> objectType, AnnotationProvider annotationProvider,
- ServiceLocator locator);
+ ObjectLocator locator);
/**
* Given an input string that <em>may</em> contain symbols, returns the string with any and
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ModuleImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ModuleImpl.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ModuleImpl.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ModuleImpl.java Mon Apr 23 18:58:49 2007
@@ -37,7 +37,7 @@
import org.apache.tapestry.ioc.ServiceBuilderResources;
import org.apache.tapestry.ioc.ServiceDecorator;
import org.apache.tapestry.ioc.ServiceLifecycle;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.ioc.ServiceResources;
import org.apache.tapestry.ioc.def.ContributionDef;
import org.apache.tapestry.ioc.def.DecoratorDef;
@@ -46,6 +46,7 @@
import org.apache.tapestry.ioc.internal.services.JustInTimeObjectCreator;
import org.apache.tapestry.ioc.internal.util.InternalUtils;
import org.apache.tapestry.ioc.services.ClassFab;
+import org.apache.tapestry.ioc.services.ClassFactory;
import org.apache.tapestry.ioc.services.MethodSignature;
import org.apache.tapestry.ioc.services.TapestryIOCModule;
@@ -55,6 +56,8 @@
private final ModuleDef _moduleDef;
+ private final ClassFactory _classFactory;
+
private final Log _log;
// Guarded by MUTEX
@@ -72,10 +75,12 @@
// the constructor. Guarded by MUTEX.
private boolean _insideConstructor;
- public ModuleImpl(InternalRegistry registry, ModuleDef moduleDef, Log log)
+ public ModuleImpl(InternalRegistry registry, ModuleDef moduleDef, ClassFactory classFactory,
+ Log log)
{
_registry = registry;
_moduleDef = moduleDef;
+ _classFactory = classFactory;
_log = log;
}
@@ -212,7 +217,8 @@
{
ServiceLifecycle lifecycle = _registry.getServiceLifecycle(def.getServiceScope());
- ServiceBuilderResources resources = new ServiceResourcesImpl(_registry, this, def, log);
+ ServiceBuilderResources resources = new ServiceResourcesImpl(_registry, this, def,
+ _classFactory, log);
// Build up a stack of operations that will be needed to realize the service
// (by the proxy, at a later date).
@@ -306,11 +312,11 @@
builderClass,
constructor));
- ServiceLocator locator = new ServiceLocatorImpl(_registry, this);
+ ObjectLocator locator = new ObjectLocatorImpl(_registry, this);
Map<Class, Object> parameterDefaults = newMap();
parameterDefaults.put(Log.class, _log);
- parameterDefaults.put(ServiceLocator.class, locator);
+ parameterDefaults.put(ObjectLocator.class, locator);
Throwable fail = null;
Copied: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ObjectLocatorImpl.java (from r529445, tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceLocatorImpl.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ObjectLocatorImpl.java?view=diff&rev=531674&p1=tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceLocatorImpl.java&r1=529445&p2=tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ObjectLocatorImpl.java&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceLocatorImpl.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ObjectLocatorImpl.java Mon Apr 23 18:58:49 2007
@@ -15,19 +15,19 @@
package org.apache.tapestry.ioc.internal;
import org.apache.tapestry.ioc.AnnotationProvider;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
/**
* Base service locator class used when only the module is known (i.e., when instantiating a module
* builder class).
*/
-public class ServiceLocatorImpl extends Object implements ServiceLocator
+public class ObjectLocatorImpl implements ObjectLocator
{
private final InternalRegistry _registry;
private final Module _module;
- public ServiceLocatorImpl(InternalRegistry registry, Module module)
+ public ObjectLocatorImpl(InternalRegistry registry, Module module)
{
_registry = registry;
_module = module;
@@ -59,4 +59,10 @@
{
return _module;
}
+
+ public <T> T autobuild(Class<T> clazz)
+ {
+ return _registry.autobuild(clazz);
+ }
+
}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java Mon Apr 23 18:58:49 2007
@@ -17,7 +17,10 @@
import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newCaseInsensitiveMap;
import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
+import static org.apache.tapestry.ioc.internal.util.Defense.notNull;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -36,7 +39,7 @@
import org.apache.tapestry.ioc.RegistryBuilder;
import org.apache.tapestry.ioc.ServiceDecorator;
import org.apache.tapestry.ioc.ServiceLifecycle;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.ioc.ServiceResources;
import org.apache.tapestry.ioc.def.ContributionDef;
import org.apache.tapestry.ioc.def.DecoratorDef;
@@ -143,7 +146,7 @@
{
Log log = _logSource.getLog(def.getBuilderClass());
- Module module = new ModuleImpl(this, def, log);
+ Module module = new ModuleImpl(this, def, classFactory, log);
_modules.add(module);
@@ -391,7 +394,8 @@
boolean debug = log.isDebugEnabled();
- ServiceLocator locator = new ServiceResourcesImpl(this, module, serviceDef, log);
+ ObjectLocator locator = new ServiceResourcesImpl(this, module, serviceDef, _classFactory,
+ log);
for (ContributionDef def : contributions)
{
@@ -417,7 +421,8 @@
boolean debug = log.isDebugEnabled();
- ServiceLocator locator = new ServiceResourcesImpl(this, module, serviceDef, log);
+ ObjectLocator locator = new ServiceResourcesImpl(this, module, serviceDef, _classFactory,
+ log);
for (ContributionDef def : contributions)
{
@@ -441,7 +446,8 @@
Log log = logForService(serviceId);
boolean debug = log.isDebugEnabled();
- ServiceLocator locator = new ServiceResourcesImpl(this, module, serviceDef, log);
+ ObjectLocator locator = new ServiceResourcesImpl(this, module, serviceDef, _classFactory,
+ log);
for (ContributionDef def : contributions)
{
@@ -536,7 +542,8 @@
if (decorators.isEmpty()) continue;
- ServiceResources resources = new ServiceResourcesImpl(this, module, serviceDef, log);
+ ServiceResources resources = new ServiceResourcesImpl(this, module, serviceDef,
+ _classFactory, log);
for (DecoratorDef dd : decorators)
{
@@ -557,7 +564,7 @@
}
public <T> T getObject(Class<T> objectType, AnnotationProvider annotationProvider,
- ServiceLocator locator)
+ ObjectLocator locator)
{
_lock.check();
@@ -600,6 +607,46 @@
_symbolSource = getService(SYMBOL_SOURCE_SERVICE_ID, SymbolSource.class);
return _symbolSource;
+ }
+
+ public <T> T autobuild(Class<T> clazz)
+ {
+ notNull(clazz, "clazz");
+
+ Constructor constructor = InternalUtils.findAutobuildConstructor(clazz);
+
+ if (constructor == null)
+ throw new RuntimeException(IOCMessages.noAutobuildConstructor(clazz));
+
+ Throwable failure = null;
+ // An empty map, because when performing autobuilding outside the context of building a
+ // service, we don't have defaults for Log, service id, etc.
+
+ Map<Class, Object> empty = Collections.emptyMap();
+
+ try
+ {
+ Object[] parameters = InternalUtils.calculateParametersForConstructor(
+ constructor,
+ this,
+ empty);
+
+ return clazz.cast(constructor.newInstance(parameters));
+ }
+ catch (InvocationTargetException ite)
+ {
+ failure = ite.getTargetException();
+ }
+ catch (Exception ex)
+ {
+ failure = ex;
+ }
+
+ String description = _classFactory.getConstructorLocation(constructor);
+
+ throw new RuntimeException(IOCMessages.autobuildConstructorError(description, failure),
+ failure);
+
}
}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryWrapper.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryWrapper.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryWrapper.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryWrapper.java Mon Apr 23 18:58:49 2007
@@ -16,11 +16,11 @@
import org.apache.tapestry.ioc.AnnotationProvider;
import org.apache.tapestry.ioc.Registry;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
/**
* A wrapper around {@link InternalRegistry} that exists to expand symbols in a service id before
- * invoking {@link ServiceLocator#getService(Class)}.
+ * invoking {@link ObjectLocator#getService(Class)}.
*/
public class RegistryWrapper implements Registry
{
@@ -56,6 +56,11 @@
public <T> T getService(Class<T> serviceInterface)
{
return _registry.getService(serviceInterface);
+ }
+
+ public <T> T autobuild(Class<T> clazz)
+ {
+ return _registry.autobuild(clazz);
}
}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceBinderImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceBinderImpl.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceBinderImpl.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceBinderImpl.java Mon Apr 23 18:58:49 2007
@@ -18,8 +18,6 @@
import static org.apache.tapestry.ioc.internal.util.Defense.notNull;
import java.lang.reflect.Constructor;
-import java.util.Arrays;
-import java.util.Comparator;
import org.apache.tapestry.ioc.IOCConstants;
import org.apache.tapestry.ioc.ObjectCreator;
@@ -29,6 +27,7 @@
import org.apache.tapestry.ioc.annotations.EagerLoad;
import org.apache.tapestry.ioc.annotations.Scope;
import org.apache.tapestry.ioc.def.ServiceDef;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
import org.apache.tapestry.ioc.internal.util.OneShotLock;
import org.apache.tapestry.ioc.services.ClassFactory;
@@ -96,37 +95,13 @@
private Constructor findConstructor()
{
- Constructor[] constructors = _serviceImplementation.getConstructors();
+ Constructor result = InternalUtils.findAutobuildConstructor(_serviceImplementation);
- switch (constructors.length)
- {
- case 1:
-
- return constructors[0];
-
- case 0:
-
- throw new RuntimeException(IOCMessages.noConstructor(
- _serviceImplementation,
- _serviceId));
-
- default:
- break;
- }
-
- // Choose a constructor with the most parameters.
-
- Comparator<Constructor> comparator = new Comparator<Constructor>()
- {
- public int compare(Constructor o1, Constructor o2)
- {
- return o2.getParameterTypes().length - o1.getParameterTypes().length;
- }
- };
-
- Arrays.sort(constructors, comparator);
+ if (result == null)
+ throw new RuntimeException(IOCMessages
+ .noConstructor(_serviceImplementation, _serviceId));
- return constructors[0];
+ return result;
}
public <T> ServiceBindingOptions bind(Class<T> implementationClass)
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceResourcesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceResourcesImpl.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceResourcesImpl.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceResourcesImpl.java Mon Apr 23 18:58:49 2007
@@ -14,13 +14,19 @@
package org.apache.tapestry.ioc.internal;
+import static org.apache.tapestry.ioc.internal.util.Defense.notNull;
+
+import java.lang.reflect.Constructor;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
+import org.apache.tapestry.ioc.ObjectCreator;
import org.apache.tapestry.ioc.ServiceBuilderResources;
import org.apache.tapestry.ioc.def.ServiceDef;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
+import org.apache.tapestry.ioc.services.ClassFactory;
/**
* Implementation of {@link org.apache.tapestry.ioc.ServiceBuilderResources}. We just have one
@@ -30,17 +36,21 @@
* just service builder methods). Since it is most commonly used for the former, we'll just leave
* the name as ServiceResourcesImpl.
*/
-public class ServiceResourcesImpl extends ServiceLocatorImpl implements ServiceBuilderResources
+public class ServiceResourcesImpl extends ObjectLocatorImpl implements ServiceBuilderResources
{
private final ServiceDef _serviceDef;
private final Log _log;
+ private final ClassFactory _classFactory;
+
public ServiceResourcesImpl(InternalRegistry registry, Module module, ServiceDef serviceDef,
- Log log)
+ ClassFactory classFactory, Log log)
{
super(registry, module);
+
_serviceDef = serviceDef;
+ _classFactory = classFactory;
_log = log;
}
@@ -96,4 +106,19 @@
return getModule().getModuleBuilder();
}
+ public <T> T autobuild(Class<T> clazz)
+ {
+ notNull(clazz, "clazz");
+
+ Constructor constructor = InternalUtils.findAutobuildConstructor(clazz);
+
+ if (constructor == null)
+ throw new RuntimeException(IOCMessages.noAutobuildConstructor(clazz));
+
+ String description = _classFactory.getConstructorLocation(constructor);
+
+ ObjectCreator creator = new ConstructorServiceCreator(this, description, constructor);
+
+ return clazz.cast(creator.createObject());
+ }
}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/JustInTimeObjectCreator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/JustInTimeObjectCreator.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/JustInTimeObjectCreator.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/JustInTimeObjectCreator.java Mon Apr 23 18:58:49 2007
@@ -56,8 +56,18 @@
if (_object == null)
{
- _object = _creator.createObject();
- _creator = null;
+ try
+ {
+ _object = _creator.createObject();
+
+ // And if that's successful ...
+
+ _creator = null;
+ }
+ catch (RuntimeException ex)
+ {
+ throw new RuntimeException(ServiceMessages.serviceBuildFailure(_serviceId, ex), ex);
+ }
}
return _object;
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/PerThreadServiceLifecycle.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/PerThreadServiceLifecycle.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/PerThreadServiceLifecycle.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/PerThreadServiceLifecycle.java Mon Apr 23 18:58:49 2007
@@ -23,6 +23,7 @@
import org.apache.tapestry.ioc.ObjectCreator;
import org.apache.tapestry.ioc.ServiceLifecycle;
import org.apache.tapestry.ioc.ServiceResources;
+import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.ioc.services.ClassFab;
import org.apache.tapestry.ioc.services.ClassFactory;
import org.apache.tapestry.ioc.services.MethodSignature;
@@ -47,7 +48,9 @@
private static final String PER_THREAD_METHOD_NAME = "_perThreadInstance";
- public PerThreadServiceLifecycle(ThreadCleanupHub threadCleanupHub, ClassFactory classFactory)
+ public PerThreadServiceLifecycle(ThreadCleanupHub threadCleanupHub,
+ @InjectService("ClassFactory")
+ ClassFactory classFactory)
{
_threadCleanupHub = threadCleanupHub;
_classFactory = classFactory;
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ServiceMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ServiceMessages.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ServiceMessages.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ServiceMessages.java Mon Apr 23 18:58:49 2007
@@ -182,4 +182,8 @@
return MESSAGES.format("registry-shutdown", serviceId);
}
+ static String serviceBuildFailure(String serviceId, Throwable cause)
+ {
+ return MESSAGES.format("service-build-failure", serviceId, cause);
+ }
}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ValueObjectProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ValueObjectProvider.java?view=diff&rev=531674&r1=531673&r2=531674
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ValueObjectProvider.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ValueObjectProvider.java Mon Apr 23 18:58:49 2007
@@ -16,7 +16,7 @@
import org.apache.tapestry.ioc.AnnotationProvider;
import org.apache.tapestry.ioc.ObjectProvider;
-import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.ioc.annotations.Value;
import org.apache.tapestry.ioc.services.SymbolSource;
@@ -39,7 +39,7 @@
}
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider,
- ServiceLocator locator)
+ ObjectLocator locator)
{
Value annotation = annotationProvider.getAnnotation(Value.class);