You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2007/03/14 01:26:58 UTC
svn commit: r517950 [1/2] - in /tapestry/tapestry5:
tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/
tapestry-core/trunk/src/main/java/org/apache/tapestry/services/
tapestry-core/trunk/src/main/java/org/apache/tapestry/test/ tap...
Author: hlship
Date: Tue Mar 13 17:26:56 2007
New Revision: 517950
URL: http://svn.apache.org/viewvc?view=rev&rev=517950
Log:
TAPESTRY-1325: Add an "asset:" object provider, to simplfy injecting assets into services
Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetObjectProvider.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetObjectProviderTest.java
Modified:
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/InjectStandardStylesheetCommand.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/PropertyConduitSourceImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/AssetFactory.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/AssetSource.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/MethodSignature.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetSourceImplTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectStandardStylesheetCommandTest.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/DecoratorDefImpl.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/ServiceBuilderMethodInvoker.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceDecoratorImpl.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/services/BridgeBuilder.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/ClassFabImpl.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFactoryClassPool.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSource.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/FilterMethodAnalyzer.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/ServiceMessages.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/util/InternalUtils.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/util/LocalizedNameGenerator.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/services/ClassFab.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/services/ClassFabUtils.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/CoercionTuple.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/services/MethodSignature.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java
tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/util/BodyBuilder.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/ServiceDecoratorImplTest.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/AbstractIntWrapper.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/SimpleService.java
tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/services/ClassFabUtilsTest.java
Added: 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=auto&rev=517950
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetObjectProvider.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetObjectProvider.java Tue Mar 13 17:26:56 2007
@@ -0,0 +1,65 @@
+// 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.internal.services;
+
+import org.apache.tapestry.Asset;
+import org.apache.tapestry.ioc.ObjectProvider;
+import org.apache.tapestry.ioc.Resource;
+import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.services.ThreadLocale;
+import org.apache.tapestry.services.AssetSource;
+
+/**
+ * Exposes assets (in the current locale).
+ */
+public class AssetObjectProvider implements ObjectProvider
+{
+ private final AssetSource _source;
+
+ private final ThreadLocale _threadLocale;
+
+ private final Resource _classpathRootResource;
+
+ public AssetObjectProvider(AssetSource source, ThreadLocale threadLocale,
+ Resource classpathRootResource)
+ {
+ _source = source;
+ _threadLocale = threadLocale;
+ _classpathRootResource = classpathRootResource;
+ }
+
+ /**
+ * Provides the asset. If the expression does not identify an asset domain, with a prefix, it is
+ * assumed to be a path on the classpath, relative to the root of the classpath.
+ *
+ * @param expression
+ * expression used to find the asset, passed to
+ * {@link AssetSource#findAsset(Resource, String, java.util.Locale)
+ * @param objectType
+ * the type of object (which must be Object or Asset)
+ * @param locator
+ * not used
+ */
+ public <T> T provide(String expression, Class<T> objectType, ServiceLocator locator)
+ {
+ if (!objectType.isAssignableFrom(Asset.class))
+ throw new RuntimeException(ServicesMessages.assetNotCompatible(expression, objectType));
+
+ Asset asset = _source.findAsset(_classpathRootResource, expression, _threadLocale
+ .getLocale());
+
+ return objectType.cast(asset);
+ }
+}
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=517950&r1=517949&r2=517950
==============================================================================
--- 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 Tue Mar 13 17:26:56 2007
@@ -24,24 +24,25 @@
import org.apache.tapestry.Asset;
import org.apache.tapestry.ioc.Resource;
+import org.apache.tapestry.ioc.services.ThreadLocale;
import org.apache.tapestry.ioc.util.StrategyRegistry;
import org.apache.tapestry.services.AssetFactory;
import org.apache.tapestry.services.AssetSource;
-/**
- * Implementation of {@link AssetSource} available as service:tapestry.AssetSource or
- * infrastructure:AssetSource.
- */
public class AssetSourceImpl implements AssetSource
{
private final StrategyRegistry<AssetFactory> _registry;
+ private final ThreadLocale _threadLocale;
+
private final Map<String, Resource> _prefixToRootResource = newMap();
private final Map<Resource, Asset> _cache = newConcurrentMap();
- public AssetSourceImpl(Map<String, AssetFactory> configuration)
+ public AssetSourceImpl(ThreadLocale threadLocale, Map<String, AssetFactory> configuration)
{
+ _threadLocale = threadLocale;
+
Map<Class, AssetFactory> byResourceClass = newMap();
for (Map.Entry<String, AssetFactory> e : configuration.entrySet())
@@ -59,6 +60,11 @@
_registry = StrategyRegistry.newInstance(AssetFactory.class, byResourceClass);
}
+ public Asset getClasspathAsset(String path)
+ {
+ return getClasspathAsset(path, _threadLocale.getLocale());
+ }
+
public Asset getClasspathAsset(String path, Locale locale)
{
Resource baseResource = _prefixToRootResource.get("classpath");
@@ -74,8 +80,7 @@
int colonx = path.indexOf(':');
- if (colonx < 0)
- return findRelativeAsset(baseResource, path, locale);
+ if (colonx < 0) return findRelativeAsset(baseResource, path, locale);
String prefix = path.substring(0, colonx);
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectStandardStylesheetCommand.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectStandardStylesheetCommand.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectStandardStylesheetCommand.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InjectStandardStylesheetCommand.java Tue Mar 13 17:26:56 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,8 +17,6 @@
import org.apache.tapestry.Asset;
import org.apache.tapestry.dom.Document;
import org.apache.tapestry.dom.Element;
-import org.apache.tapestry.ioc.services.ThreadLocale;
-import org.apache.tapestry.services.AssetSource;
import org.apache.tapestry.services.Environment;
import org.apache.tapestry.services.PageRenderCommand;
@@ -28,15 +26,11 @@
*/
public class InjectStandardStylesheetCommand implements PageRenderCommand
{
- private final ThreadLocale _threadLocale;
+ private final Asset _stylesheetAsset;
- private final AssetSource _assetSource;
-
- public InjectStandardStylesheetCommand(ThreadLocale threadLocale,
- AssetSource classpathAssetSource)
+ public InjectStandardStylesheetCommand(Asset stylesheetAsset)
{
- _threadLocale = threadLocale;
- _assetSource = classpathAssetSource;
+ _stylesheetAsset = stylesheetAsset;
}
public void setup(Environment environment)
@@ -49,14 +43,9 @@
Element head = document.find("html/head");
- if (head == null)
- return;
-
- Asset asset = _assetSource.getClasspathAsset(
- "org/apache/tapestry/default.css",
- _threadLocale.getLocale());
+ if (head == null) return;
- head.elementAt(0, "link", "rel", "stylesheet", "type", "text/css", "href", asset
+ head.elementAt(0, "link", "rel", "stylesheet", "type", "text/css", "href", _stylesheetAsset
.toClientURL());
}
}
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=517950&r1=517949&r2=517950
==============================================================================
--- 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 Tue Mar 13 17:26:56 2007
@@ -35,6 +35,7 @@
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.annotations.Inject;
import org.apache.tapestry.ioc.annotations.InjectService;
@@ -49,6 +50,7 @@
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;
@@ -712,5 +714,15 @@
checkInterval), "before:*");
configuration.add("Localization", new LocalizationFilter(localizationSetter));
+ }
+
+ public ObjectProvider buildAssetObjectProvider(@Inject("infrastructure:AssetSource")
+ AssetSource assetSource,
+
+ @InjectService("ClasspathAssetFactory")
+ AssetFactory classpathAssetFactory)
+ {
+ return new AssetObjectProvider(assetSource, _threadLocale, classpathAssetFactory
+ .getRootResource());
}
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PropertyConduitSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PropertyConduitSourceImpl.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PropertyConduitSourceImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PropertyConduitSourceImpl.java Tue Mar 13 17:26:56 2007
@@ -161,7 +161,7 @@
BodyBuilder builder = new BodyBuilder();
builder.begin();
- builder.addln("%s root = (%<s) $1;", ClassFabUtils.getJavaClassName(rootClass));
+ builder.addln("%s root = (%<s) $1;", ClassFabUtils.toJavaClassName(rootClass));
String previousStep = "root";
Class activeType = rootClass;
@@ -197,7 +197,7 @@
builder.addln(
"%s %s = ($w) %s.%s();",
- ClassFabUtils.getJavaClassName(termType),
+ ClassFabUtils.toJavaClassName(termType),
thisStep,
previousStep,
readMethod.getName());
@@ -234,7 +234,7 @@
BodyBuilder builder = new BodyBuilder();
builder.begin();
- builder.addln("%s root = (%<s) $1;", ClassFabUtils.getJavaClassName(rootClass));
+ builder.addln("%s root = (%<s) $1;", ClassFabUtils.toJavaClassName(rootClass));
String previousStep = "root";
Class activeType = rootClass;
@@ -258,7 +258,7 @@
builder.addln(
"%s %s = ($w) %s.%s();",
- ClassFabUtils.getJavaClassName(termType),
+ ClassFabUtils.toJavaClassName(termType),
thisStep,
previousStep,
readMethod.getName());
@@ -291,7 +291,7 @@
Class wrapperType = ClassFabUtils.getWrapperType(parameterType);
- builder.addln("%s value = (%<s) $2;", ClassFabUtils.getJavaClassName(wrapperType));
+ builder.addln("%s value = (%<s) $2;", ClassFabUtils.toJavaClassName(wrapperType));
builder.add("%s.%s(value", previousStep, writeMethod.getName());
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java Tue Mar 13 17:26:56 2007
@@ -323,7 +323,7 @@
classNames.add(c.getName());
return MESSAGES.format("invalid-component-event-result", component.getComponentResources()
- .getCompleteId(), result, methodDescription, ClassFabUtils.getJavaClassName(result
+ .getCompleteId(), result, methodDescription, ClassFabUtils.toJavaClassName(result
.getClass()), InternalUtils.joinSorted(classNames));
}
@@ -391,6 +391,11 @@
static String componentRecursion(String componentClassName)
{
return MESSAGES.format("component-recursion", componentClassName);
+ }
+ static String assetNotCompatible(String path, Class propertyType)
+ {
+ return MESSAGES
+ .format("asset-not-compatible", path, ClassFabUtils.toJavaClassName(propertyType));
}
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/AssetFactory.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/AssetFactory.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/AssetFactory.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/AssetFactory.java Tue Mar 13 17:26:56 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,7 +23,7 @@
public interface AssetFactory
{
/**
- * Returns the Resource reprsenting the root folder of the domain this factory is responsible
+ * Returns the Resource representing the root folder of the domain this factory is responsible
* for.
*/
Resource getRootResource();
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/AssetSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/AssetSource.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/AssetSource.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/AssetSource.java Tue Mar 13 17:26:56 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,6 +18,7 @@
import org.apache.tapestry.Asset;
import org.apache.tapestry.ioc.Resource;
+import org.apache.tapestry.ioc.services.ThreadLocale;
/**
* Used to find or create an {@link Asset} with a given path.
@@ -53,4 +54,13 @@
* @return the asset
*/
Asset getClasspathAsset(String path, Locale locale);
+
+ /**
+ * Obtains a classpath alias in the current locale (as defined by the {@link ThreadLocale}
+ * service).
+ *
+ * @param path
+ * @return the asset
+ */
+ Asset getClasspathAsset(String path);
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/MethodSignature.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/MethodSignature.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/MethodSignature.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/MethodSignature.java Tue Mar 13 17:26:56 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.
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=517950&r1=517949&r2=517950
==============================================================================
--- 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 Tue Mar 13 17:26:56 2007
@@ -19,7 +19,6 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import javax.servlet.ServletContext;
@@ -293,9 +292,12 @@
return new ApplicationGlobalsImpl();
}
- public static AssetSource buildAssetSource(Map<String, AssetFactory> configuration)
+ public static AssetSource buildAssetSource(@InjectService("ThreadLocale")
+ ThreadLocale threadLocale,
+
+ Map<String, AssetFactory> configuration)
{
- return new AssetSourceImpl(configuration);
+ return new AssetSourceImpl(threadLocale, configuration);
}
public static Cookies buildCookies(@InjectService("ContextPathSource")
@@ -685,7 +687,10 @@
MappedConfiguration<String, ObjectProvider> configuration,
@InjectService("Infrastructure")
- final Infrastructure infrastructure)
+ final Infrastructure infrastructure,
+
+ @InjectService("AssetObjectProvider")
+ ObjectProvider assetObjectProvider)
{
// There's a nasty web of dependencies related to Infrastructure; this wrapper class lets us
// defer instantiating the Infrastructure implementation just long enough to defuse those
@@ -706,6 +711,8 @@
// to do this, the wrapper has been left in place (it does very little harm).
configuration.add("infrastructure", wrapper);
+
+ configuration.add("asset", assetObjectProvider);
}
/**
@@ -1524,8 +1531,11 @@
@InjectService("ThreadLocale")
ThreadLocale threadLocale,
- @Inject("infrastructure:AssetSource")
- AssetSource assetSource,
+ @Inject("asset:org/apache/tapestry/default.css")
+ Asset stylesheetAsset,
+
+ @Inject("asset:org/apache/tapestry/field-error-marker.png")
+ Asset fieldErrorIcon,
@Inject("infrastructure:ValidationMessagesSource")
ValidationMessagesSource validationMessagesSource,
@@ -1577,14 +1587,10 @@
});
configuration.add("InjectStandardStylesheet", new InjectStandardStylesheetCommand(
- threadLocale, assetSource));
-
- Asset iconAsset = assetSource.getClasspathAsset(
- "org/apache/tapestry/field-error-marker.png",
- Locale.ENGLISH);
+ stylesheetAsset));
configuration.add("DefaultValidationDelegate", new DefaultValidationDelegateCommand(
- threadLocale, validationMessagesSource, iconAsset));
+ threadLocale, validationMessagesSource, fieldErrorIcon));
}
/**
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java Tue Mar 13 17:26:56 2007
@@ -368,7 +368,7 @@
fail(e.getMessage(), e);
}
}
-
+
protected final HttpSession newHttpSession()
{
return newMock(HttpSession.class);
@@ -628,6 +628,11 @@
expect(source.getClasspathAsset(path, locale)).andReturn(asset);
}
+ protected final void train_getClasspathAsset(AssetSource source, String path, Asset asset)
+ {
+ expect(source.getClasspathAsset(path)).andReturn(asset);
+ }
+
protected final void toClientURL(Asset asset, String clientURL)
{
expect(asset.toClientURL()).andReturn(clientURL);
@@ -912,16 +917,6 @@
protected final void train_toClientURL(Asset asset, String URL)
{
expect(asset.toClientURL()).andReturn(URL).atLeastOnce();
- }
-
- protected final void train_forFile(Resource resource, String relativePath, Resource file)
- {
- expect(resource.forFile(relativePath)).andReturn(file);
- }
-
- protected final void train_forLocale(Resource base, Locale locale, Resource resource)
- {
- expect(base.forLocale(locale)).andReturn(resource);
}
protected final void train_getMethodIdentifier(ClassTransformation transformation,
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties Tue Mar 13 17:26:56 2007
@@ -78,4 +78,5 @@
write-only-property=Property '%s' of class %s (within property expression '%s') is not readable (it has no read accessor method).
request-exception=Processing of request failed with uncaught exception: %s
component-recursion=The template for component %s is recursive (contains another direct or indirect reference to component %<s). \
- This is not supported (components may not contain themselves).
\ No newline at end of file
+ This is not supported (components may not contain themselves).
+asset-not-compatible=Asset path '%s' may not be assigned to type %s. Use type java.lang.Object or (preferrably) org.apache.tapestry.Asset.
Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetObjectProviderTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetObjectProviderTest.java?view=auto&rev=517950
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetObjectProviderTest.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetObjectProviderTest.java Tue Mar 13 17:26:56 2007
@@ -0,0 +1,88 @@
+// 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.internal.services;
+
+import java.math.BigDecimal;
+import java.util.Locale;
+
+import org.apache.tapestry.Asset;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.ioc.ObjectProvider;
+import org.apache.tapestry.ioc.Resource;
+import org.apache.tapestry.ioc.ServiceLocator;
+import org.apache.tapestry.ioc.services.ThreadLocale;
+import org.apache.tapestry.services.AssetSource;
+import org.testng.annotations.Test;
+
+public class AssetObjectProviderTest extends InternalBaseTestCase
+{
+ @Test
+ public void incorrect_object_type()
+ {
+ AssetSource source = newAssetSource();
+ ThreadLocale threadLocale = newThreadLocale();
+ Resource root = newResource();
+ ServiceLocator locator = newServiceLocator();
+
+ replay();
+
+ ObjectProvider provider = new AssetObjectProvider(source, threadLocale, root);
+
+ try
+ {
+ provider.provide("foo/bar/baz.gif", BigDecimal.class, locator);
+ unreachable();
+ }
+ catch (RuntimeException ex)
+ {
+ assertEquals(
+ ex.getMessage(),
+ "Asset path \'foo/bar/baz.gif\' may not be assigned to type java.math.BigDecimal. Use type java.lang.Object or (preferrably) org.apache.tapestry.Asset.");
+ }
+
+ verify();
+ }
+
+ @Test
+ public void normal_conversion()
+ {
+ AssetSource source = newAssetSource();
+ ThreadLocale threadLocale = newThreadLocale();
+ Resource root = newResource();
+ ServiceLocator locator = newServiceLocator();
+ Asset asset = newAsset();
+ Locale locale = Locale.GERMAN;
+ String path = "foo/bar/baz.gif";
+
+ train_getLocale(threadLocale, locale);
+ train_findAsset(source, root, path, locale, asset);
+
+ replay();
+
+ ObjectProvider provider = new AssetObjectProvider(source, threadLocale, root);
+
+ Asset result = provider.provide(path, Asset.class, locator);
+
+ assertSame(result, asset);
+
+ verify();
+ }
+
+ private void train_findAsset(AssetSource source, Resource root, String path, Locale locale,
+ Asset asset)
+ {
+ expect(source.findAsset(root, path, locale)).andReturn(asset);
+ }
+}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetSourceImplTest.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetSourceImplTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetSourceImplTest.java Tue Mar 13 17:26:56 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.
@@ -22,6 +22,7 @@
import org.apache.tapestry.internal.test.InternalBaseTestCase;
import org.apache.tapestry.ioc.Resource;
import org.apache.tapestry.ioc.internal.util.ClasspathResource;
+import org.apache.tapestry.ioc.services.ThreadLocale;
import org.apache.tapestry.services.AssetFactory;
import org.apache.tapestry.services.AssetSource;
import org.testng.annotations.Test;
@@ -37,6 +38,7 @@
public void relative_asset()
{
AssetFactory factory = newAssetFactory();
+ ThreadLocale threadLocale = newThreadLocale();
Asset asset = newAsset();
Resource expectedResource = _baseResource.forFile("SimpleComponent_en_GB.properties");
@@ -49,7 +51,7 @@
replay();
- AssetSource source = new AssetSourceImpl(configuration);
+ AssetSource source = new AssetSourceImpl(threadLocale, configuration);
// First try creates it:
@@ -66,6 +68,7 @@
public void get_classpath_asset()
{
AssetFactory factory = newAssetFactory();
+ ThreadLocale threadLocale = newThreadLocale();
Asset asset = newAsset();
Resource expectedResource = _baseResource.forFile("SimpleComponent_en_GB.properties");
@@ -78,7 +81,7 @@
replay();
- AssetSource source = new AssetSourceImpl(configuration);
+ AssetSource source = new AssetSourceImpl(threadLocale, configuration);
// First try creates it:
@@ -90,9 +93,40 @@
}
@Test
+ public void get_classpath_asset_for_unspecified_locale()
+ {
+ AssetFactory factory = newAssetFactory();
+ ThreadLocale threadLocale = newThreadLocale();
+ Asset asset = newAsset();
+ Locale locale = Locale.UK;
+
+ Resource expectedResource = _baseResource.forFile("SimpleComponent_en_GB.properties");
+
+ train_getRootResource(factory, _rootResource);
+
+ train_createAsset(factory, expectedResource, asset);
+
+ Map<String, AssetFactory> configuration = Collections.singletonMap("classpath", factory);
+
+ train_getLocale(threadLocale, locale);
+
+ replay();
+
+ AssetSource source = new AssetSourceImpl(threadLocale, configuration);
+
+ assertSame(
+ source
+ .getClasspathAsset("org/apache/tapestry/internal/services/SimpleComponent.properties"),
+ asset);
+
+ verify();
+ }
+
+ @Test
public void absolute_asset_with_known_prefix()
{
AssetFactory factory = newAssetFactory();
+ ThreadLocale threadLocale = newThreadLocale();
Asset asset = newAsset();
Resource expectedResource = _rootResource
@@ -106,7 +140,7 @@
replay();
- AssetSource source = new AssetSourceImpl(configuration);
+ AssetSource source = new AssetSourceImpl(threadLocale, configuration);
assertSame(source.findAsset(
_baseResource,
@@ -126,11 +160,13 @@
@Test
public void unknown_asset_prefix()
{
+ ThreadLocale threadLocale = newThreadLocale();
+
Map<String, AssetFactory> configuration = Collections.emptyMap();
replay();
- AssetSource source = new AssetSourceImpl(configuration);
+ AssetSource source = new AssetSourceImpl(threadLocale, configuration);
try
{
@@ -153,11 +189,13 @@
@Test
public void missing_resource()
{
+ ThreadLocale threadLocale = newThreadLocale();
+
Map<String, AssetFactory> configuration = Collections.emptyMap();
replay();
- AssetSource source = new AssetSourceImpl(configuration);
+ AssetSource source = new AssetSourceImpl(threadLocale, configuration);
try
{
@@ -173,4 +211,5 @@
verify();
}
+
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectStandardStylesheetCommandTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectStandardStylesheetCommandTest.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectStandardStylesheetCommandTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/InjectStandardStylesheetCommandTest.java Tue Mar 13 17:26:56 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,13 +14,9 @@
package org.apache.tapestry.internal.services;
-import java.util.Locale;
-
import org.apache.tapestry.Asset;
import org.apache.tapestry.dom.Document;
import org.apache.tapestry.internal.test.InternalBaseTestCase;
-import org.apache.tapestry.ioc.services.ThreadLocale;
-import org.apache.tapestry.services.AssetSource;
import org.apache.tapestry.services.Environment;
import org.testng.annotations.Test;
@@ -30,9 +26,8 @@
public void no_head_element()
{
Document d = new Document();
- ThreadLocale tl = newThreadLocale();
- AssetSource source = newAssetSource();
Environment env = newEnvironment();
+ Asset asset = newAsset();
d.newRootElement("foo");
String initial = d.toString();
@@ -41,7 +36,7 @@
replay();
- new InjectStandardStylesheetCommand(tl, source).cleanup(env);
+ new InjectStandardStylesheetCommand(asset).cleanup(env);
assertEquals(d.toString(), initial, "Document structure should not change.");
@@ -52,23 +47,18 @@
public void head_element_found()
{
Document d = new Document();
- ThreadLocale tl = newThreadLocale();
- AssetSource source = newAssetSource();
Environment env = newEnvironment();
Asset asset = newAsset();
- Locale l = Locale.FRENCH;
d.newRootElement("html").element("head");
train_peek(env, Document.class, d);
- train_getLocale(tl, l);
- train_getClasspathAsset(source, "org/apache/tapestry/default.css", l, asset);
toClientURL(asset, "{clientURL}");
replay();
- new InjectStandardStylesheetCommand(tl, source).cleanup(env);
+ new InjectStandardStylesheetCommand(asset).cleanup(env);
verify();
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/DecoratorDefImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/DecoratorDefImpl.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/DecoratorDefImpl.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/DecoratorDefImpl.java Tue Mar 13 17:26:56 2007
@@ -82,7 +82,8 @@
public ServiceDecorator createDecorator(ModuleBuilderSource moduleBuilderSource,
ServiceResources resources)
{
- return new ServiceDecoratorImpl(_decoratorMethod, moduleBuilderSource, resources);
+ return new ServiceDecoratorImpl(_decoratorMethod, moduleBuilderSource, resources,
+ _classFactory);
}
/**
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCMessages.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCMessages.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCMessages.java Tue Mar 13 17:26:56 2007
@@ -15,7 +15,7 @@
package org.apache.tapestry.ioc.internal;
import static org.apache.tapestry.ioc.internal.util.InternalUtils.asString;
-import static org.apache.tapestry.ioc.services.ClassFabUtils.getJavaClassName;
+import static org.apache.tapestry.ioc.services.ClassFabUtils.toJavaClassName;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
@@ -71,9 +71,9 @@
return MESSAGES.format("instantiate-builder-error", builderClass.getName(), cause);
}
- static String builderMethodError(Method method, String serviceId, Throwable cause)
+ static String builderMethodError(String methodId, String serviceId, Throwable cause)
{
- return MESSAGES.format("builder-method-error", asString(method), serviceId, cause);
+ return MESSAGES.format("builder-method-error", methodId, serviceId, cause);
}
static String decoratorMethodError(Method method, String serviceId, Throwable cause)
@@ -81,9 +81,9 @@
return MESSAGES.format("decorator-method-error", asString(method), serviceId, cause);
}
- static String builderMethodReturnedNull(Method method, String serviceId)
+ static String builderMethodReturnedNull(String methodId, String serviceId)
{
- return MESSAGES.format("builder-method-returned-null", asString(method), serviceId);
+ return MESSAGES.format("builder-method-returned-null", methodId, serviceId);
}
static String noServiceMatchesType(Class serviceInterface)
@@ -135,9 +135,9 @@
return MESSAGES.format("creating-service", serviceId);
}
- static String invokingMethod(Method method)
+ static String invokingMethod(String methodId)
{
- return MESSAGES.format("invoking-method", asString(method));
+ return MESSAGES.format("invoking-method", methodId);
}
static String invokingMethod(ContributionDef def)
@@ -156,7 +156,7 @@
return MESSAGES.format(
"contribution-wrong-return-type",
asString(method),
- getJavaClassName(method.getReturnType()));
+ toJavaClassName(method.getReturnType()));
}
static String tooManyContributionParameters(Method method)
@@ -202,9 +202,9 @@
expectedClass.getName());
}
- static String tooManyConfigurationParameters(Method method)
+ static String tooManyConfigurationParameters(String methodId)
{
- return MESSAGES.format("too-many-configuration-parameters", asString(method));
+ return MESSAGES.format("too-many-configuration-parameters", methodId);
}
static String genericTypeNotSupported(Type type)
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceBuilderMethodInvoker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceBuilderMethodInvoker.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceBuilderMethodInvoker.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceBuilderMethodInvoker.java Tue Mar 13 17:26:56 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,264 +12,269 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry.ioc.internal;
-
+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.InvocationTargetException;
-import java.lang.reflect.Method;
-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;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+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;
import org.apache.tapestry.ioc.internal.util.InternalUtils;
-
-/**
- * Basic implementation of {@link org.apache.tapestry.ioc.ObjectCreator} that handles invoking a
- * method on the module builder, and figures out the correct parameters to pass into the annotated
- * method.
- */
-public class ServiceBuilderMethodInvoker implements ObjectCreator
-{
- private final String _serviceId;
-
- private final Map<Class, Object> _parameterDefaults = newMap();
-
- private final ServiceBuilderResources _resources;
-
- private final Method _builderMethod;
-
- private final Log _log;
-
- private final static Map<Class, ConfigurationType> PARAMETER_TYPE_TO_CONFIGURATION_TYPE = newMap();
-
- 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 ServiceBuilderMethodInvoker(Method method, ServiceBuilderResources resources)
- {
- _serviceId = resources.getServiceId();
- _builderMethod = method;
- _resources = resources;
- _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 builder method's
- * parameters
- */
- private Map<Class, Object> getParameterDefaultsWithConfigurations()
- {
- Map<Class, Object> result = newMap(_parameterDefaults);
- ConfigurationType type = null;
-
- Class[] parameterTypes = _builderMethod.getParameterTypes();
-
- 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(_builderMethod));
- break;
- }
-
- // Remember that we've seen a configuration parameter, in case there
- // is another.
-
- type = thisType;
-
- Type genericType = _builderMethod.getGenericParameterTypes()[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 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;
-
- }
-
- /**
- * Invoked from the proxy to create the actual service implementation.
- */
- public Object createObject()
- {
- // Defer getting (and possibly instantitating) the module builder until the last possible
- // moment. If the method is static, there's no need to even get the builder.
-
- Object moduleBuilder = InternalUtils.isStatic(_builderMethod) ? null : _resources
- .getModuleBuilder();
-
- Object result = null;
- Throwable failure = null;
-
- try
- {
- Object[] parameters = InternalUtils.calculateParametersForMethod(
- _builderMethod,
- _resources,
- getParameterDefaultsWithConfigurations());
-
- if (_log.isDebugEnabled())
- _log.debug(IOCMessages.invokingMethod(_builderMethod));
-
- result = _builderMethod.invoke(moduleBuilder, parameters);
- }
- catch (InvocationTargetException ite)
- {
- failure = ite.getTargetException();
- }
- catch (Exception ex)
- {
- failure = ex;
- }
-
- if (failure != null)
- throw new RuntimeException(IOCMessages.builderMethodError(
- _builderMethod,
- _serviceId,
- failure), failure);
-
- if (result == null)
- throw new RuntimeException(IOCMessages.builderMethodReturnedNull(
- _builderMethod,
- _serviceId));
-
- return result;
- }
-}
+import org.apache.tapestry.ioc.services.ClassFactory;
+
+/**
+ * Basic implementation of {@link org.apache.tapestry.ioc.ObjectCreator} that handles invoking a
+ * method on the module builder, and figures out the correct parameters to pass into the annotated
+ * method.
+ */
+public class ServiceBuilderMethodInvoker implements ObjectCreator
+{
+ private final String _serviceId;
+
+ private final Map<Class, Object> _parameterDefaults = newMap();
+
+ private final ServiceBuilderResources _resources;
+
+ private final Method _builderMethod;
+
+ private final Log _log;
+
+ private final ClassFactory _classFactory;
+
+ private final static Map<Class, ConfigurationType> PARAMETER_TYPE_TO_CONFIGURATION_TYPE = newMap();
+
+ 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 ServiceBuilderMethodInvoker(Method method, ServiceBuilderResources resources,
+ ClassFactory classFactory)
+ {
+ _serviceId = resources.getServiceId();
+ _builderMethod = method;
+ _resources = resources;
+ _log = resources.getServiceLog();
+ _classFactory = classFactory;
+
+ _parameterDefaults.put(String.class, _serviceId);
+ _parameterDefaults.put(ServiceResources.class, resources);
+ _parameterDefaults.put(Log.class, _log);
+ _parameterDefaults.put(Class.class, resources.getServiceInterface());
+ }
+
+ private String methodId()
+ {
+ return InternalUtils.asString(_builderMethod, _classFactory);
+ }
+
+ /**
+ * Returns a map (based on _parameterDefaults) that includes (possibly) an additional mapping
+ * containing the collected configuration data. This involves scanning the builder method's
+ * parameters
+ */
+ private Map<Class, Object> getParameterDefaultsWithConfigurations()
+ {
+ Map<Class, Object> result = newMap(_parameterDefaults);
+ ConfigurationType type = null;
+
+ Class[] parameterTypes = _builderMethod.getParameterTypes();
+
+ 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(methodId()));
+ break;
+ }
+
+ // Remember that we've seen a configuration parameter, in case there
+ // is another.
+
+ type = thisType;
+
+ Type genericType = _builderMethod.getGenericParameterTypes()[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 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;
+
+ }
+
+ /**
+ * Invoked from the proxy to create the actual service implementation.
+ */
+ public Object createObject()
+ {
+ // Defer getting (and possibly instantitating) the module builder until the last possible
+ // moment. If the method is static, there's no need to even get the builder.
+
+ Object moduleBuilder = InternalUtils.isStatic(_builderMethod) ? null : _resources
+ .getModuleBuilder();
+
+ Object result = null;
+ Throwable failure = null;
+
+ try
+ {
+ Object[] parameters = InternalUtils.calculateParametersForMethod(
+ _builderMethod,
+ _resources,
+ getParameterDefaultsWithConfigurations());
+
+ if (_log.isDebugEnabled()) _log.debug(IOCMessages.invokingMethod(methodId()));
+
+ result = _builderMethod.invoke(moduleBuilder, parameters);
+ }
+ catch (InvocationTargetException ite)
+ {
+ failure = ite.getTargetException();
+ }
+ catch (Exception ex)
+ {
+ failure = ex;
+ }
+
+ if (failure != null)
+ throw new RuntimeException(IOCMessages.builderMethodError(
+ methodId(),
+ _serviceId,
+ failure), failure);
+
+ if (result == null)
+ throw new RuntimeException(IOCMessages
+ .builderMethodReturnedNull(methodId(), _serviceId));
+
+ return result;
+ }
+}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceDecoratorImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceDecoratorImpl.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceDecoratorImpl.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceDecoratorImpl.java Tue Mar 13 17:26:56 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,112 +12,119 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry.ioc.internal;
-
+package org.apache.tapestry.ioc.internal;
+
import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.tapestry.ioc.ModuleBuilderSource;
-import org.apache.tapestry.ioc.ServiceDecorator;
-import org.apache.tapestry.ioc.ServiceResources;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.tapestry.ioc.ModuleBuilderSource;
+import org.apache.tapestry.ioc.ServiceDecorator;
+import org.apache.tapestry.ioc.ServiceResources;
import org.apache.tapestry.ioc.internal.util.InternalUtils;
-
-/**
- * A wrapper around a decorator method.
- *
- *
- */
-public class ServiceDecoratorImpl implements ServiceDecorator
-{
- private final ModuleBuilderSource _moduleBuilderSource;
-
- private final String _serviceId;
-
- private final Map<Class, Object> _parameterDefaults = newMap();
-
- private final Log _log;
-
- private final ServiceResources _resources;
-
- private final Method _decoratorMethod;
-
- private final Class _serviceInterface;
-
- public ServiceDecoratorImpl(Method method, ModuleBuilderSource moduleBuilderSource,
- ServiceResources resources)
- {
- _serviceId = resources.getServiceId();
- _decoratorMethod = method;
- _moduleBuilderSource = moduleBuilderSource;
- _resources = resources;
- _serviceInterface = resources.getServiceInterface();
- _log = resources.getServiceLog();
-
- _parameterDefaults.put(String.class, _serviceId);
- _parameterDefaults.put(ServiceResources.class, resources);
- _parameterDefaults.put(Log.class, _log);
- _parameterDefaults.put(Class.class, _serviceInterface);
- }
-
- public Object createInterceptor(Object delegate)
- {
- // Create a copy of the parameters map so that Object.class points to the delegate instance.
-
- Map<Class, Object> parameterDefaults = newMap(_parameterDefaults);
- parameterDefaults.put(Object.class, delegate);
-
- if (_log.isDebugEnabled())
- _log.debug(IOCMessages.invokingMethod(_decoratorMethod));
-
- Object result = null;
- Throwable failure = null;
-
- Object moduleBuilder = InternalUtils.isStatic(_decoratorMethod) ? null : _moduleBuilderSource
- .getModuleBuilder();
-
- try
- {
- Object[] parameters = InternalUtils.calculateParametersForMethod(
- _decoratorMethod,
- _resources,
- parameterDefaults);
-
- result = _decoratorMethod.invoke(moduleBuilder, parameters);
- }
- catch (InvocationTargetException ite)
- {
- failure = ite.getTargetException();
- }
-
- catch (Exception ex)
- {
- failure = ex;
- }
-
- if (failure != null)
- throw new RuntimeException(IOCMessages.decoratorMethodError(
- _decoratorMethod,
- _serviceId,
- failure), failure);
-
- if (result != null && !_serviceInterface.isInstance(result))
- {
- _log.warn(IOCMessages.decoratorReturnedWrongType(
- _decoratorMethod,
- _serviceId,
- result,
- _serviceInterface), null);
-
- // Change the result to null so that we won't use the interceptor,
- // and so that ClassCastExceptions don't occur later down the pipeline.
-
- result = null;
- }
-
- return result;
- }
-}
+import org.apache.tapestry.ioc.services.ClassFactory;
+
+/**
+ * A wrapper around a decorator method.
+ */
+public class ServiceDecoratorImpl implements ServiceDecorator
+{
+ private final ModuleBuilderSource _moduleBuilderSource;
+
+ private final String _serviceId;
+
+ private final Map<Class, Object> _parameterDefaults = newMap();
+
+ private final Log _log;
+
+ private final ServiceResources _resources;
+
+ private final ClassFactory _classFactory;
+
+ private final Method _decoratorMethod;
+
+ private final Class _serviceInterface;
+
+ public ServiceDecoratorImpl(Method method, ModuleBuilderSource moduleBuilderSource,
+ ServiceResources resources, ClassFactory classFactory)
+ {
+ _serviceId = resources.getServiceId();
+ _decoratorMethod = method;
+ _moduleBuilderSource = moduleBuilderSource;
+ _resources = resources;
+ _serviceInterface = resources.getServiceInterface();
+ _log = resources.getServiceLog();
+ _classFactory = classFactory;
+
+ _parameterDefaults.put(String.class, _serviceId);
+ _parameterDefaults.put(ServiceResources.class, resources);
+ _parameterDefaults.put(Log.class, _log);
+ _parameterDefaults.put(Class.class, _serviceInterface);
+
+ }
+
+ private String methodId()
+ {
+ return InternalUtils.asString(_decoratorMethod, _classFactory);
+ }
+
+ public Object createInterceptor(Object delegate)
+ {
+ // Create a copy of the parameters map so that Object.class points to the delegate instance.
+
+ Map<Class, Object> parameterDefaults = newMap(_parameterDefaults);
+ parameterDefaults.put(Object.class, delegate);
+
+ if (_log.isDebugEnabled()) _log.debug(IOCMessages.invokingMethod(methodId()));
+
+ Object result = null;
+ Throwable failure = null;
+
+ Object moduleBuilder = InternalUtils.isStatic(_decoratorMethod) ? null
+ : _moduleBuilderSource.getModuleBuilder();
+
+ try
+ {
+ Object[] parameters = InternalUtils.calculateParametersForMethod(
+ _decoratorMethod,
+ _resources,
+ parameterDefaults);
+
+ result = _decoratorMethod.invoke(moduleBuilder, parameters);
+ }
+ catch (InvocationTargetException ite)
+ {
+ failure = ite.getTargetException();
+ }
+
+ catch (Exception ex)
+ {
+ failure = ex;
+ }
+
+ if (failure != null)
+ throw new RuntimeException(IOCMessages.decoratorMethodError(
+ _decoratorMethod,
+ _serviceId,
+ failure), failure);
+
+ if (result != null && !_serviceInterface.isInstance(result))
+ {
+ _log.warn(IOCMessages.decoratorReturnedWrongType(
+ _decoratorMethod,
+ _serviceId,
+ result,
+ _serviceInterface), null);
+
+ // Change the result to null so that we won't use the interceptor,
+ // and so that ClassCastExceptions don't occur later down the pipeline.
+
+ result = null;
+ }
+
+ return result;
+ }
+}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceDefImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceDefImpl.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceDefImpl.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/ServiceDefImpl.java Tue Mar 13 17:26:56 2007
@@ -57,7 +57,7 @@
public ObjectCreator createServiceCreator(ServiceBuilderResources resources)
{
- return new ServiceBuilderMethodInvoker(_builderMethod, resources);
+ return new ServiceBuilderMethodInvoker(_builderMethod, resources, _classFactory);
}
public String getServiceId()
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/BridgeBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/BridgeBuilder.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/BridgeBuilder.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/BridgeBuilder.java Tue Mar 13 17:26:56 2007
@@ -1,4 +1,4 @@
-// Copyright 2004, 2005, 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.
@@ -33,8 +33,6 @@
* bridge classes and to create instances of bridge classes. A bridge class implements the
* <em>service</em> interface. Within the chain, bridge 1 is passed to filter 1. Invoking methods
* on bridge 1 will invoke methods on filter 2.
- *
- * @author Howard Lewis Ship
*/
class BridgeBuilder<S, F>
{
@@ -129,8 +127,7 @@
*/
public S instantiateBridge(S nextBridge, F filter)
{
- if (_constructor == null)
- createClass();
+ if (_constructor == null) createClass();
try
{
@@ -211,8 +208,7 @@
for (int i = 0; i < position; i++)
{
- if (comma)
- buffer.append(", ");
+ if (comma) buffer.append(", ");
buffer.append("$");
// Add one to the index to get the parameter symbol ($0 is the implicit
@@ -222,8 +218,7 @@
comma = true;
}
- if (comma)
- buffer.append(", ");
+ if (comma) buffer.append(", ");
// _next is the variable in -this- Bridge that points to the -next- Bridge
// or the terminator for the pipeline. The filter is expected to reinvoke the
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ChainBuilderImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ChainBuilderImpl.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ChainBuilderImpl.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ChainBuilderImpl.java Tue Mar 13 17:26:56 2007
@@ -92,7 +92,7 @@
// Also, generics don't help (<T> new T[]) is still java.lang.Object[].
String arrayClassName = commandInterface.getCanonicalName() + "[]";
- String jvmName = ClassFabUtils.getJVMClassName(arrayClassName);
+ String jvmName = ClassFabUtils.toJVMBinaryName(arrayClassName);
Class array = null;
@@ -166,7 +166,7 @@
BodyBuilder builder = new BodyBuilder();
builder.begin();
- builder.addln("%s result = %s;", ClassFabUtils.getJavaClassName(returnType), defaultValue);
+ builder.addln("%s result = %s;", ClassFabUtils.toJavaClassName(returnType), defaultValue);
builder.addln("for (int i = 0; i < _commands.length; i++)");
builder.begin();
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFabImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFabImpl.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFabImpl.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFabImpl.java Tue Mar 13 17:26:56 2007
@@ -1,4 +1,4 @@
-// Copyright 2004, 2005, 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.
@@ -41,8 +41,6 @@
/**
* Implementation of {@link org.apache.tapestry.ioc.services.ClassFab}. Hides, as much as possible,
* the underlying library (Javassist).
- *
- * @author Howard Lewis Ship
*/
public class ClassFabImpl extends AbstractFab implements ClassFab
{
@@ -118,8 +116,7 @@
for (int i = 0; i < interfaces.length; i++)
{
- if (i > 0)
- buffer.append(", ");
+ if (i > 0) buffer.append(", ");
buffer.append(interfaces[i].getName());
}
@@ -157,7 +154,7 @@
throw new RuntimeException(ServiceMessages.unableToAddField(name, getCtClass(), ex), ex);
}
- _formatter.format("private %s %s;\n\n", ClassFabUtils.getJavaClassName(type), name);
+ _formatter.format("private %s %s;\n\n", ClassFabUtils.toJavaClassName(type), name);
}
public void proxyMethodsToDelegate(Class serviceInterface, String delegateExpression,
@@ -180,8 +177,7 @@
addMethod(Modifier.PUBLIC, sig, body);
}
- if (!mi.getToString())
- addToString(toString);
+ if (!mi.getToString()) addToString(toString);
}
public void addToString(String toString)
@@ -228,7 +224,7 @@
// modifiers, return type, name
_formatter.format("%s %s %s", Modifier.toString(modifiers), ClassFabUtils
- .getJavaClassName(ms.getReturnType()), ms.getName());
+ .toJavaClassName(ms.getReturnType()), ms.getName());
// parameters, exceptions and body from this:
addMethodDetailsToDescription(ms.getParameterTypes(), ms.getExceptionTypes(), body);
@@ -252,8 +248,7 @@
if (returnType.isPrimitive())
{
value = DEFAULT_RETURN.get(returnType);
- if (value == null)
- value = "0";
+ if (value == null) value = "0";
}
addMethod(Modifier.PUBLIC, signature, "return " + value + ";");
@@ -313,10 +308,9 @@
int count = InternalUtils.size(parameterTypes);
for (int i = 0; i < count; i++)
{
- if (i > 0)
- _description.append(", ");
+ if (i > 0) _description.append(", ");
- _description.append(ClassFabUtils.getJavaClassName(parameterTypes[i]));
+ _description.append(ClassFabUtils.toJavaClassName(parameterTypes[i]));
_description.append(" $");
_description.append(i + 1);
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFactoryClassPool.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFactoryClassPool.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFactoryClassPool.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/ClassFactoryClassPool.java Tue Mar 13 17:26:56 2007
@@ -28,8 +28,6 @@
* Used to ensure that {@link javassist.ClassPool#appendClassPath(javassist.ClassPath)} is invoked
* within a synchronized lock, and also handles tricky class loading issues (caused by the creation
* of classes, and class loaders, at runtime).
- *
- * @author Howard Lewis Ship
*/
public class ClassFactoryClassPool extends ClassPool
{
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSource.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSource.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/CtClassSource.java Tue Mar 13 17:26:56 2007
@@ -1,4 +1,4 @@
-// Copyright 2004, 2005, 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.
@@ -24,8 +24,6 @@
/**
* Wrapper around Javassist's {@link javassist.ClassPool} that manages the creation of new instances
* of {@link javassist.CtClass} and converts finished CtClass's into instantiable Classes.
- *
- * @author Howard Lewis Ship
*/
class CtClassSource
{
@@ -60,7 +58,7 @@
_pool.addClassLoaderIfNeeded(loader);
- String name = ClassFabUtils.getJavaClassName(searchClass);
+ String name = ClassFabUtils.toJavaClassName(searchClass);
try
{
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/FilterMethodAnalyzer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/FilterMethodAnalyzer.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/FilterMethodAnalyzer.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/FilterMethodAnalyzer.java Tue Mar 13 17:26:56 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,79 +12,71 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry.ioc.internal.services;
-
-import org.apache.tapestry.ioc.services.MethodSignature;
-
-/**
- * Used by {@link org.apache.tapestry.ioc.internal.services.PipelineBuilderImpl} to analyze service
- * interface methods against filter interface methods to find the position of the extra service
- * parameter (in the filter method).
- *
- * @author Howard Lewis Ship
- */
-public class FilterMethodAnalyzer
-{
- private final Class _serviceInterface;
-
- FilterMethodAnalyzer(Class serviceInterface)
- {
- _serviceInterface = serviceInterface;
- }
-
- public int findServiceInterfacePosition(MethodSignature ms, MethodSignature fms)
- {
- if (ms.getReturnType() != fms.getReturnType())
- return -1;
-
- if (!ms.getName().equals(fms.getName()))
- return -1;
-
- Class[] filterParameters = fms.getParameterTypes();
- int filterParameterCount = filterParameters.length;
- Class[] serviceParameters = ms.getParameterTypes();
-
- if (filterParameterCount != (serviceParameters.length + 1))
- return -1;
-
- // TODO: check compatible exceptions!
-
- // This needs work; it assumes the first occurance of the service interface
- // in the filter interface method signature is the right match. That will suit
- // most of the time.
-
- boolean found = false;
- int result = -1;
-
- for (int i = 0; i < filterParameterCount; i++)
- {
- if (filterParameters[i] == _serviceInterface)
- {
- result = i;
- found = true;
- break;
- }
- }
-
- if (!found)
- return -1;
-
- // Check that all the parameters before and after the service interface still
- // match.
-
- for (int i = 0; i < result; i++)
- {
- if (filterParameters[i] != serviceParameters[i])
- return -1;
- }
-
- for (int i = result + 1; i < filterParameterCount; i++)
- {
- if (filterParameters[i] != serviceParameters[i - 1])
- return -1;
- }
-
- return result;
- }
-
-}
+package org.apache.tapestry.ioc.internal.services;
+
+import org.apache.tapestry.ioc.services.MethodSignature;
+
+/**
+ * Used by {@link org.apache.tapestry.ioc.internal.services.PipelineBuilderImpl} to analyze service
+ * interface methods against filter interface methods to find the position of the extra service
+ * parameter (in the filter method).
+ */
+public class FilterMethodAnalyzer
+{
+ private final Class _serviceInterface;
+
+ FilterMethodAnalyzer(Class serviceInterface)
+ {
+ _serviceInterface = serviceInterface;
+ }
+
+ public int findServiceInterfacePosition(MethodSignature ms, MethodSignature fms)
+ {
+ if (ms.getReturnType() != fms.getReturnType()) return -1;
+
+ if (!ms.getName().equals(fms.getName())) return -1;
+
+ Class[] filterParameters = fms.getParameterTypes();
+ int filterParameterCount = filterParameters.length;
+ Class[] serviceParameters = ms.getParameterTypes();
+
+ if (filterParameterCount != (serviceParameters.length + 1)) return -1;
+
+ // TODO: check compatible exceptions!
+
+ // This needs work; it assumes the first occurance of the service interface
+ // in the filter interface method signature is the right match. That will suit
+ // most of the time.
+
+ boolean found = false;
+ int result = -1;
+
+ for (int i = 0; i < filterParameterCount; i++)
+ {
+ if (filterParameters[i] == _serviceInterface)
+ {
+ result = i;
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) return -1;
+
+ // Check that all the parameters before and after the service interface still
+ // match.
+
+ for (int i = 0; i < result; i++)
+ {
+ if (filterParameters[i] != serviceParameters[i]) return -1;
+ }
+
+ for (int i = result + 1; i < filterParameterCount; i++)
+ {
+ if (filterParameters[i] != serviceParameters[i - 1]) return -1;
+ }
+
+ return result;
+ }
+
+}
Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/LoggingDecoratorImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/LoggingDecoratorImpl.java?view=diff&rev=517950&r1=517949&r2=517950
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/LoggingDecoratorImpl.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/services/LoggingDecoratorImpl.java Tue Mar 13 17:26:56 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,7 +15,7 @@
package org.apache.tapestry.ioc.internal.services;
import static java.lang.String.format;
-import static org.apache.tapestry.ioc.services.ClassFabUtils.getJavaClassName;
+import static org.apache.tapestry.ioc.services.ClassFabUtils.toJavaClassName;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -120,7 +120,7 @@
builder.begin();
if (!isVoid)
- builder.add("%s result = ", getJavaClassName(returnType));
+ builder.add("%s result = ", toJavaClassName(returnType));
builder.addln("_delegate.%s($$);", signature.getName());