//Sample code file: var/ndk/webBuildengine/tmp/viewable_samples/a4ad0b48-dd95-46b6-8289-721e99c8dc76/login_method/mgmt/consoleone/src/com/novell/admin/ndssnapins/loginMethods/CPassword/CPasswordSnapin.java //Warning: This code has been marked up for HTML

/*=======================================================================
  CPasswordSnapin.java

  Copyright (c) 1999-2002 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.admin.ndssnapins.loginMethods.CPassword;

import java.text.*;

import com.novell.admin.ns.*;
import com.novell.admin.ns.nds.*;
import com.novell.admin.common.snapins.*;
import com.novell.application.console.snapin.*;
import com.novell.utility.nmsgbox.*;
import com.novell.security.japi.nmas.*;
import com.novell.admin.security.util.*;
import com.novell.application.console.snapin.context.*;
// Snapin interface implementation for the CPasswordPanel.
public final class CPasswordSnapin extends AdminPageSnapin
{
    private boolean debug = true;
   private String  tree;
    private String  userDN;
    
  // Interface implementation.
  // @return - true if snapin is to be initialized, false otherwise.
   public boolean initSnapin(InitSnapinInfo snapinInfo)
   {
      String             objectTypeString;  //local - used to store string representation of object type
      String             coUserDN;
      int               slashLoc;
   
      if(debug)
          System.out.println("CPasswordSnapin.initSnapin()");
      
     // Call our super class initSnapin() and continue if it executes OK
      if (super.initSnapin(snapinInfo))
      {
         int ccode;
         
        // Init strings
          tabName             = CPassword.getString(CPassword.CPassword_METHOD_TAB);
          menuName             = CPassword.getString(CPassword.CPassword_MENU_NAME);
          snapin_name          = CPassword.getString(CPassword.CPassword_SNAPIN_NAME);
          snapin_description        = CPassword.getString(CPassword.CPassword_METHOD_SNAPIN_DESCRIPTION);
            
        // If we are running on the server then load the UnsupportedPanel.
          if (OSUtil.getOStype() == OSUtil.NETWARE)
          {
            // Put up a panel that says the feature is not available on this platform
            // thePanel, info, and nsObj are protected fields of the AdminPageSnapin class.
             thePanel = new UnsupportedPanel(info, this, nsObj);
             return true;
          }
          
         // load the wrapper dll
            try
            {
                System.loadLibrary("NMASWrap");
            }
            catch(UnsatisfiedLinkError ex)
            {
                NMsgBox msg = new NMsgBox(shell.getShellFrame(), 
                                            CPassword.getString(CPassword.CPassword_LOAD_LIBRARY_FAILED_TITLE), 
                                            CPassword.getString(CPassword.CPassword_LOAD_LIBRARY_FAILED_MESSAGE), 
                                            3, null, null);
                msg.show();
                return false;
            }

         PageSnapinContext pageContext = (PageSnapinContext)snapinInfo.getSnapinContext();
         
         // Get the selected object(s)
        // The ViewSelections() method is used to get the selections from the VIEW panel
        // Since the user object is not a container object it one can only be selected
        // in the View panel
         ObjectEntryCollection oec = pageContext.getObjectCollection(); 
         

           // If there are no selections then the snapin does not load
         if (oec.hasNoElements())
         {
             if(debug)
                 System.out.println("oec.hasNoElements() == true");

            return false;
         }

        // Get the full DN of the User
        // Console One returns the DN which is prefixed by "TREE/"

         coUserDN = oec.getFirstElement().getFullName();
         slashLoc = coUserDN.indexOf('/');
         tree    = coUserDN.substring(0, slashLoc);
            userDN = coUserDN.substring(slashLoc+1, coUserDN.length());
         if (debug)
         {
            System.out.println("The tree we are working on is " + tree);
         }

         ObjectEntry oe = oec.getFirstElement();
         objectTypeString = oe.getObjectType().getName();
         if (debug)
         {
            System.out.println("The value of object type is " + objectTypeString);
         }

        // This snapin applies only to user objects. In some sense this test is reducdant
        // as this snapin was ONLY REGISTERED for user objects.  So all we get here is a
        // little added insurance
         if (!objectTypeString.equals("User"))
         {
             System.out.println("objectTypeString != User");
            return false;
         }
         else
         {
            if (debug)
            {
               System.out.println("The selected object is a \"User\" object");
            }
         }

            if(debug)
                System.out.println("Creating CPasswordPanel...");

           // Init panel passing a valid nsObj
         thePanel = new CPasswordPanel(info, this, nsObj, tree, userDN);
         return true;
      }
      else
      {
         return false;
      }
   }
   
   /*
   *
   * Launches context sensitive help.
   */
   public void showHelp()
   {
     //shell.launchHelp("novell_clearpw", "cs_nmas_cleartext_password_help");
   }
   
   /*
   * This method allows us more control on when we save data. 
   * The panel saveData() method is called whenever the user exits 
   * the panel. For example, if the user clicks the tab of a different 
   * snapin panel then the current panels saveData() method is called.
   * The "snapin level" saveData() method (below) is called when the user
   * selects "Ok" or "Apply".  
   */
   public boolean saveData()
   {
       return(((CPasswordPanel)thePanel).savePassword());
   }
}