// Sample code file: ChatServiceSnapin.java

// Warning: This code has been marked up for HTML

/*
   Copyright (c) 2000 Novell, Inc.  All Rights Reserved.

   THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES. 
   USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE LICENSE AGREEMENT 
   ACCOMPANYING THE SOFTWARE DEVELOPMENT KIT (SDK) THAT CONTAINS THIS WORK. 
   PURSUANT TO THE SDK LICENSE AGREEMENT, NOVELL HEREBY GRANTS TO DEVELOPER A 
   ROYALTY-FREE, NON-EXCLUSIVE LICENSE TO INCLUDE NOVELL'S SAMPLE CODE IN ITS 
   PRODUCT. NOVELL GRANTS DEVELOPER WORLDWIDE DISTRIBUTION RIGHTS TO MARKET, 
   DISTRIBUTE, OR SELL NOVELL'S SAMPLE CODE AS A COMPONENT OF DEVELOPER'S 
   PRODUCTS. NOVELL SHALL HAVE NO OBLIGATIONS TO DEVELOPER OR DEVELOPER'S 
   CUSTOMERS WITH RESPECT TO THIS CODE. 
*/
 


package com.novell.Chat;

//Java imports
import javax.swing.*;
import java.util.ResourceBundle;
import java.io.*;

// ConsoleOne imports
import com.novell.application.console.snapin.*;
import com.novell.application.console.snapin.scope.*;

/**
 * Starts and stops Chat.  If this user is the host to a Chat Room's
 * server, that server will be transferred to another user on shutdown.
 */
public class ChatServiceSnapin implements ServiceSnapin
{        
   /**
    * Implementation of the Snapin Interface.
    *
    * @return The snapin's name.
    */
    public String getSnapinName()
    {
        return Chat.chatRes.getString("ChatServiceSnapin_Name");
    }

   /**
    * Implementation of the Snapin Interface.
    *
    * @return The snapin's description.
    */
    public String getSnapinDescription()
    {
        return Chat.chatRes.getString("ChatServiceSnapin_Description");
    }

   /**
    * Implementation of the Snapin Interface.
    *
    * This method is called by the shell to allow each snap-in to perform 
    * any necessary initialization; for example adding itself as an event 
    * listener. The snap-in is initialized by passing a reference to the 
    * InitSnapinInfo class. The getSnapinName() and getSnapinDescription() 
    * methods will be called before initSnapin().
    *
    * @param info Contains data the snap-in may use for initialization, 
    *             such as references to the shell and the snap-in type, and 
    *             may contain a reference to snap-in context data. 
    * @return     If the snap-in is able to successfully complete initialization, 
    *             true is returned, or if initialization fails, false is returned 
    *             and the snap-in will be disabled. 
    */
    public boolean initSnapin(InitSnapinInfo info)
    {        
        Shell shell = info.getShell();
        Chat.getInstance().setShell(shell);     
        
        //Start the process of initializing Chat
        Chat.getInstance().initialize();     
                       
        return true;  //Returning true enables the snapin
    }
    
   
   /**
    * Implementation of the Snapin Interface.
    *
    * Called by the shell when the snap-in is being shut down. 
    * Called by the shell for each snap-in when it is no longer required. 
    * This allows the snap-in to perform any necessary cleanup; for example
    * removing itself as an event listener. 
    */
    public void shutdownSnapin()
    {
        Chat.getInstance().shutDown();  //Shuts down Chat
    }                                    
}