1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2006</p>
22 * <p>Company: Ontotext Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.discovery.epfl;
26
27 import ie.deri.wsmx.discovery.lightweight.LightweightDiscovery;
28
29 import java.io.File;
30 import java.net.MalformedURLException;
31 import java.net.URL;
32 import java.util.*;
33
34 import org.eclipse.core.runtime.*;
35 import org.eclipse.jface.dialogs.MessageDialog;
36 import org.eclipse.swt.widgets.Display;
37 import org.wsmo.common.IRI;
38 import org.wsmo.datastore.WsmoRepository;
39 import org.wsmo.service.Goal;
40 import org.wsmo.service.WebService;
41 import org.wsmostudio.discovery.Activator;
42 import org.wsmostudio.runtime.LogManager;
43 import org.wsmostudio.runtime.WSMORuntime;
44 import org.wsmostudio.runtime.cache.WSMOTopEntity;
45
46 import ch.epfl.qosdisc.operators.Manager;
47 import ch.epfl.qosdisc.operators.TestFrame;
48
49
50 public class Discoverer {
51 private static final String FILE_PROTO = "file://";
52 private static final String COMPARISON = "comparison";
53 private static final String RANKING = "ranking";
54 private static final String DIR_CONF = "conf";
55 private static final String DIR_DATA = "data";
56 private static final String FNAME_ONTO_RANKING = "QoSRankingOntology.wsml";
57 private static final String FNAME_ONTO_COMPARITION = "QoSUpperOntology.wsml";
58
59 private TestFrame testFrame;
60
61 public Discoverer() {
62 URL confURL = Activator.getDefault().getBundle().getEntry(DIR_CONF);
63 IPath confPath = null;
64 try {
65 confPath = new Path(FileLocator.toFileURL(confURL).getPath());
66 } catch(Exception ioe) {
67 MessageDialog.openError(Display.getCurrent().getActiveShell(),
68 "Error",
69 "Error reading configuration file:\n"
70 + ioe.getMessage());
71 ioe.printStackTrace();
72 }
73 URL dataURL = Activator.getDefault().getBundle().getEntry(DIR_DATA);
74 IPath dataPath = null;
75 try {
76 dataPath = new Path(FileLocator.toFileURL(dataURL).getPath());
77 } catch(Exception ioe) {
78 MessageDialog.openError(Display.getCurrent().getActiveShell(),
79 "Error",
80 "Error reading ranking and comparition ontologies:\n"
81 + ioe.getMessage());
82 ioe.printStackTrace();
83 }
84
85 this.testFrame = new TestFrame(confPath.toString());
86 TestFrame.props.put(RANKING, FILE_PROTO+dataPath.toString()+FNAME_ONTO_RANKING);
87 TestFrame.props.put(COMPARISON, FILE_PROTO+dataPath.toString()+FNAME_ONTO_COMPARITION);
88 }
89
90 public List<WebService> discover(Set<WebService> services, Goal goal, boolean functional) {
91 if(functional) {
92 try {
93
94 LightweightDiscovery lwd = new LightweightDiscovery();
95 lwd.addWebService(services);
96
97
98 List<WebService> funcServices = lwd.discover(goal);
99
100
101
102 services.clear();
103 services.addAll(funcServices);
104 }
105 catch(NoClassDefFoundError noClass) {
106 MessageDialog.openError(Display.getCurrent().getActiveShell(),
107 "Missing KAON2 Libraries",
108 "Error loading KAON2 libraries:\n"
109 + noClass.getMessage());
110 LogManager.logWarning(noClass);
111 return null;
112 }
113 catch (Exception e) {
114 MessageDialog.openError(Display.getCurrent().getActiveShell(),
115 "Functional Discovery Failed",
116 e.getMessage());
117 LogManager.logError("org.wsmostudio.discovery",
118 "Functional discovery failed",
119 e);
120 return null;
121 }
122
123 }
124
125
126 for(WebService s : services)
127 this.testFrame.addService(s);
128
129
130 List<WebService> result = this.testFrame.achieveGoal(goal);
131 return result;
132 }
133
134 public List<WebService> discover(WsmoRepository repo, Goal goal, boolean functional) {
135 List wsIriList = repo.listWebServices();
136 Set<WebService> services = new HashSet<WebService>();
137
138
139 for(Iterator it = wsIriList.iterator();it.hasNext();) {
140 IRI wsIri = (IRI)it.next();
141 WebService ws = repo.getWebService(wsIri);
142 services.add(ws);
143 }
144
145 String goalFileLoc = WSMORuntime.getCache().getFileLocationForId((IRI)goal.getIdentifier(), WSMOTopEntity.GOAL);
146 Goal g = null;
147 try {
148 g = Manager.getGoal(new File(goalFileLoc).toURI().toURL().toString());
149 }
150 catch(MalformedURLException error) {
151 LogManager.logError(error);
152 return null;
153 }
154 return discover(services, g, functional);
155 }
156
157 }
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173