View Javadoc

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.common;
20  
21  
22  import java.util.Collections;
23  import java.util.LinkedHashMap;
24  import java.util.LinkedHashSet;
25  import java.util.Set;
26  
27  import org.omwg.ontology.Ontology;
28  import org.wsmo.common.IRI;
29  import org.wsmo.common.Identifier;
30  import org.wsmo.common.Namespace;
31  import org.wsmo.common.TopEntity;
32  
33  /**
34   * <p>Title: WSMO4J</p>
35   * <p>Description: WSMO API and a Reference Implementation</p>
36   * <p>Copyright:  Copyright (c) 2004-2005</p>
37   * <p>Company: OntoText Lab. / SIRMA </p>
38   * @author not attributable
39   * @version 1.0
40   *
41   */
42  public class TopEntityImpl extends EntityImpl implements TopEntity {
43  
44      private String wsmlVariant;
45  
46      private Namespace defaultNS;
47  
48      private LinkedHashSet <IRI> mediators;
49  
50      private LinkedHashMap <String, Namespace> namespaces;
51  
52      private LinkedHashMap <Identifier, Ontology> ontologies;
53  
54      public TopEntityImpl(Identifier id) {
55          super(id);
56          mediators = new LinkedHashSet <IRI>();
57          namespaces = new LinkedHashMap <String, Namespace> ();
58          ontologies = new LinkedHashMap <Identifier, Ontology> ();
59      }
60  
61      
62      public String getWsmlVariant() {
63          /* 
64           * If variant is not set, you cannot conclude that it's core,
65           * you need the validator to determine the variant.
66           */
67  
68  //        if (this.wsmlVariant == null) {
69  //            return WSML.WSML_CORE;
70  //        }
71  //        else {
72              return this.wsmlVariant;
73  //        }
74      }
75  
76      public void setWsmlVariant(String variant) {
77          if (variant != null 
78                  && variant.trim().length() == 0) {
79              variant = null;
80          }
81          this.wsmlVariant = variant;
82      }
83  
84      public Set <Namespace> listNamespaces() {
85          return new LinkedHashSet <Namespace>(namespaces.values());
86      }
87  
88      public void addNamespace(Namespace ns) {
89          if (ns == null) {
90              throw new IllegalArgumentException();
91          }
92          namespaces.put(ns.getPrefix(), ns);
93      }
94  
95      public void removeNamespace(String prefix) {
96          if (prefix == null) {
97              throw new IllegalArgumentException();
98          }
99          namespaces.remove(prefix);
100     }
101 
102     public void removeNamespace(Namespace ns) {
103         if (ns == null) {
104             throw new IllegalArgumentException();
105         }
106         removeNamespace(ns.getPrefix());
107     }
108 
109     public Namespace findNamespace(String prefix) {
110         if (prefix == null) {
111             throw new IllegalArgumentException();
112         }
113         return namespaces.get(prefix);
114     }
115 
116     public Namespace getDefaultNamespace() {
117         return this.defaultNS;
118     }
119 
120     public void setDefaultNamespace(Namespace ns) {
121         this.defaultNS = ns;
122     }
123 
124     /**
125      * sets a default namespace for the container
126      * @param iri IRI of namespace to set as default
127      * @see #setDefaultNamespace(Namespace ns)
128      */
129     public void setDefaultNamespace(IRI iri) {
130         if (iri == null) {
131             this.defaultNS = null;
132         }
133         else {
134             this.defaultNS = new NamespaceImpl("", iri);
135         }
136     }
137 
138     public void addMediator(IRI mediator) {
139         if (mediator == null) {
140             throw new IllegalArgumentException();
141         }
142         mediators.add(mediator);
143     }
144 
145     public void removeMediator(IRI mediator) {
146         if (mediator == null) {
147             throw new IllegalArgumentException();
148         }
149         mediators.remove(mediator);
150     }
151 
152 
153     public Set <IRI> listMediators() {
154         return Collections.unmodifiableSet(mediators);
155     }
156 
157     public void addOntology(Ontology ontology) {
158         if (ontology == null) {
159             throw new IllegalArgumentException();
160         }
161         ontologies.put(ontology.getIdentifier(), ontology);
162     }
163 
164     public void removeOntology(IRI iri) {
165         if (iri == null) {
166             throw new IllegalArgumentException();
167         }
168         ontologies.remove(iri);
169     }
170 
171     public void removeOntology(Ontology ontology) {
172         if (ontology == null) {
173             throw new IllegalArgumentException();
174         }
175         ontologies.remove(ontology.getIdentifier());
176     }
177 
178     public Set <Ontology> listOntologies() {
179         return new LinkedHashSet <Ontology> (ontologies.values());
180     }
181 
182     public boolean equals(Object object) {
183         if (object == this) {
184             return true; // instance match
185         }
186         if (object == null
187                 || false == object instanceof TopEntity) {
188             return false;
189         }
190         return super.equals(object);
191     }
192 }
193 
194 /*
195  * $Log$
196  * Revision 1.7  2007/04/02 12:13:20  morcen
197  * Generics support added to wsmo-api, wsmo4j and wsmo-test
198  *
199  * Revision 1.6  2006/04/05 13:24:03  vassil_momtchev
200  * usesMediator now refer mediators by  IRI instead of handle to object
201  *
202  * Revision 1.5  2005/11/09 12:32:06  alex_simov
203  * setDefaultNamespace(IRI) did not handle null IRI argument
204  *
205  * Revision 1.4  2005/09/14 14:10:03  alex_simov
206  * setWsmlVariant() allows null argument values
207  *
208  * Revision 1.3  2005/09/09 14:57:51  nathaliest
209  * changed method getWsmlVariant
210  *
211  * Revision 1.2  2005/06/22 09:16:05  alex_simov
212  * Simplified equals() method. Identity strongly relies on identifier string
213  *
214  * Revision 1.1  2005/06/01 12:00:32  marin_dimitrov
215  * v0.4.0
216  *
217  * Revision 1.5  2005/05/17 11:16:19  alex
218  * 'import ... Mediator' added
219  *
220  * Revision 1.4  2005/05/17 10:49:52  marin
221  * 1. added pre-condition on setWsmlVariant
222  * 2. getWsmlVariant return WSML_CORE by default
223  *
224  * Revision 1.3  2005/05/16 08:50:21  alex
225  * implementation method setDefaultNamespace(IRI) added
226  *
227  * Revision 1.2  2005/05/11 13:34:26  alex
228  * equals() method added
229  *
230  * Revision 1.1  2005/05/11 11:50:56  alex
231  * initial commit
232  *
233  */