1 package org.telscenter.sailotrunk;
2
3 import java.net.MalformedURLException;
4 import java.net.URL;
5 import java.util.ArrayList;
6 import java.util.Collection;
7
8 import net.sf.sail.core.bundle.Bundle;
9 import net.sf.sail.core.bundle.ContextUrlAware;
10 import net.sf.sail.core.curnit.ICurnit;
11 import net.sf.sail.core.service.ServiceContext;
12 import net.sf.sail.core.session.ICurnitProvider;
13 import net.sf.sail.core.uuid.CurnitUuid;
14
15 public class OtmlUrlCurnitProvider
16 implements ICurnitProvider, Bundle, ContextUrlAware{
17
18 private String url;
19 private URL contextUrl;
20
21 private OTrunkCurnit curnit;
22
23 public ICurnit getCurnit(CurnitUuid curnitId)
24 {
25 ICurnit localCurnit = null;
26 try {
27 localCurnit = getOTrunkCurnit();
28 if(!localCurnit.getCurnitId().equals(curnitId)){
29 return null;
30 }
31
32 } catch (MalformedURLException e) {
33
34 e.printStackTrace();
35 }
36
37 return localCurnit;
38 }
39
40 public Collection<CurnitUuid> getRegisteredCurnitUuids()
41 {
42 ICurnit localCurnit;
43 try {
44 localCurnit = getOTrunkCurnit();
45 CurnitUuid localCurnitId = (CurnitUuid) localCurnit.getCurnitId();
46 ArrayList<CurnitUuid> curnits = new ArrayList<CurnitUuid>();
47
48 curnits.add(localCurnitId);
49
50 return curnits;
51 } catch (MalformedURLException e) {
52
53 e.printStackTrace();
54 }
55
56 return null;
57 }
58
59 public void registerServices(ServiceContext serviceContext)
60 {
61 serviceContext.addService(ICurnitProvider.class, this);
62 }
63
64 public void initializeBundle(ServiceContext serviceContext)
65 {
66 }
67
68 public String getUrl() {
69 return url;
70 }
71
72 public void setUrl(String urlStr) {
73 this.url = urlStr;
74 }
75
76 public void setContextUrl(URL url) {
77 contextUrl = url;
78 }
79
80 public URL getOtmlUrl() throws MalformedURLException
81 {
82
83 String urlStr = System.getProperty(SailOTViewer.SAILOTRUNK_OTMLURL, null);
84
85 if(urlStr == null){
86 urlStr = getUrl();
87 }
88
89 if(urlStr == null){
90 System.err.println("No URL specified for the otml file");
91 return null;
92 }
93
94 URL otmlURL = new URL(contextUrl, urlStr);
95
96 return otmlURL;
97 }
98
99 public ICurnit getOTrunkCurnit()
100 throws MalformedURLException
101 {
102 if(curnit != null){
103 return curnit;
104 }
105
106 URL otmlURL = getOtmlUrl();
107
108 curnit = new OTrunkCurnit(otmlURL);
109 return curnit;
110 }
111 }