/*  Copyright (c) 2001 by Oracle Corporation. All Rights Reserved. */

package oracle.portal.provider.v2;

import oracle.portal.provider.v2.PortletDefinition;
import oracle.portal.utils.xml.v2.*;
import java.util.*;

/**
 * DefaultEventDefinition extends EventDefinition to handle
 * getting the the resource bundle for an event from it's parent portlet.
 *
 * It is encouraged for all strings for a portlet to be specified in a single
 * resource bundle, rather than specifying a separate one for each event.
 * Please see {@link oracle.portal.provider.v2.PortletDefinition} for details
 * on how portlets may provide translatable strings.
 */

public class DefaultEventDefinition extends EventDefinition
    implements InitializableXMLObject
{
    /**
     * mParent stores the parent of this event
     */
    private PortletDefinition mParent;


    /**
     * Called during parsing of provider.xml when this object is created.
     *
     * Used here to store the parent portlet.
     */
    public void preInitialize(Object parent) throws NodeHandlerException
    {
        if (!(parent instanceof PortletDefinition))
        {
            throw new NodeHandlerException("Parent of a Portlet must be a ProviderDefinition");
        }
        mParent = (PortletDefinition)parent;
    }

    /**
     * Not used.
     */
    public void postInitialize() throws NodeHandlerException
    {
    }

    /**
     * @return the parent portlet for this event
     */
    public PortletDefinition getParent()
    {
        return mParent;
    }

    /**
     * Gets the resource bundle for this event in the given Locale.
     *
     * @param l the Locale of the resource bundle being requested.
     * @return the resource bundle for this event.  <b>null</b> if
     * there isn't one.
     */
    public ResourceBundle getResourceBundle(Locale l)
    {
        // check if a resouce bundle was specified for this event.
        ResourceBundle b = super.getResourceBundle(l);

        // If none was specified, the portlet's resource bundle.
        if (b == null)
        {
            return mParent.getResourceBundle(l);
        }

        return b;
    }

    /**
     * Add a parameter to the event.
     *
     * These are the parameters which will be passed with the event when 
     * it is raised.  They are rendered by the portlet with the event.
     *
     * @param parameter a {@link oracle.portal.provider.v2.ParameterDefinition}
     *
     * @exception oracle.portal.provider.v2.PortletException if the given
     *      Object is not a valid
     *      {@link oracle.portal.provider.v2.ParameterDefinition}
     */
    public void addParameter(Object parameter) throws PortletException
    {
        if (!(parameter instanceof ParameterDefinition))
        {
            throw new PortletException("Object not a ParameterDefinition");   
        }
        super.addParameter((ParameterDefinition)parameter);
    }
}

 

