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 2007/03/11 20:11:04 UTC
svn commit: r516990 [1/2] - in
/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry:
internal/services/InternalModule.java services/TapestryModule.java
Author: hlship
Date: Sun Mar 11 12:11:03 2007
New Revision: 516990
URL: http://svn.apache.org/viewvc?view=rev&rev=516990
Log:
TAPESTRY-1341: Allow service builders named "build" and determine service id from the result type
Modified:
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/services/TapestryModule.java
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=516990&r1=516989&r2=516990
==============================================================================
--- 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 Sun Mar 11 12:11:03 2007
@@ -73,6 +73,88 @@
public final class InternalModule
{
+ @Lifecycle("perthread")
+ public static TemplateParser build(Log log)
+ {
+ return new TemplateParserImpl(log);
+ }
+
+ public static PageResponseRenderer build(@InjectService("PageMarkupRenderer")
+ PageMarkupRenderer markupRenderer, @InjectService("MarkupWriterFactory")
+ MarkupWriterFactory markupWriterFactory)
+ {
+ return new PageResponseRendererImpl(markupWriterFactory, markupRenderer);
+ }
+
+ public static PageMarkupRenderer build(@InjectService("PageRenderInitializer")
+ PageRenderInitializer pageRenderInitializer)
+ {
+ return new PageMarkupRendererImpl(pageRenderInitializer);
+ }
+
+ /**
+ * A map from a {@link org.apache.tapestry.dom.Element} to a {@link ComponentInvocation}
+ * Components rendering a link element that is intended to be "clickable" by the
+ * {@link org.apache.tapestry.test.pagelevel.PageTester} must map that element to an
+ * ComponentInvocation so that the PageTester can find it.
+ * <p>
+ * By default (production mode), the map does nothing.
+ */
+ public static ComponentInvocationMap buildComponentInvocationMap()
+ {
+ return new NoOpComponentInvocationMap();
+ }
+
+ @Lifecycle("perthread")
+ public static ObjectRenderer buildLocationRenderer()
+ {
+ return new LocationRenderer();
+ }
+
+ /**
+ * The UpdateListenerHub provides events that other services use to check for invalidations.
+ * Such services usually are {@link org.apache.tapestry.internal.event.InvalidationEventHub}s,
+ * and fire invalidation events to their listeners.
+ */
+ public static UpdateListenerHub buildUpdateListenerHub()
+ {
+ return new UpdateListenerHubImpl();
+ }
+
+ /**
+ * Contributes factory defaults that map be overridden.
+ */
+ public static void contributeFactoryDefaults(MappedConfiguration<String, String> configuration)
+ {
+ // Remember this is request-to-request time, presumably it'll take the developer more than
+ // one second to make a change, save it, and switch back to the browser.
+
+ configuration.add("tapestry.file-check-interval", "1000"); // 1 second
+ configuration.add("tapestry.supported-locales", "en");
+ configuration.add("tapestry.default-cookie-max-age", "604800"); // One week
+
+ configuration.add("tapestry.start-page-name", "start");
+
+ // This is designed to make it easy to keep syncrhonized with script.aculo.ous. As we
+ // support a new version, we create a new folder, and update the path entry. We can then
+ // delete the old version folder (or keep it around). This should be more manageable than
+ // ovewriting the local copy with updates. There's also a ClasspathAliasManager
+ // contribution based on the path.
+
+ configuration.add("tapestry.scriptaculous", "classpath:${tapestry.scriptaculous.path}");
+ configuration.add("tapestry.scriptaculous.path", "org/apache/tapestry/scriptaculous_1_7_0");
+ }
+
+ public static void contributeInfrastructure(
+ Configuration<InfrastructureContribution> configuration,
+
+ @InjectService("DefaultRequestExceptionHandler")
+ RequestExceptionHandler defaultRequestExceptionHandler)
+ {
+ configuration.add(new InfrastructureContribution("RequestExceptionHandler",
+ defaultRequestExceptionHandler));
+ }
+
private final ComponentInstantiatorSource _componentInstantiatorSource;
private final ComponentTemplateSource _componentTemplateSource;
@@ -147,23 +229,17 @@
_linkFactory = linkFactory;
}
- public ComponentClassTransformer buildComponentClassTransformer(
- @InjectService("ComponentClassTransformWorker")
- ComponentClassTransformWorker workerChain, @InjectService("LogSource")
- LogSource logSource)
+ public PageTemplateLocator build(@InjectService("ContextAssetFactory")
+ AssetFactory contextAssetFactory, @Inject("infrastructure:ComponentClassResolver")
+ ComponentClassResolver componentClassResolver)
{
- ComponentClassTransformerImpl transformer = new ComponentClassTransformerImpl(workerChain,
- logSource);
-
- _componentInstantiatorSource.addInvalidationListener(transformer);
-
- return transformer;
+ return new PageTemplateLocatorImpl(contextAssetFactory.getRootResource(),
+ componentClassResolver);
}
- public ComponentInstantiatorSource buildComponentInstantiatorSource(
- @InjectService("ClassFactory")
- ClassFactory classFactory, @InjectService("ComponentClassTransformer")
- ComponentClassTransformer transformer, Log log)
+ public ComponentInstantiatorSource build(@InjectService("ClassFactory")
+ ClassFactory classFactory, @InjectService("ComponentClassTransformer")
+ ComponentClassTransformer transformer, Log log)
{
ComponentInstantiatorSourceImpl source = new ComponentInstantiatorSourceImpl(classFactory
.getClassLoader(), transformer, log);
@@ -173,37 +249,57 @@
return source;
}
- public ComponentTemplateSource buildComponentTemplateSource(@InjectService("TemplateParser")
- TemplateParser parser, @InjectService("PageTemplateLocator")
- PageTemplateLocator locator)
+ public ComponentClassTransformer build(@InjectService("ComponentClassTransformWorker")
+ ComponentClassTransformWorker workerChain, @InjectService("LogSource")
+ LogSource logSource)
{
- ComponentTemplateSourceImpl service = new ComponentTemplateSourceImpl(parser, locator);
+ ComponentClassTransformerImpl transformer = new ComponentClassTransformerImpl(workerChain,
+ logSource);
- _updateListenerHub.addUpdateListener(service);
+ _componentInstantiatorSource.addInvalidationListener(transformer);
- return service;
+ return transformer;
}
- @Lifecycle("perthread")
- public static TemplateParser buildTemplateParser(Log log)
- {
- return new TemplateParserImpl(log);
- }
+ /** Service used to create links for components and pages. */
+ public LinkFactory build(@InjectService("ContextPathSource")
+ ContextPathSource contextPathSource,
- public PageElementFactory buildPageElementFactory(@Inject("infrastructure:TypeCoercer")
- TypeCoercer typeCoercer,
+ @InjectService("URLEncoder")
+ URLEncoder encoder,
- @Inject("infrastructure:BindingSource")
- BindingSource bindingSource,
+ @InjectService("ComponentInvocationMap")
+ ComponentInvocationMap componentInvocationMap,
- @Inject("infrastructure:ComponentMessagesSource")
+ @Inject("infrastructure:TypeCoercer")
+ TypeCoercer typeCoercer)
+ {
+ return new LinkFactoryImpl(contextPathSource, encoder, _componentClassResolver,
+ componentInvocationMap, _pageCache, typeCoercer);
+ }
+
+ public PagePool build(Log log, @InjectService("PageLoader")
+ PageLoader pageLoader, @Inject("infrastructure:ComponentMessagesSource")
ComponentMessagesSource componentMessagesSource)
{
- return new PageElementFactoryImpl(_componentInstantiatorSource, _componentClassResolver,
- typeCoercer, bindingSource, componentMessagesSource);
+ PagePoolImpl service = new PagePoolImpl(log, pageLoader, _threadLocale);
+
+ // This covers invalidations due to changes to classes
+
+ pageLoader.addInvalidationListener(service);
+
+ // This covers invalidation due to changes to message catalogs (properties files)
+
+ componentMessagesSource.addInvalidationListener(service);
+
+ // ... and this covers invalidations due to changes to templates
+
+ _componentTemplateSource.addInvalidationListener(service);
+
+ return service;
}
- public PageLoader buildPageLoader(@InjectService("PageElementFactory")
+ public PageLoader build(@InjectService("PageElementFactory")
PageElementFactory pageElementFactory,
@InjectService("BindingSource")
@@ -224,113 +320,168 @@
return service;
}
- public PagePool buildPagePool(Log log, @InjectService("PageLoader")
- PageLoader pageLoader, @Inject("infrastructure:ComponentMessagesSource")
- ComponentMessagesSource componentMessagesSource)
+ @Lifecycle("perthread")
+ public RequestPageCache build(@InjectService("PagePool")
+ PagePool pagePool)
{
- PagePoolImpl service = new PagePoolImpl(log, pageLoader, _threadLocale);
+ RequestPageCacheImpl service = new RequestPageCacheImpl(_componentClassResolver, pagePool);
- // This covers invalidations due to changes to classes
+ _threadCleanupHub.addThreadCleanupListener(service);
- pageLoader.addInvalidationListener(service);
+ return service;
+ }
- // This covers invalidation due to changes to message catalogs (properties files)
+ public LocalizationSetter build(@InjectService("PersistentLocale")
+ PersistentLocale persistentLocale,
- componentMessagesSource.addInvalidationListener(service);
+ @Inject("${tapestry.supported-locales}")
+ String localeNames)
+ {
+ return new LocalizationSetterImpl(persistentLocale, _threadLocale, localeNames);
+ }
- // ... and this covers invalidations due to changes to templates
+ public ResourceCache build(@Inject("infrastructure:ResourceDigestGenerator")
+ ResourceDigestGenerator digestGenerator)
+ {
+ ResourceCacheImpl service = new ResourceCacheImpl(digestGenerator);
- _componentTemplateSource.addInvalidationListener(service);
+ _updateListenerHub.addUpdateListener(service);
return service;
}
- /**
- * The UpdateListenerHub provides events that other services use to check for invalidations.
- * Such services usually are {@link org.apache.tapestry.internal.event.InvalidationEventHub}s,
- * and fire invalidation events to their listeners.
- */
- public static UpdateListenerHub buildUpdateListenerHub()
+ public ComponentTemplateSource build(@InjectService("TemplateParser")
+ TemplateParser parser, @InjectService("PageTemplateLocator")
+ PageTemplateLocator locator)
{
- return new UpdateListenerHubImpl();
+ ComponentTemplateSourceImpl service = new ComponentTemplateSourceImpl(parser, locator);
+
+ _updateListenerHub.addUpdateListener(service);
+
+ return service;
}
- @Lifecycle("perthread")
- public RequestPageCache buildRequestPageCache(@InjectService("PagePool")
- PagePool pagePool)
+ public PageElementFactory build(@Inject("infrastructure:TypeCoercer")
+ TypeCoercer typeCoercer,
+
+ @Inject("infrastructure:BindingSource")
+ BindingSource bindingSource,
+
+ @Inject("infrastructure:ComponentMessagesSource")
+ ComponentMessagesSource componentMessagesSource)
{
- RequestPageCacheImpl service = new RequestPageCacheImpl(_componentClassResolver, pagePool);
+ return new PageElementFactoryImpl(_componentInstantiatorSource, _componentClassResolver,
+ typeCoercer, bindingSource, componentMessagesSource);
+ }
- _threadCleanupHub.addThreadCleanupListener(service);
+ public ActionLinkHandler buildActionLinkHandler(
+ @Inject("infrastructure:ComponentEventResultProcessor")
+ ComponentEventResultProcessor resultProcessor)
+ {
+ return new ActionLinkHandlerImpl(resultProcessor, _pageCache, _linkFactory);
+ }
- return service;
+ public AssetFactory buildClasspathAssetFactory(@InjectService("ResourceCache")
+ ResourceCache resourceCache, @Inject("infrastructure:ClasspathAssetAliasManager")
+ ClasspathAssetAliasManager aliasManager)
+ {
+ ClasspathAssetFactory factory = new ClasspathAssetFactory(resourceCache, aliasManager);
+
+ resourceCache.addInvalidationListener(factory);
+
+ return factory;
}
- public static PageResponseRenderer buildPageResponseRenderer(
- @InjectService("PageMarkupRenderer")
- PageMarkupRenderer markupRenderer, @InjectService("MarkupWriterFactory")
- MarkupWriterFactory markupWriterFactory)
+ public AssetFactory buildContextAssetFactory(@Inject("infrastructure:ApplicationGlobals")
+ ApplicationGlobals globals)
{
- return new PageResponseRendererImpl(markupWriterFactory, markupRenderer);
+ return new ContextAssetFactory(_request, globals.getContext());
}
- public static PageMarkupRenderer buildPageMarkupRenderer(
- @InjectService("PageRenderInitializer")
- PageRenderInitializer pageRenderInitializer)
+ public ContextPathSource buildContextPathSource()
{
- return new PageMarkupRendererImpl(pageRenderInitializer);
+ return _request;
}
- /**
- * Adds a filter that checks for updates to classes and other resources. It is ordered before:*.
- */
- public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration,
- @InjectService("RequestGlobals")
- final RequestGlobals requestGlobals,
+ public CookieSink buildCookieSink()
+ {
+ return new CookieSink()
+ {
- @Inject("${tapestry.file-check-interval}")
- long checkInterval,
+ public void addCookie(Cookie cookie)
+ {
+ _requestGlobals.getHTTPServletResponse().addCookie(cookie);
+ }
- @InjectService("LocalizationSetter")
- LocalizationSetter localizationSetter)
+ };
+ }
+
+ public CookieSource buildCookieSource()
{
- configuration.add("CheckForUpdates", new CheckForUpdatesFilter(_updateListenerHub,
- checkInterval), "before:*");
+ return new CookieSource()
+ {
- configuration.add("Localization", new LocalizationFilter(localizationSetter));
+ public Cookie[] getCookies()
+ {
+ return _requestGlobals.getHTTPServletRequest().getCookies();
+ }
+
+ };
}
- public LocalizationSetter buildLocalizationSetter(@InjectService("PersistentLocale")
- PersistentLocale persistentLocale,
+ public RequestExceptionHandler buildDefaultRequestExceptionHandler(Log log,
- @Inject("${tapestry.supported-locales}")
- String localeNames)
+ @InjectService("PageResponseRenderer")
+ PageResponseRenderer renderer)
{
- return new LocalizationSetterImpl(persistentLocale, _threadLocale, localeNames);
+ return new DefaultRequestExceptionHandler(_pageCache, renderer, _response, log);
+ }
+
+ public FormParameterLookup buildFormParameterLookup()
+ {
+ return _request;
+ }
+
+ public PageLinkHandler buildPageLinkHandler(
+ @Inject("infrastructure:ComponentEventResultProcessor")
+ ComponentEventResultProcessor resultProcessor)
+ {
+ return new PageLinkHandlerImpl(_pageCache, resultProcessor);
}
/**
- * Contributes factory defaults that map be overridden.
+ * Builds the PropBindingFactory as a chain of command. The terminator of the chain is
+ * responsible for ordinary property names (and property paths). Contributions to the service
+ * cover additional special cases, such as simple literal values.
+ *
+ * @param configuration
+ * contributions of special factories for some constants, each contributed factory
+ * may return a binding if applicable, or null otherwise
*/
- public static void contributeFactoryDefaults(MappedConfiguration<String, String> configuration)
+ public BindingFactory buildPropBindingFactory(List<BindingFactory> configuration,
+ @Inject("infrastructure:PropertyConduitSource")
+ PropertyConduitSource propertyConduitSource)
{
- // Remember this is request-to-request time, presumably it'll take the developer more than
- // one second to make a change, save it, and switch back to the browser.
+ PropBindingFactory service = new PropBindingFactory(propertyConduitSource);
- configuration.add("tapestry.file-check-interval", "1000"); // 1 second
- configuration.add("tapestry.supported-locales", "en");
- configuration.add("tapestry.default-cookie-max-age", "604800"); // One week
+ configuration.add(service);
- configuration.add("tapestry.start-page-name", "start");
+ return _chainBuilder.build(BindingFactory.class, configuration);
+ }
- // This is designed to make it easy to keep syncrhonized with script.aculo.ous. As we
- // support a new version, we create a new folder, and update the path entry. We can then
- // delete the old version folder (or keep it around). This should be more manageable than
- // ovewriting the local copy with updates. There's also a ClasspathAliasManager
- // contribution based on the path.
+ public ResourceStreamer buildResourceStreamer()
+ {
+ return new ResourceStreamerImpl(_response);
+ }
- configuration.add("tapestry.scriptaculous", "classpath:${tapestry.scriptaculous.path}");
- configuration.add("tapestry.scriptaculous.path", "org/apache/tapestry/scriptaculous_1_7_0");
+ public SessionHolder buildSessionHolder()
+ {
+ return _request;
+ }
+
+ public URLEncoder buildURLEncoder()
+ {
+ return _response;
}
/**
@@ -390,26 +541,6 @@
configuration.add("ClearCachesOnInvalidation", clearCaches);
}
- /**
- * Builds the PropBindingFactory as a chain of command. The terminator of the chain is
- * responsible for ordinary property names (and property paths). Contributions to the service
- * cover additional special cases, such as simple literal values.
- *
- * @param configuration
- * contributions of special factories for some constants, each contributed factory
- * may return a binding if applicable, or null otherwise
- */
- public BindingFactory buildPropBindingFactory(List<BindingFactory> configuration,
- @Inject("infrastructure:PropertyConduitSource")
- PropertyConduitSource propertyConduitSource)
- {
- PropBindingFactory service = new PropBindingFactory(propertyConduitSource);
-
- configuration.add(service);
-
- return _chainBuilder.build(BindingFactory.class, configuration);
- }
-
public void contributePropBindingFactory(OrderedConfiguration<BindingFactory> configuration)
{
BindingFactory keywordFactory = new BindingFactory()
@@ -545,157 +676,22 @@
configuration.add("StringLiteral", stringFactory);
}
- public RequestExceptionHandler buildDefaultRequestExceptionHandler(Log log,
-
- @InjectService("PageResponseRenderer")
- PageResponseRenderer renderer)
- {
- return new DefaultRequestExceptionHandler(_pageCache, renderer, _response, log);
- }
-
- /** Service used to create links for components and pages. */
- public LinkFactory buildLinkFactory(@InjectService("ContextPathSource")
- ContextPathSource contextPathSource,
-
- @InjectService("URLEncoder")
- URLEncoder encoder,
-
- @InjectService("ComponentInvocationMap")
- ComponentInvocationMap componentInvocationMap,
-
- @Inject("infrastructure:TypeCoercer")
- TypeCoercer typeCoercer)
- {
- return new LinkFactoryImpl(contextPathSource, encoder, _componentClassResolver,
- componentInvocationMap, _pageCache, typeCoercer);
- }
-
- public ContextPathSource buildContextPathSource()
- {
- return _request;
- }
-
- public URLEncoder buildURLEncoder()
- {
- return _response;
- }
-
- public ResourceStreamer buildResourceStreamer()
- {
- return new ResourceStreamerImpl(_response);
- }
-
- public AssetFactory buildContextAssetFactory(@Inject("infrastructure:ApplicationGlobals")
- ApplicationGlobals globals)
- {
- return new ContextAssetFactory(_request, globals.getContext());
- }
-
- public AssetFactory buildClasspathAssetFactory(@InjectService("ResourceCache")
- ResourceCache resourceCache, @Inject("infrastructure:ClasspathAssetAliasManager")
- ClasspathAssetAliasManager aliasManager)
- {
- ClasspathAssetFactory factory = new ClasspathAssetFactory(resourceCache, aliasManager);
-
- resourceCache.addInvalidationListener(factory);
-
- return factory;
- }
-
- public ResourceCache buildResourceCache(@Inject("infrastructure:ResourceDigestGenerator")
- ResourceDigestGenerator digestGenerator)
- {
- ResourceCacheImpl service = new ResourceCacheImpl(digestGenerator);
-
- _updateListenerHub.addUpdateListener(service);
-
- return service;
- }
-
/**
- * A map from a {@link org.apache.tapestry.dom.Element} to a {@link ComponentInvocation}
- * Components rendering a link element that is intended to be "clickable" by the
- * {@link org.apache.tapestry.test.pagelevel.PageTester} must map that element to an
- * ComponentInvocation so that the PageTester can find it.
- * <p>
- * By default (production mode), the map does nothing.
+ * Adds a filter that checks for updates to classes and other resources. It is ordered before:*.
*/
- public static ComponentInvocationMap buildComponentInvocationMap()
- {
- return new NoOpComponentInvocationMap();
- }
-
- public FormParameterLookup buildFormParameterLookup()
- {
- return _request;
- }
-
- public SessionHolder buildSessionHolder()
- {
- return _request;
- }
-
- public PageTemplateLocator buildPageTemplateLocator(@InjectService("ContextAssetFactory")
- AssetFactory contextAssetFactory, @Inject("infrastructure:ComponentClassResolver")
- ComponentClassResolver componentClassResolver)
- {
- return new PageTemplateLocatorImpl(contextAssetFactory.getRootResource(),
- componentClassResolver);
- }
-
- public CookieSource buildCookieSource()
- {
- return new CookieSource()
- {
-
- public Cookie[] getCookies()
- {
- return _requestGlobals.getHTTPServletRequest().getCookies();
- }
-
- };
- }
-
- public CookieSink buildCookieSink()
- {
- return new CookieSink()
- {
-
- public void addCookie(Cookie cookie)
- {
- _requestGlobals.getHTTPServletResponse().addCookie(cookie);
- }
-
- };
- }
-
- public static void contributeInfrastructure(
- Configuration<InfrastructureContribution> configuration,
-
- @InjectService("DefaultRequestExceptionHandler")
- RequestExceptionHandler defaultRequestExceptionHandler)
- {
- configuration.add(new InfrastructureContribution("RequestExceptionHandler",
- defaultRequestExceptionHandler));
- }
+ public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration,
+ @InjectService("RequestGlobals")
+ final RequestGlobals requestGlobals,
- public ActionLinkHandler buildActionLinkHandler(
- @Inject("infrastructure:ComponentEventResultProcessor")
- ComponentEventResultProcessor resultProcessor)
- {
- return new ActionLinkHandlerImpl(resultProcessor, _pageCache, _linkFactory);
- }
+ @Inject("${tapestry.file-check-interval}")
+ long checkInterval,
- public PageLinkHandler buildPageLinkHandler(
- @Inject("infrastructure:ComponentEventResultProcessor")
- ComponentEventResultProcessor resultProcessor)
+ @InjectService("LocalizationSetter")
+ LocalizationSetter localizationSetter)
{
- return new PageLinkHandlerImpl(_pageCache, resultProcessor);
- }
+ configuration.add("CheckForUpdates", new CheckForUpdatesFilter(_updateListenerHub,
+ checkInterval), "before:*");
- @Lifecycle("perthread")
- public static ObjectRenderer buildLocationRenderer()
- {
- return new LocationRenderer();
+ configuration.add("Localization", new LocalizationFilter(localizationSetter));
}
}