public class XMLNamespaces extends java.lang.Object
This class of objects is defined by libSBML only and has no direct equivalent in terms of SBML components. This class is not prescribed by the SBML specifications, although it is used to implement features defined in SBML.
This class serves to organize functionality for tracking XML namespaces in a document or data stream. The namespace declarations are stored as a list of pairs of XML namespace URIs and prefix strings. These correspond to the parts of a namespace declaration on an XML element. For example, in the following XML fragment,
<annotation> <mysim:nodecolors xmlns:mysim='urn:lsid:mysim.org' mysim:bgcolor='green' mysim:fgcolor='white'/> </annotation>
urn:lsid:mysim.org
and its prefix is mysim
.
This pair could be stored as one item in an XMLNamespaces
list.
XMLNamespaces
provides various methods for manipulating the list of
prefix-URI pairs. Individual namespaces stored in a given XMLNamespace
object instance can be retrieved based on their index using
XMLNamespaces.getPrefix(int index)
, or by their characteristics such as
their URI or position in the list.
Constructor and Description |
---|
XMLNamespaces()
Creates a new empty list of XML namespace declarations.
|
XMLNamespaces(XMLNamespaces orig)
Copy constructor creates a copy of this
XMLNamespaces list. |
Modifier and Type | Method and Description |
---|---|
int |
add(java.lang.String uri)
Appends an XML namespace prefix and URI pair to this list of namespace
declarations.
|
int |
add(java.lang.String uri,
java.lang.String prefix)
Appends an XML namespace prefix and URI pair to this list of namespace
declarations.
|
int |
clear()
Clears (deletes) all XML namespace declarations in this
XMLNamespaces
object. |
XMLNamespaces |
cloneObject()
Creates and returns a deep copy of this
XMLNamespaces list. |
boolean |
containsUri(java.lang.String uri)
Tests whether the given uri is contained in this set of namespaces.
|
void |
delete()
Explicitly deletes the underlying native object.
|
boolean |
equals(java.lang.Object sb)
Equality comparison method for XMLNamespaces.
|
int |
getIndex(java.lang.String uri)
Look up the index of an XML namespace declaration by URI.
|
int |
getIndexByPrefix(java.lang.String prefix)
Look up the index of an XML namespace declaration by prefix.
|
int |
getLength()
Returns the total number of URI-and-prefix pairs stored in this
particular
XMLNamespaces instance. |
int |
getNumNamespaces()
Returns the total number of URI-and-prefix pairs stored in this
particular
XMLNamespaces instance. |
java.lang.String |
getPrefix(int index)
Look up the prefix of an XML namespace declaration by its position.
|
java.lang.String |
getPrefix(java.lang.String uri)
Look up the prefix of an XML namespace declaration by its URI.
|
java.lang.String |
getURI()
Look up the URI of an XML namespace declaration by its prefix.
|
java.lang.String |
getURI(int index)
Look up the URI of an XML namespace declaration by its position.
|
java.lang.String |
getURI(java.lang.String prefix)
Look up the URI of an XML namespace declaration by its prefix.
|
int |
hashCode()
Returns a hashcode for this XMLNamespaces object.
|
boolean |
hasNS(java.lang.String uri,
java.lang.String prefix)
Predicate returning
true or false depending on whether an XML
Namespace with the given URI and prefix pair is contained in this
XMLNamespaces list. |
boolean |
hasPrefix(java.lang.String prefix)
Predicate returning
true or false depending on whether an XML
Namespace with the given prefix is contained in this XMLNamespaces
list. |
boolean |
hasURI(java.lang.String uri)
Predicate returning
true or false depending on whether an XML
Namespace with the given URI is contained in this XMLNamespaces list. |
boolean |
isEmpty()
|
int |
remove(int index)
Removes an XML Namespace stored in the given position of this list.
|
int |
remove(java.lang.String prefix)
Removes an XML Namespace with the given prefix.
|
public XMLNamespaces() throws XMLConstructorException
XMLConstructorException
public XMLNamespaces(XMLNamespaces orig) throws XMLConstructorException
XMLNamespaces
list.
orig
- the XMLNamespaces
object to copy
XMLConstructorException
- Thrown if the argument orig
is null.
public int add(java.lang.String uri)
An XMLNamespaces
object stores a list of pairs of namespaces and their
prefixes. If there is an XML namespace with the given uri
prefix
in this list, then its corresponding URI will be overwritten by the
new uri
unless the uri represents the core sbml namespace.
Calling programs could use one of the other XMLNamespaces
methods, such as
XMLNamespaces.hasPrefix(String)
and
XMLNamespaces.hasURI(String)
to
inquire whether a given prefix and/or URI
is already present in this XMLNamespaces
object.
If the uri
represents the sbml namespaces then it will not be
overwritten, as this has potentially serious consequences. If it
is necessary to replace the sbml namespace the namespace should be removed
prior to adding the new namespace.
uri
- a string, the uri for the namespaceprefix
- a string, the prefix for the namespace
public int add(java.lang.String uri, java.lang.String prefix)
An XMLNamespaces
object stores a list of pairs of namespaces and their
prefixes. If there is an XML namespace with the given uri
prefix
in this list, then its corresponding URI will be overwritten by the
new uri
unless the uri represents the core sbml namespace.
Calling programs could use one of the other XMLNamespaces
methods, such as
XMLNamespaces.hasPrefix(String)
and
XMLNamespaces.hasURI(String)
to
inquire whether a given prefix and/or URI
is already present in this XMLNamespaces
object.
If the uri
represents the sbml namespaces then it will not be
overwritten, as this has potentially serious consequences. If it
is necessary to replace the sbml namespace the namespace should be removed
prior to adding the new namespace.
uri
- a string, the uri for the namespaceprefix
- a string, the prefix for the namespace
public int clear()
XMLNamespaces
object.
XMLNamespaces.remove(int index)
public XMLNamespaces cloneObject()
XMLNamespaces
list.
XMLNamespaces
list.public boolean containsUri(java.lang.String uri)
public void delete()
In general, application software will not need to call this method directly. The Java language binding for libSBML is implemented as a language wrapper that provides a Java interface to libSBML's underlying C++/C code. Some of the Java methods return objects that are linked to objects created not by Java code, but by C++ code. The Java objects wrapped around them will be deleted when the garbage collector invokes the corresponding C++ finalize()
methods for the objects. The finalize()
methods in turn call the XMLNamespaces.delete()
method on the libSBML object.
This method is exposed in case calling programs want to ensure that the underlying object is freed immediately, and not at some arbitrary time determined by the Java garbage collector. In normal usage, callers do not need to invoke XMLNamespaces.delete()
themselves.
public boolean equals(java.lang.Object sb)
Because the Java methods for libSBML are actually wrappers around code
implemented in C++ and C, certain operations will not behave as
expected. Equality comparison is one such case. An instance of a
libSBML object class is actually a proxy object
wrapping the real underlying C/C++ object. The normal ==
equality operator in Java will only compare the Java proxy objects,
not the underlying native object. The result is almost never what you
want in practical situations. Unfortunately, Java does not provide a
way to override ==
.
The alternative that must be followed is to use the
equals()
method. The equals
method on this
class overrides the default java.lang.Object one, and performs an
intelligent comparison of instances of objects of this class. The
result is an assessment of whether two libSBML Java objects are truly
the same underlying native-code objects.
The use of this method in practice is the same as the use of any other
Java equals
method. For example,
a.equals(
b)
returns
true
if a and b are references to the
same underlying object.
equals
 in class java.lang.Object
