ai.krr
Class NameSpace

java.lang.Object
  extended by ai.krr.NameSpace
All Implemented Interfaces:
java.lang.Comparable<NameSpace>

public class NameSpace
extends java.lang.Object
implements java.lang.Comparable<NameSpace>

This class implements a table of Symbols that belong to this NameSpace. Effectively, it is a hash table that associates the name of a symbol with the symbol itself. Since NamedSymbols have to belong to a NameSpace and do not provide a public constructor, this class provides a simple method (getNamedSymbol(java.lang.String)) to create and retrieve these symbols.

Author:
Gerhard Wickler

Method Summary
protected  java.lang.Object clone()
           This class does not support cloning and an Exception will be thrown if this method is called.
 int compareTo(NameSpace ns)
           This function compares this NameSpace to the given NameSpace.
 java.util.Collection<NamedSymbol> getAllSymbols()
           This function can be used to retrieve all the NamedSymbols that are currently defined in this NameSpace.
 NamedSymbol getNamedSymbol(java.lang.String aName)
           This function must be used to get hold of NamedSymbols with the given name.
static NameSpace getNameSpace(java.net.URI uri)
           This function must be used to obtain a new or the existing NameSpace that is associated with the given URI.
 java.net.URI getNameSpaceURI()
           This function returns the URI with which this NameSpace is associated.
 java.lang.String getProxy()
           This function returns a potentially previously assigned short prefix for this NameSpace.
 int hashCode()
           This function returns a hash value for this NameSpace.
 void setProxy(java.lang.String name)
           This function can be used to assign a short prefix to this NameSpace.
 int size()
           This function returns the number of symbols currently stored in this NameSpace.
 java.lang.String toString()
           This function returns a String representation of this NameSpace, which is the same as the String representing its URI.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException

This class does not support cloning and an Exception will be thrown if this method is called.

Overrides:
clone in class java.lang.Object
Returns:
nothing
Throws:
java.lang.CloneNotSupportedException - will be thrown

compareTo

public int compareTo(NameSpace ns)

This function compares this NameSpace to the given NameSpace. The order between NameSpaces is the order of their URIs.

Specified by:
compareTo in interface java.lang.Comparable<NameSpace>
Parameters:
ns - the NameSpace to which this NameSpace is to be compared
Returns:
0 if the two NameSpaces are identical; -1 if the given NameSpace should come after this NameSpace; and +1 if the given NameSpace should come before this NameSpace

getNameSpaceURI

public final java.net.URI getNameSpaceURI()

This function returns the URI with which this NameSpace is associated. Note that there can only be one NameSpace for this URI.

Returns:
the URI that uniquely identifies this NameSpace

setProxy

public void setProxy(java.lang.String name)

This function can be used to assign a short prefix to this NameSpace. This is useful, for example, when generating XML documents in which the use of standard prefixes make a document more readable. The given String must not be null or the empty String. Also, care should be taken when this prefix is overwritten as it maybe used as was elsewhere.

Parameters:
name - a String that may be used as a short name for this NameSpace

getProxy

public java.lang.String getProxy()

This function returns a potentially previously assigned short prefix for this NameSpace. It returns null if no such prefix was assigned.

Returns:
the String that can be used as a short prefix for this NameSpace; possibly null

size

public int size()

This function returns the number of symbols currently stored in this NameSpace.

Returns:
int the size of this NameSpace

getNamedSymbol

public NamedSymbol getNamedSymbol(java.lang.String aName)

This function must be used to get hold of NamedSymbols with the given name. For example:

 NamedSymbol mySy = ns.getNamedSymbol("Foo");
 

will return a NamedSymbol that belongs to this NameSpace and has the name "Foo". If a NamedSymbol with the given name exists in this NameSpace, this very NamedSymbol will be returned. Otherwise this function will use the protected constructor to create the new NamedSymbol.

Parameters:
aName - the name of the sought NamedSymbol (in this NameSpace)
Returns:
a possibly new NamedSymbol with the given name

getAllSymbols

public java.util.Collection<NamedSymbol> getAllSymbols()

This function can be used to retrieve all the NamedSymbols that are currently defined in this NameSpace.

Returns:
a Collection of all the NamedSymbols in this NameSpace

hashCode

public final int hashCode()

This function returns a hash value for this NameSpace.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash value of the URI of this NameSpace

toString

public java.lang.String toString()

This function returns a String representation of this NameSpace, which is the same as the String representing its URI.

Overrides:
toString in class java.lang.Object
Returns:
The String for the URI of this NameSpace

getNameSpace

public static NameSpace getNameSpace(java.net.URI uri)

This function must be used to obtain a new or the existing NameSpace that is associated with the given URI. Note: the given URI must not be null.

Parameters:
uri - the URI that uniquely identifies the NameSpace
Returns:
the one and only NameSpace identified by the given URI