/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (http://www.swig.org).
 * Version 1.3.38
 *
 * Do not make changes to this file unless you know what you are doing--modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */

package org.sbml.libsbml;

/** 
 * Representation of a node in an XML document tree.
 * <p>
 * Beginning with version 3.0.0, libSBML implements an XML abstraction
 * layer.  This layer presents a uniform XML interface to calling programs
 * regardless of which underlying XML parser libSBML has actually been
 * configured to use.  The basic data object in the XML abstraction is a
 * <em>node</em>, represented by XMLNode.
 * <p>
 * An XMLNode can contain any number of children.  Each child is another
 * XMLNode, thereby forming a tree.  The methods {@link XMLNode#getNumChildren()}
 * and {@link XMLNode#getChild(long n)}
 * can be used to access the tree structure starting from a given node.
 * <p>
 * <p>
 * Each XMLNode is subclassed from XMLToken, and thus has the same methods
 * available as XMLToken.  These methods include {@link XMLToken#getNamespaces()},
 * {@link XMLToken#getPrefix()}, {@link XMLToken#getName()}, {@link XMLToken#getURI()}, and
 * {@link XMLToken#getAttributes()}.
 */

public class XMLNode extends XMLToken {
   private long swigCPtr;

   protected XMLNode(long cPtr, boolean cMemoryOwn)
   {
     super(libsbmlJNI.SWIGXMLNodeUpcast(cPtr), cMemoryOwn);
     swigCPtr = cPtr;
   }

   protected static long getCPtr(XMLNode obj)
   {
     return (obj == null) ? 0 : obj.swigCPtr;
   }

   protected static long getCPtrAndDisown (XMLNode obj)
   {
     long ptr = 0;

     if (obj != null)
     {
       ptr             = obj.swigCPtr;
       obj.swigCMemOwn = false;
     }

     return ptr;
   }

  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if(swigCPtr != 0 && swigCMemOwn) {
      swigCMemOwn = false;
      libsbmlJNI.delete_XMLNode(swigCPtr);
    }
    swigCPtr = 0;
    super.delete();
  }

  /**
   * Equality comparison method for XMLNode.
   * <p>
   * 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 <em>proxy object</em>
   * wrapping the real underlying C/C++ object.  The normal <code>==</code>
   * equality operator in Java will <em>only compare the Java proxy objects</em>,
   * 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 <code>==</code>.
   *  <p>
   * The alternative that must be followed is to use the
   * <code>equals()</code> method.  The <code>equals</code> 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.
   *  <p>
   * The use of this method in practice is the same as the use of any other
   * Java <code>equals</code> method.  For example,
   * <em>a</em><code>.equals(</code><em>b</em><code>)</code> returns
   * <code>true</code> if <em>a</em> and <em>b</em> are references to the
   * same underlying object.
   *
   * @param sb a reference to an object to which the current object
   * instance will be compared
   *
   * @return <code>true</code> if <code>sb</code> refers to the same underlying 
   * native object as this one, <code>false</code> otherwise
   */
  public boolean equals(Object sb)
  {
    if ( this == sb ) 
    {
      return true;
    }
    return swigCPtr == getCPtr((XMLNode)(sb));
  }

  /**
   * Returns a hashcode for this XMLNode object.
   *
   * @return a hash code usable by Java methods that need them.
   */
  public int hashCode()
  {
    return (int)(swigCPtr^(swigCPtr>>>32));
  }

  
  /**
   * Creates a new empty XMLNode with no children.
   */
 public XMLNode() {
    this(libsbmlJNI.new_XMLNode__SWIG_0(), true);
  }

  
  /**
   * Creates a new XMLNode by copying token.
   * <p>
   * @param token XMLToken to be copied to XMLNode
   */
 public XMLNode(XMLToken token) {
    this(libsbmlJNI.new_XMLNode__SWIG_1(XMLToken.getCPtr(token), token), true);
  }

  
  /**
   * Creates a new start element XMLNode with the given set of attributes and
   * namespace declarations.
   * <p>
   * @param triple XMLTriple.
   * @param attributes XMLAttributes, the attributes to set.
   * @param namespaces XMLNamespaces, the namespaces to set.
   * @param line a long integer, the line number (default = 0).
   * @param column a long integer, the column number (default = 0).
   * <p>
   * @docnote The native C++ implementation of this method defines a
   * default argument value.  In the documentation generated for different
   * libSBML language bindings, you may or may not see corresponding
   * arguments in the method declarations.  For example, in Java, a default
   * argument is handled by declaring two separate methods, with one of
   * them having the argument and the other one lacking the argument.
   * However, the libSBML documentation will be <em>identical</em> for both
   * methods.  Consequently, if you are reading this and do not see an
   * argument even though one is described, please look for descriptions of
   * other variants of this method near where this one appears in the
   * documentation.
   */
 public XMLNode(XMLTriple triple, XMLAttributes attributes, XMLNamespaces namespaces, long line, long column) {
    this(libsbmlJNI.new_XMLNode__SWIG_2(XMLTriple.getCPtr(triple), triple, XMLAttributes.getCPtr(attributes), attributes, XMLNamespaces.getCPtr(namespaces), namespaces, line, column), true);
  }

  
  /**
   * Creates a new start element XMLNode with the given set of attributes and
   * namespace declarations.
   * <p>
   * @param triple XMLTriple.
   * @param attributes XMLAttributes, the attributes to set.
   * @param namespaces XMLNamespaces, the namespaces to set.
   * @param line a long integer, the line number (default = 0).
   * @param column a long integer, the column number (default = 0).
   * <p>
   * @docnote The native C++ implementation of this method defines a
   * default argument value.  In the documentation generated for different
   * libSBML language bindings, you may or may not see corresponding
   * arguments in the method declarations.  For example, in Java, a default
   * argument is handled by declaring two separate methods, with one of
   * them having the argument and the other one lacking the argument.
   * However, the libSBML documentation will be <em>identical</em> for both
   * methods.  Consequently, if you are reading this and do not see an
   * argument even though one is described, please look for descriptions of
   * other variants of this method near where this one appears in the
   * documentation.
   */
 public XMLNode(XMLTriple triple, XMLAttributes attributes, XMLNamespaces namespaces, long line) {
    this(libsbmlJNI.new_XMLNode__SWIG_3(XMLTriple.getCPtr(triple), triple, XMLAttributes.getCPtr(attributes), attributes, XMLNamespaces.getCPtr(namespaces), namespaces, line), true);
  }

  
  /**
   * Creates a new start element XMLNode with the given set of attributes and
   * namespace declarations.
   * <p>
   * @param triple XMLTriple.
   * @param attributes XMLAttributes, the attributes to set.
   * @param namespaces XMLNamespaces, the namespaces to set.
   * @param line a long integer, the line number (default = 0).
   * @param column a long integer, the column number (default = 0).
   * <p>
   * @docnote The native C++ implementation of this method defines a
   * default argument value.  In the documentation generated for different
   * libSBML language bindings, you may or may not see corresponding
   * arguments in the method declarations.  For example, in Java, a default
   * argument is handled by declaring two separate methods, with one of
   * them having the argument and the other one lacking the argument.
   * However, the libSBML documentation will be <em>identical</em> for both
   * methods.  Consequently, if you are reading this and do not see an
   * argument even though one is described, please look for descriptions of
   * other variants of this method near where this one appears in the
   * documentation.
   */
 public XMLNode(XMLTriple triple, XMLAttributes attributes, XMLNamespaces namespaces) {
    this(libsbmlJNI.new_XMLNode__SWIG_4(XMLTriple.getCPtr(triple), triple, XMLAttributes.getCPtr(attributes), attributes, XMLNamespaces.getCPtr(namespaces), namespaces), true);
  }

  
  /**
   * Creates a start element XMLNode with the given set of attributes.
   * <p>
   * @param triple XMLTriple.
   * @param attributes XMLAttributes, the attributes to set.
   * @param line a long integer, the line number (default = 0).
   * @param column a long integer, the column number (default = 0).
   * <p>
   * @docnote The native C++ implementation of this method defines a
   * default argument value.  In the documentation generated for different
   * libSBML language bindings, you may or may not see corresponding
   * arguments in the method declarations.  For example, in Java, a default
   * argument is handled by declaring two separate methods, with one of
   * them having the argument and the other one lacking the argument.
   * However, the libSBML documentation will be <em>identical</em> for both
   * methods.  Consequently, if you are reading this and do not see an
   * argument even though one is described, please look for descriptions of
   * other variants of this method near where this one appears in the
   * documentation.
  */
 public XMLNode(XMLTriple triple, XMLAttributes attributes, long line, long column) {
    this(libsbmlJNI.new_XMLNode__SWIG_5(XMLTriple.getCPtr(triple), triple, XMLAttributes.getCPtr(attributes), attributes, line, column), true);
  }

  
  /**
   * Creates a start element XMLNode with the given set of attributes.
   * <p>
   * @param triple XMLTriple.
   * @param attributes XMLAttributes, the attributes to set.
   * @param line a long integer, the line number (default = 0).
   * @param column a long integer, the column number (default = 0).
   * <p>
   * @docnote The native C++ implementation of this method defines a
   * default argument value.  In the documentation generated for different
   * libSBML language bindings, you may or may not see corresponding
   * arguments in the method declarations.  For example, in Java, a default
   * argument is handled by declaring two separate methods, with one of
   * them having the argument and the other one lacking the argument.
   * However, the libSBML documentation will be <em>identical</em> for both
   * methods.  Consequently, if you are reading this and do not see an
   * argument even though one is described, please look for descriptions of
   * other variants of this method near where this one appears in the
   * documentation.
  */
 public XMLNode(XMLTriple triple, XMLAttributes attributes, long line) {
    this(libsbmlJNI.new_XMLNode__SWIG_6(XMLTriple.getCPtr(triple), triple, XMLAttributes.getCPtr(attributes), attributes, line), true);
  }

  
  /**
   * Creates a start element XMLNode with the given set of attributes.
   * <p>
   * @param triple XMLTriple.
   * @param attributes XMLAttributes, the attributes to set.
   * @param line a long integer, the line number (default = 0).
   * @param column a long integer, the column number (default = 0).
   * <p>
   * @docnote The native C++ implementation of this method defines a
   * default argument value.  In the documentation generated for different
   * libSBML language bindings, you may or may not see corresponding
   * arguments in the method declarations.  For example, in Java, a default
   * argument is handled by declaring two separate methods, with one of
   * them having the argument and the other one lacking the argument.
   * However, the libSBML documentation will be <em>identical</em> for both
   * methods.  Consequently, if you are reading this and do not see an
   * argument even though one is described, please look for descriptions of
   * other variants of this method near where this one appears in the
   * documentation.
  */
 public XMLNode(XMLTriple triple, XMLAttributes attributes) {
    this(libsbmlJNI.new_XMLNode__SWIG_7(XMLTriple.getCPtr(triple), triple, XMLAttributes.getCPtr(attributes), attributes), true);
  }

  
  /**
   * Creates an end element XMLNode.
   * <p>
   * @param triple XMLTriple.
   * @param line a long integer, the line number (default = 0).
   * @param column a long integer, the column number (default = 0).
   * <p>
   * @docnote The native C++ implementation of this method defines a
   * default argument value.  In the documentation generated for different
   * libSBML language bindings, you may or may not see corresponding
   * arguments in the method declarations.  For example, in Java, a default
   * argument is handled by declaring two separate methods, with one of
   * them having the argument and the other one lacking the argument.
   * However, the libSBML documentation will be <em>identical</em> for both
   * methods.  Consequently, if you are reading this and do not see an
   * argument even though one is described, please look for descriptions of
   * other variants of this method near where this one appears in the
   * documentation.
   */
 public XMLNode(XMLTriple triple, long line, long column) {
    this(libsbmlJNI.new_XMLNode__SWIG_8(XMLTriple.getCPtr(triple), triple, line, column), true);
  }

  
  /**
   * Creates an end element XMLNode.
   * <p>
   * @param triple XMLTriple.
   * @param line a long integer, the line number (default = 0).
   * @param column a long integer, the column number (default = 0).
   * <p>
   * @docnote The native C++ implementation of this method defines a
   * default argument value.  In the documentation generated for different
   * libSBML language bindings, you may or may not see corresponding
   * arguments in the method declarations.  For example, in Java, a default
   * argument is handled by declaring two separate methods, with one of
   * them having the argument and the other one lacking the argument.
   * However, the libSBML documentation will be <em>identical</em> for both
   * methods.  Consequently, if you are reading this and do not see an
   * argument even though one is described, please look for descriptions of
   * other variants of this method near where this one appears in the
   * documentation.
   */
 public XMLNode(XMLTriple triple, long line) {
    this(libsbmlJNI.new_XMLNode__SWIG_9(XMLTriple.getCPtr(triple), triple, line), true);
  }

  
  /**
   * Creates an end element XMLNode.
   * <p>
   * @param triple XMLTriple.
   * @param line a long integer, the line number (default = 0).
   * @param column a long integer, the column number (default = 0).
   * <p>
   * @docnote The native C++ implementation of this method defines a
   * default argument value.  In the documentation generated for different
   * libSBML language bindings, you may or may not see corresponding
   * arguments in the method declarations.  For example, in Java, a default
   * argument is handled by declaring two separate methods, with one of
   * them having the argument and the other one lacking the argument.
   * However, the libSBML documentation will be <em>identical</em> for both
   * methods.  Consequently, if you are reading this and do not see an
   * argument even though one is described, please look for descriptions of
   * other variants of this method near where this one appears in the
   * documentation.
   */
 public XMLNode(XMLTriple triple) {
    this(libsbmlJNI.new_XMLNode__SWIG_10(XMLTriple.getCPtr(triple), triple), true);
  }

  
  /**
   * Creates a text XMLNode.
   * <p>
   * @param chars a string, the text to be added to the XMLToken
   * @param line a long integer, the line number (default = 0).
   * @param column a long integer, the column number (default = 0).
   * <p>
   * @docnote The native C++ implementation of this method defines a
   * default argument value.  In the documentation generated for different
   * libSBML language bindings, you may or may not see corresponding
   * arguments in the method declarations.  For example, in Java, a default
   * argument is handled by declaring two separate methods, with one of
   * them having the argument and the other one lacking the argument.
   * However, the libSBML documentation will be <em>identical</em> for both
   * methods.  Consequently, if you are reading this and do not see an
   * argument even though one is described, please look for descriptions of
   * other variants of this method near where this one appears in the
   * documentation.
   */
 public XMLNode(String chars, long line, long column) {
    this(libsbmlJNI.new_XMLNode__SWIG_11(chars, line, column), true);
  }

  
  /**
   * Creates a text XMLNode.
   * <p>
   * @param chars a string, the text to be added to the XMLToken
   * @param line a long integer, the line number (default = 0).
   * @param column a long integer, the column number (default = 0).
   * <p>
   * @docnote The native C++ implementation of this method defines a
   * default argument value.  In the documentation generated for different
   * libSBML language bindings, you may or may not see corresponding
   * arguments in the method declarations.  For example, in Java, a default
   * argument is handled by declaring two separate methods, with one of
   * them having the argument and the other one lacking the argument.
   * However, the libSBML documentation will be <em>identical</em> for both
   * methods.  Consequently, if you are reading this and do not see an
   * argument even though one is described, please look for descriptions of
   * other variants of this method near where this one appears in the
   * documentation.
   */
 public XMLNode(String chars, long line) {
    this(libsbmlJNI.new_XMLNode__SWIG_12(chars, line), true);
  }

  
  /**
   * Creates a text XMLNode.
   * <p>
   * @param chars a string, the text to be added to the XMLToken
   * @param line a long integer, the line number (default = 0).
   * @param column a long integer, the column number (default = 0).
   * <p>
   * @docnote The native C++ implementation of this method defines a
   * default argument value.  In the documentation generated for different
   * libSBML language bindings, you may or may not see corresponding
   * arguments in the method declarations.  For example, in Java, a default
   * argument is handled by declaring two separate methods, with one of
   * them having the argument and the other one lacking the argument.
   * However, the libSBML documentation will be <em>identical</em> for both
   * methods.  Consequently, if you are reading this and do not see an
   * argument even though one is described, please look for descriptions of
   * other variants of this method near where this one appears in the
   * documentation.
   */
 public XMLNode(String chars) {
    this(libsbmlJNI.new_XMLNode__SWIG_13(chars), true);
  }

  
  /**
   * Creates a new XMLNode by reading XMLTokens from stream.  
   * <p>
   * The stream must be positioned on a start element
   * (<code>stream.peek().isStart() == true</code>) and will be read until
   * the matching end element is found.
   * <p>
   * @param stream XMLInputStream from which XMLNode is to be created.
   <p>
 * @deprecated libSBML internal
 */
 public XMLNode(XMLInputStream stream) {
    this(libsbmlJNI.new_XMLNode__SWIG_14(XMLInputStream.getCPtr(stream), stream), true);
  }

  
  /**
   * Copy constructor; creates a copy of this XMLNode.
   * <p>
   * @param orig the XMLNode instance to copy.
   */
 public XMLNode(XMLNode orig) {
    this(libsbmlJNI.new_XMLNode__SWIG_15(XMLNode.getCPtr(orig), orig), true);
  }

  
  /**
   * Creates and returns a deep copy of this XMLNode.
   * <p>
   * @return a (deep) copy of this XMLNode.
   */
 public XMLNode cloneObject() {
    long cPtr = libsbmlJNI.XMLNode_cloneObject(swigCPtr, this);
    return (cPtr == 0) ? null : new XMLNode(cPtr, true);
  }

  
  /**
   * Adds a copy of <code>node</code> as a child of this XMLNode.
   * <p>
   * The given <code>node</code> is added at the end of the list of children.
   * <p>
   * @param node the XMLNode to be added as child.
   */
 public void addChild(XMLNode node) {
    libsbmlJNI.XMLNode_addChild(swigCPtr, this, XMLNode.getCPtr(node), node);
  }

  
  /**
   * Inserts a copy of the given node as the <code>n</code>th child of this
   * XMLNode.
   * <p>
   * If the given index <code>n</code> is out of range for this XMLNode instance,
   * the <code>node</code> is added at the end of the list of children.  Even in
   * that situation, this method does not throw an error.
   * <p>
   * @param n an integer, the index at which the given node is inserted
   * @param node an XMLNode to be inserted as <code>n</code>th child.
   * <p>
   * @return a reference to the newly-inserted child <code>node</code>
   */
 public XMLNode insertChild(long n, XMLNode node) {
    return new XMLNode(libsbmlJNI.XMLNode_insertChild(swigCPtr, this, n, XMLNode.getCPtr(node), node), false);
  }

  
  /**
   * Removes the <code>n</code>th child of this XMLNode and returns the
   * removed node.
   * <p>
   * It is important to keep in mind that a given XMLNode may have more
   * than one child.  Calling this method erases all existing references to
   * child nodes <em>after</em> the given position <code>n</code>.  If the index <code>n</code> is
   * greater than the number of child nodes in this XMLNode, this method
   * takes no action (and returns NULL).
   * <p>
   * @param n an integer, the index of the node to be removed
   * <p>
   * @return the removed child, or NULL if <code>n</code> is greater than the number
   * of children in this node
   * <p>
   * @note The caller owns the returned node and is responsible for deleting it.
   */
 public XMLNode removeChild(long n) {
    long cPtr = libsbmlJNI.XMLNode_removeChild(swigCPtr, this, n);
    return (cPtr == 0) ? null : new XMLNode(cPtr, true);
  }

  
  /**
   * Removes all children from this node.
   */
 public void removeChildren() {
    libsbmlJNI.XMLNode_removeChildren(swigCPtr, this);
  }

  
  /**
   * Returns the <code>n</code>th child of this XMLNode.
   * <p>
   * If the index <code>n</code> is greater than the number of child nodes, or it is
   * 0 or less, this method returns an empty node.
   * <p>
   * @param n the index of the node to return
   * <p>
   * @return the  <code>n</code>th child of this XMLNode.
   */
 public XMLNode getChild(long n) {
    return new XMLNode(libsbmlJNI.XMLNode_getChild__SWIG_0(swigCPtr, this, n), false);
  }

  
  /**
   * Returns the number of children for this XMLNode.
   * <p>
   * @return the number of children for this XMLNode.
   */
 public long getNumChildren() {
    return libsbmlJNI.XMLNode_getNumChildren(swigCPtr, this);
  }

  
  /**
   * Writes this XMLNode and its children to stream.
   * <p>
   * @param stream XMLOutputStream, stream to which this XMLNode
   * is to be written.
   <p>
 * @deprecated libSBML internal
 */
 public void write(XMLOutputStream stream) {
    libsbmlJNI.XMLNode_write(swigCPtr, this, XMLOutputStream.getCPtr(stream), stream);
  }

  
  /**
   * Returns a string representation of this XMLNode. 
   * <p>
   * @return a string derived from this XMLNode.
   */
 public String toXMLString() {
    return libsbmlJNI.XMLNode_toXMLString(swigCPtr, this);
  }

  
  /**
   * Returns a string representation of a given XMLNode. 
   * <p>
   * @param node the XMLNode to be represented as a string
   * <p>
   * @return a string-form representation of <code>node</code>
   */
 public static String convertXMLNodeToString(XMLNode node) {
    return libsbmlJNI.XMLNode_convertXMLNodeToString(XMLNode.getCPtr(node), node);
  }

  
  /**
   * Returns an XMLNode which is derived from a string containing XML
   * content.
   * <p>
   * The XML namespace must be defined using argument <code>xmlns</code> if the
   * corresponding XML namespace attribute is not part of the string of the
   * first argument.
   * <p>
   * @param xmlstr string to be converted to a XML node.
   * @param xmlns XMLNamespaces the namespaces to set (default value is NULL).
   * <p>
   * @return a XMLNode which is converted from string <code>xmlstr</code>.  The
   * caller owns the returned XMLNode and is reponsible for deleting it.
   * <p>
   * @docnote The native C++ implementation of this method defines a
   * default argument value.  In the documentation generated for different
   * libSBML language bindings, you may or may not see corresponding
   * arguments in the method declarations.  For example, in Java, a default
   * argument is handled by declaring two separate methods, with one of
   * them having the argument and the other one lacking the argument.
   * However, the libSBML documentation will be <em>identical</em> for both
   * methods.  Consequently, if you are reading this and do not see an
   * argument even though one is described, please look for descriptions of
   * other variants of this method near where this one appears in the
   * documentation.
   */
 public static XMLNode convertStringToXMLNode(String xmlstr, XMLNamespaces xmlns) {
    long cPtr = libsbmlJNI.XMLNode_convertStringToXMLNode__SWIG_0(xmlstr, XMLNamespaces.getCPtr(xmlns), xmlns);
    return (cPtr == 0) ? null : new XMLNode(cPtr, true);
  }

  
  /**
   * Returns an XMLNode which is derived from a string containing XML
   * content.
   * <p>
   * The XML namespace must be defined using argument <code>xmlns</code> if the
   * corresponding XML namespace attribute is not part of the string of the
   * first argument.
   * <p>
   * @param xmlstr string to be converted to a XML node.
   * @param xmlns XMLNamespaces the namespaces to set (default value is NULL).
   * <p>
   * @return a XMLNode which is converted from string <code>xmlstr</code>.  The
   * caller owns the returned XMLNode and is reponsible for deleting it.
   * <p>
   * @docnote The native C++ implementation of this method defines a
   * default argument value.  In the documentation generated for different
   * libSBML language bindings, you may or may not see corresponding
   * arguments in the method declarations.  For example, in Java, a default
   * argument is handled by declaring two separate methods, with one of
   * them having the argument and the other one lacking the argument.
   * However, the libSBML documentation will be <em>identical</em> for both
   * methods.  Consequently, if you are reading this and do not see an
   * argument even though one is described, please look for descriptions of
   * other variants of this method near where this one appears in the
   * documentation.
   */
 public static XMLNode convertStringToXMLNode(String xmlstr) {
    long cPtr = libsbmlJNI.XMLNode_convertStringToXMLNode__SWIG_1(xmlstr);
    return (cPtr == 0) ? null : new XMLNode(cPtr, true);
  }

}
