public class XMLAttributes extends 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.
Constructor and Description |
---|
XMLAttributes()
Creates a new empty
XMLAttributes set. |
XMLAttributes(XMLAttributes orig)
Copy constructor creates a copy of this
XMLAttributes set. |
Modifier and Type | Method and Description |
---|---|
int |
add(String name,
String value)
Adds an attribute (a name/value pair) to this
XMLAttributes object,
optionally with a prefix and URI defining a namespace. |
int |
add(String name,
String value,
String namespaceURI)
Adds an attribute (a name/value pair) to this
XMLAttributes object,
optionally with a prefix and URI defining a namespace. |
int |
add(String name,
String value,
String namespaceURI,
String prefix)
Adds an attribute (a name/value pair) to this
XMLAttributes object,
optionally with a prefix and URI defining a namespace. |
int |
add(XMLTriple triple,
String value)
Adds an attribute with the given
XMLTriple /value pair to this XMLAttributes set. |
int |
clear()
Clears (deletes) all attributes in this
XMLAttributes object. |
XMLAttributes |
cloneObject()
Creates and returns a deep copy of this
XMLAttributes set. |
void |
delete()
Explicitly deletes the underlying native object.
|
boolean |
equals(Object sb)
Equality comparison method for XMLAttributes.
|
int |
getIndex(String name)
Return the index of an attribute with the given name.
|
int |
getIndex(String name,
String uri)
Return the index of an attribute with the given local name and namespace URI.
|
int |
getIndex(XMLTriple triple)
Return the index of an attribute with the given
XMLTriple . |
int |
getLength()
Return the number of attributes in the set.
|
String |
getName(int index)
Return the local name of an attribute in this
XMLAttributes set (by position). |
int |
getNumAttributes()
Return the number of attributes in the set.
|
String |
getPrefix(int index)
Return the prefix of an attribute in this
XMLAttributes set (by position). |
String |
getPrefixedName(int index)
Return the prefixed name of an attribute in this
XMLAttributes set (by position). |
String |
getURI(int index)
Return the namespace URI of an attribute in this
XMLAttributes set (by position). |
String |
getValue(int index)
Return the value of an attribute in this
XMLAttributes set (by position). |
String |
getValue(String name)
Return an attribute's value by name.
|
String |
getValue(String name,
String uri)
Return a value of an attribute with the given local name and namespace URI.
|
String |
getValue(XMLTriple triple)
Return a value of an attribute with the given
XMLTriple . |
boolean |
hasAttribute(int index)
Predicate returning
true or false depending on whether
an attribute with the given index exists in this XMLAttributes . |
boolean |
hasAttribute(String name)
Predicate returning
true or false depending on whether
an attribute with the given local name and namespace URI exists in this
XMLAttributes . |
boolean |
hasAttribute(String name,
String uri)
Predicate returning
true or false depending on whether
an attribute with the given local name and namespace URI exists in this
XMLAttributes . |
boolean |
hasAttribute(XMLTriple triple)
Predicate returning
true or false depending on whether
an attribute with the given XML triple exists in this XMLAttributes . |
int |
hashCode()
Returns a hashcode for this XMLAttributes object.
|
boolean |
isEmpty()
|
int |
remove(int n)
Removes an attribute with the given index from this
XMLAttributes set. |
int |
remove(String name)
Removes an attribute with the given local name and namespace URI from
this
XMLAttributes set. |
int |
remove(String name,
String uri)
Removes an attribute with the given local name and namespace URI from
this
XMLAttributes set. |
int |
remove(XMLTriple triple)
Removes an attribute with the given
XMLTriple from this XMLAttributes set. |
int |
removeResource(int n)
Removes an attribute with the given index from this
XMLAttributes set. |
public XMLAttributes() throws XMLConstructorException
XMLAttributes
set.XMLConstructorException
public XMLAttributes(XMLAttributes orig) throws XMLConstructorException
XMLAttributes
set.
orig
the XMLAttributes
object to copy.
XMLConstructorException
- Thrown if the argument orig
is null.
public int add(String name, String value)
XMLAttributes
object,
optionally with a prefix and URI defining a namespace.
name
- a string, the local name of the attribute.value
- a string, the value of the attribute.namespaceURI
- a string, the namespace URI of the attribute.prefix
- a string, the prefix of the namespace
public int add(String name, String value, String namespaceURI)
XMLAttributes
object,
optionally with a prefix and URI defining a namespace.
name
- a string, the local name of the attribute.value
- a string, the value of the attribute.namespaceURI
- a string, the namespace URI of the attribute.prefix
- a string, the prefix of the namespace
public int add(String name, String value, String namespaceURI, String prefix)
XMLAttributes
object,
optionally with a prefix and URI defining a namespace.
name
- a string, the local name of the attribute.value
- a string, the value of the attribute.namespaceURI
- a string, the namespace URI of the attribute.prefix
- a string, the prefix of the namespace
public int add(XMLTriple triple, String value)
XMLTriple
/value pair to this XMLAttributes
set.
triple
- an XMLTriple
, the XML triple of the attribute.value
- a string, the value of the attribute.
public int clear()
XMLAttributes
object.
public XMLAttributes cloneObject()
XMLAttributes
set.
XMLAttributes
set.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 XMLAttributes.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 XMLAttributes.delete()
themselves.
public boolean equals(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.
public int getIndex(String name)
name
- a string, the local name of the attribute for which the
index is required.
XMLAttributes.getIndex(String name, String uri)
const or
XMLAttributes.getIndex(XMLTriple triple)
const should be used to get an index of an
attribute with the given local name and namespace.
public int getIndex(String name, String uri)
name
- a string, the local name of the attribute.uri
- a string, the namespace URI of the attribute.
public int getIndex(XMLTriple triple)
XMLTriple
.
public int getLength()
XMLAttributes
set.public String getName(int index)
XMLAttributes
set (by position).
index
- an integer, the position of the attribute whose local name is
required.
XMLAttributes.hasAttribute(int index)
const to test for the attribute
existence.public int getNumAttributes()
XMLAttributes
set.
This function is an alias for getLength introduced for consistency with other XML classes.
public String getPrefix(int index)
XMLAttributes
set (by position).
index
- an integer, the position of the attribute whose prefix is
required.
XMLAttributes.hasAttribute(int index)
const to test for the attribute
existence.public String getPrefixedName(int index)
XMLAttributes
set (by position).
index
- an integer, the position of the attribute whose prefixed
name is required.
XMLAttributes.hasAttribute(int index)
const to test for attribute existence.public String getURI(int index)
XMLAttributes
set (by position).
index
- an integer, the position of the attribute whose namespace URI is
required.
XMLAttributes.hasAttribute(int index)
const to test for attribute existence.public String getValue(int index)
XMLAttributes
set (by position).
index
- an integer, the position of the attribute whose value is
required.
XMLAttributes.hasAttribute(int index)
const to test for attribute existence.public String getValue(String name)
name
- a string, the local name of the attribute whose value is required.
XMLAttributes.hasAttribute(String name, String uri)
const
to test for attribute existence. A namespace bound to the local name
is not checked by this function. Thus, if there are multiple
attributes with the given local name and different namespaces, the
value of an attribute with the smallest index among those attributes
will be returned. XMLAttributes.getValue(String name)
const or
XMLAttributes.getValue(XMLTriple triple)
const should be used to get a value of an
attribute with the given local name and namespace.public String getValue(String name, String uri)
name
- a string, the local name of the attribute whose value is required.uri
- a string, the namespace URI of the attribute.
XMLAttributes.hasAttribute(String name, String uri)
const
to test for attribute existence.public String getValue(XMLTriple triple)
XMLTriple
.
triple
- an XMLTriple
, the XML triple of the attribute whose
value is required.
XMLTriple
does not exist, an
empty string will be returned. Use
XMLAttributes.hasAttribute(XMLTriple triple)
const to test for attribute existence.public boolean hasAttribute(int index)
true
or false
depending on whether
an attribute with the given index exists in this XMLAttributes
.
index
- an integer, the position of the attribute.
true
if an attribute with the given index exists in this
XMLAttributes
, false
otherwise.public boolean hasAttribute(String name)
true
or false
depending on whether
an attribute with the given local name and namespace URI exists in this
XMLAttributes
.
name
- a string, the local name of the attribute.uri
- a string, the namespace URI of the attribute.
true
if an attribute with the given local name and namespace
URI exists in this XMLAttributes
, false
otherwise.public boolean hasAttribute(String name, String uri)
true
or false
depending on whether
an attribute with the given local name and namespace URI exists in this
XMLAttributes
.
name
- a string, the local name of the attribute.uri
- a string, the namespace URI of the attribute.
true
if an attribute with the given local name and namespace
URI exists in this XMLAttributes
, false
otherwise.public boolean hasAttribute(XMLTriple triple)
true
or false
depending on whether
an attribute with the given XML triple exists in this XMLAttributes
.
triple
- an XMLTriple
, the XML triple of the attribute
true
if an attribute with the given XML triple exists in this
XMLAttributes
, false
otherwise.
public int hashCode()
public boolean isEmpty()
true
if this XMLAttributes
set is empty, false
otherwise.public int remove(int n)
XMLAttributes
set.
(This function is an alias of XMLAttributes.removeResource(int n)
).
n
- an integer the index of the resource to be deleted
public int remove(String name)
XMLAttributes
set.
name
- a string, the local name of the attribute.uri
- a string, the namespace URI of the attribute.
public int remove(String name, String uri)
XMLAttributes
set.
name
- a string, the local name of the attribute.uri
- a string, the namespace URI of the attribute.
public int remove(XMLTriple triple)
XMLTriple
from this XMLAttributes
set.
triple
- an XMLTriple
, the XML triple of the attribute.
public int removeResource(int n)
XMLAttributes
set.
n
- an integer the index of the resource to be deleted