/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.fop.xml;

import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.FObjectNames;

import org.xml.sax.helpers.AttributesImpl;

/**
 * This is a data class to encapsulate the data of an individual XML
 * parse event in an XML-FO file. The current version, while defining
 * accessor methods, leaves the component data of the event as protected.
 * The <tt>XMLSerialHandler</tt> methods set the values directly.
 * @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
 */

public class FoXMLEvent extends XMLEvent {

    private static final String tag = "$Name$";
    private static final String revision = "$Revision$";

    /** The FO type, as defined in FObjectNames, of fo: XML events. */
    protected int foType = FObjectNames.NO_FO;

    /**
     * The one-argument constructor uses the default initialization values:
     * NOEVENT for the event <i>type</i>, and null references for all others
     * except <i>namespaces</i>.
     */
    public FoXMLEvent (XMLNamespaces namespaces) {
        super(namespaces);
    }

    /**
     * The fully defined constructor takes values for each of the data
     * elements.
     */
    public FoXMLEvent(int type, String chars, int uriIndex,
                    String localName, String qName,
                    AttributesImpl attributes, XMLNamespaces namespaces,
                    int foType)
    {
        super
            (type, chars, uriIndex, localName, qName, attributes, namespaces);
        this.foType = foType;
    }

    /**
     * The cloning constructor takes a reference to an existing
     * <tt>FoXMLEvent</tt> object.
     */
    public FoXMLEvent(FoXMLEvent ev) {
        super(ev);
        foType = ev.foType;
    }

    public FoXMLEvent(int type, String chars, XMLNamespaces namespaces) {
        super(type, chars, namespaces);
    }

    public FoXMLEvent(int type, int uriIndex, AttributesImpl attributes,
                    XMLNamespaces namespaces, int foType) {
        super(namespaces);
        this.type = type;
        this.uriIndex = uriIndex;
        this.attributes = attributes;
        this.foType = foType;
    }

    /**
     * Clear the fields of this event.  Provided for pool operations.
     * Neither the <i>namespaces</i> nor the <i>id</i> field is cleared.
     * @return the cleared <tt>XMLEvent</tt> event.
     */
    public XMLEvent clear() {
        foType = FObjectNames.NO_FO;
        return super.clear();
    }

    /**
     * Clear the fields of this event.  Provided for pool operations.
     * Neither the <i>namespaces</i> nor the <i>id</i> field is cleared.
     * @return the cleared <tt>XMLEvent</tt> event.
     */
    public FoXMLEvent clearFo() {
        return (FoXMLEvent)clear();
    }

    /**
     * Copy the fields of the argument event to this event.
     * Provided for pool operations.
     * Neither the <i>namespaces</i> nor the <i>id</i> field is copied.
     * The <i>namespaces</i> field is not cleared.
     * @param ev the <tt>XMLEvent</tt> to copy.
     * @return the copied <tt>XMLEvent</tt> event.
     */
    public XMLEvent copyEvent(FoXMLEvent ev) {
        foType = ev.foType;
        return super.copyEvent(ev);
    }

    /**
     * Copy the fields of the argument event to this event.
     * Provided for pool operations.
     * Neither the <i>namespaces</i> nor the <i>id</i> field is copied.
     * The <i>namespaces</i> field is not cleared.
     * @return the copied <tt>XMLEvent</tt> event.
     */
    public FoXMLEvent copyFoEvent(FoXMLEvent ev) {
        return (FoXMLEvent)copyEvent(ev);
    }

    /**
     * Get the FO type of this <i>FoXMLEvent</i>.
     * @returns the FO type.
     */
    public int getFoType() { return foType; }

    /**
     * Set the FO type of this <i>FoXMLEvent</i>.
     * @param foType -the FO type.
     */
    public void setFoType(int foType) { this.foType = foType; }

    public String toString() {
        String tstr;
        try {
            tstr = "FO type: " + FObjectNames.getFOName(foType) + "\n";
        } catch (FOPException e) {
            throw new RuntimeException(e.getMessage());
        }
        tstr = tstr + super.toString();
        return tstr;
    }

}