Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 576   Methods: 41
NCLOC: 488   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
WsmoFactoryImpl.java 0% 0% 0% 0%
coverage
 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    package com.ontotext.wsmo4j.factory;
 20   
 21    /**
 22    * <p>Title: WSMO4J</p>
 23    * <p>Description: WSMO API and a Reference Implementation</p>
 24    * <p>Copyright: Copyright (c) 2004-2005</p>
 25    * <p>Company: OntoText Lab. / SIRMA </p>
 26    * @author not attributable
 27    * @version 1.0
 28    *
 29    */
 30   
 31    import java.lang.reflect.*;
 32    import java.util.*;
 33   
 34    import org.omwg.ontology.*;
 35    import org.wsmo.common.*;
 36    import org.wsmo.common.exception.*;
 37    import org.wsmo.factory.*;
 38    import org.wsmo.mediator.*;
 39    import org.wsmo.service.*;
 40   
 41    import com.ontotext.wsmo4j.service.*;
 42    import com.ontotext.wsmo4j.ontology.*;
 43    import com.ontotext.wsmo4j.common.*;
 44    import com.ontotext.wsmo4j.mediator.*;
 45   
 46   
 47    public class WsmoFactoryImpl
 48    implements WsmoFactory {
 49   
 50  0 static EntityRegistry getReg() {
 51  0 return EntityRegistry.get();
 52    }
 53   
 54  0 public WsmoFactoryImpl(Map <String, Object> map) {
 55  0 getReg();
 56  0 Factory.getLocatorManager().addLocator(getReg());
 57    }
 58   
 59  0 public Goal createGoal(IRI id) {
 60  0 _validateIdentifier(id);
 61  0 Goal alredyUsed = (Goal)_prologCreate(id, Goal.class);
 62  0 if (alredyUsed != null) {
 63  0 IDReference ref = _checkNotResolved(alredyUsed);
 64  0 if (ref == null)
 65  0 return alredyUsed;
 66  0 ref.setDelegate(new GoalImpl(id));
 67  0 return alredyUsed;
 68    }
 69  0 alredyUsed = new GoalImpl(id);
 70  0 getReg().registerEntity(alredyUsed);
 71  0 return alredyUsed;
 72    }
 73   
 74  0 public WebService createWebService(IRI id) {
 75  0 _validateIdentifier(id);
 76   
 77  0 WebService alredyUsed = (WebService)_prologCreate(id, WebService.class);
 78  0 if (alredyUsed != null) {
 79  0 IDReference ref = _checkNotResolved(alredyUsed);
 80  0 if (ref == null)
 81  0 return alredyUsed;
 82  0 ref.setDelegate(new WebServiceImpl(id));
 83  0 return alredyUsed;
 84    }
 85  0 alredyUsed = new WebServiceImpl(id);
 86  0 getReg().registerEntity(alredyUsed);
 87  0 return alredyUsed;
 88    }
 89   
 90  0 public Capability createCapability(IRI id) {
 91  0 _validateIdentifier(id);
 92  0 Capability alredyUsed = (Capability)_prologCreate(id, Capability.class);
 93  0 if (alredyUsed != null) {
 94  0 IDReference ref = _checkNotResolved(alredyUsed);
 95  0 if (ref == null)
 96  0 return alredyUsed;
 97  0 ref.setDelegate(new CapabilityImpl(id));
 98  0 return alredyUsed;
 99    }
 100  0 alredyUsed = new CapabilityImpl(id);
 101  0 getReg().registerEntity(alredyUsed);
 102  0 return alredyUsed;
 103    }
 104   
 105  0 public Interface createInterface(IRI id) {
 106  0 _validateIdentifier(id);
 107  0 Interface alredyUsed = (Interface)_prologCreate(id, Interface.class);
 108  0 if (alredyUsed != null) {
 109  0 IDReference ref = _checkNotResolved(alredyUsed);
 110  0 if (ref == null)
 111  0 return alredyUsed;
 112  0 ref.setDelegate(new InterfaceImpl(id));
 113  0 return alredyUsed;
 114    }
 115  0 alredyUsed = new InterfaceImpl(id);
 116  0 getReg().registerEntity(alredyUsed);
 117  0 return alredyUsed;
 118    }
 119   
 120  0 public Ontology createOntology(IRI id) {
 121  0 _validateIdentifier(id);
 122  0 Ontology alredyUsed = (Ontology)_prologCreate(id, Ontology.class);
 123  0 if (alredyUsed != null) {
 124  0 IDReference ref = _checkNotResolved(alredyUsed);
 125  0 if (ref == null)
 126  0 return alredyUsed;
 127  0 ref.setDelegate(new OntologyImpl(id));
 128  0 return alredyUsed;
 129    }
 130  0 alredyUsed = new OntologyImpl(id);
 131  0 getReg().registerEntity(alredyUsed);
 132  0 return alredyUsed;
 133    }
 134   
 135   
 136  0 public OOMediator createOOMediator(IRI id) {
 137  0 OOMediator alredyUsed = (OOMediator)_prologCreate(id, OOMediator.class);
 138  0 if (alredyUsed != null) {
 139  0 IDReference ref = _checkNotResolved(alredyUsed);
 140  0 if (ref == null)
 141  0 return alredyUsed;
 142  0 ref.setDelegate(new OOMediatorImpl(id));
 143  0 return alredyUsed;
 144    }
 145  0 alredyUsed = new OOMediatorImpl(id);
 146  0 getReg().registerEntity(alredyUsed);
 147  0 return alredyUsed;
 148    }
 149  0 public WWMediator createWWMediator(IRI id) {
 150  0 WWMediator alredyUsed = (WWMediator)_prologCreate(id, WWMediator.class);
 151  0 if (alredyUsed != null) {
 152  0 IDReference ref = _checkNotResolved(alredyUsed);
 153  0 if (ref == null)
 154  0 return alredyUsed;
 155  0 ref.setDelegate(new WWMediatorImpl(id));
 156  0 return alredyUsed;
 157    }
 158  0 alredyUsed = new WWMediatorImpl(id);
 159  0 getReg().registerEntity(alredyUsed);
 160  0 return alredyUsed;
 161    }
 162  0 public WGMediator createWGMediator(IRI id) {
 163  0 WGMediator alredyUsed = (WGMediator)_prologCreate(id, WGMediator.class);
 164  0 if (alredyUsed != null) {
 165  0 IDReference ref = _checkNotResolved(alredyUsed);
 166  0 if (ref == null)
 167  0 return alredyUsed;
 168  0 ref.setDelegate(new WGMediatorImpl(id));
 169  0 return alredyUsed;
 170    }
 171  0 alredyUsed = new WGMediatorImpl(id);
 172  0 getReg().registerEntity(alredyUsed);
 173  0 return alredyUsed;
 174    }
 175  0 public GGMediator createGGMediator(IRI id) {
 176  0 GGMediator alredyUsed = (GGMediator)_prologCreate(id, GGMediator.class);
 177  0 if (alredyUsed != null) {
 178  0 IDReference ref = _checkNotResolved(alredyUsed);
 179  0 if (ref == null)
 180  0 return alredyUsed;
 181  0 ref.setDelegate(new GGMediatorImpl(id));
 182  0 return alredyUsed;
 183    }
 184  0 alredyUsed = new GGMediatorImpl(id);
 185  0 getReg().registerEntity(alredyUsed);
 186  0 return alredyUsed;
 187    }
 188   
 189  0 public Axiom createAxiom(Identifier id) {
 190  0 _validateIdentifier(id);
 191  0 Axiom alredyUsed = (Axiom)_prologCreate(id, Axiom.class);
 192  0 if (alredyUsed != null) {
 193  0 IDReference ref = _checkNotResolved(alredyUsed);
 194  0 if (ref == null)
 195  0 return alredyUsed;
 196  0 ref.setDelegate(new AxiomImpl(id));
 197  0 return alredyUsed;
 198    }
 199  0 alredyUsed = new AxiomImpl(id);
 200  0 getReg().registerEntity(alredyUsed);
 201  0 return alredyUsed;
 202    }
 203   
 204  0 public Concept createConcept(Identifier id) {
 205  0 _validateIdentifier(id);
 206  0 Concept alredyUsed = (Concept)_prologCreate(id, Concept.class);
 207  0 if (alredyUsed != null) {
 208  0 IDReference ref = _checkNotResolved(alredyUsed);
 209  0 if (ref == null)
 210  0 return alredyUsed;
 211  0 ref.setDelegate(new ConceptImpl(id, this));
 212  0 return alredyUsed;
 213    }
 214  0 alredyUsed = new ConceptImpl(id, this);
 215  0 getReg().registerEntity(alredyUsed);
 216  0 return alredyUsed;
 217    }
 218   
 219  0 public Relation createRelation(Identifier id) {
 220  0 _validateIdentifier(id);
 221   
 222  0 Relation alredyUsed = (Relation)_prologCreate(id, Relation.class);
 223  0 if (alredyUsed != null) {
 224  0 IDReference ref = _checkNotResolved(alredyUsed);
 225  0 if (ref == null)
 226  0 return alredyUsed;
 227  0 ref.setDelegate(new RelationImpl(id));
 228  0 return alredyUsed;
 229    }
 230  0 alredyUsed = new RelationImpl(id);
 231  0 getReg().registerEntity(alredyUsed);
 232  0 return alredyUsed;
 233    }
 234   
 235  0 public Instance createInstance(Identifier id) {
 236  0 _validateIdentifier(id);
 237   
 238  0 Instance alredyUsed = (Instance)_prologCreate(id, Instance.class);
 239  0 if (alredyUsed != null) {
 240  0 IDReference ref = _checkNotResolved(alredyUsed);
 241  0 if (ref == null)
 242  0 return alredyUsed;
 243  0 ref.setDelegate(new InstanceImpl(id));
 244  0 return alredyUsed;
 245    }
 246  0 alredyUsed = new InstanceImpl(id);
 247  0 getReg().registerEntity(alredyUsed);
 248  0 return alredyUsed;
 249    }
 250   
 251    //@todo: fix the exception that should be thrown
 252    /**
 253    * Method is not part of the interface. It's internally used by the ConceptImpl
 254    * to register the Attribute to the EntityRegistry
 255    * @param attribute to add to the list of the created objects
 256    */
 257  0 public void createAttribute(Attribute attribute) {
 258  0 _validateIdentifier(attribute.getIdentifier());
 259  0 Attribute alredyUsed = (Attribute)_prologCreate(attribute.getIdentifier(), Attribute.class);
 260  0 if (alredyUsed != null) {
 261  0 IDReference ref = _checkNotResolved(alredyUsed);
 262  0 if (ref == null)
 263  0 return;
 264  0 ref.setDelegate(attribute);
 265  0 return;
 266    }
 267  0 alredyUsed = attribute;
 268  0 getReg().registerEntity(alredyUsed);
 269  0 return;
 270    }
 271   
 272  0 public Instance createInstance(Identifier id, Concept concept)
 273    throws SynchronisationException, InvalidModelException {
 274   
 275  0 Instance result = createInstance(id);
 276  0 result.addConcept(concept);
 277   
 278  0 return result;
 279    }
 280   
 281  0 public RelationInstance createRelationInstance(Relation rel)
 282    throws SynchronisationException, InvalidModelException {
 283  0 Identifier anonId = createAnonymousID();
 284  0 return createRelationInstance(anonId, rel);
 285    }
 286   
 287  0 public RelationInstance createRelationInstance(Identifier id, Relation rel)
 288    throws SynchronisationException, InvalidModelException {
 289  0 _validateIdentifier(id);
 290  0 RelationInstance alredyUsed = (RelationInstance)_prologCreate(id, RelationInstance.class);
 291  0 if (alredyUsed != null) {
 292  0 IDReference ref = _checkNotResolved(alredyUsed);
 293  0 if (ref == null) {
 294    // The following lines fix an inconsistency exposed after ClearTopEntity#clearTopEntity().
 295    // The problem is caused by inability to untie the connection RelationInstance -> Relation
 296    // and this disables automatic adding the reverse connection on rebuilding.
 297  0 if (false == rel.listRelationInstances().contains(alredyUsed)) {
 298  0 rel.addRelationInstance(alredyUsed);
 299    }
 300  0 return alredyUsed;
 301    }
 302  0 ref.setDelegate(new RelationInstanceImpl(id, rel));
 303  0 return alredyUsed;
 304    }
 305  0 alredyUsed = new RelationInstanceImpl(id, rel);
 306  0 getReg().registerEntity(alredyUsed);
 307  0 return alredyUsed;
 308    }
 309   
 310  0 public Namespace createNamespace(String prefix, IRI iri) {
 311  0 if (null == iri) {
 312  0 throw new IllegalArgumentException("Illegal namespace URI supplied: null value ...");
 313    }
 314   
 315  0 return new NamespaceImpl(prefix, iri);
 316   
 317    }
 318   
 319  0 public IRI createIRI(String fullIRI) {
 320   
 321  0 if (null == fullIRI || 0 == fullIRI.trim().length()) {
 322  0 throw new IllegalArgumentException("Illegal IRI supplied: ["+ fullIRI +"] ...");
 323    }
 324   
 325  0 return new IRIImpl(fullIRI);
 326    }
 327   
 328  0 public IRI createIRI(Namespace ns, String localPart) {
 329   
 330  0 if (ns == null) {
 331  0 throw new IllegalArgumentException("Namespace not supplied: it can't be null.");
 332    }
 333  0 if (null == localPart
 334    || 0 == localPart.trim().length()) {
 335  0 throw new IllegalArgumentException("Illegal local name supplied.");
 336    }
 337  0 StringBuffer rawIRI = new StringBuffer();
 338  0 String nsIRI = ns.getIRI().toString();
 339  0 rawIRI.append(nsIRI);
 340  0 if (false == nsIRI.endsWith("#")
 341    && false == nsIRI.endsWith("/")) {
 342  0 rawIRI.append('#');
 343    }
 344  0 rawIRI.append(localPart);
 345  0 return new IRIImpl(rawIRI.toString());
 346    }
 347   
 348  0 public UnnumberedAnonymousID createAnonymousID() {
 349  0 return new UnnumberedAnonymousIDImpl();
 350    }
 351   
 352  0 private void _validateIdentifier(Identifier id) {
 353    //@todo - add more checks, e.g. whether an entity with such ID already exists?
 354  0 if (null == id) {
 355  0 throw new IllegalArgumentException("Invalid ID supplied: null value ...");
 356    }
 357    }
 358   
 359   
 360  0 private Object _prologCreate(Identifier id, Class iface) {
 361  0 Object o = null;
 362  0 try {
 363  0 o = getReg().isRegistered(id, iface);
 364    } catch (RuntimeException rte) {
 365  0 rte.printStackTrace();
 366  0 throw new SynchronisationException(rte);
 367    }
 368  0 return o;
 369    }
 370   
 371  0 private IDReference _checkNotResolved(Entity obj) {
 372  0 if (! (obj instanceof Proxy) )
 373  0 return null;
 374  0 Object ref = Proxy.getInvocationHandler(obj);
 375  0 if (ref instanceof IDReference) {
 376  0 if (((IDReference)ref).isResolved())
 377  0 return null;
 378  0 return (IDReference)ref;
 379    }
 380  0 throw new SynchronisationException();
 381    }
 382   
 383  0 public Goal getGoal(IRI id) {
 384  0 Entity inst = null;
 385  0 try {
 386  0 inst = getReg().isRegistered(id, Goal.class);
 387  0 if (inst == null) {
 388  0 inst = (Entity)IDReference.createNewReference(id, new Class[]{Goal.class});
 389  0 getReg().registerEntity(inst);
 390    }
 391    } catch (RuntimeException rte) {
 392  0 throw new SynchronisationException(rte);
 393    }
 394  0 return (Goal)inst;
 395    }
 396  0 public WebService getWebService(IRI id) {
 397  0 Entity inst = null;
 398  0 try {
 399  0 inst = getReg().isRegistered(id, WebService.class);
 400  0 if (inst == null) {
 401  0 inst = (Entity)IDReference.createNewReference(id, new Class[]{WebService.class});
 402  0 getReg().registerEntity(inst);
 403    }
 404    } catch (RuntimeException rte) {
 405  0 throw new SynchronisationException(rte);
 406    }
 407  0 return (WebService)inst;
 408    }
 409  0 public Interface getInterface(IRI id) {
 410  0 Entity inst = null;
 411  0 try {
 412  0 inst = getReg().isRegistered(id, Interface.class);
 413  0 if (inst == null) {
 414  0 inst = (Entity)IDReference.createNewReference(id, new Class[]{Interface.class});
 415  0 getReg().registerEntity(inst);
 416    }
 417    } catch (RuntimeException rte) {
 418  0 throw new SynchronisationException(rte);
 419    }
 420  0 return (Interface)inst;
 421    }
 422  0 public Capability getCapability(IRI id) {
 423  0 Entity inst = null;
 424  0 try {
 425  0 inst = getReg().isRegistered(id, Capability.class);
 426  0 if (inst == null) {
 427  0 inst = (Entity)IDReference.createNewReference(id, new Class[]{Capability.class});
 428  0 getReg().registerEntity(inst);
 429    }
 430    } catch (RuntimeException rte) {
 431  0 throw new SynchronisationException(rte);
 432    }
 433  0 return (Capability)inst;
 434    }
 435  0 public Ontology getOntology(IRI id) {
 436  0 Entity inst = null;
 437  0 try {
 438  0 inst = getReg().isRegistered(id, Ontology.class);
 439  0 if (inst == null) {
 440  0 inst = (Entity)IDReference.createNewReference(id, new Class[]{Ontology.class});
 441  0 getReg().registerEntity(inst);
 442    }
 443    } catch (RuntimeException rte) {
 444  0 throw new SynchronisationException(rte);
 445    }
 446  0 return (Ontology)inst;
 447    }
 448  0 public OOMediator getOOMediator(IRI id) {
 449  0 Entity inst = null;
 450  0 try {
 451  0 inst = getReg().isRegistered(id, OOMediator.class);
 452  0 if (inst == null) {
 453  0 inst = (Entity)IDReference.createNewReference(id, new Class[]{OOMediator.class});
 454  0 getReg().registerEntity(inst);
 455    }
 456    } catch (RuntimeException rte) {
 457  0 throw new SynchronisationException(rte);
 458    }
 459  0 return (OOMediator)inst;
 460    }
 461  0 public WWMediator getWWMediator(IRI id) {
 462  0 Entity inst = null;
 463  0 try {
 464  0 inst = getReg().isRegistered(id, WWMediator.class);
 465  0 if (inst == null) {
 466  0 inst = (Entity)IDReference.createNewReference(id, new Class[]{WWMediator.class});
 467  0 getReg().registerEntity(inst);
 468    }
 469    } catch (RuntimeException rte) {
 470  0 throw new SynchronisationException(rte);
 471    }
 472  0 return (WWMediator)inst;
 473    }
 474  0 public WGMediator getWGMediator(IRI id) {
 475  0 Entity inst = null;
 476  0 try {
 477  0 inst = getReg().isRegistered(id, WGMediator.class);
 478  0 if (inst == null) {
 479  0 inst = (Entity)IDReference.createNewReference(id, new Class[]{WGMediator.class});
 480  0 getReg().registerEntity(inst);
 481    }
 482    } catch (RuntimeException rte) {
 483  0 throw new SynchronisationException(rte);
 484    }
 485  0 return (WGMediator)inst;
 486    }
 487  0 public GGMediator getGGMediator(IRI id) {
 488  0 Entity inst = null;
 489  0 try {
 490  0 inst = getReg().isRegistered(id, GGMediator.class);
 491  0 if (inst == null) {
 492  0 inst = (Entity)IDReference.createNewReference(id, new Class[]{GGMediator.class});
 493  0 getReg().registerEntity(inst);
 494    }
 495    } catch (RuntimeException rte) {
 496  0 throw new SynchronisationException(rte);
 497    }
 498  0 return (GGMediator)inst;
 499    }
 500  0 public Axiom getAxiom(Identifier id) {
 501  0 Entity inst = null;
 502  0 try {
 503  0 inst = getReg().isRegistered(id, Axiom.class);
 504  0 if (inst == null) {
 505  0 inst = (Entity)IDReference.createNewReference(id, new Class[]{Axiom.class});
 506  0 getReg().registerEntity(inst);
 507    }
 508    } catch (RuntimeException rte) {
 509  0 throw new SynchronisationException(rte);
 510    }
 511  0 return (Axiom)inst;
 512    }
 513  0 public Concept getConcept(Identifier id) {
 514  0 Entity inst = null;
 515  0 try {
 516  0 inst = getReg().isRegistered(id, Concept.class);
 517  0 if (inst == null) {
 518  0 inst = (Entity)IDReference.createNewReference(id, new Class[]{Concept.class});
 519  0 getReg().registerEntity(inst);
 520    }
 521    } catch (RuntimeException rte) {
 522  0 throw new SynchronisationException(rte);
 523    }
 524  0 return (Concept)inst;
 525    }
 526  0 public Instance getInstance(Identifier id) {
 527  0 Entity inst = null;
 528  0 try {
 529  0 inst = getReg().isRegistered(id, Instance.class);
 530  0 if (inst == null) {
 531  0 inst = (Entity)IDReference.createNewReference(id, new Class[]{Instance.class});
 532  0 getReg().registerEntity(inst);
 533    }
 534   
 535    } catch (RuntimeException rte) {
 536  0 throw new SynchronisationException(rte);
 537    }
 538  0 return (Instance)inst;
 539    }
 540  0 public Relation getRelation(Identifier id) {
 541  0 Entity inst = null;
 542  0 try {
 543  0 inst = getReg().isRegistered(id, Relation.class);
 544  0 if (inst == null) {
 545  0 inst = (Entity)IDReference.createNewReference(id, new Class[]{Relation.class});
 546  0 getReg().registerEntity(inst);
 547    }
 548    } catch (RuntimeException rte) {
 549  0 throw new SynchronisationException(rte);
 550    }
 551  0 return (Relation)inst;
 552    }
 553  0 public RelationInstance getRelationInstance(Identifier id) {
 554  0 Entity inst = null;
 555  0 try {
 556  0 inst = getReg().isRegistered(id, RelationInstance.class);
 557  0 if (inst == null) {
 558  0 inst = (Entity)IDReference.createNewReference(id, new Class[]{RelationInstance.class});
 559  0 getReg().registerEntity(inst);
 560    }
 561    } catch (RuntimeException rte) {
 562  0 throw new SynchronisationException(rte);
 563    }
 564  0 return (RelationInstance)inst;
 565    }
 566   
 567    /**
 568    * Return existing Varible instance
 569    * @param name The name of the var
 570    * @return existing var
 571    */
 572  0 public Variable getVariable(String name) {
 573  0 throw new UnsupportedOperationException();
 574    }
 575   
 576    }