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/12 00:21:12 UTC
svn commit: r517046 - in /tapestry/tapestry5/tapestry-ioc/trunk/src:
main/java/org/apache/tapestry/ioc/def/
main/java/org/apache/tapestry/ioc/internal/
main/java/org/apache/tapestry/ioc/internal/services/ site/apt/
test/java/org/apache/tapestry/ioc/int...
Author: hlship
Date: Sun Mar 11 16:21:12 2007
New Revision: 517046
URL: http://svn.apache.org/viewvc?view=rev&rev=517046
Log:
TAPESTRY-1323: Support caseless mapped service configurations
Modified:
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ContributionDef.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/MasterObjectProvider.java
tapestry/tapestry5/tapestry-ioc/trunk/src/site/apt/configuration.apt
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/MasterObjectProviderTest.java
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ContributionDef.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ContributionDef.java?view=diff&rev=517046&r1=517045&r2=517046
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ContributionDef.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/def/ContributionDef.java Sun Mar 11 16:21:12 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,69 +12,71 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry.ioc.def;
-
-import org.apache.tapestry.ioc.Configuration;
-import org.apache.tapestry.ioc.MappedConfiguration;
-import org.apache.tapestry.ioc.ModuleBuilderSource;
-import org.apache.tapestry.ioc.OrderedConfiguration;
-import org.apache.tapestry.ioc.ServiceLocator;
-
-/**
- * Contribution to a service configuration.
- *
- *
- */
-public interface ContributionDef
-{
- /** Identifies the service contributed to. */
- String getServiceId();
-
- /**
- * Performs the work needed to contribute into the standard, unordered configuration.
- *
- * @param moduleBuilderSource
- * the source, if needed, of the module builder instance associated with the
- * contribution
- * @param locator
- * allows access to services visible to the module builder instance
- * @param configuration
- * the unordered configuration into which values should be loaded. This instance will
- * encapsulate all related error checks (such as passing of nulls or inappropriate
- * classes).
- */
- void contribute(ModuleBuilderSource moduleBuilderSource, ServiceLocator locator,
- Configuration configuration);
-
- /**
- * Performs the work needed to contribute into the ordered configuration.
- *
- * @param moduleBuilderSource
- * the source, if needed, of the module builder instance associated with the
- * contribution
- * @param locator
- * allows access to services visible to the module builder instance
- * @param configuration
- * the ordered configuration into which values should be loaded. This instance will
- * encapsulate all related error checks (such as passing of nulls or inappropriate
- * classes).
- */
- void contribute(ModuleBuilderSource moduleBuilderSource, ServiceLocator locator,
- OrderedConfiguration configuration);
-
- /**
- * Performs the work needed to contribute into the mapped configuration.
- *
- * @param moduleBuilderSource
- * the source, if needed, of the module builder instance associated with the
- * contribution
- * @param locator
- * allows access to services visible to the module builder instance
- * @param configuration
- * the mapped configuration into which values should be loaded. This instance will
- * encapsulate all related error checks (such as passing of null keys or values or
- * inappropriate classes, or duplicate keys).
- */
- void contribute(ModuleBuilderSource moduleBuilderSource, ServiceLocator locator,
- MappedConfiguration configuration);
-}
+package org.apache.tapestry.ioc.def;
+
+import org.apache.tapestry.ioc.Configuration;
+import org.apache.tapestry.ioc.MappedConfiguration;
+import org.apache.tapestry.ioc.ModuleBuilderSource;
+import org.apache.tapestry.ioc.OrderedConfiguration;
+import org.apache.tapestry.ioc.ServiceLocator;
+
+/**
+ * Contribution to a service configuration.
+ * <p>
+ * The toString() method of the ContributionDef will be used for some exception reporting and should
+ * clearly identify where the contribution comes from; the normal behavior is to identify the class
+ * and method of the contribution method.
+ */
+public interface ContributionDef
+{
+ /** Identifies the service contributed to. */
+ String getServiceId();
+
+ /**
+ * Performs the work needed to contribute into the standard, unordered configuration.
+ *
+ * @param moduleBuilderSource
+ * the source, if needed, of the module builder instance associated with the
+ * contribution
+ * @param locator
+ * allows access to services visible to the module builder instance
+ * @param configuration
+ * the unordered configuration into which values should be loaded. This instance will
+ * encapsulate all related error checks (such as passing of nulls or inappropriate
+ * classes).
+ */
+ void contribute(ModuleBuilderSource moduleBuilderSource, ServiceLocator locator,
+ Configuration configuration);
+
+ /**
+ * Performs the work needed to contribute into the ordered configuration.
+ *
+ * @param moduleBuilderSource
+ * the source, if needed, of the module builder instance associated with the
+ * contribution
+ * @param locator
+ * allows access to services visible to the module builder instance
+ * @param configuration
+ * the ordered configuration into which values should be loaded. This instance will
+ * encapsulate all related error checks (such as passing of nulls or inappropriate
+ * classes).
+ */
+ void contribute(ModuleBuilderSource moduleBuilderSource, ServiceLocator locator,
+ OrderedConfiguration configuration);
+
+ /**
+ * Performs the work needed to contribute into the mapped configuration.
+ *
+ * @param moduleBuilderSource
+ * the source, if needed, of the module builder instance associated with the
+ * contribution
+ * @param locator
+ * allows access to services visible to the module builder instance
+ * @param configuration
+ * the mapped configuration into which values should be loaded. This instance will
+ * encapsulate all related error checks (such as passing of null keys or values or
+ * inappropriate classes, or duplicate keys).
+ */
+ void contribute(ModuleBuilderSource moduleBuilderSource, ServiceLocator locator,
+ MappedConfiguration configuration);
+}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java?view=diff&rev=517046&r1=517045&r2=517046
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/RegistryImpl.java Sun Mar 11 16:21:12 2007
@@ -341,7 +341,10 @@
{
_lock.check();
- final Map<K, V> result = newMap();
+ // When the key type is String, then a case insensitive map is used for both cases.
+
+ final Map<K, V> result = newConfigurationMap(keyType);
+ Map<K, ContributionDef> keyToContribution = newConfigurationMap(keyType);
MappedConfiguration<K, V> configuration = new MappedConfiguration<K, V>()
{
@@ -351,8 +354,6 @@
}
};
- Map<K, ContributionDef> keyToContribution = newMap();
-
Collection<Module> modules = _modules;
for (Module m : modules)
@@ -365,6 +366,19 @@
m);
return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ private <K, V> Map<K, V> newConfigurationMap(Class<K> keyType)
+ {
+ if (keyType.equals(String.class))
+ {
+ Map<String, K> result = newCaseInsensitiveMap();
+
+ return (Map<K, V>) result;
+ }
+
+ return newMap();
}
private <K, V> void addToMappedConfiguration(MappedConfiguration<K, V> configuration,
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/MasterObjectProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/MasterObjectProvider.java?view=diff&rev=517046&r1=517045&r2=517046
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/MasterObjectProvider.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/MasterObjectProvider.java Sun Mar 11 16:21:12 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.
@@ -18,7 +18,6 @@
import org.apache.tapestry.ioc.ObjectProvider;
import org.apache.tapestry.ioc.ServiceLocator;
-import org.apache.tapestry.ioc.internal.util.CollectionFactory;
import org.apache.tapestry.ioc.services.SymbolSource;
import org.apache.tapestry.ioc.services.TypeCoercer;
@@ -38,8 +37,7 @@
public MasterObjectProvider(Map<String, ObjectProvider> configuration,
SymbolSource symbolSource, TypeCoercer typeCoercer)
{
- _configuration = CollectionFactory.newCaseInsensitiveMap(configuration);
-
+ _configuration = configuration;
_symbolSource = symbolSource;
_typeCoercer = typeCoercer;
}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/site/apt/configuration.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/site/apt/configuration.apt?view=diff&rev=517046&r1=517045&r2=517046
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/site/apt/configuration.apt (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/site/apt/configuration.apt Sun Mar 11 16:21:12 2007
@@ -223,10 +223,10 @@
The value may not be null.
- <<TODO:>> It is planned that for mapped configurations where the key is String, a
+ For mapped configurations where the key type is String, a
{{{apidocs/org/apache/tapestry/ioc/util/CaseInsensitiveMap.html}CaseInsensitiveMap}}
- will be used automatically, to help ensure that case insensitivity is automatic and pervasive. This has not yet been
- implemented.
+ will be automatically used (and passed to the service builder method), to help ensure that {{{case.html}case insensitivity}}
+ is automatic and pervasive.
Injecting Resources
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/MasterObjectProviderTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/MasterObjectProviderTest.java?view=diff&rev=517046&r1=517045&r2=517046
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/MasterObjectProviderTest.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/MasterObjectProviderTest.java Sun Mar 11 16:21:12 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.
@@ -29,7 +29,7 @@
{
private Map<String, ObjectProvider> newMap(String prefix, ObjectProvider provider)
{
- return Collections.singletonMap(prefix, provider);
+ return CollectionFactory.newCaseInsensitiveMap(Collections.singletonMap(prefix, provider));
}
@Test