Clover coverage report - Maven Clover report
Coverage timestamp: Tue Sep 16 2008 01:16:37 EEST
file stats: LOC: 286   Methods: 17
NCLOC: 149   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RelationImpl.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.ontology;
 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.util.*;
 32   
 33    import org.omwg.ontology.*;
 34    import org.wsmo.common.*;
 35    import org.wsmo.common.exception.*;
 36   
 37   
 38    public class RelationImpl extends OntologyElementImpl
 39    implements Relation {
 40   
 41    private LinkedHashSet <Relation> superRelations;
 42   
 43    private LinkedHashSet <Relation> subRelations;
 44   
 45    private LinkedHashSet <RelationInstance> relInstances;
 46   
 47    private final static String ERROR_CYCLE = "Cycle in relation hierarchy detected!";
 48   
 49    private List <Parameter> parameters;
 50   
 51  0 public RelationImpl(Identifier thisID) {
 52  0 super(thisID);
 53  0 superRelations = new LinkedHashSet <Relation> ();
 54  0 subRelations = new LinkedHashSet <Relation> ();
 55  0 relInstances = new LinkedHashSet <RelationInstance> ();
 56  0 parameters = new LinkedList <Parameter> ();
 57    }
 58   
 59  0 public Set <Relation> listSuperRelations() throws SynchronisationException {
 60  0 return Collections.unmodifiableSet(superRelations);
 61    }
 62   
 63  0 public void addSuperRelation(Relation relation)
 64    throws SynchronisationException, InvalidModelException {
 65  0 if (relation == null) {
 66  0 throw new InvalidModelException();
 67    }
 68  0 if (checkInheritanceCycles(relation)) {
 69  0 throw new InvalidModelException(ERROR_CYCLE);
 70    }
 71  0 superRelations.add(relation);
 72    // establishing the reverse connection
 73  0 if (false == relation.listSubRelations().contains(this)) {
 74  0 relation.addSubRelation(this);
 75    }
 76    }
 77   
 78  0 public void removeSuperRelation(Relation relation)
 79    throws SynchronisationException, InvalidModelException {
 80  0 if (relation == null) {
 81  0 throw new InvalidModelException();
 82    }
 83  0 superRelations.remove(relation);
 84    // removing the reverse connection
 85  0 if (relation.listSubRelations().contains(this)) {
 86  0 relation.removeSubRelation(this);
 87    }
 88    }
 89   
 90  0 public Set <RelationInstance> listRelationInstances() throws SynchronisationException {
 91  0 return Collections.unmodifiableSet(relInstances);
 92    }
 93   
 94  0 public void addRelationInstance(RelationInstance instance)
 95    throws SynchronisationException, InvalidModelException {
 96  0 if (instance == null) {
 97  0 throw new InvalidModelException();
 98    }
 99  0 relInstances.add(instance);
 100  0 if (instance.getRelation() != this) {
 101  0 instance.setRelation(this);
 102    }
 103    }
 104   
 105  0 public void removeRelationInstance(RelationInstance instance)
 106    throws SynchronisationException, InvalidModelException {
 107  0 if (instance == null) {
 108  0 throw new InvalidModelException();
 109    }
 110  0 relInstances.remove(instance);
 111    }
 112   
 113  0 public Set <Relation> listSubRelations() throws SynchronisationException {
 114  0 return Collections.unmodifiableSet(subRelations);
 115    }
 116   
 117  0 public void addSubRelation(Relation relation)
 118    throws SynchronisationException, InvalidModelException {
 119  0 if (relation == null) {
 120  0 throw new InvalidModelException();
 121    }
 122  0 subRelations.add(relation);
 123    // establishing the reverse connection
 124  0 if (false == relation.listSuperRelations().contains(this)) {
 125  0 relation.addSuperRelation(this);
 126    }
 127    }
 128   
 129  0 public void removeSubRelation(Relation relation)
 130    throws SynchronisationException, InvalidModelException {
 131  0 if (relation == null) {
 132  0 throw new InvalidModelException();
 133    }
 134  0 subRelations.remove(relation);
 135    // removing the reverse connection
 136  0 if (relation.listSuperRelations().contains(this)) {
 137  0 relation.removeSuperRelation(this);
 138    }
 139    }
 140   
 141  0 public List <Parameter> listParameters() throws SynchronisationException {
 142  0 return Collections.unmodifiableList(parameters);
 143    }
 144   
 145    /**
 146    * The positioning of the parameters is zero-based, i.e. the first parameter
 147    * is at position 0. The initial order of parameters creation must be
 148    * succesive, starting from the 0th position. Any other order raises an
 149    * InvalidModelException. If this method is called more than once for a
 150    * certain position, only the parameter created on the last call is
 151    * preserved - all the rest are discarded.
 152    *
 153    * @param pos
 154    * The position of the new Parameter for this Relation
 155    * @throws org.wsmo.common.exception.InvalidModelException
 156    * @return The newly created Parameter
 157    */
 158  0 public Parameter createParameter(byte pos)
 159    throws SynchronisationException, InvalidModelException {
 160  0 if (pos < 0 || pos > parameters.size()) {
 161  0 throw new InvalidModelException();
 162    }
 163  0 Parameter param = new ParameterImpl(this);
 164  0 if (pos == parameters.size()) {
 165  0 parameters.add(param);
 166    }
 167    else {
 168  0 parameters.set(pos, param);
 169    }
 170  0 return param;
 171    }
 172   
 173    /**
 174    * retrieve the parameter at a given position
 175    * Note: the parameter must already exist (e.g. a call to createParameter() must precede this call)
 176    * @param pos The position of the parameter in interest
 177    * @return a reference to the Parameter
 178    * @throws org.wsmo.common.exception.SynchronisationException
 179    * @see #createParameter(byte pos)
 180    */
 181  0 public Parameter getParameter(byte pos)
 182    throws SynchronisationException {
 183  0 if (pos < 0
 184    || pos > parameters.size()-1) {
 185  0 throw new IllegalArgumentException();
 186    }
 187  0 return parameters.get(pos);
 188    }
 189   
 190    /**
 191    * The positioning of the parameters is zero-based, i.e. the first parameter
 192    * is at position 0. The removal of parameters can only be performed from the
 193    * end of the list. Trying to remove a parameter followed by another parameter
 194    * will raise an exception.
 195    * @param param The parameter to be removed
 196    * @throws java.lang.IllegalArgumentException
 197    */
 198   
 199  0 public void removeParameter(Parameter param)
 200    throws SynchronisationException, InvalidModelException {
 201  0 if (parameters.size() == 0
 202    || false == parameters.get(parameters.size()-1).equals(param)) {
 203  0 throw new InvalidModelException();
 204    }
 205  0 parameters.remove(param);
 206    }
 207   
 208    /**
 209    * The positioning of the parameters is zero-based, i.e. the first parameter
 210    * is at position 0. The removal of parameters can only be performed from the
 211    * end of the list. Trying to remove a parameter followed by another parameter
 212    * will raise an exception.
 213    * @param pos The position of the parameter to be removed
 214    * @throws java.lang.IllegalArgumentException
 215    */
 216   
 217  0 public void removeParameter(byte pos)
 218    throws SynchronisationException, InvalidModelException {
 219  0 if (pos < 0 || parameters.size() != pos+1) {
 220  0 throw new InvalidModelException();
 221    }
 222  0 parameters.remove(pos);
 223    }
 224   
 225  0 public boolean equals(Object object) {
 226  0 if (object == this) {
 227  0 return true; // instance match
 228    }
 229  0 if (object == null
 230    || false == object instanceof Relation) {
 231  0 return false;
 232    }
 233  0 return super.equals(object);
 234    }
 235   
 236  0 private boolean checkInheritanceCycles(Relation relation) {
 237  0 if (relation.equals(this))
 238  0 return true;
 239   
 240  0 for (Iterator i = relation.listSuperRelations().iterator(); i.hasNext();) {
 241  0 Relation superRelation = (Relation) i.next();
 242  0 if (checkInheritanceCycles(superRelation))
 243  0 return true;
 244    }
 245   
 246  0 return false;
 247    }
 248   
 249    }
 250   
 251    /*
 252    * $Log$
 253    * Revision 1.21 2007/04/02 12:13:21 morcen
 254    * Generics support added to wsmo-api, wsmo4j and wsmo-test
 255    *
 256    * Revision 1.20 2006/03/23 16:12:13 nathaliest
 257    * moving the anon Id check to the validator
 258    *
 259    * Revision 1.19 2006/02/27 10:22:58 nathaliest
 260    * added anonId check at relation.addXXXRelation(Relation)
 261    *
 262    * Revision 1.18 2005/09/15 14:59:41 vassil_momtchev
 263    * cycles in the inheritance hierarchy are not allowed - checkInheritanceCycles method implemented; imports organized;
 264    *
 265    * Revision 1.17 2005/06/25 13:16:50 damyan_rm
 266    * fixed getParameter() to avoid throwing Exception in case that index is correct
 267    *
 268    * Revision 1.16 2005/06/22 09:16:06 alex_simov
 269    * Simplified equals() method. Identity strongly relies on identifier string
 270    *
 271    * Revision 1.15 2005/06/03 13:02:12 alex_simov
 272    * fix
 273    *
 274    * Revision 1.14 2005/06/01 12:09:33 marin_dimitrov
 275    * v0.4.0
 276    *
 277    * Revision 1.3 2005/05/17 12:04:57 alex
 278    * Collections.unmodifiableSet() used instead of new set construction
 279    *
 280    * Revision 1.2 2005/05/16 08:49:31 alex
 281    * implementation method getParameter(byte) added
 282    *
 283    * Revision 1.1 2005/05/12 09:20:13 alex
 284    * initial commit
 285    *
 286    */