1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.nordija.tapestry.bayeux.stream;
17
18 import org.apache.hivemind.Location;
19 import org.apache.hivemind.Resource;
20 import org.apache.tapestry.IAsset;
21 import org.apache.tapestry.engine.IEngineService;
22 import org.apache.tapestry.engine.ILink;
23 import org.apache.tapestry.link.DirectLink;
24
25 import java.io.InputStream;
26
27
28
29
30
31
32 public class StreamAsset implements IAsset {
33
34 private IEngineService streamService;
35 private String streamResourceSourceExtentionName;
36 private Object[] parameters;
37 private IStream stream;
38
39 public StreamAsset(IEngineService streamService, String streamResourceSourceExtentionName, Object[] parameters, IStream stream) {
40 this.streamService = streamService;
41 this.streamResourceSourceExtentionName = streamResourceSourceExtentionName;
42 this.parameters = parameters;
43 this.stream = stream;
44 }
45
46 public String buildURL() {
47 return getLink().getURL();
48 }
49
50 public InputStream getResourceAsStream() {
51 throw new UnsupportedOperationException("getResourceAsStream is not supported by the StreamAsset. Only use buildURL on a StreamAsset");
52 }
53
54 public Resource getResourceLocation() {
55 throw new UnsupportedOperationException("getResourceLocation is not supported by the StreamAsset. Only use buildURL on a StreamAsset");
56 }
57
58 public Location getLocation() {
59 throw new UnsupportedOperationException("getLocation is not supported by the StreamAsset. Only use buildURL on a StreamAsset");
60 }
61
62 protected ILink getLink() {
63 Object[] serviceParameters = DirectLink.constructServiceParameters(parameters);
64 StreamServiceParameter ssp = new StreamServiceParameter(stream, streamResourceSourceExtentionName, serviceParameters);
65 return streamService.getLink(stream.isStateful(), ssp);
66 }
67
68 }