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  
20  package com.ontotext.wsmo4j.common;
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.io.Serializable;
32  
33  import org.wsmo.common.IRI;
34  import org.wsmo.common.Namespace;
35  
36  
37  public class NamespaceImpl
38          implements Namespace, Serializable {
39  
40      private String prefix;
41  
42      private IRI fullIRI;
43  
44      public NamespaceImpl(String prefix, IRI fullIRI) {
45          if (null == prefix 
46              || null == fullIRI 
47  //            || prefix.length() == 0 
48              || fullIRI.toString().length() == 0) {
49              throw new IllegalArgumentException("cannot use 'null' as "
50                      + "prefix of fullIRI!");
51          }
52          this.prefix = prefix;
53          if (fullIRI.toString().endsWith("#") 
54                  || fullIRI.toString().endsWith("/")) {
55              this.fullIRI = fullIRI;
56          }
57          else {
58              this.fullIRI = new IRIImpl(fullIRI.toString() + '#');
59          }
60      }
61  
62      public String getPrefix() {
63          return prefix;
64      }
65  
66      public IRI getIRI() {
67          return fullIRI;
68      }
69  
70      public boolean equals(Object object) {
71          if (object == this) {
72              return true;
73          }
74          if (object == null
75                  || false == object instanceof Namespace) {
76              return false;
77          }
78          
79          // internal preconditions
80          assert prefix != null;
81          assert fullIRI != null;
82          
83          Namespace anotherNS = (Namespace)object;
84          return (this.prefix.equals(anotherNS.getPrefix())
85                  && this.fullIRI.equals(anotherNS.getIRI()));
86      }
87      
88      public int hashCode() {
89          return this.prefix.hashCode() + this.fullIRI.hashCode();
90      }
91  }
92  
93  /*
94   * $Log$
95   * Revision 1.14  2005/09/16 14:02:44  alex_simov
96   * Identifier.asString() removed, use Object.toString() instead
97   * (Implementations MUST override toString())
98   *
99   * Revision 1.13  2005/06/02 14:20:51  alex_simov
100  * Namespace allows empty string prefix for the default namespace
101  *
102  * Revision 1.12  2005/06/01 12:00:53  marin_dimitrov
103  * v0.4.0
104  *
105  * Revision 1.2  2005/05/11 13:33:58  alex
106  * copyright notice updated
107  *
108  * Revision 1.1  2005/05/11 12:24:05  alex
109  * initial commit
110  *
111  */