1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package zeus.concepts;
25 import java.util.*;
26
27
28
29 /***
30 df_Description holds a description of an df as per fipa
31 */
32
33 public class DF_Description {
34
35 private FIPA_AID_Address name = null;
36 private Vector services = new Vector();
37 private Vector protocol = null;
38 private Vector ontology = null;
39 private Vector language = null;
40
41
42
43 public void setName (FIPA_AID_Address aid) {
44 this.name = aid;
45 }
46
47
48 public FIPA_AID_Address getName () {
49 return this.name;
50 }
51
52
53 public void addService (FIPA_Service_Description service ) {
54 this.services.addElement(service);
55 }
56
57
58 public Vector getServices () {
59 return this.services;
60 }
61
62
63 public void setProtocol (Vector protocol) {
64 this.protocol = protocol;
65 }
66
67
68 public Vector getProtocol () {
69 return this.protocol;
70 }
71
72
73 public void setOntology (Vector ontology) {
74 this.ontology = ontology;
75 }
76
77 public Vector getOntology () {
78 return this.ontology;
79 }
80
81 public void setLanguage (Vector language) {
82 this.language = language;
83 }
84
85 public Vector getLanguage() {
86 return this.language;
87 }
88
89
90
91
92 public String toString () {
93 String retVal = new String ("(df-agent-description ");
94 if (name!=null) {
95 retVal += ":name (" + name.toFIPAString()+") ";
96 }
97 if (services!= null) {
98 retVal += SL_Util.makeSet (":services", services);
99 }
100 if (protocol != null ) {
101 retVal += SL_Util.makeSet (":protocol", protocol);
102 }
103 if (ontology != null ) {
104 retVal += SL_Util.makeSet (":ontology", ontology);
105 }
106 if (language!= null) {
107 retVal += SL_Util.makeSet (":language",language);
108 }
109
110 retVal += ")";
111
112 return retVal;
113
114 }
115
116 /***
117 for debug
118 */
119 public static void main (String argv[]) {
120 DF_Description df = new DF_Description ();
121 System.out.println(df.toString());
122
123 }
124
125
126 public boolean match (DF_Description desc) {
127 debug ("in match");
128 if (name != null ) {
129 if (!desc.getName().equals (name)) {
130 debug ("name doesnt match " + desc.getName() +" " + name );
131 return false;
132 }
133 }
134 if (services != null){
135 if (!vecMatch(services,desc.getServices())) {
136 debug ("services don't match " );
137 return false;
138 }
139 }
140 if (protocol != null){
141 if (!vecMatch(protocol,desc.getProtocol()))
142 {
143 debug ("protocols don't match");
144 return false;
145 }
146 }
147 if (ontology != null){
148 if (!vecMatch(ontology,desc.getOntology())) {
149 debug ("ontologies don't match ");
150 return false;
151 }
152 }
153 if (language != null) {
154 if (!vecMatch(language,desc.getLanguage())) {
155 debug ("languages don't match ");
156 return false;
157 }
158 }
159 return (true);
160 }
161
162
163 public boolean vecMatch (Vector vec1, Vector vec2) {
164 debug ("in vecMatch");
165 Enumeration elementsNeeded = vec1.elements();
166 while (elementsNeeded.hasMoreElements()) {
167 Enumeration elementsWeHaveGot = vec2.elements();
168 boolean found = false;
169 Object element = elementsNeeded.nextElement();
170 while (elementsWeHaveGot.hasMoreElements() &&!found) {
171 Object elementToTest=elementsWeHaveGot.nextElement();
172 if (element instanceof java.util.Vector
173 && elementToTest instanceof java.util.Vector) {
174 found = vecMatch ((Vector)element,(Vector)elementToTest); }
175 else if (element instanceof zeus.concepts.ContentElement) {
176 debug ("is ContentElement") ;
177 found = ((ContentElement)element).match ((ContentElement)elementToTest);
178 }
179 else
180 {
181 System.out.println("elementToTest = " + elementToTest);
182 System.out.println("elementToTest.toString = " + elementToTest.toString() + " element.toString = " + element.toString());
183 if (elementToTest.toString().equals (element.toString()))
184 found = true;
185 }
186 }
187 if (found == false) return false;
188 }
189 return true;
190
191 }
192
193
194 void debug (String str) {
195 System.out.println(str);
196
197 }
198
199 }