sb
- a reference to an object to which the current object
instance will be comparedtrue
if sb
refers to the same underlying
native object as this one, false
otherwisepublic int getIndex(java.lang.String uri)
An XMLNamespaces
object stores a list of pairs of namespaces and their
prefixes. If this XMLNamespaces
object contains a pair with the given
URI uri
, this method returns its index in the list.
uri
- a string, the URI of the sought-after namespace.
-1
if not
present.public int getIndexByPrefix(java.lang.String prefix)
An XMLNamespaces
object stores a list of pairs of namespaces and their
prefixes. If this XMLNamespaces
object contains a pair with the given
prefix prefix
, this method returns its index in the list.
prefix
- a string, the prefix string of the sought-after
namespace
-1
if not
present.public int getLength()
XMLNamespaces
instance.
public int getNumNamespaces()
XMLNamespaces
instance.
This function is an alias for getLength introduced for consistency with other XML classes.
public java.lang.String getPrefix(int index)
An XMLNamespaces
object stores a list of pairs of namespaces and their
prefixes. This method returns the prefix of the n
th
element in that list (if it exists). Callers should use
XMLAttributes.getLength()
first to find out how many namespaces are
stored in the list.
index
- an integer, position of the sought-after prefix
index
is out of range
XMLNamespaces.getLength()
public java.lang.String getPrefix(java.lang.String uri)
An XMLNamespaces
object stores a list of pairs of namespaces and their
prefixes. This method returns the prefix for a pair that has the
given uri
.
uri
- a string, the URI of the prefix being sought
uri
exists in this XMLNamespaces
objectpublic java.lang.String getURI()
An XMLNamespaces
object stores a list of pairs of namespaces and their
prefixes. This method returns the namespace URI for a pair that has
the given prefix
.
prefix
- a string, the prefix of the required URI
prefix
, or an empty string if no such prefix-and-URI pair exists
in this XMLNamespaces
object
XMLNamespaces.getURI()
public java.lang.String getURI(int index)
An XMLNamespaces
object stores a list of pairs of namespaces and their
prefixes. This method returns the URI of the n
th element
in that list (if it exists). Callers should use
XMLAttributes.getLength()
first to find out how many namespaces are
stored in the list.
index
- an integer, position of the required URI.
index
is out of range.
XMLNamespaces.getLength()
public java.lang.String getURI(java.lang.String prefix)
An XMLNamespaces
object stores a list of pairs of namespaces and their
prefixes. This method returns the namespace URI for a pair that has
the given prefix
.
prefix
- a string, the prefix of the required URI
prefix
, or an empty string if no such prefix-and-URI pair exists
in this XMLNamespaces
object
XMLNamespaces.getURI()
public int hashCode()
hashCode
 in class java.lang.Object
public boolean hasNS(java.lang.String uri, java.lang.String prefix)
true
or false
depending on whether an XML
Namespace with the given URI and prefix pair is contained in this
XMLNamespaces
list.
uri
- a string, the URI for the namespaceprefix
- a string, the prefix for the namespace
true
if an XML Namespace with the given uri/prefix pair is
contained in this XMLNamespaces
list, false
otherwise.public boolean hasPrefix(java.lang.String prefix)
true
or false
depending on whether an XML
Namespace with the given prefix is contained in this XMLNamespaces
list.
prefix
- a string, the prefix for the namespace
true
if an XML Namespace with the given URI is contained in
this XMLNamespaces
list, false
otherwise.public boolean hasURI(java.lang.String uri)
true
or false
depending on whether an XML
Namespace with the given URI is contained in this XMLNamespaces
list.
uri
- a string, the uri for the namespace
true
if an XML Namespace with the given URI is contained in
this XMLNamespaces
list, false
otherwise.public boolean isEmpty()
true
if this XMLNamespaces
list is empty, false
otherwise.public int remove(int index)
index
- an integer, position of the namespace to remove.
public int remove(java.lang.String prefix)
prefix
- a string, prefix of the required namespace.
XMLNamespaces.remove(int index)