<?php
/**
 * Jeta_Applet:: defines an API to interact with different java applets.
 *
 * Copyright 2006-2007 The Horde Project (http://www.horde.org/)
 *
 * $Horde: jeta/lib/Applet.php,v 1.3 2007/01/02 12:48:17 jan Exp $
 *
 * See the enclosed file LICENSE for license information (GPL).  If you
 * did not receive this file, see http://www.horde.org/licenses/gpl.php.
 *
 * @author  Michael Slusarz <slusarz@curecanti.org>
 * @package Jeta
 */
class Jeta_Applet {

    /**
     * Parameters used by the class.
     *
     * @var array
     */
    var $_params = array();

    /**
     * Attempts to return a concrete Jeta_Applet instance based on $driver.
     *
     * @param string $driver  The type of concrete Jeta_Applet subclass to
     *                        return.
     * @param array $params   A hash containing any additional configuration or
     *                        connection parameters a subclass might need.
     *
     * @return mixed  The newly created concrete Jeta_Applet instance, or
     *                false on error.
     */
    function &factory($driver, $params = array())
    {
        $driver = basename($driver);
        require_once dirname(__FILE__) . '/Applet/' . $driver . '.php';
        $class = 'Jeta_Applet_' . $driver;
        if (class_exists($class)) {
            $jeta = &new $class($params);
        } else {
            $jeta = false;
        }

        return $jeta;
    }

    /**
     * Constructor.
     */
    function Jeta_Applet($params = array())
    {
        $this->_params = array_merge($this->_params, $params);
    }

    /**
     * Generate the HTML code used to load the applet.
     *
     * @abstract
     *
     * @return string  The HTML needed to load the applet.
     */
    function generateAppletCode()
    {
    }

    /**
     * Generate the HTML param tags. 
     *
     * @access private
     *
     * @param array $params  An array of parameter names and values.
     *
     * @return string  The parameters in HTML code.
     */
    function _generateParamTags($params = array())
    {
        $out = '';
        foreach ($params as $key => $val) {
            $out .= '<param name="' . $key . '" value="' . $val . '" />';
        }
        return $out;
    }

}
