1   /*
2    * OClassImpl.java
3    *
4    * Copyright (c) 2002-2004, The University of Sheffield.
5    *
6    * This file is part of GATE (see http://gate.ac.uk/), and is free
7    * software, licenced under the GNU Library General Public License,
8    * Version 2, June1991.
9    *
10   * A copy of this licence is included in the distribution in the file
11   * licence.html, and is also available at http://gate.ac.uk/gate/licence.html.
12   *
13   * Kalina Bontcheva 11/2003
14   *
15   *
16   *  $Id: OClassImpl.java,v 1.7 2004/07/23 17:45:30 kalina Exp $
17   */
18  
19  package gate.creole.ontology;
20  
21  import java.util.*;
22  
23  public class OClassImpl extends TClassImpl implements OClass  {
24  
25    private Set disjointClassesSet;
26    private Set sameClassesSet;
27    private Set propertiesSet;
28  
29    /**
30     * Creates a new class given id,name,comment and ontology.
31     * @param anId the id of the new class
32     * @param aName the name of the new class
33     * @param aComment the comment of the new class
34     * @param anOntology the ontology to which the new class belongs
35     */
36    public OClassImpl(String anId, String aName, String aComment, Ontology anOntology) {
37      super(anId, aName, aComment, anOntology);
38      disjointClassesSet = new HashSet();
39      sameClassesSet = new HashSet();
40      propertiesSet = new HashSet();
41    }
42  
43    public void setDisjointWith(OClass theClass) {
44      if (theClass == null)
45        return;
46      disjointClassesSet.add(theClass);
47    }
48  
49    public void setSameClassAs(OClass theClass) {
50      if (theClass == null)
51        return;
52      this.sameClassesSet.add(theClass);
53    }
54  
55    public Set getDisjointClasses() {
56      if (this.disjointClassesSet.isEmpty())
57        return null;
58      return this.disjointClassesSet;
59    }
60  
61    public Set getSameClasses() {
62      if (this.sameClassesSet.isEmpty())
63        return null;
64      return this.sameClassesSet;
65    }
66  
67    public Set getProperties() {
68      if (this.propertiesSet.isEmpty())
69        return null;
70      return this.propertiesSet;
71    }
72  
73    public Set getPropertiesByName(String name) {
74      if (this.propertiesSet.isEmpty())
75        return null;
76      if (name == null)
77        return null;
78      Iterator iter = this.propertiesSet.iterator();
79      HashSet resultSet = new HashSet();
80      while (iter.hasNext()) {
81        Property property = (Property) iter.next();
82        if (name.equals(property.getName()))
83          resultSet.add(property);
84      }
85      return resultSet;
86    }
87  
88    public Set getInheritedProperties() {
89      Set superClasses = null;
90      try {
91        this.getSuperClasses(OClass.TRANSITIVE_CLOSURE);
92      } catch (NoSuchClosureTypeException ex) {};
93  
94      if (superClasses == null || superClasses.isEmpty())
95        return null;
96      Set inheritedProperties = new HashSet();
97      Iterator iter = superClasses.iterator();
98      while (iter.hasNext()) {
99        Set classProperties = ((OClass)iter.next()).getProperties();
100       if (classProperties != null)
101         inheritedProperties.addAll(classProperties);
102     }//while
103     return inheritedProperties;
104   }
105 
106   public boolean addProperty(Property theProperty) {
107     if (this.propertiesSet == null)
108       this.propertiesSet = new HashSet();
109     if (! this.equals(theProperty.getDomain()))
110       return false;
111     this.propertiesSet.add(theProperty);
112     return true;
113   }
114 
115   public String toString() {
116     return this.getName();
117   }
118 }