1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.tacos.binding;
18
19 import net.sf.tacos.asset.AbsoluteAsset;
20 import org.apache.hivemind.Location;
21 import org.apache.hivemind.util.Defense;
22 import org.apache.tapestry.BindingException;
23 import org.apache.tapestry.IAsset;
24 import org.apache.tapestry.IComponent;
25 import org.apache.tapestry.binding.AbstractBinding;
26 import org.apache.tapestry.coerce.ValueConverter;
27 import org.apache.tapestry.services.AbsoluteURLBuilder;
28
29
30
31
32
33
34
35 public class AbsoluteAssetBinding extends AbstractBinding
36 {
37 private final IComponent component;
38 private AbsoluteURLBuilder absoluteURLBuilder;
39
40 public AbsoluteAssetBinding(String description, ValueConverter valueConverter,
41 AbsoluteURLBuilder absoluteURLBuilder, Location location, IComponent component, String assetName)
42 {
43 super(assetName, valueConverter, location);
44
45 Defense.notNull(component, "component");
46 Defense.notNull(assetName, "assetName");
47
48 this.component = component;
49 this.absoluteURLBuilder = absoluteURLBuilder;
50 }
51
52 public Object getObject()
53 {
54 IAsset asset = component.getAsset(_description);
55
56 if (asset == null)
57 throw new BindingException("Component " + component.getExtendedId() +
58 " does not contain an asset named ''" + _description + "''.",
59 component, getLocation(), this, null);
60
61 return new AbsoluteAsset(asset, absoluteURLBuilder);
62 }
63
64 public Object getComponent()
65 {
66 return component;
67 }
68 }
69