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/04/17 01:31:54 UTC
svn commit: r529445 [1/3] - in /tapestry/tapestry5:
tapestry-core/trunk/.settings/
tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/
tapestry-core/trunk/src/main/java/org/apache/tapestry/services/
tapestry-hibernate/trunk/src/mai...
Author: hlship
Date: Mon Apr 16 16:31:50 2007
New Revision: 529445
URL: http://svn.apache.org/viewvc?view=rev&rev=529445
Log:
Allow services to be defined via the new ServiceBinder interface (on a static bind() method on the module).
Allow services to not have a service interface (which turns off proxying, interceptors, etc.).
Change searches by service interface to include inheritance as a factor, rather than an exact match on service interface.
Added:
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBinder.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBindingOptions.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/AbstractServiceCreator.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ConstructorServiceCreator.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ObjectCreatorSource.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/ServiceDefAccumulator.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/AutobuildModule.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/NonProxiedServiceModule.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ComplexAutobuildModule.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/EagerLoadViaAnnotationModule.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/EagerLoadViaAnnotationServiceImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ExceptionInBindMethod.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ExceptionInConstructorModule.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ExceptionInConstructorServiceImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/MultipleConstructorsAutobuildService.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/MutlipleAutobuildServiceConstructorsModule.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/NonStaticBindMethodModule.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/RunnableServiceImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ToUpperCaseStringHolder.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/UninstantiableAutobuildServiceModule.java
Modified:
tapestry/tapestry5/tapestry-core/trunk/.settings/org.eclipse.jdt.core.prefs
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ApplicationStateManagerImpl.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/AssetSourceImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ClasspathAssetAliasManagerImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentSourceImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CookiesImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/EnvironmentImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/EnvironmentalShadowBuilderImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorDefaultSourceImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorSourceImpl.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/services/LocationRenderer.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageMarkupRendererImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageResponseRendererImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PersistentFieldManagerImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/RequestGlobalsImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocaleImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateModule.java
tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/IOCConstants.java
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/ServiceResources.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/annotations/EagerLoad.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/annotations/Scope.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ServiceDef.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/DefaultModuleDefImpl.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/LifecycleWrappedServiceCreator.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/Module.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/ServiceBuilderMethodInvoker.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceDefImpl.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/ChainBuilderImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFactoryImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/DefaultImplementationBuilderImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ExceptionAnalyzerImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ExceptionTrackerImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/LoggingDecoratorImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/PipelineBuilderImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/PropertyShadowBuilderImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/StrategyBuilderImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ThreadLocaleImpl.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/services/ClassFactory.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/site/apt/module.apt
tapestry/tapestry5/tapestry-ioc/trunk/src/site/apt/provider.apt
tapestry/tapestry5/tapestry-ioc/trunk/src/site/apt/service.apt
tapestry/tapestry5/tapestry-ioc/trunk/src/site/apt/strategy.apt
tapestry/tapestry5/tapestry-ioc/trunk/src/site/apt/symbols.apt
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/DefaultModuleDefImplTest.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/RecursiveServiceCreationCheckWrapperTest.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ServiceBuilderMethodInvokerTest.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ClassFactoryImplTest.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/LineNumberBean.java
tapestry/tapestry5/tapestry-spring/trunk/pom.xml
tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringModule.java
tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringObjectProvider.java
Modified: tapestry/tapestry5/tapestry-core/trunk/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/.settings/org.eclipse.jdt.core.prefs?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/.settings/org.eclipse.jdt.core.prefs (original)
+++ tapestry/tapestry5/tapestry-core/trunk/.settings/org.eclipse.jdt.core.prefs Mon Apr 16 16:31:50 2007
@@ -1,4 +1,4 @@
-#Thu Mar 08 12:48:00 PST 2007
+#Sun Apr 15 08:16:56 PDT 2007
eclipse.preferences.version=1
org.eclipse.jdt.core.codeComplete.argumentPrefixes=
org.eclipse.jdt.core.codeComplete.argumentSuffixes=
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ApplicationStateManagerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ApplicationStateManagerImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ApplicationStateManagerImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ApplicationStateManagerImpl.java Mon Apr 16 16:31:50 2007
@@ -70,7 +70,9 @@
@SuppressWarnings("unchecked")
public ApplicationStateManagerImpl(Map<Class, ApplicationStateContribution> configuration,
- ApplicationStatePersistenceStrategySource source)
+
+ @org.apache.tapestry.ioc.annotations.Inject
+ ApplicationStatePersistenceStrategySource source)
{
_source = source;
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=529445&r1=529444&r2=529445
==============================================================================
--- 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 16 16:31:50 2007
@@ -20,6 +20,7 @@
import org.apache.tapestry.ioc.ObjectProvider;
import org.apache.tapestry.ioc.Resource;
import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.ioc.services.SymbolSource;
import org.apache.tapestry.ioc.services.TypeCoercer;
import org.apache.tapestry.services.AssetSource;
@@ -36,8 +37,14 @@
private final SymbolSource _symbolSource;
- public AssetObjectProvider(AssetSource source, TypeCoercer typeCoercer,
- SymbolSource symbolSource)
+ public AssetObjectProvider(@InjectService("AssetSource")
+ AssetSource source,
+
+ @InjectService("TypeCoercer")
+ TypeCoercer typeCoercer,
+
+ @InjectService("SymbolSource")
+ SymbolSource symbolSource)
{
_source = source;
_typeCoercer = typeCoercer;
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetSourceImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetSourceImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetSourceImpl.java Mon Apr 16 16:31:50 2007
@@ -23,6 +23,7 @@
import org.apache.tapestry.Asset;
import org.apache.tapestry.ioc.Resource;
+import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.ioc.services.ThreadLocale;
import org.apache.tapestry.ioc.util.StrategyRegistry;
import org.apache.tapestry.services.AssetFactory;
@@ -40,7 +41,10 @@
private final Map<Resource, Asset> _cache = newConcurrentMap();
- public AssetSourceImpl(ThreadLocale threadLocale, Map<String, AssetFactory> configuration)
+ public AssetSourceImpl(@InjectService("ThreadLocale")
+ ThreadLocale threadLocale,
+
+ Map<String, AssetFactory> configuration)
{
_threadLocale = threadLocale;
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ClasspathAssetAliasManagerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ClasspathAssetAliasManagerImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ClasspathAssetAliasManagerImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ClasspathAssetAliasManagerImpl.java Mon Apr 16 16:31:50 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.
@@ -23,6 +23,7 @@
import java.util.Map;
import org.apache.tapestry.TapestryConstants;
+import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.services.ClasspathAssetAliasManager;
public class ClasspathAssetAliasManagerImpl implements ClasspathAssetAliasManager
@@ -42,11 +43,11 @@
/**
* Configuration is a map of aliases (short names) to complete names. Keys and values should not
* start with a slash, but should end with one. Example: "tapestry/" --> "org/apache/tapestry/".
- *
- * @param configuration
*/
- public ClasspathAssetAliasManagerImpl(ContextPathSource contextPathSource,
- final Map<String, String> configuration)
+ public ClasspathAssetAliasManagerImpl(@InjectService("ContextPathSource")
+ ContextPathSource contextPathSource,
+
+ final Map<String, String> configuration)
{
_contextPathSource = contextPathSource;
@@ -102,10 +103,8 @@
for (String alias : _sortedAliases)
{
- if (basePath.startsWith(alias))
- {
- return _aliasToPathPrefix.get(alias) + basePath.substring(alias.length());
- }
+ if (basePath.startsWith(alias)) { return _aliasToPathPrefix.get(alias)
+ + basePath.substring(alias.length()); }
}
return basePath;
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentSourceImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentSourceImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentSourceImpl.java Mon Apr 16 16:31:50 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,6 +17,7 @@
import static org.apache.tapestry.ioc.internal.util.Defense.notNull;
import org.apache.tapestry.internal.structure.Page;
+import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.runtime.Component;
import org.apache.tapestry.services.ComponentSource;
@@ -24,7 +25,8 @@
{
private final RequestPageCache _pageCache;
- public ComponentSourceImpl(RequestPageCache pageCache)
+ public ComponentSourceImpl(@InjectService("RequestPageCache")
+ RequestPageCache pageCache)
{
_pageCache = pageCache;
}
@@ -65,5 +67,5 @@
return page.getRootComponent();
}
-
+
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CookiesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CookiesImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CookiesImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CookiesImpl.java Mon Apr 16 16:31:50 2007
@@ -16,6 +16,9 @@
import javax.servlet.http.Cookie;
+import org.apache.tapestry.ioc.annotations.Inject;
+import org.apache.tapestry.ioc.annotations.InjectService;
+import org.apache.tapestry.ioc.annotations.Value;
import org.apache.tapestry.services.Cookies;
/**
@@ -31,8 +34,18 @@
private int _defaultMaxAge;
- public CookiesImpl(ContextPathSource contextPathSource, CookieSource cookieSource,
- CookieSink cookieSink, int defaultMaxAge)
+ public CookiesImpl(@InjectService("ContextPathSource")
+ ContextPathSource contextPathSource,
+
+ @InjectService("CookieSource")
+ CookieSource cookieSource,
+
+ @InjectService("CookieSink")
+ CookieSink cookieSink,
+
+ @Inject
+ @Value("${tapestry.default-cookie-max-age}")
+ int defaultMaxAge)
{
_contextPathSource = contextPathSource;
_cookieSource = cookieSource;
@@ -44,13 +57,11 @@
{
Cookie[] cookies = _cookieSource.getCookies();
- if (cookies == null)
- return null;
+ if (cookies == null) return null;
for (int i = 0; i < cookies.length; i++)
{
- if (cookies[i].getName().equals(name))
- return cookies[i].getValue();
+ if (cookies[i].getName().equals(name)) return cookies[i].getValue();
}
return null;
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/EnvironmentImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/EnvironmentImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/EnvironmentImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/EnvironmentImpl.java Mon Apr 16 16:31:50 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.
@@ -21,12 +21,14 @@
import java.util.List;
import java.util.Map;
+import org.apache.tapestry.ioc.annotations.Scope;
import org.apache.tapestry.ioc.internal.util.CollectionFactory;
import org.apache.tapestry.services.Environment;
/**
* A non-threadsafe implementation (expects to use the "perthread" service lifecyle).
*/
+@Scope("perthread")
public class EnvironmentImpl implements Environment
{
// My generics mojo breaks down when we talk about the key and the value being related
@@ -66,8 +68,7 @@
{
LinkedList list = e.getValue();
- if (list != null && !list.isEmpty())
- types.add(e.getKey());
+ if (list != null && !list.isEmpty()) types.add(e.getKey());
}
throw new RuntimeException(ServicesMessages.missingFromEnvironment(type, types));
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/EnvironmentalShadowBuilderImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/EnvironmentalShadowBuilderImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/EnvironmentalShadowBuilderImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/EnvironmentalShadowBuilderImpl.java Mon Apr 16 16:31:50 2007
@@ -19,6 +19,8 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
+import org.apache.tapestry.ioc.annotations.Inject;
+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;
@@ -31,8 +33,11 @@
private final Environment _environment;
- public EnvironmentalShadowBuilderImpl(final ClassFactory classFactory,
- final Environment environment)
+ public EnvironmentalShadowBuilderImpl(@InjectService("ClassFactory")
+ ClassFactory classFactory,
+
+ @Inject
+ Environment environment)
{
_classFactory = classFactory;
_environment = environment;
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorDefaultSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorDefaultSourceImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorDefaultSourceImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorDefaultSourceImpl.java Mon Apr 16 16:31:50 2007
@@ -23,6 +23,7 @@
import org.apache.tapestry.FieldValidator;
import org.apache.tapestry.ioc.AnnotationProvider;
import org.apache.tapestry.ioc.Messages;
+import org.apache.tapestry.ioc.annotations.Inject;
import org.apache.tapestry.services.FieldValidatorDefaultSource;
import org.apache.tapestry.services.FieldValidatorSource;
import org.apache.tapestry.services.ValidationConstraintGenerator;
@@ -33,9 +34,11 @@
private final FieldValidatorSource _fieldValidatorSource;
- public FieldValidatorDefaultSourceImpl(
- ValidationConstraintGenerator validationConstraintGenerator,
- FieldValidatorSource fieldValidatorSource)
+ public FieldValidatorDefaultSourceImpl(@Inject
+ ValidationConstraintGenerator validationConstraintGenerator,
+
+ @Inject
+ FieldValidatorSource fieldValidatorSource)
{
_validationConstraintGenerator = validationConstraintGenerator;
_fieldValidatorSource = fieldValidatorSource;
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorSourceImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorSourceImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorSourceImpl.java Mon Apr 16 16:31:50 2007
@@ -29,6 +29,7 @@
import org.apache.tapestry.Validator;
import org.apache.tapestry.ioc.MessageFormatter;
import org.apache.tapestry.ioc.Messages;
+import org.apache.tapestry.ioc.annotations.Inject;
import org.apache.tapestry.ioc.internal.util.InternalUtils;
import org.apache.tapestry.ioc.services.TypeCoercer;
import org.apache.tapestry.runtime.Component;
@@ -45,9 +46,16 @@
private final PageRenderSupport _pageRenderSupport;
- public FieldValidatorSourceImpl(ValidationMessagesSource messagesSource,
- TypeCoercer typeCoercer, PageRenderSupport pageRenderSupport,
- Map<String, Validator> validators)
+ public FieldValidatorSourceImpl(@Inject
+ ValidationMessagesSource messagesSource,
+
+ @Inject
+ TypeCoercer typeCoercer,
+
+ @Inject
+ PageRenderSupport pageRenderSupport,
+
+ Map<String, Validator> validators)
{
_messagesSource = messagesSource;
_typeCoercer = typeCoercer;
@@ -132,8 +140,7 @@
.getConstraintValue()));
}
- if (fieldValidators.size() == 1)
- return fieldValidators.get(0);
+ if (fieldValidators.size() == 1) return fieldValidators.get(0);
return new CompositeFieldValidator(fieldValidators);
}
@@ -141,8 +148,7 @@
@SuppressWarnings("unchecked")
private Object coerceConstraintValue(String constraintValue, Class constraintType)
{
- if (constraintType == null)
- return null;
+ if (constraintType == null) return null;
return _typeCoercer.coerce(constraintValue, constraintType);
}
@@ -150,7 +156,8 @@
/**
* A code defining what the parser is looking for.
*/
- enum State {
+ enum State
+ {
/** The start of a validator type. */
TYPE_START,
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=529445&r1=529444&r2=529445
==============================================================================
--- 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 16 16:31:50 2007
@@ -32,27 +32,30 @@
import org.apache.tapestry.internal.bindings.LiteralBinding;
import org.apache.tapestry.internal.bindings.PropBindingFactory;
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.annotations.Inject;
import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.ioc.annotations.Scope;
import org.apache.tapestry.ioc.annotations.Value;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
import org.apache.tapestry.ioc.services.ChainBuilder;
import org.apache.tapestry.ioc.services.ClassFactory;
import org.apache.tapestry.ioc.services.PropertyAccess;
-import org.apache.tapestry.ioc.services.SymbolSource;
import org.apache.tapestry.ioc.services.ThreadCleanupHub;
import org.apache.tapestry.ioc.services.ThreadLocale;
import org.apache.tapestry.ioc.services.TypeCoercer;
+import org.apache.tapestry.services.AliasContribution;
import org.apache.tapestry.services.ApplicationGlobals;
import org.apache.tapestry.services.ApplicationInitializer;
import org.apache.tapestry.services.ApplicationInitializerFilter;
import org.apache.tapestry.services.AssetFactory;
-import org.apache.tapestry.services.AssetSource;
import org.apache.tapestry.services.BindingFactory;
import org.apache.tapestry.services.BindingSource;
import org.apache.tapestry.services.ClasspathAssetAliasManager;
@@ -61,9 +64,7 @@
import org.apache.tapestry.services.ComponentEventResultProcessor;
import org.apache.tapestry.services.ComponentMessagesSource;
import org.apache.tapestry.services.Context;
-import org.apache.tapestry.services.MarkupWriterFactory;
import org.apache.tapestry.services.ObjectRenderer;
-import org.apache.tapestry.services.PageRenderInitializer;
import org.apache.tapestry.services.PersistentFieldManager;
import org.apache.tapestry.services.PersistentLocale;
import org.apache.tapestry.services.PropertyConduitSource;
@@ -76,10 +77,37 @@
public final class InternalModule
{
- @Scope("perthread")
- public static TemplateParser build(Log log, Map<String, URL> configuration)
+ public static void bind(ServiceBinder binder)
{
- return new TemplateParserImpl(log, configuration);
+ binder.bind(TemplateParser.class, TemplateParserImpl.class);
+ binder.bind(PageResponseRenderer.class, PageResponseRendererImpl.class);
+ binder.bind(PageMarkupRenderer.class, PageMarkupRendererImpl.class);
+ binder.bind(ComponentInvocationMap.class, NoOpComponentInvocationMap.class);
+ binder.bind(ObjectRenderer.class, LocationRenderer.class).withId("LocationRenderer");
+ binder.bind(UpdateListenerHub.class, UpdateListenerHubImpl.class);
+ binder.bind(ObjectProvider.class, AssetObjectProvider.class).withId("AssetObjectProvider");
+ }
+
+ public static void contributeAlias(Configuration<AliasContribution> configuration,
+ ServiceLocator locator)
+ {
+ add(configuration, locator, FormParameterLookup.class);
+ }
+
+ @SuppressWarnings("unchecked")
+ private static void add(Configuration<AliasContribution> configuration, ServiceLocator locator,
+ Class... serviceInterfaces)
+ {
+ for (Class serviceInterface : serviceInterfaces)
+ {
+ String name = serviceInterface.getName();
+ String serviceId = InternalUtils.lastTerm(name);
+
+ AliasContribution contribution = AliasContribution.create(serviceInterface, locator
+ .getService(serviceId, serviceInterface));
+
+ configuration.add(contribution);
+ }
}
public static void contributeTemplateParser(MappedConfiguration<String, URL> configuration)
@@ -98,48 +126,6 @@
.getResource("xhtml-special.ent"));
}
- 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();
- }
-
- @Scope("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.
*/
@@ -733,17 +719,5 @@
checkInterval), "before:*");
configuration.add("Localization", new LocalizationFilter(localizationSetter));
- }
-
- public static ObjectProvider buildAssetObjectProvider(@InjectService("AssetSource")
- AssetSource assetSource,
-
- @InjectService("SymbolSource")
- SymbolSource symbolSource,
-
- @InjectService("TypeCoercer")
- TypeCoercer typeCoercer)
- {
- return new AssetObjectProvider(assetSource, typeCoercer, symbolSource);
}
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocationRenderer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocationRenderer.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocationRenderer.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocationRenderer.java Mon Apr 16 16:31:50 2007
@@ -29,6 +29,7 @@
import org.apache.tapestry.internal.TapestryInternalUtils;
import org.apache.tapestry.ioc.Location;
import org.apache.tapestry.ioc.Resource;
+import org.apache.tapestry.ioc.annotations.Scope;
import org.apache.tapestry.services.ObjectRenderer;
/**
@@ -36,6 +37,7 @@
* (which includes a snippet of the source file) once per render. This requires the use of the
* "perthread" model (since the service tracks, internally,
*/
+@Scope("perthread")
public class LocationRenderer implements ObjectRenderer<Location>
{
private static final int RANGE = 5;
@@ -47,8 +49,7 @@
writer.write(location.toString());
/** If the full details were already rendered this request, then skip the rest. */
- if (_rendered.contains(location))
- return;
+ if (_rendered.contains(location)) return;
_rendered.add(location);
@@ -57,13 +58,11 @@
// No line number? then nothing more to render.
- if (line <= 0)
- return;
+ if (line <= 0) return;
URL url = r.toURL();
- if (url == null)
- return;
+ if (url == null) return;
int start = line - RANGE;
int end = line + RANGE;
@@ -82,16 +81,13 @@
{
String input = reader.readLine();
- if (input == null)
- break;
+ if (input == null) break;
int current = reader.getLineNumber();
- if (current < start)
- continue;
+ if (current < start) continue;
- if (current > end)
- break;
+ if (current > end) break;
writer.element("tr");
@@ -102,10 +98,8 @@
writer.end();
String css = "t-location-content";
- if (line == current)
- css += " t-location-current";
- if (start == current)
- css += " t-location-content-first";
+ if (line == current) css += " t-location-current";
+ if (start == current) css += " t-location-content-first";
writer.element("td");
writer.attributes("class", css);
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageMarkupRendererImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageMarkupRendererImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageMarkupRendererImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageMarkupRendererImpl.java Mon Apr 16 16:31:50 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.
@@ -16,13 +16,15 @@
import org.apache.tapestry.MarkupWriter;
import org.apache.tapestry.internal.structure.Page;
+import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.services.PageRenderInitializer;
public class PageMarkupRendererImpl implements PageMarkupRenderer
{
private final PageRenderInitializer _pageRenderInitializer;
- public PageMarkupRendererImpl(PageRenderInitializer pageRenderInitializer)
+ public PageMarkupRendererImpl(@InjectService("PageRenderInitializer")
+ PageRenderInitializer pageRenderInitializer)
{
_pageRenderInitializer = pageRenderInitializer;
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageResponseRendererImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageResponseRendererImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageResponseRendererImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageResponseRendererImpl.java Mon Apr 16 16:31:50 2007
@@ -19,6 +19,7 @@
import org.apache.tapestry.MarkupWriter;
import org.apache.tapestry.internal.structure.Page;
+import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.services.MarkupWriterFactory;
import org.apache.tapestry.services.Response;
@@ -28,8 +29,11 @@
private final MarkupWriterFactory _markupWriterFactory;
- public PageResponseRendererImpl(MarkupWriterFactory markupWriterFactory,
- PageMarkupRenderer markupRenderer)
+ public PageResponseRendererImpl(@InjectService("MarkupWriterFactory")
+ MarkupWriterFactory markupWriterFactory,
+
+ @InjectService("PageMarkupRenderer")
+ PageMarkupRenderer markupRenderer)
{
_markupWriterFactory = markupWriterFactory;
_markupRenderer = markupRenderer;
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PersistentFieldManagerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PersistentFieldManagerImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PersistentFieldManagerImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PersistentFieldManagerImpl.java Mon Apr 16 16:31:50 2007
@@ -18,6 +18,7 @@
import java.util.Map;
import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.ioc.annotations.Inject;
import org.apache.tapestry.ioc.internal.util.CollectionFactory;
import org.apache.tapestry.ioc.internal.util.InternalUtils;
import org.apache.tapestry.model.ComponentModel;
@@ -37,8 +38,10 @@
private final Map<String, PersistentFieldStrategy> _strategies;
- public PersistentFieldManagerImpl(MetaDataLocator locator,
- Map<String, PersistentFieldStrategy> strategies)
+ public PersistentFieldManagerImpl(@Inject
+ MetaDataLocator locator,
+
+ Map<String, PersistentFieldStrategy> strategies)
{
_metaDataLocator = locator;
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/RequestGlobalsImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/RequestGlobalsImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/RequestGlobalsImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/RequestGlobalsImpl.java Mon Apr 16 16:31:50 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,60 +12,60 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry.internal.services;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.tapestry.services.RequestGlobals;
-import org.apache.tapestry.services.Request;
-import org.apache.tapestry.services.Response;
-
-/**
- * Dumb data holder for per-request data.
- *
- *
- */
-public class RequestGlobalsImpl implements RequestGlobals
-{
- private HttpServletRequest _servletRequest;
-
- private HttpServletResponse _servletResponse;
-
- private Request _request;
-
- private Response _response;
-
- public void store(HttpServletRequest request, HttpServletResponse response)
- {
- _servletRequest = request;
- _servletResponse = response;
- }
-
- public HttpServletRequest getHTTPServletRequest()
- {
- return _servletRequest;
- }
-
- public HttpServletResponse getHTTPServletResponse()
- {
- return _servletResponse;
- }
-
- public void store(Request request, Response response)
- {
- _request = request;
- _response = response;
- }
-
- public Request getRequest()
- {
- return _request;
- }
-
- public Response getResponse()
- {
- return _response;
- }
-
-}
+package org.apache.tapestry.internal.services;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tapestry.ioc.annotations.Scope;
+import org.apache.tapestry.services.Request;
+import org.apache.tapestry.services.RequestGlobals;
+import org.apache.tapestry.services.Response;
+
+/**
+ * Dumb data holder for per-request data.
+ */
+@Scope("perthread")
+public class RequestGlobalsImpl implements RequestGlobals
+{
+ private HttpServletRequest _servletRequest;
+
+ private HttpServletResponse _servletResponse;
+
+ private Request _request;
+
+ private Response _response;
+
+ public void store(HttpServletRequest request, HttpServletResponse response)
+ {
+ _servletRequest = request;
+ _servletResponse = response;
+ }
+
+ public HttpServletRequest getHTTPServletRequest()
+ {
+ return _servletRequest;
+ }
+
+ public HttpServletResponse getHTTPServletResponse()
+ {
+ return _servletResponse;
+ }
+
+ public void store(Request request, Response response)
+ {
+ _request = request;
+ _response = response;
+ }
+
+ public Request getRequest()
+ {
+ return _request;
+ }
+
+ public Response getResponse()
+ {
+ return _response;
+ }
+
+}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java Mon Apr 16 16:31:50 2007
@@ -42,6 +42,7 @@
import org.apache.tapestry.internal.parser.TextToken;
import org.apache.tapestry.ioc.Location;
import org.apache.tapestry.ioc.Resource;
+import org.apache.tapestry.ioc.annotations.Scope;
import org.apache.tapestry.ioc.internal.util.InternalUtils;
import org.apache.tapestry.ioc.internal.util.LocationImpl;
import org.apache.tapestry.ioc.internal.util.TapestryException;
@@ -58,6 +59,7 @@
/**
* Non-threadsafe implementation; the IOC service uses the perthread lifecycle.
*/
+@Scope("perthread")
public class TemplateParserImpl implements TemplateParser, LexicalHandler, ContentHandler,
EntityResolver
{
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocaleImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocaleImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocaleImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocaleImpl.java Mon Apr 16 16:31:50 2007
@@ -16,6 +16,7 @@
import java.util.Locale;
+import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.services.Cookies;
public class PersistentLocaleImpl implements PersistentLocale
@@ -27,7 +28,8 @@
private Cookies _cookieSource;
- public PersistentLocaleImpl(Cookies cookieSource)
+ public PersistentLocaleImpl(@InjectService("Cookies")
+ Cookies cookieSource)
{
_cookieSource = cookieSource;
}
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=529445&r1=529444&r2=529445
==============================================================================
--- 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 16 16:31:50 2007
@@ -90,9 +90,6 @@
import org.apache.tapestry.internal.services.ComponentSourceImpl;
import org.apache.tapestry.internal.services.ComponentWorker;
import org.apache.tapestry.internal.services.ContextImpl;
-import org.apache.tapestry.internal.services.ContextPathSource;
-import org.apache.tapestry.internal.services.CookieSink;
-import org.apache.tapestry.internal.services.CookieSource;
import org.apache.tapestry.internal.services.CookiesImpl;
import org.apache.tapestry.internal.services.DefaultDataTypeAnalyzer;
import org.apache.tapestry.internal.services.DefaultValidationDelegateCommand;
@@ -162,10 +159,10 @@
import org.apache.tapestry.ioc.Messages;
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.annotations.Inject;
import org.apache.tapestry.ioc.annotations.InjectService;
-import org.apache.tapestry.ioc.annotations.Scope;
import org.apache.tapestry.ioc.annotations.SubModule;
import org.apache.tapestry.ioc.annotations.Value;
import org.apache.tapestry.ioc.internal.util.InternalUtils;
@@ -200,6 +197,30 @@
@SubModule(InternalModule.class)
public final class TapestryModule
{
+ public static void bind(ServiceBinder binder)
+ {
+ binder.bind(ClasspathAssetAliasManager.class, ClasspathAssetAliasManagerImpl.class);
+ binder.bind(PersistentLocale.class, PersistentLocaleImpl.class);
+ binder.bind(ApplicationStateManager.class, ApplicationStateManagerImpl.class);
+ binder.bind(
+ ApplicationStatePersistenceStrategySource.class,
+ ApplicationStatePersistenceStrategySourceImpl.class);
+ binder.bind(BindingSource.class, BindingSourceImpl.class);
+ binder.bind(TranslatorSource.class, TranslatorSourceImpl.class);
+ binder.bind(PersistentFieldManager.class, PersistentFieldManagerImpl.class);
+ binder.bind(FieldValidatorSource.class, FieldValidatorSourceImpl.class);
+ binder.bind(ApplicationGlobals.class, ApplicationGlobalsImpl.class);
+ binder.bind(AssetSource.class, AssetSourceImpl.class);
+ binder.bind(Cookies.class, CookiesImpl.class);
+ binder.bind(Environment.class, EnvironmentImpl.class);
+ binder.bind(FieldValidatorDefaultSource.class, FieldValidatorDefaultSourceImpl.class);
+ binder.bind(RequestGlobals.class, RequestGlobalsImpl.class);
+ binder.bind(ResourceDigestGenerator.class, ResourceDigestGeneratorImpl.class);
+ binder.bind(ValidationConstraintGenerator.class, ValidationConstraintGeneratorImpl.class);
+ binder.bind(EnvironmentalShadowBuilder.class, EnvironmentalShadowBuilderImpl.class);
+ binder.bind(ComponentSource.class, ComponentSourceImpl.class);
+ }
+
public static MarkupWriterFactory build(@InjectService("ComponentInvocationMap")
final ComponentInvocationMap componentInvocationMap)
{
@@ -213,18 +234,6 @@
};
}
- public static ClasspathAssetAliasManager build(@InjectService("ContextPathSource")
- ContextPathSource contextPathSource, Map<String, String> configuration)
- {
- return new ClasspathAssetAliasManagerImpl(contextPathSource, configuration);
- }
-
- public static PersistentLocale build(@InjectService("Cookies")
- Cookies cookies)
- {
- return new PersistentLocaleImpl(cookies);
- }
-
public static Alias build(Log log,
@InjectService("AliasOverrides")
@@ -281,104 +290,6 @@
}
}
- public static ApplicationStateManager build(
- Map<Class, ApplicationStateContribution> configuration,
-
- @Inject
- ApplicationStatePersistenceStrategySource source)
- {
- return new ApplicationStateManagerImpl(configuration, source);
- }
-
- public static ApplicationStatePersistenceStrategySource build(
- Map<String, ApplicationStatePersistenceStrategy> configuration)
- {
- return new ApplicationStatePersistenceStrategySourceImpl(configuration);
- }
-
- public static BindingSource build(Map<String, BindingFactory> configuration)
- {
- return new BindingSourceImpl(configuration);
- }
-
- public static TranslatorSource build(Map<String, Translator> configuration)
- {
- return new TranslatorSourceImpl(configuration);
- }
-
- /** A public service since extensions may provide new persistent strategies. */
- public static PersistentFieldManager build(@Inject
- MetaDataLocator locator,
-
- Map<String, PersistentFieldStrategy> configuration)
- {
- return new PersistentFieldManagerImpl(locator, configuration);
- }
-
- public static FieldValidatorSource build(@Inject
- ValidationMessagesSource messagesSource,
-
- @Inject
- TypeCoercer typeCoercer,
-
- @Inject
- PageRenderSupport pageRenderSupport,
-
- Map<String, Validator> configuration)
- {
- return new FieldValidatorSourceImpl(messagesSource, typeCoercer, pageRenderSupport,
- configuration);
- }
-
- // Primarily used as a InvalidationEventHub for service implementations
- // that should clear their cache when the underlying component class loader
- // is discarded.
-
- public static ApplicationGlobals buildApplicationGlobals()
- {
- return new ApplicationGlobalsImpl();
- }
-
- public static AssetSource buildAssetSource(@InjectService("ThreadLocale")
- ThreadLocale threadLocale,
-
- Map<String, AssetFactory> configuration)
- {
- return new AssetSourceImpl(threadLocale, configuration);
- }
-
- public static Cookies buildCookies(@InjectService("ContextPathSource")
- ContextPathSource contextPathSource,
-
- @InjectService("CookieSource")
- CookieSource cookieSource,
-
- @InjectService("CookieSink")
- CookieSink cookieSink,
-
- @Inject
- @Value("${tapestry.default-cookie-max-age}")
- int defaultMaxAge)
- {
- return new CookiesImpl(contextPathSource, cookieSource, cookieSink, defaultMaxAge);
- }
-
- @Scope("perthread")
- public static Environment buildEnvironment()
- {
- return new EnvironmentImpl();
- }
-
- public static FieldValidatorDefaultSource buildFieldValidatorDefaultSource(@Inject
- ValidationConstraintGenerator validationConstraintGenerator,
-
- @Inject
- FieldValidatorSource fieldValidatorSource)
- {
- return new FieldValidatorDefaultSourceImpl(validationConstraintGenerator,
- fieldValidatorSource);
- }
-
/**
* A companion service to {@linkplain #build(Log, AliasManager, Collection) the Alias service}
* whose configuration contribution define spot overrides to specific services.
@@ -389,23 +300,6 @@
return new AliasManagerImpl(log, configuration);
}
- @Scope("perthread")
- public static RequestGlobals buildRequestGlobals()
- {
- return new RequestGlobalsImpl();
- }
-
- public static ResourceDigestGenerator buildResourceDigestGenerator()
- {
- return new ResourceDigestGeneratorImpl();
- }
-
- public static ValidationConstraintGenerator buildValidationConstraintGenerator(
- List<ValidationConstraintGenerator> configuration)
- {
- return new ValidationConstraintGeneratorImpl(configuration);
- }
-
/**
* Contributes the factory for serveral built-in binding prefixes ("literal", prop", "block",
* "component" "message", "validate", "translate").
@@ -1013,15 +907,6 @@
return _shadowBuilder.build(globals, "context", Context.class);
}
- /**
- * A service for building proxies that shadow a value stored in the {@link Environment}.
- */
- public EnvironmentalShadowBuilder build(@InjectService("ClassFactory")
- ClassFactory classFactory)
- {
- return new EnvironmentalShadowBuilderImpl(classFactory, _environment);
- }
-
public ComponentClassResolver build(Collection<LibraryMapping> configuration,
@InjectService("ClassNameLocator")
ClassNameLocator classNameLocator)
@@ -1258,12 +1143,6 @@
_componentInstantiatorSource.addInvalidationListener(service);
return service;
- }
-
- public ComponentSource build(@InjectService("RequestPageCache")
- RequestPageCache pageCache)
- {
- return new ComponentSourceImpl(pageCache);
}
public ObjectRenderer build(@InjectService("StrategyBuilder")
Modified: tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateModule.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateModule.java (original)
+++ tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/hibernate/HibernateModule.java Mon Apr 16 16:31:50 2007
@@ -14,13 +14,10 @@
package org.apache.tapestry.hibernate;
-import java.util.Collection;
-
-import org.apache.commons.logging.Log;
import org.apache.tapestry.internal.hibernate.HibernateSessionManagerImpl;
import org.apache.tapestry.internal.hibernate.HibernateSessionSourceImpl;
-import org.apache.tapestry.internal.services.ClassNameLocator;
import org.apache.tapestry.ioc.Configuration;
+import org.apache.tapestry.ioc.ServiceBinder;
import org.apache.tapestry.ioc.annotations.Inject;
import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.ioc.annotations.Scope;
@@ -33,18 +30,9 @@
public class HibernateModule
{
- /**
- * The HibernateSessionSource is responsible for creating Hibernate sessions, which includes the
- * initial configuration of Hibernate.
- */
- public static HibernateSessionSource build(Log log,
-
- @InjectService("ClassNameLocator")
- ClassNameLocator classNameLocator,
-
- Collection<String> packageNames)
+ public static void bind(ServiceBinder binder)
{
- return new HibernateSessionSourceImpl(log, packageNames, classNameLocator);
+ binder.bind(HibernateSessionSource.class, HibernateSessionSourceImpl.class);
}
/**
Modified: tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImpl.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImpl.java (original)
+++ tapestry/tapestry5/tapestry-hibernate/trunk/src/main/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImpl.java Mon Apr 16 16:31:50 2007
@@ -19,6 +19,7 @@
import org.apache.commons.logging.Log;
import org.apache.tapestry.hibernate.HibernateSessionSource;
import org.apache.tapestry.internal.services.ClassNameLocator;
+import org.apache.tapestry.ioc.annotations.InjectService;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
@@ -28,7 +29,9 @@
private SessionFactory _sessionFactory;
public HibernateSessionSourceImpl(Log log, Collection<String> packageNames,
- ClassNameLocator classNameLocator)
+
+ @InjectService("ClassNameLocator")
+ ClassNameLocator classNameLocator)
{
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
long startTime = System.currentTimeMillis();
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/IOCConstants.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/IOCConstants.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/IOCConstants.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/IOCConstants.java Mon Apr 16 16:31:50 2007
@@ -16,7 +16,7 @@
public class IOCConstants
{
- public static final String DEFAULT_LIFECYCLE = "singleton";
+ public static final String DEFAULT_SCOPE = "singleton";
public static final String MODULE_BUILDER_MANIFEST_ENTRY_NAME = "Tapestry-Module-Classes";
Added: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBinder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBinder.java?view=auto&rev=529445
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBinder.java (added)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBinder.java Mon Apr 16 16:31:50 2007
@@ -0,0 +1,55 @@
+// Copyright 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.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.ioc;
+
+import org.apache.tapestry.ioc.annotations.Scope;
+import org.apache.tapestry.ioc.def.ServiceDef;
+
+/**
+ * Allows a module to bind service interfaces to service implementation classes in support of
+ * autobuilding services. A ServiceBinder is passed to to a method with the following signature:
+ * <code>public static void bind(ServiceBinder binder)</code>. This is an adaptation of ideas
+ * from <a href="http://code.google.com/p/google-guice/">Guice</a>.
+ */
+public interface ServiceBinder
+{
+ /**
+ * Defines a service in terms of an implementation class, without a service interface. In this
+ * case, the service will not be proxiable (proxying requires a service interface) and
+ * {@link ServiceDef#getServiceInterface()} will return the implementation class. In this
+ * situation, the service will not be proxied; it will be instantiated fully on first reference
+ * (ignoring its scope, if any) and will not be decorated.
+ *
+ * @param <T>
+ * @param implementationClass
+ * @return
+ */
+ <T> ServiceBindingOptions bind(Class<T> implementationClass);
+
+ /**
+ * Binds the service interface to a service implementation class. The default service name is
+ * the unqualified name of the service interface. The default service scope is "singleton",
+ * unless the service implementation class includes the {@link Scope} annotation.
+ *
+ * @param <T>
+ * @param serviceInterface
+ * service interface (used when locating services, and when building proxies)
+ * @param serviceImplementation
+ * implementation class that implements the service interface
+ * @return binding options, used to specify additional details about the service.
+ */
+ <T> ServiceBindingOptions bind(Class<T> serviceInterface,
+ Class<? extends T> serviceImplementation);
+}
Added: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBindingOptions.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBindingOptions.java?view=auto&rev=529445
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBindingOptions.java (added)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/ServiceBindingOptions.java Mon Apr 16 16:31:50 2007
@@ -0,0 +1,55 @@
+// Copyright 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.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.ioc;
+
+import org.apache.tapestry.ioc.annotations.EagerLoad;
+import org.apache.tapestry.ioc.annotations.Scope;
+import org.apache.tapestry.ioc.def.ServiceDef;
+
+/**
+ * Allows additional options for a service to be specified, overriding hard coded defaults or
+ * defaults from annotations on the service.
+ *
+ * @see ServiceDef
+ */
+public interface ServiceBindingOptions
+{
+ /**
+ * Allows a specific service id for the service to be provided, rather than the default (from
+ * the service interface). This is useful when multiple services implement the same interface,
+ * since service ids must be unique.
+ *
+ * @param id
+ * @return this binding options, for further configuration
+ */
+ ServiceBindingOptions withId(String id);
+
+ /**
+ * Sets the scope of the service, overriding the {@link Scope} annotation on the service
+ * implementation class.
+ *
+ * @param scope
+ * @return this binding options, for further configuration
+ */
+ ServiceBindingOptions scope(String scope);
+
+ /**
+ * Turns eager loading on for this service. This may also be accomplished using the
+ * {@link EagerLoad} annotation on the service implementation class.
+ *
+ * @return this binding options, for further configuration
+ */
+ ServiceBindingOptions eagerLoad();
+}
Modified: 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/ServiceLocator.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- 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/ServiceLocator.java Mon Apr 16 16:31:50 2007
@@ -31,19 +31,21 @@
* @param <T>
* @param serviceId
* unique ervice id used to locate the service object (may contain <em>symbols</em>,
- * which will be expanded)
+ * which will be expanded), case is ignored
* @param serviceInterface
* the interface implemented by the service (or an interface extended by the service
* interface)
* @return the service instance
* @throws RuntimeException
- * if the service is not defined, or if an error occurs instantitating it
+ * if the service is not defined, or if an error occurs instantiating it
*/
<T> T getService(String serviceId, Class<T> serviceInterface);
/**
* Locates a service given just a service interface. A single service must implement the service
- * interface (which can be hard to guarantee).
+ * interface (which can be hard to guarantee). The search takes into account inheritance of the
+ * service interface (not the service <em>implementation</em>), which may result in a failure
+ * due to extra matches.
*
* @param <T>
* @param serviceInterface
@@ -51,7 +53,7 @@
* @return the service's proxy
* @throws RuntimeException
* if the service does not exist (this is considered programmer error), or multiple
- * services implement the service interface
+ * services directly implement, or extend from, the service interface
*/
<T> T getService(Class<T> serviceInterface);
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=529445&r1=529444&r2=529445
==============================================================================
--- 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 16 16:31:50 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,35 +12,28 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry.ioc;
-
-import org.apache.commons.logging.Log;
-
-/**
- * Contains resources that may be provided to a service when it initializes, which includes other
- * services visible to the service. ServiceResources provides access to other services (it extends
- * {@link org.apache.tapestry.ioc.ServiceLocator}), however service ids (when used with
- * {@link org.apache.tapestry.ioc.ServiceLocator#getService(String, Class)}) may be unqualified (to
- * access another service within the same containing module). Futher,
- * {@link org.apache.tapestry.ioc.ServiceLocator#getService(Class)} will take into account private
- * services visible only within the module, as well as public services from both the containing
- * module and from other modules.
- *
- *
- */
-public interface ServiceResources extends ServiceLocator
-{
- /** Returns the fully qualified id of the service. */
- String getServiceId();
-
- /** Returns the service interface implemented by the service. */
- Class getServiceInterface();
-
- /**
- * Returns a Log object appropriate for logging messages. This includes debug level messages
- * about the creation and configuration of the underlying service, as well as debug, warning, or
- * error level messages from the service itself. Often service interceptors will make use of the
- * service's log.
- */
- Log getServiceLog();
-}
+package org.apache.tapestry.ioc;
+
+import org.apache.commons.logging.Log;
+
+/**
+ * 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}).
+ */
+public interface ServiceResources extends ServiceLocator
+{
+ /** Returns the fully qualified id of the service. */
+ String getServiceId();
+
+ /** Returns the service interface implemented by the service. */
+ Class getServiceInterface();
+
+ /**
+ * Returns a Log object appropriate for logging messages. This includes debug level messages
+ * about the creation and configuration of the underlying service, as well as debug, warning, or
+ * error level messages from the service itself. Often service interceptors will make use of the
+ * service's log.
+ */
+ Log getServiceLog();
+}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/annotations/EagerLoad.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/annotations/EagerLoad.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/annotations/EagerLoad.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/annotations/EagerLoad.java Mon Apr 16 16:31:50 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,25 +12,31 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry.ioc.annotations;
-
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-/**
- * Marker annotation placed on a service builder method to indicate that the service should be
- * eagerly loaded: instantiated as if a service method had been invoked. This will cause the service
- * builder method to be invoked, as well as any service decorator methods that apply to the service.
- *
- *
- */
-@Target(ElementType.METHOD)
-@Retention(RUNTIME)
-@Documented
-public @interface EagerLoad {
-
-}
+package org.apache.tapestry.ioc.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.apache.tapestry.ioc.ServiceBinder;
+
+/**
+ * Marker annotation placed on a service builder method to indicate that the service should be
+ * eagerly loaded: realized as if a service method had been invoked. Service realization invokes the
+ * service builder method and applys any decorators to the service.
+ * <p>
+ * This annotation may also be placed directly on a service implementation class, when using
+ * autobuilding via the {@link ServiceBinder}.
+ */
+@Target(
+{ TYPE, METHOD })
+@Retention(RUNTIME)
+@Documented
+public @interface EagerLoad
+{
+
+}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/annotations/Scope.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/annotations/Scope.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/annotations/Scope.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/annotations/Scope.java Mon Apr 16 16:31:50 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.
@@ -15,12 +15,14 @@
package org.apache.tapestry.ioc.annotations;
import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
+import org.apache.tapestry.ioc.ServiceBinder;
import org.apache.tapestry.ioc.ServiceLifecycle;
import org.apache.tapestry.ioc.services.ServiceLifecycleSource;
@@ -32,8 +34,12 @@
* scope should have a corresponding {@link ServiceLifecycle} implementation. The linkage from scope
* name to service lifecycle occurs via a contribution to the {@link ServiceLifecycleSource} service
* configuration.
+ * <p>
+ * The annotation may also be placed directly on a service implementation class, when using service
+ * autobuilding (via the {@link ServiceBinder}.
*/
-@Target(METHOD)
+@Target(
+{ TYPE, METHOD })
@Retention(RUNTIME)
@Documented
public @interface Scope
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ServiceDef.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ServiceDef.java?view=diff&rev=529445&r1=529444&r2=529445
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ServiceDef.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ServiceDef.java Mon Apr 16 16:31:50 2007
@@ -36,14 +36,19 @@
/**
* Returns the service interface associated with this service. This is the interface exposed to
- * the outside world, as well as the one used to build proxies.
+ * the outside world, as well as the one used to build proxies. In cases where the service is
+ * <em>not</em> defined in terms of an interface, this will return the actual implementation
+ * class of the service. Services without a true service interfaced are <strong>not proxied</strong>.
*/
Class getServiceInterface();
/**
* Returns the lifecycle defined for the service. This is indicated by adding a
- * {@link org.apache.tapestry.ioc.annotations.Scope} annotation to the service builder
- * method for the service.
+ * {@link org.apache.tapestry.ioc.annotations.Scope} annotation to the service builder method
+ * for the service.
+ * <p>
+ * Services that are not proxied will ignore thier scope; such services are always treated as
+ * singletons.
*/
String getServiceScope();
Added: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/AbstractServiceCreator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/AbstractServiceCreator.java?view=auto&rev=529445
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/AbstractServiceCreator.java (added)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/AbstractServiceCreator.java Mon Apr 16 16:31:50 2007
@@ -0,0 +1,216 @@
+// Copyright 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.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.ioc.internal;
+
+import static org.apache.tapestry.ioc.internal.ConfigurationType.MAPPED;
+import static org.apache.tapestry.ioc.internal.ConfigurationType.ORDERED;
+import static org.apache.tapestry.ioc.internal.ConfigurationType.UNORDERED;
+import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+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.ServiceResources;
+
+/**
+ * Abstract implementation of {@link ObjectCreator} geared towards the creation of the core service
+ * implementation, either by invoking a service builder method on a module, or by invoking a
+ * constructor.
+ */
+public abstract class AbstractServiceCreator implements ObjectCreator
+{
+ protected final String _serviceId;
+
+ private final Map<Class, Object> _parameterDefaults = newMap();
+
+ protected final ServiceBuilderResources _resources;
+
+ protected final Log _log;
+
+ private final static Map<Class, ConfigurationType> PARAMETER_TYPE_TO_CONFIGURATION_TYPE = newMap();
+
+ protected final String _creatorDescription;
+
+ static
+ {
+ PARAMETER_TYPE_TO_CONFIGURATION_TYPE.put(Collection.class, UNORDERED);
+ PARAMETER_TYPE_TO_CONFIGURATION_TYPE.put(List.class, ORDERED);
+ PARAMETER_TYPE_TO_CONFIGURATION_TYPE.put(Map.class, MAPPED);
+ }
+
+ public AbstractServiceCreator(ServiceBuilderResources resources, String creatorDescription)
+ {
+ _serviceId = resources.getServiceId();
+ _resources = resources;
+ _creatorDescription = creatorDescription;
+ _log = resources.getServiceLog();
+
+ _parameterDefaults.put(String.class, _serviceId);
+ _parameterDefaults.put(ServiceResources.class, resources);
+ _parameterDefaults.put(Log.class, _log);
+ _parameterDefaults.put(Class.class, resources.getServiceInterface());
+ }
+
+ /**
+ * Returns a map (based on _parameterDefaults) that includes (possibly) an additional mapping
+ * containing the collected configuration data. This involves scanning the parameters and
+ * generic types.
+ */
+ protected final Map<Class, Object> getParameterDefaultsWithConfiguration(
+ Class[] parameterTypes, Type[] genericParameterTypes)
+ {
+ Map<Class, Object> result = newMap(_parameterDefaults);
+ ConfigurationType type = null;
+
+ for (int i = 0; i < parameterTypes.length; i++)
+ {
+ Class parameterType = parameterTypes[i];
+
+ ConfigurationType thisType = PARAMETER_TYPE_TO_CONFIGURATION_TYPE.get(parameterType);
+
+ if (thisType == null) continue;
+
+ if (type != null)
+ {
+ _log.warn(IOCMessages.tooManyConfigurationParameters(_creatorDescription));
+ break;
+ }
+
+ // Remember that we've seen a configuration parameter, in case there
+ // is another.
+
+ type = thisType;
+
+ Type genericType = genericParameterTypes[i];
+
+ switch (type)
+ {
+
+ case UNORDERED:
+
+ addUnorderedConfigurationParameter(result, genericType);
+
+ break;
+
+ case ORDERED:
+
+ addOrderedConfigurationParameter(result, genericType);
+
+ break;
+
+ case MAPPED:
+
+ addMappedConfigurationParameter(result, genericType);
+
+ break;
+ }
+ }
+
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ private final void addOrderedConfigurationParameter(Map<Class, Object> parameterDefaults,
+ Type genericType)
+ {
+ Class valueType = findParameterizedTypeFromGenericType(genericType);
+ List configuration = _resources.getOrderedConfiguration(valueType);
+
+ parameterDefaults.put(List.class, configuration);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void addUnorderedConfigurationParameter(Map<Class, Object> parameterDefaults,
+ Type genericType)
+ {
+ Class valueType = findParameterizedTypeFromGenericType(genericType);
+ Collection configuration = _resources.getUnorderedConfiguration(valueType);
+
+ parameterDefaults.put(Collection.class, configuration);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void addMappedConfigurationParameter(Map<Class, Object> parameterDefaults,
+ Type genericType)
+ {
+ Class keyType = findParameterizedTypeFromGenericType(genericType, 0);
+ Class valueType = findParameterizedTypeFromGenericType(genericType, 1);
+
+ if (keyType == null || valueType == null)
+ throw new IllegalArgumentException(IOCMessages.genericTypeNotSupported(genericType));
+
+ Map configuration = _resources.getMappedConfiguration(keyType, valueType);
+
+ parameterDefaults.put(Map.class, configuration);
+ }
+
+ /**
+ * Extracts from a generic type the underlying parameterized type. I.e., for List<Runnable>,
+ * will return Runnable. This is limited to simple parameterized types, not the more complex
+ * cases involving wildcards and upper/lower boundaries.
+ *
+ * @param type
+ * the genetic type of the parameter, i.e., List<Runnable>
+ * @return the parameterize type (i.e. Runnable.class if type represents List<Runnable>).
+ */
+
+ // package private for testing
+ static Class findParameterizedTypeFromGenericType(Type type)
+ {
+ Class result = findParameterizedTypeFromGenericType(type, 0);
+
+ if (result == null)
+ throw new IllegalArgumentException(IOCMessages.genericTypeNotSupported(type));
+
+ return result;
+ }
+
+ /**
+ * "Sniffs" a generic type to find the underlying parameterized type. If the Type is a class,
+ * then Object.class is returned. Otherwise, the type must be a ParameterizedType. We check to
+ * make sure it has the correct number of a actual types (1 for a Collection or List, 2 for a
+ * Map). The actual types must be classes (wildcards just aren't supported)
+ *
+ * @param type
+ * a Class or ParameterizedType to inspect
+ * @param typeIndex
+ * the index within the ParameterizedType to extract
+ * @return the actual type, or Object.class if the input type is not generic, or null if any
+ * other pre-condition is not met
+ */
+ private static Class findParameterizedTypeFromGenericType(Type type, int typeIndex)
+ {
+ // For a raw Class type, it means the parameter is not parameterized (i.e. Collection, not
+ // Collection<Foo>), so we can return Object.class to allow no restriction.
+
+ if (type instanceof Class) return Object.class;
+
+ if (!(type instanceof ParameterizedType)) return null;
+
+ ParameterizedType pt = (ParameterizedType) type;
+
+ Type[] types = pt.getActualTypeArguments();
+
+ Type actualType = types[typeIndex];
+
+ return actualType instanceof Class ? (Class) actualType : null;
+ }
+}