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 2011/07/25 01:04:38 UTC
svn commit: r1150520 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/internal/services/
main/java/org/apache/tapestry5/services/
test/java/org/apache/tapestry5/internal/services/
Author: hlship
Date: Sun Jul 24 23:04:38 2011
New Revision: 1150520
URL: http://svn.apache.org/viewvc?rev=1150520&view=rev
Log:
TAP5-1508: Record AssetInjectionProvider to implement InjectionProvider2
Removed:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/AssetInjectionProviderTest.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetInjectionProvider.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetInjectionProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetInjectionProvider.java?rev=1150520&r1=1150519&r2=1150520&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetInjectionProvider.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetInjectionProvider.java Sun Jul 24 23:04:38 2011
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2010 The Apache Software Foundation
+// Copyright 2007, 2008, 2010, 2011 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,8 +14,6 @@
package org.apache.tapestry5.internal.services;
-import java.util.Locale;
-
import org.apache.tapestry5.Asset;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.Path;
@@ -23,18 +21,20 @@ import org.apache.tapestry5.ioc.ObjectLo
import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.services.SymbolSource;
import org.apache.tapestry5.model.MutableComponentModel;
+import org.apache.tapestry5.plastic.ComputedValue;
+import org.apache.tapestry5.plastic.InstanceContext;
+import org.apache.tapestry5.plastic.PlasticField;
import org.apache.tapestry5.services.AssetSource;
-import org.apache.tapestry5.services.ClassTransformation;
-import org.apache.tapestry5.services.ComponentValueProvider;
-import org.apache.tapestry5.services.InjectionProvider;
-import org.apache.tapestry5.services.TransformField;
+import org.apache.tapestry5.services.transform.InjectionProvider2;
+
+import java.util.Locale;
/**
* Performs injection of assets, based on the presence of the {@link Path} annotation. This is more
* useful than the
* general {@link AssetObjectProvider}, because relative assets are supported.
*/
-public class AssetInjectionProvider implements InjectionProvider
+public class AssetInjectionProvider implements InjectionProvider2
{
private final SymbolSource symbolSource;
@@ -46,32 +46,32 @@ public class AssetInjectionProvider impl
this.assetSource = assetSource;
}
- public boolean provideInjection(String fieldName, Class fieldType, ObjectLocator locator,
- ClassTransformation transformation, MutableComponentModel componentModel)
+ public boolean provideInjection(PlasticField field, ObjectLocator locator, MutableComponentModel componentModel)
{
- TransformField field = transformation.getField(fieldName);
-
Path path = field.getAnnotation(Path.class);
if (path == null)
+ {
return false;
+ }
final String expanded = symbolSource.expandSymbols(path.value());
final Resource baseResource = componentModel.getBaseResource();
- ComponentValueProvider<Asset> provider = new ComponentValueProvider<Asset>()
+ ComputedValue<Asset> computedAsset = new ComputedValue<Asset>()
{
-
- public Asset get(ComponentResources resources)
+ public Asset get(InstanceContext context)
{
+ ComponentResources resources = context.get(ComponentResources.class);
+
Locale locale = resources.getLocale();
return assetSource.getAsset(baseResource, expanded, locale);
}
};
- field.injectIndirect(provider);
+ field.injectComputed(computedAsset);
return true;
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=1150520&r1=1150519&r2=1150520&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java Sun Jul 24 23:04:38 2011
@@ -750,14 +750,19 @@ public final class TapestryModule
* <dd>injects fields of type {@link Block}</dd>
* <dt>CommonResources</dt>
* <dd>Access to properties of resources (log, messages, etc.)</dd>
+ * <dt>Asset</dt>
+ * <dd>injection of assets (triggered via {@link Path} annotation), with the path relative to the component class</dd>
* </dl>
*/
@Contribute(InjectionProvider2.class)
- public static void provideStandardInjectionProviders(OrderedConfiguration<InjectionProvider2> configuration)
+ public static void provideStandardInjectionProviders(OrderedConfiguration<InjectionProvider2> configuration, SymbolSource symbolSource,
+
+ AssetSource assetSource)
{
configuration.addInstance("Named", InjectNamedProvider.class, "before:Default");
configuration.add("Block", new BlockInjectionProvider(), "before:Default");
configuration.add("CommonResources", new CommonResourcesInjectionProvider(), "after:Default");
+ configuration.add("Asset", new AssetInjectionProvider(symbolSource, assetSource), "before:Default");
}
/**
@@ -767,8 +772,6 @@ public final class TapestryModule
* <dd>based on {@link MasterObjectProvider}</dd>
* <dt>ComponentResources</dt>
* <dd>give component access to its resources</dd>
- * <dt>Asset</dt>
- * <dd>injection of assets (triggered via {@link Path} annotation), with the path relative to the component class</dd>
* <dt>Service</dt>
* <dd>ordered last, for use when Inject is present and nothing else works, matches field type against Tapestry IoC
* services</dd>
@@ -779,22 +782,11 @@ public final class TapestryModule
MasterObjectProvider masterObjectProvider,
- ObjectLocator locator,
-
- SymbolSource symbolSource,
-
- AssetSource assetSource)
+ ObjectLocator locator)
{
configuration.add("Default", new DefaultInjectionProvider(masterObjectProvider, locator));
configuration.add("ComponentResources", new ComponentResourcesInjectionProvider());
- // This comes after default, to deal with conflicts between injecting a
- // String as the
- // component id, and injecting a string with @Symbol or @Value.
-
-
- configuration.add("Asset", new AssetInjectionProvider(symbolSource, assetSource), "before:Default");
-
// This needs to be the last one, since it matches against services
// and might blow up if there is no match.