1 /* 2 wsmo4j - a WSMO API and Reference Implementation 3 4 Copyright (c) 2004-2005, OntoText Lab. / SIRMA 5 6 This library is free software; you can redistribute it and/or modify it under 7 the terms of the GNU Lesser General Public License as published by the Free 8 Software Foundation; either version 2.1 of the License, or (at your option) 9 any later version. 10 This library is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 13 details. 14 You should have received a copy of the GNU Lesser General Public License along 15 with this library; if not, write to the Free Software Foundation, Inc., 16 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 /** 20 * <p>Title: WSMO4J</p> 21 * <p>Description: WSMO API and a Reference Implementation</p> 22 * <p>Copyright: Copyright (c) 2004-2005</p> 23 * <p>Company: OntoText Lab. / SIRMA </p> 24 */ 25 26 package com.ontotext.wsmo4j.service; 27 28 /** 29 * An implementation of an interface representing a web service 30 * capability. 31 * 32 * @author not attributable 33 * @version $Revision: 1946 $ $Date: 2007-04-02 15:13:28 +0300 (Mon, 02 Apr 2007) $ 34 */ 35 36 import java.util.LinkedHashMap; 37 import java.util.LinkedHashSet; 38 import java.util.Set; 39 40 import org.omwg.ontology.Axiom; 41 import org.omwg.ontology.Variable; 42 import org.wsmo.common.*; 43 import org.wsmo.common.exception.InvalidModelException; 44 import org.wsmo.common.exception.SynchronisationException; 45 import org.wsmo.service.Capability; 46 47 import com.ontotext.wsmo4j.common.TopEntityImpl; 48 49 50 public class CapabilityImpl extends TopEntityImpl 51 implements Capability { 52 53 private LinkedHashMap <String, Variable> sharedVars; 54 55 private LinkedHashMap <Identifier, Axiom> assumptions; 56 private LinkedHashMap <Identifier, Axiom> preconditions; 57 private LinkedHashMap <Identifier, Axiom> postconditions; 58 private LinkedHashMap <Identifier, Axiom> effects; 59 60 public CapabilityImpl(IRI capabilityIRI) { 61 super(capabilityIRI); 62 63 sharedVars = new LinkedHashMap <String, Variable> (); 64 preconditions = new LinkedHashMap <Identifier, Axiom> (); 65 postconditions = new LinkedHashMap <Identifier, Axiom> (); 66 assumptions = new LinkedHashMap <Identifier, Axiom> (); 67 effects = new LinkedHashMap <Identifier, Axiom> (); 68 } 69 70 /** 71 * Adds a new shared variable to the list of 72 * variables used by the logical expressions of this capability. 73 * @param var The variable to be added 74 * @throws org.wsmo.common.exception.SynchronisationException 75 * @throws org.wsmo.common.exception.InvalidModelException 76 * @see #removeSharedVariable(Variable var) 77 * @see #removeSharedVariable(String name) 78 */ 79 public void addSharedVariable(Variable var) 80 throws SynchronisationException, InvalidModelException { 81 if (var == null) { 82 throw new IllegalArgumentException(); 83 } 84 sharedVars.put(var.getName(), var); 85 } 86 87 /** 88 * Removes a shared variable from the list of 89 * variables used by the logical expressions of this capability. 90 * @param var The variable to be removed. 91 * @throws org.wsmo.common.exception.SynchronisationException 92 * @throws org.wsmo.common.exception.InvalidModelException 93 */ 94 public void removeSharedVariable(Variable var) 95 throws SynchronisationException, InvalidModelException { 96 if (var == null) { 97 throw new IllegalArgumentException(); 98 } 99 sharedVars.remove(var.getName()); 100 } 101 102 /** 103 * Removes a shared variable from the list of 104 * variables used by the logical expressions of this capability. 105 * @param name The name of the variable to be removed. 106 * @throws org.wsmo.common.exception.SynchronisationException 107 * @throws org.wsmo.common.exception.InvalidModelException 108 */ 109 public void removeSharedVariable(String name) 110 throws SynchronisationException, InvalidModelException { 111 if (name == null 112 || name.trim().length() == 0) { 113 throw new IllegalArgumentException(); 114 } 115 sharedVars.remove(name); 116 } 117 118 /** 119 * returns the set of shared variables used by the logical expressions of this capability. 120 * @return The set of shared variables 121 * @throws org.wsmo.common.exception.SynchronisationException 122 * @see org.omwg.ontology.Variable 123 */ 124 public Set <Variable> listSharedVariables() 125 throws SynchronisationException { 126 return new LinkedHashSet <Variable> (sharedVars.values()); 127 } 128 129 /** 130 * Adds a new post-condition to the list of 131 * post-conditions associated with this capability. 132 * @param axiom The new post-condition to be added 133 * to the lsit of post-conditions associated with this 134 * capability. 135 * @throws org.wsmo.common.exception.SynchronisationException 136 * @throws org.wsmo.common.exception.InvalidModelException 137 * @see #removePostCondition(Axiom axiom) 138 * @see #removePostCondition(Identifier id) 139 */ 140 public void addPostCondition(Axiom axiom) 141 throws SynchronisationException, InvalidModelException { 142 if (axiom == null) { 143 throw new IllegalArgumentException(); 144 } 145 postconditions.put(axiom.getIdentifier(), axiom); 146 } 147 148 /** 149 * Removes a post-condition from the list of 150 * post-conditions associated with this capability. 151 * @param axiom The post-condition to be removed. 152 * @throws org.wsmo.common.exception.SynchronisationException 153 * @throws org.wsmo.common.exception.InvalidModelException 154 */ 155 public void removePostCondition(Axiom axiom) 156 throws SynchronisationException, InvalidModelException { 157 if (axiom == null) { 158 throw new IllegalArgumentException(); 159 } 160 postconditions.remove(axiom.getIdentifier()); 161 } 162 163 /** 164 * Removes a post-condition from the list of 165 * post-conditions associated with this capability. 166 * @param id The ID of post-condition to be removed. 167 * @throws org.wsmo.common.exception.SynchronisationException 168 * @throws org.wsmo.common.exception.InvalidModelException 169 */ 170 public void removePostCondition(Identifier id) 171 throws SynchronisationException, InvalidModelException { 172 if (id == null) { 173 throw new IllegalArgumentException(); 174 } 175 postconditions.remove(id); 176 } 177 178 /** 179 * Returns the list of post-conditions associated 180 * with this capability. 181 * @return The set of post-conditions 182 * associated with this capability. 183 * @throws org.wsmo.common.exception.SynchronisationException 184 * @see org.omwg.ontology.Axiom 185 */ 186 public Set <Axiom> listPostConditions() 187 throws SynchronisationException { 188 return new LinkedHashSet <Axiom> (postconditions.values()); 189 } 190 191 /** 192 * Adds a pre-condition to the list of pre-conditions 193 * of this capability. 194 * @param axiom The pre-condition to be added 195 * to the list of pre-conditions of this capability. 196 * @throws org.wsmo.common.exception.SynchronisationException 197 * @throws org.wsmo.common.exception.InvalidModelException 198 * @see #removePreCondition(Axiom axiom) 199 * @see #removePreCondition(Identifier id) 200 */ 201 public void addPreCondition(Axiom axiom) 202 throws SynchronisationException, InvalidModelException { 203 if (axiom == null) { 204 throw new IllegalArgumentException(); 205 } 206 preconditions.put(axiom.getIdentifier(), axiom); 207 } 208 209 /** 210 * Removes a pre-condition from the list of pre-conditions 211 * associated with this capability. 212 * @param axiom The pre-condition to be removed 213 * from the list. 214 * @throws org.wsmo.common.exception.SynchronisationException 215 * @throws org.wsmo.common.exception.InvalidModelException 216 */ 217 public void removePreCondition(Axiom axiom) 218 throws SynchronisationException, InvalidModelException { 219 if (axiom == null) { 220 throw new IllegalArgumentException(); 221 } 222 preconditions.remove(axiom.getIdentifier()); 223 } 224 225 /** 226 * Removes a pre-condition from the list of pre-conditions 227 * associated with this capability. 228 * @param id The ID of the pre-condition to be removed 229 * from the list. 230 * @throws org.wsmo.common.exception.SynchronisationException 231 * @throws org.wsmo.common.exception.InvalidModelException 232 */ 233 public void removePreCondition(Identifier id) 234 throws SynchronisationException, InvalidModelException { 235 if (id == null) { 236 throw new IllegalArgumentException(); 237 } 238 preconditions.remove(id); 239 } 240 241 /** 242 * Lists the pre-conditions of this capability. 243 * @return The list of pre-conditions of this 244 * capability. 245 * @throws org.wsmo.common.exception.SynchronisationException 246 * @see org.omwg.ontology.Axiom 247 */ 248 public Set <Axiom> listPreConditions() 249 throws SynchronisationException { 250 return new LinkedHashSet <Axiom> (preconditions.values()); 251 } 252 253 /** 254 * Adds an effect to the list of effects of this 255 * capability. 256 * @param axiom The effect to be added to the list 257 * of effects of this capability. 258 * @throws org.wsmo.common.exception.SynchronisationException 259 * @throws org.wsmo.common.exception.InvalidModelException 260 * @see #removeEffect(Axiom axiom) 261 * @see #removeEffect(Identifier id) 262 */ 263 public void addEffect(Axiom axiom) 264 throws SynchronisationException, InvalidModelException { 265 if (axiom == null) { 266 throw new IllegalArgumentException(); 267 } 268 effects.put(axiom.getIdentifier(), axiom); 269 } 270 271 /** 272 * Removes an effect from the list of effects 273 * associated with this capability. 274 * @param axiom The effect to be removed from 275 * the list. 276 * @throws org.wsmo.common.exception.SynchronisationException 277 * @throws org.wsmo.common.exception.InvalidModelException 278 */ 279 public void removeEffect(Axiom axiom) 280 throws SynchronisationException, InvalidModelException { 281 if (axiom == null) { 282 throw new IllegalArgumentException(); 283 } 284 effects.remove(axiom.getIdentifier()); 285 } 286 287 /** 288 * Removes an effect from the list of effects 289 * associated with this capability. 290 * @param id The ID of the effect to be removed from 291 * the list. 292 * @throws org.wsmo.common.exception.SynchronisationException 293 * @throws org.wsmo.common.exception.InvalidModelException 294 */ 295 public void removeEffect(Identifier id) 296 throws SynchronisationException, InvalidModelException { 297 if (id == null) { 298 throw new IllegalArgumentException(); 299 } 300 effects.remove(id); 301 } 302 303 /** 304 * Lists the effects of this capability. 305 * @return The list of effects that this capability 306 * produces. 307 * @throws org.wsmo.common.exception.SynchronisationException 308 * @see org.omwg.ontology.Axiom 309 */ 310 public Set <Axiom> listEffects() 311 throws SynchronisationException { 312 return new LinkedHashSet <Axiom> (effects.values()); 313 } 314 315 /** 316 * Adds an assumption to the list of assumptions 317 * associated with this capability. 318 * @param axiom The new assumption to be added 319 * to the list. 320 * @throws org.wsmo.common.exception.SynchronisationException 321 * @throws org.wsmo.common.exception.InvalidModelException 322 * @see #removeAssumption(Axiom axiom) 323 * @see #removeAssumption(Identifier id) 324 */ 325 public void addAssumption(Axiom axiom) 326 throws SynchronisationException, InvalidModelException { 327 if (axiom == null) { 328 throw new IllegalArgumentException(); 329 } 330 assumptions.put(axiom.getIdentifier(), axiom); 331 } 332 333 /** 334 * Removes an assumption from the list of assumptions 335 * associated with this capability. 336 * @param axiom The assumption to be removed 337 * from the list of assumtions. 338 * @throws org.wsmo.common.exception.SynchronisationException 339 * @throws org.wsmo.common.exception.InvalidModelException 340 */ 341 public void removeAssumption(Axiom axiom) 342 throws SynchronisationException, InvalidModelException { 343 if (axiom == null) { 344 throw new IllegalArgumentException(); 345 } 346 assumptions.remove(axiom.getIdentifier()); 347 } 348 349 /** 350 * Removes an assumption from the list of assumptions 351 * associated with this capability. 352 * @param id The ID of the assumption to be removed 353 * from the list of assumtions. 354 * @throws org.wsmo.common.exception.SynchronisationException 355 * @throws org.wsmo.common.exception.InvalidModelException 356 */ 357 public void removeAssumption(Identifier id) 358 throws SynchronisationException, InvalidModelException { 359 if (id == null) { 360 throw new IllegalArgumentException(); 361 } 362 assumptions.remove(id); 363 } 364 365 /** 366 * Lists the assumptions associated with 367 * this capability. 368 * @return The list of assumptions associated 369 * with this capability. 370 * @throws org.wsmo.common.exception.SynchronisationException 371 * @see org.omwg.ontology.Axiom 372 */ 373 public Set <Axiom> listAssumptions() 374 throws SynchronisationException { 375 return new LinkedHashSet <Axiom> (assumptions.values()); 376 } 377 378 public boolean equals(Object object) { 379 if (object == this) { 380 return true; // instance match 381 } 382 if (object == null 383 || false == object instanceof Capability) { 384 return false; 385 } 386 return super.equals(object); 387 } 388 } 389 390 /* 391 * $Log$ 392 * Revision 1.16 2007/04/02 12:13:21 morcen 393 * Generics support added to wsmo-api, wsmo4j and wsmo-test 394 * 395 * Revision 1.15 2006/02/13 10:41:05 vassil_momtchev 396 * the constructors of the topentities to disallow Identifier; see WsmoFactoryImpl 397 * 398 * Revision 1.14 2005/06/22 09:16:06 alex_simov 399 * Simplified equals() method. Identity strongly relies on identifier string 400 * 401 * Revision 1.13 2005/06/01 12:14:23 marin_dimitrov 402 * v0.4.0 403 * 404 * Revision 1.2 2005/05/17 12:01:49 alex 405 * equals() fixed to compare compatible collection types 406 * 407 * Revision 1.1 2005/05/13 09:27:03 alex 408 * initial commit 409 * 410 */ 411