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/10/15 17:46:55 UTC
svn commit: r584809 - in /tapestry/tapestry5/trunk/tapestry-ioc/src:
main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java
main/java/org/apache/tapestry/ioc/internal/RegistryWrapper.java
test/java/org/apache/tapestry/ioc/IntegrationTest.java
Author: hlship
Date: Mon Oct 15 08:46:54 2007
New Revision: 584809
URL: http://svn.apache.org/viewvc?rev=584809&view=rev
Log:
TAPESTRY-1831: Builtin services (TypeCoercer, ClassFactory, etc.) are not marked with the @Builtin annotation
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/RegistryWrapper.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java?rev=584809&r1=584808&r2=584809&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java Mon Oct 15 08:46:54 2007
@@ -32,10 +32,12 @@
import org.apache.tapestry.ioc.IOCConstants;
import org.apache.tapestry.ioc.LoggerSource;
import org.apache.tapestry.ioc.MappedConfiguration;
+import org.apache.tapestry.ioc.ObjectCreator;
import org.apache.tapestry.ioc.ObjectLocator;
import org.apache.tapestry.ioc.ObjectProvider;
import org.apache.tapestry.ioc.OrderedConfiguration;
import org.apache.tapestry.ioc.Registry;
+import org.apache.tapestry.ioc.ServiceBuilderResources;
import org.apache.tapestry.ioc.ServiceDecorator;
import org.apache.tapestry.ioc.ServiceLifecycle;
import org.apache.tapestry.ioc.ServiceResources;
@@ -56,6 +58,7 @@
import org.apache.tapestry.ioc.services.SymbolSource;
import org.apache.tapestry.ioc.services.TapestryIOCModule;
import org.apache.tapestry.ioc.services.ThreadCleanupHub;
+import org.apache.tapestry.ioc.services.TapestryIOCModule.Builtin;
import org.apache.tapestry.services.MasterObjectProvider;
import org.slf4j.Logger;
@@ -220,13 +223,48 @@
return _loggerSource.getLogger(TapestryIOCModule.class + "." + serviceId);
}
- private <T> void addBuiltin(String serviceId, Class<T> serviceInterface, T service)
+ private <T> void addBuiltin(final String serviceId, final Class<T> serviceInterface, T service)
{
_builtinTypes.put(serviceId, serviceInterface);
_builtinServices.put(serviceId, service);
- // TODO: Figure out a way to "mark" the builtins with the TapestryIoCModule.Builtin
- // annotation.
+ // Make sure each of the builtin services is also available via the Builtin annotation
+ // marker.
+
+ ServiceDef serviceDef = new ServiceDef()
+ {
+ public ObjectCreator createServiceCreator(ServiceBuilderResources resources)
+ {
+ return null;
+ }
+
+ public Class getMarker()
+ {
+ return Builtin.class;
+ }
+
+ public String getServiceId()
+ {
+ return serviceId;
+ }
+
+ public Class getServiceInterface()
+ {
+ return serviceInterface;
+ }
+
+ public String getServiceScope()
+ {
+ return IOCConstants.DEFAULT_SCOPE;
+ }
+
+ public boolean isEagerLoad()
+ {
+ return false;
+ }
+ };
+
+ InternalUtils.addToMapList(_markerToServiceDef, serviceDef.getMarker(), serviceDef);
}
public synchronized void shutdown()
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/RegistryWrapper.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/RegistryWrapper.java?rev=584809&r1=584808&r2=584809&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/RegistryWrapper.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/RegistryWrapper.java Mon Oct 15 08:46:54 2007
@@ -43,7 +43,7 @@
public <T> T getObject(Class<T> objectType, AnnotationProvider annotationProvider)
{
- return _registry.getObject(objectType, null);
+ return _registry.getObject(objectType, annotationProvider);
}
public <T> T getService(String serviceId, Class<T> serviceInterface)
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java?rev=584809&r1=584808&r2=584809&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java Mon Oct 15 08:46:54 2007
@@ -23,6 +23,8 @@
import org.apache.tapestry.ioc.internal.ExceptionInConstructorModule;
import org.apache.tapestry.ioc.internal.IOCInternalTestCase;
+import org.apache.tapestry.ioc.services.TypeCoercer;
+import org.apache.tapestry.ioc.services.TapestryIOCModule.Builtin;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -638,5 +640,27 @@
" Unable to locate any service assignable to type org.apache.tapestry.ioc.Greeter with marker annotation org.apache.tapestry.ioc.YellowMarker.");
}
+ }
+
+ @Test
+ public void builtin_services_available_via_marker_annotation()
+ {
+ Registry r = buildRegistry();
+
+ TypeCoercer tc1 = r.getService("TypeCoercer", TypeCoercer.class);
+
+ Builtin annotation = newMock(Builtin.class);
+
+ AnnotationProvider ap = mockAnnotationProvider();
+
+ train_getAnnotation(ap, Builtin.class, annotation);
+
+ replay();
+
+ TypeCoercer tc2 = r.getObject(TypeCoercer.class, ap);
+
+ assertSame(tc1, tc2);
+
+ verify();
}
}