1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package zeus.concepts;
23 import java.util.*;
24 import JADE_SL.abs.*;
25 import zeus.util.SystemProps;
26
27
28 /***
29 * provide a datatype that is used to hold the service descriptions
30 * and provide matching services for them
31 *@author Simon Thompson
32 *@version various, but actively used from 1.3 on.
33 */
34 public class FIPA_Service_Description implements ContentElement {
35
36 private String name = null;
37 private String type = null;
38 private Vector services = null;
39 private Vector protocol = null;
40 private Vector ontology = null;
41 private Vector language = null;
42 private String ownership = null;
43 private Vector properties = null;
44
45
46 public FIPA_Service_Description () {
47 ;
48 }
49
50 /***
51 * this takes a service description in the form of a parse tree from
52 *the JADE_SL parser, and then pulls the leaves off and puts it into
53 *this nice datastructure
54 */
55 public FIPA_Service_Description (AbsConcept description) {
56 AbsPrimitive typePrim = (AbsPrimitive) description.getAbsObject("type");
57 setType (typePrim.getString());
58 AbsPrimitive ownershipPrim = (AbsPrimitive) description.getAbsObject("ownership");
59 setOwnership (ownershipPrim.getString());
60 AbsPrimitive namePrim = (AbsPrimitive) description.getAbsObject ("name");
61
62 setName (namePrim.getString());
63 AbsAggregate propertiesConcept = (AbsAggregate) description.getAbsObject ("properties");
64 Vector props = SL_Util.makeVector(propertiesConcept);
65 setProperties (props);
66 AbsAggregate langAggr = (AbsAggregate) description.getAbsObject ("language");
67 Vector langs = SL_Util.makeVector (langAggr);
68 setLanguage(langs);
69 AbsAggregate protoAggr = (AbsAggregate) description.getAbsObject ("protocol");
70 Vector protos = SL_Util.makeVector (protoAggr);
71 setProtocol (protos);
72 AbsAggregate ontoAggr = (AbsAggregate) description.getAbsObject ("ontology");
73 Vector ontos = SL_Util.makeVector (ontoAggr);
74 setOntology (ontos);
75 }
76
77
78 public void setType (String type) {
79 this.type = type;
80 }
81
82
83 public String getType () {
84 return type;
85 }
86
87
88
89 public void setOwnership (String ownership) {
90 this.ownership = ownership;
91 }
92
93
94 public String getOwnership () {
95 return ownership;
96 }
97
98 public void setProperties (Vector props) {
99 this.properties = props;
100 }
101
102
103 public Vector getProperties () {
104 return properties;
105 }
106
107
108 public void setName (String name) {
109 this.name = name;
110 }
111
112
113 public String getName () {
114 return this.name;
115 }
116
117
118 public void setServices (Vector services ) {
119 this.services = services;
120 }
121
122
123 public Vector getServices () {
124 return this.services;
125 }
126
127
128 public void setProtocol (Vector protocol) {
129 this.protocol = protocol;
130 }
131
132
133 public Vector getProtocol () {
134 return this.protocol;
135 }
136
137
138 public void setOntology (Vector ontology) {
139 this.ontology = ontology;
140 }
141
142 public Vector getOntology () {
143 return this.ontology;
144 }
145
146 public void setLanguage (Vector language) {
147 this.language = language;
148 }
149
150 public Vector getLanguage() {
151 return this.language;
152 }
153
154 /***
155 *setAgentcitiesProperties is called with three parameters to make the
156 *service registration in the DF carry the metadata required for service
157 *lookup in agentcities.
158 *@param classfication is a string that gives the services classifcation
159 *as in the sort of service that it is {information,...}
160 *@param domain is a string that indicates the type of domain that the
161 *service applies to
162 *@param scope is the geographic range of the service; is it useful only
163 *within 2 miles of a particular place for example?
164 *@author Simon Thompson
165 *@date 27/1/03
166 *below is the set of properties that this should emit.
167 *you must set the servicePlatform property in .zeus.prp for this to
168 *work, the first property is automatically generated.
169 *(Property
170 * :name “DAML-SServiceProfile”
171 * :value “http://link2.daml-s.description.org/”
172 * )
173 *(Property
174 * :name “ServiceClassification::ServiceType”
175 * :value “Information”
176 * )
177 * (Property
178 * :name “ServiceClassification::Domain”
179 * :value “Entertainment::FoodAndBeverages::Restaurant”
180 * )
181 * (Property
182 * :name “ServiceClassification::GeographicScope”
183 * :value “World::Europe::Portugal::district:Lisboa”
184 * )
185 **/
186 public void setAgentcitiesProperties ( String classification, String domain, String scope) {
187
188 Vector properties = new Vector();
189 String taxonomy = new String("( property :name //\"DAML-SServiceProfile//\" :value //\""+ SystemProps.getProperty("servicePlatform") +
190 "/services/classes/"+ getName() + "//\") ");
191 properties.addElement(taxonomy);
192 String serviceClass = new String("(property :name //\"ServiceClassification::ServiceType//\" :value //\""+classification +"//\") ");
193 properties.addElement(serviceClass);
194 String serviceDomain = new String ("(property :name //\"ServiceClassification::Domain//\" :value //\""+domain+"//\") ");
195 properties.addElement(serviceDomain);
196 String serviceScope = new String ("(property :name //\"ServiceClassification::GeographicScope//\" :value //\""+ scope+"//\") ");
197 properties.addElement(serviceScope);
198
199 this.setProperties(properties);
200
201 }
202
203 /***
204 * returns a String representation of the service description, formatted into SL
205 *
206 **/
207 public String toString () {
208 String retVal = new String ("(service-description ");
209 if (name!=null) {
210 retVal += ":name " + name +" ";
211 }
212 if (type != null) {
213 retVal += ":type " + type + " ";
214 }
215 if (protocol != null ) {
216 retVal += SL_Util.makeSet (":protocol", protocol);
217 }
218 if (ontology != null ) {
219 retVal += SL_Util.makeSet (":ontology",ontology);
220 }
221 if (ownership != null) {
222 retVal += ":ownership " + ownership + " ";
223 }
224 if (language!= null) {
225 retVal += SL_Util.makeSet (":language",language);
226 }
227 if (properties != null ){
228 retVal += SL_Util.makeSet(":properties", properties);
229 }
230 retVal += ")";
231 debug (retVal);
232 return retVal;
233
234 }
235
236 /***
237 for debug
238 */
239 public static void main (String argv[]) {
240 FIPA_Service_Description fds = new FIPA_Service_Description ();
241 System.out.println(fds.toString());
242
243 }
244
245 /***
246 *debug method - prints to the system, or not depending on
247 *if this is activated (commented out) or not
248 */
249 void debug (String str) {
250 System.out.println("FIPA_Service_Description: " + str);
251 }
252
253
254
255 /***
256 match checks to see if the thing sent to it matches (according to
257 generalx == specificx criteria) with it
258 This method assumes that this object is the general case and the toMatchTo
259 object is the specific case, so toMatchTo can have fields that are
260 null here and still match to this.
261 */
262 public boolean match (ContentElement matcher) {
263 if (!(matcher instanceof zeus.concepts.FIPA_Service_Description)) return false;
264
265 FIPA_Service_Description toMatchTo = (FIPA_Service_Description) matcher;
266
267 if (name != null) {
268 if (!name.equals (toMatchTo.getName()))
269 {
270 debug ("names don't match");
271 return false;
272 }}
273 if (type != null) {
274 if (!type.equals (toMatchTo.getType())) {
275 debug ("types don't match, me = " + type +" he = " + toMatchTo.getType());
276 return false;
277 }}
278 if (services !=null && (toMatchTo.getServices() != null)) {
279 if (!vecMatch (services, toMatchTo.getServices())) {
280 debug ("services don't match");
281 return false;
282 }}
283 if (protocol != null && (toMatchTo.getProtocol() != null)) {
284 if (!vecMatch (protocol, toMatchTo.getProtocol ())) {
285 debug ("protocols don't match");
286 return false;
287 }}
288 if (ontology != null && (toMatchTo.getOntology()!=null) ) {
289 if (!vecMatch (ontology, toMatchTo.getOntology())) {
290 debug ("ontologies don't match");
291 return false;
292 }}
293 if ( language != null && (toMatchTo.getLanguage()!=null) ) {
294 if (!vecMatch (language, toMatchTo.getLanguage ())) {
295 debug ("languages don't match ");
296 return false;
297 }}
298 if (ownership != null ) {
299 if (!ownership.equals (toMatchTo.getOwnership())) {
300 debug ("ownerships don't match");
301 return false;
302 }}
303 if (properties != null && (toMatchTo.getProperties()!=null)) {
304 if (!vecMatch (properties, toMatchTo.getProperties ())) {
305 debug ("properties don't match");
306 return false;
307 }}
308 return (true);
309 }
310
311
312 /***
313 *checks through the elements of both vectors ans tries to find if they
314 *contain the same thing
315 */
316 public boolean vecMatch (Vector vec1, Vector vec2) {
317 debug ("in vecMatch");
318 Enumeration elementsNeeded = vec1.elements();
319 while (elementsNeeded.hasMoreElements()) {
320 Enumeration elementsWeHaveGot = vec2.elements();
321 boolean found = false;
322 Object element = elementsNeeded.nextElement();
323 while (elementsWeHaveGot.hasMoreElements() &&!found) {
324 Object elementToTest=elementsWeHaveGot.nextElement();
325 if (element instanceof java.util.Vector
326 && elementToTest instanceof java.util.Vector) {
327 found = vecMatch ((Vector)element,(Vector)elementToTest); }
328 else if (element instanceof zeus.concepts.ContentElement) {
329 ;
330 }
331 else {
332 System.out.println("elementToTest.toString = " + elementToTest.toString() + " element.toString = " + element.toString());
333 if (elementToTest.toString().equals (element.toString()))
334 found = true;
335 }
336 }
337 if (found == false) return false;
338 }
339 return true;
340 }
341
342
343 }
344
345
346
347