/*
 * (C) Copyright IBM Corp. 1997-1998  All rights reserved.
 *
 * US Government Users Restricted Rights Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *
 * The program is provided "as is" without any warranty express or
 * implied, including the warranty of non-infringement and the implied
 * warranties of merchantibility and fitness for a particular purpose.
 * IBM will not be liable for any damages suffered by you as a result
 * of using the Program. In no event will IBM be liable for any
 * special, indirect or consequential damages or lost profits even if
 * IBM has been advised of the possibility of their occurrence. IBM
 * will not be liable for any third party claims against you.
 */

package com.ibm.xml.parser;

import java.io.*;

/**
 * <P>The <CODE>NamespacePI</CODE> class provides specific support for the namespace 
 * processing instruction (PI).
 * <p>A namespace PI is formatted as:
 * <pre>
 * 
 * <CODE>&lt;?xml:namespace ns="..." prefix="..." src="..."&gt;</CODE>
 *
 </pre>
 *
 * @version 1.1
 * @author TAMURA Kent &lt;kent@trl.ibm.co.jp&gt;
 * @see com.ibm.xml.parser.TXPI
 * @see com.ibm.xml.parser.Namespace
 */
public class NamespacePI extends TXPI {
                                                
            String nsURI        =   null;   // Namespace URI, required
            String prefixName   =   null;   // Prefix name, required
            String srcURI       =   null;   // Schema URI, optional

    /**
     * Constructor.
     * @param nsURI         The value of the <code>ns=</code> attribute.
     * @param prefixName    The value of the <code>prefix=</code> attribute.
     */
    public NamespacePI(String nsURI, String prefixName) {
        this("xml:namespace", 
             " ns=\""+nsURI+"\" prefix=\""+prefixName+"\"", 
             nsURI, 
             prefixName, 
             null);
    }

    /**
     * Constructor.
     * @param nsURI         The value of the <code>ns=</code> attribute.
     * @param prefixName    The value of the <code>prefix=</code> attribute.
     * @param srcURI        The value of the <code>src=</code> attribute, or <var>null</var>.
     */
    public NamespacePI(String nsURI, String prefixName, String srcURI) {
        this("xml:namespace", 
             " ns=\""+nsURI+"\" prefix=\""+prefixName+"\"", 
             nsURI, 
             prefixName, 
             srcURI);
    }
    
    /**
     * Constructor.
     * @param name          The first token following the markup (i.e. "xml:namespace").
     * @param data          From the character immediately after the name to the character immediately preceding the <code>?&gt;</code>.
     * @param nsURI         The value of the <code>ns=</code> attribute.
     * @param prefixName    The value of the <code>prefix=</code> attribute.
     * @param srcURI        The value of the <code>src=</code> attribute, or <var>null</var>.
     * @see com.ibm.xml.parser.Namespace
     */
    public NamespacePI(String name, String data, String nsURI, String prefixName, String srcURI) {
        super(name, data);
        //setNSPrefixName("xml");
        setNSLocalName("namespace");
        this.nsURI       = nsURI;
        this.prefixName  = prefixName;
        this.srcURI      = srcURI;
    }
    
    /**
     * Clone this Namespace PI Node using the appropriate factory.
     * <p>This method is defined by Child.
     * @return          Cloned Namespace PI Node.
     * @see com.ibm.xml.parser.Child#clone
     */
    public synchronized Object clone() {
        checkFactory();
        NamespacePI pi = factory.createNamespacePI(this.name, this.data, this.nsURI,
                                                   this.prefixName, this.srcURI);
        pi.setFactory(getFactory());
        //pi.setNSPrefixName(getNSPrefixName());
        pi.setNSLocalName(getNSLocalName());
        pi.setNSName(getNSName());
        return pi;
    }

    /**
     * Returns the Namespace URI (the value of the <code>ns=</code> attribute) which
     * defines where to retrieve the namespace definition.
     * @return          The value of the <code>ns=</code> attribute.
     */
    public String getNs() {
        return this.nsURI;
    }

    /**
     * Returns the prefix name (the value of the <code>prefix=</code> attribute) which
     * defines the prefix that will be used to refer to this namespace throughout the
     * remainder of the document.
     * @return          The value of the <code>prefix=</code> attribute.
     */
    public String getPrefix() {
        return this.prefixName;
    }

    /**
     * Returns the schema URI (the value of the <code>src=</code> parameter) which
     * defines where to retrieve the schema definition.
     * @return          The value of the <code>src=</code> parameter, or <var>null</var> if no schema.
     */
    public String getSrc() {
        return this.srcURI;
    }

}

