| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
package org.apache.tapestry5.internal.services; |
| 16 | |
|
| 17 | |
import org.apache.tapestry5.Asset; |
| 18 | |
import org.apache.tapestry5.annotations.Path; |
| 19 | |
import org.apache.tapestry5.ioc.AnnotationProvider; |
| 20 | |
import org.apache.tapestry5.ioc.ObjectLocator; |
| 21 | |
import org.apache.tapestry5.ioc.ObjectProvider; |
| 22 | |
import org.apache.tapestry5.ioc.services.Builtin; |
| 23 | |
import org.apache.tapestry5.ioc.services.SymbolSource; |
| 24 | |
import org.apache.tapestry5.ioc.services.TypeCoercer; |
| 25 | |
import org.apache.tapestry5.services.AssetSource; |
| 26 | |
import org.apache.tapestry5.services.Core; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
public class AssetObjectProvider implements ObjectProvider |
| 33 | |
{ |
| 34 | |
private final AssetSource source; |
| 35 | |
|
| 36 | |
private final TypeCoercer typeCoercer; |
| 37 | |
|
| 38 | |
private final SymbolSource symbolSource; |
| 39 | |
|
| 40 | |
public AssetObjectProvider(@Core AssetSource source, |
| 41 | |
|
| 42 | |
@Builtin TypeCoercer typeCoercer, |
| 43 | |
|
| 44 | |
@Builtin SymbolSource symbolSource) |
| 45 | 64 | { |
| 46 | 64 | this.source = source; |
| 47 | 64 | this.typeCoercer = typeCoercer; |
| 48 | 64 | this.symbolSource = symbolSource; |
| 49 | 64 | } |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) |
| 59 | |
{ |
| 60 | 23165 | Path path = annotationProvider.getAnnotation(Path.class); |
| 61 | |
|
| 62 | 23165 | if (path == null) return null; |
| 63 | |
|
| 64 | 60 | String expanded = symbolSource.expandSymbols(path.value()); |
| 65 | |
|
| 66 | 60 | Asset asset = source.getAsset(null, expanded, null); |
| 67 | |
|
| 68 | 60 | return typeCoercer.coerce(asset, objectType); |
| 69 | |
} |
| 70 | |
} |