Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 279   Methods: 17
NCLOC: 154   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ConceptImpl.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   
 20    package com.ontotext.wsmo4j.ontology;
 21   
 22    /**
 23    * <p>Title: WSMO4J</p>
 24    * <p>Description: WSMO API and a Reference Implementation</p>
 25    * <p>Copyright: Copyright (c) 2004-2005</p>
 26    * <p>Company: OntoText Lab. / SIRMA </p>
 27    * @author not attributable
 28    * @version 1.0
 29    *
 30    */
 31    import java.util.*;
 32   
 33    import org.omwg.ontology.*;
 34    import org.wsmo.common.*;
 35    import org.wsmo.common.exception.*;
 36   
 37    import com.ontotext.wsmo4j.factory.*;
 38   
 39   
 40    public class ConceptImpl extends OntologyElementImpl
 41    implements Concept {
 42   
 43    private LinkedHashSet <Concept> superConcepts;
 44   
 45    private LinkedHashSet <Concept> subConcepts;
 46   
 47    private LinkedHashSet <Instance> instances;
 48   
 49    private LinkedHashMap <Identifier, Attribute> attributes;
 50   
 51    private final static String ERROR_CYCLE = "Cycle in concept hierarchy detected!";
 52   
 53  0 public ConceptImpl(Identifier thisID, WsmoFactoryImpl factory) {
 54  0 super(thisID);
 55  0 superConcepts = new LinkedHashSet <Concept> ();
 56  0 subConcepts = new LinkedHashSet <Concept> ();
 57  0 attributes = new LinkedHashMap <Identifier, Attribute> ();
 58  0 instances = new LinkedHashSet <Instance> ();
 59    }
 60   
 61  0 public Set <Concept> listSuperConcepts() throws SynchronisationException {
 62  0 return Collections.unmodifiableSet(superConcepts);
 63    }
 64   
 65  0 public void addSuperConcept(Concept superConcept)
 66    throws SynchronisationException, InvalidModelException {
 67  0 if (superConcept == null) {
 68  0 throw new IllegalArgumentException();
 69    }
 70  0 if (checkInheritanceCycles(superConcept)) {
 71  0 throw new InvalidModelException(ERROR_CYCLE);
 72    }
 73  0 superConcepts.add(superConcept);
 74    // establishing the inverse connection
 75  0 if (false == superConcept.listSubConcepts().contains(this)) {
 76  0 superConcept.addSubConcept(this);
 77    }
 78    }
 79   
 80  0 public void removeSuperConcept(Concept superConcept)
 81    throws SynchronisationException, InvalidModelException {
 82  0 if (superConcept == null) {
 83  0 throw new IllegalArgumentException();
 84    }
 85  0 superConcepts.remove(superConcept);
 86    // removing the inverse connection
 87  0 if (superConcept.listSubConcepts().contains(this)) {
 88  0 superConcept.removeSubConcept(this);
 89    }
 90    }
 91   
 92  0 public Set <Concept> listSubConcepts() throws SynchronisationException {
 93  0 return Collections.unmodifiableSet(subConcepts);
 94    }
 95   
 96  0 public void addSubConcept(Concept subConcept)
 97    throws SynchronisationException, InvalidModelException {
 98  0 if (subConcept == null) {
 99  0 throw new IllegalArgumentException();
 100    }
 101  0 subConcepts.add(subConcept);
 102    // establishing the inverse connection
 103  0 if (false == subConcept.listSuperConcepts().contains(this)) {
 104  0 subConcept.addSuperConcept(this);
 105    }
 106    }
 107   
 108  0 public void removeSubConcept(Concept subConcept)
 109    throws SynchronisationException, InvalidModelException {
 110  0 if (subConcept == null) {
 111  0 throw new IllegalArgumentException();
 112    }
 113  0 subConcepts.remove(subConcept);
 114    // removing the inverse connection
 115  0 if (subConcept.listSuperConcepts().contains(this)) {
 116  0 subConcept.removeSuperConcept(this);
 117    }
 118    }
 119   
 120  0 public Set <Instance> listInstances() throws SynchronisationException {
 121  0 return Collections.unmodifiableSet(instances);
 122    }
 123   
 124  0 public void addInstance(Instance instance)
 125    throws SynchronisationException, InvalidModelException {
 126  0 if (instance == null) {
 127  0 throw new IllegalArgumentException();
 128    }
 129  0 instances.add(instance);
 130    // establishing the inverse connection
 131  0 if (false == instance.listConcepts().contains(this)) {
 132  0 instance.addConcept(this);
 133    }
 134    }
 135   
 136  0 public void removeInstance(Instance instance)
 137    throws SynchronisationException, InvalidModelException {
 138  0 if (instance == null) {
 139  0 throw new IllegalArgumentException();
 140    }
 141  0 instances.remove(instance);
 142    // removing the inverse connection
 143  0 if (instance.listConcepts().contains(this)) {
 144  0 instance.removeConcept(this);
 145    }
 146    }
 147   
 148  0 public Set <Attribute> listAttributes() throws SynchronisationException {
 149  0 return new LinkedHashSet <Attribute> (attributes.values());
 150    }
 151   
 152  0 public Set <Attribute> findAttributes(Identifier id)
 153    throws SynchronisationException {
 154  0 if (id == null) {
 155  0 throw new IllegalArgumentException();
 156    }
 157   
 158  0 Set <Attribute> attrs = new HashSet <Attribute> ();
 159  0 Attribute att = attributes.get(id);
 160  0 if (att != null) {
 161  0 attrs.add(att);
 162    }
 163   
 164  0 for (Iterator i = superConcepts.iterator(); i.hasNext();) {
 165  0 attrs.addAll(((Concept) i.next()).findAttributes(id));
 166    }
 167   
 168  0 return attrs;
 169    }
 170   
 171  0 public Attribute createAttribute(Identifier id) throws InvalidModelException{
 172  0 Attribute attribute = attributes.get(id);
 173  0 if (attribute == null) {
 174  0 attribute = new AttributeImpl(id, this);
 175  0 attributes.put(id, attribute);
 176    }
 177  0 return attribute;
 178    }
 179   
 180  0 public void removeAttribute(Identifier identifier) {
 181  0 if (identifier == null) {
 182  0 throw new IllegalArgumentException();
 183    }
 184  0 attributes.remove(identifier);
 185    }
 186   
 187  0 public void removeAttribute(Attribute attribute)
 188    throws SynchronisationException, InvalidModelException {
 189  0 if (attribute == null) {
 190  0 throw new IllegalArgumentException();
 191    }
 192  0 AttributeImpl attr = (AttributeImpl) attributes.remove(attribute.getIdentifier());
 193  0 if (attr != null && attr.getConcept() != null)
 194  0 attr.removeFromConcept();
 195    }
 196   
 197  0 public boolean equals(Object object) {
 198  0 if (object == this) {
 199  0 return true; // instance match
 200    }
 201  0 if (object == null
 202    || false == object instanceof Concept) {
 203  0 return false;
 204    }
 205  0 return super.equals(object);
 206    }
 207   
 208  0 private boolean checkInheritanceCycles(Concept concept) {
 209  0 if (concept.equals(this))
 210  0 return true;
 211   
 212  0 for (Iterator i = concept.listSuperConcepts().iterator(); i.hasNext();) {
 213  0 Concept superConcept = (Concept) i.next();
 214  0 if (checkInheritanceCycles(superConcept))
 215  0 return true;
 216    }
 217   
 218  0 return false;
 219    }
 220    }
 221   
 222    /*
 223    * $Log$
 224    * Revision 1.30 2007/04/02 12:13:21 morcen
 225    * Generics support added to wsmo-api, wsmo4j and wsmo-test
 226    *
 227    * Revision 1.29 2006/11/17 10:52:41 vassil_momtchev
 228    * conceptImpl now uses attributeImpl, when attribute is removed to reset the domain of the attribute
 229    *
 230    * Revision 1.28 2006/03/23 16:12:13 nathaliest
 231    * moving the anon Id check to the validator
 232    *
 233    * Revision 1.27 2006/02/16 14:34:57 nathaliest
 234    * added removeAttribute(Identifier) method
 235    *
 236    * Revision 1.26 2006/02/13 22:49:23 nathaliest
 237    * - changed concept.createAttribute() and Parameter.addType to throw InvalidModelException.
 238    * - small change at check AnonIds in ConceptImpl
 239    *
 240    * Revision 1.25 2006/02/13 11:49:58 nathaliest
 241    * changed anonId-check error String
 242    *
 243    * Revision 1.24 2006/02/13 09:21:21 nathaliest
 244    * added AnonIds Check
 245    *
 246    * Revision 1.23 2006/02/10 14:33:04 vassil_momtchev
 247    * attributes are now stricly local to the scope of a concept; findAttributes implemented to search all superconcept attributes
 248    *
 249    * Revision 1.22 2005/09/15 14:59:41 vassil_momtchev
 250    * cycles in the inheritance hierarchy are not allowed - checkInheritanceCycles method implemented; imports organized;
 251    *
 252    * Revision 1.21 2005/09/07 14:33:01 vassil_momtchev
 253    * createAttribute did not add the created attribute to the internal map of attributes
 254    *
 255    * Revision 1.20 2005/09/01 14:55:19 vassil_momtchev
 256    * createAttribute(IRI) replaced addAttribute(Attribute)
 257    *
 258    * Revision 1.19 2005/07/04 14:25:04 marin_dimitrov
 259    * createAttribute-->addAttribute
 260    *
 261    * Revision 1.18 2005/06/22 09:16:05 alex_simov
 262    * Simplified equals() method. Identity strongly relies on identifier string
 263    *
 264    * Revision 1.17 2005/06/01 12:09:33 marin_dimitrov
 265    * v0.4.0
 266    *
 267    * Revision 1.4 2005/05/31 14:41:30 damian
 268    * createAttribute changed
 269    *
 270    * Revision 1.3 2005/05/17 12:04:57 alex
 271    * Collections.unmodifiableSet() used instead of new set construction
 272    *
 273    * Revision 1.2 2005/05/12 11:14:05 alex
 274    * createAttribute() instantiated Attribute instead of ConceptAttribute
 275    *
 276    * Revision 1.1 2005/05/11 14:19:53 alex
 277    * initial commit
 278    *
 279    */