//=--------------------------------------------------------------------------=
// CNSAdapter_JavaPlugin::Destroy
//=--------------------------------------------------------------------------=
// This will destroy Java Plug-in instance
//
//result - NS_OK if call succeed
// notes :
//
NS_METHOD
CNSAdapter_JavaPlugin::Destroy()
{
    TRACE("CNSAdapter_JavaPlugin::Destroy\n");
    if (m_pJavaPlugin == NULL)
	return NS_ERROR_NULL_POINTER;

    nsresult res = m_pJavaPlugin->Destroy();

    // Remove from pluginMap when applet is destroyed
    pluginMap.InsertElement((void*)m_pJavaPlugin, NULL);

    return res;
}
//=--------------------------------------------------------------------------=
// CNSAdapter_JavaPlugin::Start
//=--------------------------------------------------------------------------=
// This call will start Java Plug-in instance
//
// return: NS_OK if call succeed
//
// notes :
//
NS_METHOD
CNSAdapter_JavaPlugin::Start()
{
    TRACE("CNSAdapter_JavaPlugin::Start\n");
    if (m_pJavaPlugin == NULL)
	return NS_ERROR_NULL_POINTER;
    
    nsresult res = NS_OK;
    res = m_pJavaPlugin->Start();
    
    if (NS_SUCCEEDED(res) && pluginMap.FindElement((void*)m_pJavaPlugin) == NULL)
        pluginMap.InsertElement((void*)m_pJavaPlugin, (void*)this);

    return res;
}
//=--------------------------------------------------------------------------=
// CNSAdapter_JavaPlugin::Stop
//=--------------------------------------------------------------------------=
// This call will stop Java Plug-in instance
//
// return: NS_OK if call succeed
//
// notes :
//
NS_METHOD
CNSAdapter_JavaPlugin::Stop()
{
    TRACE("CNSAdapter_JavaPlugin::Stop\n");
    if (m_pJavaPlugin == NULL)
	return NS_ERROR_NULL_POINTER;

    nsresult res = m_pJavaPlugin->Stop();

    // Remove from pluginMap when applet stops
    if (NS_SUCCEEDED(res) && pluginMap.FindElement((void*)m_pJavaPlugin) != NULL)
	pluginMap.InsertElement((void*)m_pJavaPlugin, NULL);

    return res;
}
//=--------------------------------------------------------------------------=
// CNSAdapter_JavaPlugin::Initialize
//=--------------------------------------------------------------------------=
// params: nsIPluginInstancePeer* peer 
//         the PluginInstancePeer is an object in the browser side to get information
//	   about plugin and get some service done
// return: NS_OK if call succeed
//
// notes :
//
NS_METHOD
CNSAdapter_JavaPlugin::Initialize(nsIPluginInstancePeer* peer)
{
    TRACE("CNSAdapter_JavaPlugin::Initialize\n");
    if (peer == NULL || m_pJavaPlugin == NULL)
	return NS_ERROR_NULL_POINTER;

    m_peer = peer;
    m_peer->AddRef();

    JDSmartPtr<IPluginInstancePeer> spPluginInstancePeerAdapter(new CNSAdapter_PluginInstancePeer(peer));

    if (spPluginInstancePeerAdapter == NULL)
	return NS_ERROR_OUT_OF_MEMORY;

    nsresult res = m_pJavaPlugin->Initialize(spPluginInstancePeerAdapter);

    // Store the CNSAdapter_JavaPlugin and CPluginInstancePeerAdapter into the map
    // The reason is for liveconnect dispatch
    if (NS_SUCCEEDED(res))
	pluginMap.InsertElement((void*)m_pJavaPlugin, (void*)this);
    
    return res;
}