3.4 How to Create an NJCL Applet

This JNDI solution describes how to create the functionality of an NJCL applet, which shows some of the capability of JNDI and NJCL. A demo NJCLApplet utility, with accompanying source code, is provided to show the functionality of this browser solution.

3.4.1 Creating an NJCL Applet

The NJCL applet consists of one major components (NJCLApplet class) with other supporting interfaces and classes.

The NJCL applet is intended to demonstrate the following popular features of NJCL and the Novell providers for JNDI:

JNDI Features

  • list
  • lookup
  • attributes
  • search
  • schema

Session Management

  • public session manager

Authentication

  • login
  • logout

Services

  • NDS replicas and partitions
  • File streams
  • Print queue file submission
  • Server statistics

NJCLApplet Class

The NJCLApplet class is the applet root for the NJCL applet demo. It implements the InterfaceCompare interface, and it contains the init method, which is called by the applet manager, for the NJCL applet. Source code for this demo applet is provided in the NJCLApplet.java file. The NJCLApplet class initializes the rootFrame, the PopupHandler, the pluginParamStr, and the paramInfo (which consists of an array of strings describing each parameter). The following methods are provided for setting up and launching the NJCL applet:

init

The init method first initializes the properties, which are based on the system properties, the default properties, and properties passed in as parameters. It then combines the default properties with the applet parameters passed in, keeping the applet parameters if specified. Any plug-ins specified in the HTML are used first. Finally init sets up the browser implementation as follows:

  1. Gets an AboutFrame object, which provides an About dialog (frame) listing the applet's features. Because this About frame provides a lot of useful information that may be needed as a continual guide, it is created with all controls, and is configured so that it is hidden and then shown when needed.
  2. Constructs a ContextTreeNode object, which represents a JNDI Context as a tree node. The node is constructed based on a frame to which this node belongs and the user object for the node. A number of methods are provided for configuring and manipulating the parameters and variables.
  3. Gets the initial context and changes it to a real context based on the Context property passed in.
  4. Sets up the Message Box for reporting errors and exceptions.

getParameterInfo

The getParameterInfo method returns a string array of information about the supported applet parameters.

getAppletInfo

The getAppletInfo method returns a String of information about the application suitable for an About dialog. The information string includes the applet name, version, author, and copyright information.

implementsInterface

The implementsInterface(Object) method determines if a class implements the interface passed in as the Object parameter and returns a boolean set to TRUE if the passed-in object is the correct interface.

getDefaultProperties

The getDefaultProperties method returns the default properties of the applet. The properties returned are the default or hard coded set.

main

The main(String) method allows the applet to be launched as an application. The input parameter String contains the command line arguments.

Other Supporting Interfaces and Classes

The NJCLApplet class utilizes the following additional interfaces and classes.

  • AboutFrame class - provides an About dialog (frame) that lists the applet's features. The AboutFrame constructor creates the AboutFrame object with all controls. The getAboutFrame(URL) method returns an AboutFrame based on the URL parameter, which specifies where the about.html file is located. An ActionListener event handler method, actionPerformed(ActionEvent), is provided for describing what action occurred.
  • ContextFrame class - provides a graphical view control for a JNDI context. The constructor creates the GUI portion of the ContextFrame object, given a root node as a ContextTreeNode object. A setStatusLabel(String) method sets the status label to the given message and returns the previous contents, and a setRootFlag(boolean) method sets the root flag for the frame. An ActionListener event handler method, actionPerformed(ActionEvent), is provided for describing what action occurred. A group of MouseListener interface methods are provided for various mouse events. Finally, the following handler methods are provided for action events:
    • attributeButton_Action(ActionEvent) for handling the Attribute button and pop-up menu item.
    • classDefMenuItem_Action(ActionEvent) for handling the ClassDef pop-up menu item.
    • lookupButton_Action(ActionEvent) for handling the Lookup button and pop-up menu item.
    • rebindMenuItem_Action(ActionEvent) for handling the Rebind pop-up menu item.
    • renameMenuItem_Action(ActionEvent) for handling the Rename pop-up menu item.
    • schemaMenuItem_Action(ActionEvent) for handling the Schema button.
    • lookupMenuItem_Action(ActionEvent) for handling the lookup menu item.
    • searchMenuItem_Action(ActionEvent) for handling the search menu item.
    • showClassesMenuItem_Action(ActionEvent) for handling the show classes menu item.
    • refreshMenuItem_Action(ActionEvent) for handling the refresh menu item.
    • aboutMenuItem_Action(ActionEvent) for handling the about menu item.
  • InterfaceCompare interface - defines the implementsInterface(Object) method, which checks to see if a class implements a given interface. The input Object parameter is the object to be checked. TRUE is returned if the object implements the right interface.
  • LookupFrame class - provides a graphical input dialog for retrieving the lookup string. The constructor creates the GUI portion of the lookup frame. An inner class, LookupWindowAdapter, is provided for handling focus change and window close events. An ActionListener event handler method, actionPerformed(ActionEvent), is provided for handling the action events. Finally, a getText method returns the text entered, or NULL if none is entered.
  • MessageBox class - provides a message dialog box for the applet based on the parent Frame object.
  • PopupHandler interface - defines a snap-in that keys off a pop-up menu. Custom object handlers can be defined to provide additional functionality for an object based on its class or any of the interfaces it implements. This allows for endless extensibility to the common browser interface provided in this applet. A single method, popupRequested(JFrame, JPopupMenu, Object), is provided for the registered handlers when the pop-up event occurs. The JFrame parameter is the frame in which the pop-up is being requested; the JPopupMenu is the pop-up menu being created; and the Object parameter is the object being customized, which is likely to be a ContextTreeNode object.
  • RenameFrame class - provides a graphical input dialog for renaming a context. The constructor creates the GUI portion of the rename frame. An inner class, RenameWindowAdapter, handles focus change and window close events. An ActionListener event handler method, actionPerformed(ActionEvent), is provided for handling action events. A getText method returns the text entered, or NULL if no text is entered.
  • SearchFrame class - provides a graphical input dialog for retrieving the search string. The constructor creates the GUI portion of the search frame (SearchFrame object) based on the JFrame parameter. An inner class, SearchWindowAdapter, handles focus change and window close events. An ActionListener event handler method, actionPerformed(ActionEvent), is provided for handling action events. A getText method returns the text entered, or NULL if no text is entered.
  • Util class - provides the following general purpose utility functions, which are not graphical in nature and have no JNDI dependencies:
    • getPropertiesFromParams(Applet, String) retrieves the properties from the Applet parameters.
    • mergeProperties(Properties, Properties, boolean) constructs a property list by merging the new property list with the original property list. If the boolean parameter, preserve, is set to TRUE the new properties will be added to the original property list, not overwriting them.
    • getHashTableFromProperties(Properties) converts the recursive Properties object into a flag Hashtable.
    • loadExtensions(InterfaceCompare, String) returns an array of objects that implements a given interface. The input parameter InterfaceCompare contains the compare object to use against the objects found in the directory specified by the String parameter.
    • loadExtensions(InterfaceCompare, Properties, String) returns an array of objects that implements a given interface. The input parameter InterfaceCompare contains the compare object to use against the objects found in the directory; the Properties parameter contains the properties to search for the plug-ins; and the String parameter, paramName, contains the parameter name of the plug-ins to load.
    • getExceptionTrace(Throwable) returns a String that includes an exception's stack trace. The Throwable object input parameter contains the exception for which to get the trace.
    • addGridBagComponent(Container, Component, int, int, int, int, double, double) sets up the GridBagConstraints for an object and adds it to the Container using a GridBagLayout.

    An internal class, ClassFilenameFilter, is provided to accept only ".class" files. Its only method, accept(File, String) determines if the input directory path parameter (File) and file name (String) are acceptable for the filter.

  • AuthPopupHandler.java - provides a snap-in that keys off a pop-up menu for authentication. It requires a public NULL constructor. The popupRequested(JFrame, JPopupMenu, Object) method calls for registered handlers when the pop-up event occurs. The JFrame parameter is the frame in which the pop-up is being requested; the JPopupMenu parameter is the pop-up menu being created; and the Object parameter is the object being customized, which is likely to be a ContextTreeNode.

    An internal class, NWAuthActionListener, handles NetWare® session style authentication. This internal class has two constructors: a default NULL constructor required for plug-ins, and a constructor with four parameters that hangs onto a session.

    The following ActionListener methods are provided for handling action events:

    • actionPerformed(ActionEvent) describes what action occurred.
    • login_Action(ActionEvent) handles login menu item actions.
    • logout_Action(ActionEvent) handles logout menu item actions.
  • DataPopupHandler.java - provides a snap-in that keys off of a pop-up menu for file display. The handler basically provides a text/hex file viewer for anything that can have a stream (via DataAccessable). It requires a public NULL constructor. The popupRequested(JFrame, JPopupMenu, Object) method calls for registered handlers when the pop-up event occurs. The JFrame parameter is the frame in which the pop-up is being requested; the JPopupMenu parameter is the pop-up menu being created; and the Object parameter is the object being customized, which is likely to be a ContextTreeNode.

    An internal class, DataActionListener, handles NetWare data objects. This internal class has two constructors: A default NULL constructor required for plug-ins, and a constructor with four parameters that hangs onto the context.

    The following ActionListener methods are provided for handling action events:

    • actionPerformed(ActionEvent) describes what action occurred.
    • data_Action(ActionEvent) handles data menu item actions.

    Another internal class, DataViewFrame, presents a text or hex file viewer. The constructor creates a file viewer in text mode based on two parameters: the name of the file to be viewed and the context to be used to access the file. An ActionListener method, actionPerformed(ActionEvent) handles four different button action events: ASCII button, hex button, save button and close button. Two additional methods are provided for setting the main panel view: showText sets the main panel view to text mode view, and showHex sets the main panel view to hex mode view.

  • ServerPopupHandler.java - provides a snap-in that keys off a pop-up menu for simple server management. It requires a public NULL constructor. The popupRequested(JFrame, JPopupMenu, Object) method calls for registered handlers when the pop-up event occurs. The JFrame parameter is the frame in which the pop-up is being requested; the JPopupMenu parameter is the pop-up menu being created; and the Object parameter is the object being customized, which is likely to be a ContextTreeNode.

    An internal class, SWServerActionListener, handles NetWare server objects. This internal class has two constructors: A default NULL constructor required for plug-ins, and a constructor with four parameters that hangs onto the server.

    The following ActionListener methods are provided for handling action events:

    • actionPerformed(ActionEvent) describes what action occurred.
    • server_Action(ActionEvent) handles server menu item actions.

    Another internal class, ServerMgmtFrame, presents and handles server management features. This internal class has two constructors: a default NULL constructor required for plug-ins, and a constructor with two parameters: the name of the server and the server context to be used. An ActionListener method, actionPerformed(ActionEvent) handles three different button action events: load NLM button, unload NLM button, and close button.

3.4.2 Executing the NJCL Applet Utility

The purpose of this utility is to demonstrate a few of the capabilities of JNDI and NJCL. NJCL includes several providers for JNDI. These providers for JNDI encompass much of NetWare’s functionality. These providers are defined under the Java package com.novell.service and are included in the following sub-packages:

  • bindery - NetWare 3.x legacy resource database
  • file - NetWare file system
  • ncpext - NetWare Core Protocol Extensions
  • nds - Novell Directory Services (NDS)
  • nw - Provides a desktop metaphor to NDS and legacy servers
  • qms - NetWare Queue Management System (legacy print)
  • server - NetWare server

The browser metaphor allows you to explore the features available. A pop-up menu is available by right-clicking an object in the browser. This menu contains both generic JNDI features (above the line) and custom NetWare features (below the line) to demonstrate the mixture of JNDI and NetWare calls.

The following JNDI features are demonstrated:

  • Context.list feature shows the browser tree.
  • Context.lookup feature is used when a tree is expanded and also in the View|Lookup menu item and pop-up menu on any Context.
  • Context.rename feature is used to view the pop-up menu on any object.
  • DirContext.getAttributes feature is used to view the Attribute button and the pop-up menu on any DirContext.
  • DirContext.getSchema feature is used to view the pop-up menu on any DirContext.
  • DirContext.search feature is used to view the View|Search menu item.

The following Novell Provider features are demonstrated:

  • Authentication feature shows Login and Logout support through a pop-up menu on any context with a Session.
  • File feature shows file view/edit support through a pop-up menu on any object supporting DataAccessable (files).
  • Server feature shows server information and NLM load and unload through a pop-up menu on a server object.

Setting up the Server for the Web Administrator

  1. Install NetWare 5.
  2. Install the latest NetWare 5 Support Pack.
  3. Install the Novonyx Fasttrack Server for NetWare.
  4. Create a directory under SYS:Novonyx\suitespot\docs for your applet.

    Map a network drive to this directory as follows:

       map i:=\\myserver\sys\novonyx\sujitespot\docs
       

    Following this drive mapping create an applet directory as follows:

       i:
       
       md njcl
       
  5. Copy the jar files, class files, and HTML files to the applet directory just created.
       map i:=\\myserver\sys\novonyx\sujitespot\docs\njcl
       
       copy c:\novell\java\lib i:
       
       copy demo.jar i:
       
       copy plugins.jar i:
       

Setting up the Applet's HTML File for the Web Administrator

  1. Create the applet's HTML file (possibly with a text editor), specifying the applet and the archives. Then specify the following parameters (no file I/O and no System property access is allowed):
    • Initial context factory
    • Provider URL
    • Security information
    • Other parameters as needed

    Following is an example applet HTML file.

       <HTML> 
       <HEAD< 
       <TITLE>NJCL Applet - (C) Copyright Novell, Inc.</TITLE> 
       </HEAD> 
       <BODY> 
       <APPLET CODE="NJCLApplet.class" ARCHIVE="demo.jar,plugins.jar,njcl.jar,jndi.jar,swing.jar,jgl3.1.0.jar" WIDTH=600 HEIGHT=500> 
       PARAM name="java.naming.factory.initial" value="com.novell.service.ldap.LdapCtxFactory"> 
       <PARAM name="java.naming.provider.url" value="ldap://123.123.123.256/"> 
       >PARAM name="java.naming.security.authentication" value="simple"> 
       <PARAM name="plugins" value="AuthPopupHandler;DataPopupHandler; ServerPopupHandler;"> 
       </APPLET> 
       </BODY> 
       </HTML>
       
  2. Install and run the Java Plug-in HTML converter.

    This converter is installed somewhere in your Start menu. Do not change the generated HTML because there are too many oddities in it. You should change the source HTML and run the converter again.

  3. Copy the converted HTML file to the Web server as follows:
       map i:=\\myserver\sys\novonyx\suitespot\docs\njcl
       
       copy ldap.html i:
       

Setting Up the Client for the Application User

  1. Install and load the Netscape Communicator (tested with version 4.5)
  2. Load the HTML file you created for the applet
       http://123.123.123.256/njcl/ldap.html
       

    If the Java plug-in is not available, the browser will take you to the proper page where the plug-in can be downloaded. After installing the plug-in, reload the Web page. Note: the NJCLApplet has been tested with JRE 1.1.7b and JRE 1.2 plug-ins.

Troubleshooting

If you do not see the applet and you get the message "Applet not Initialized", use the Java plug-in console window to view why the applet may be failing to load. Load the Java plug-in control panel from the start menu and set the Show Java Console option to ON (in the Basic panel).

If you need to debug or report an error, turn off the JIT (in the Advanced panel) so you can see/report the code line numbers. The JRE 1.2 does a better job of reporting errors; however, you can force the applet to load with the JRE 1.2 by selecting it in the Advanced panel. When you run an applet, the Java console shows which JRE version is being used.

If you do not see new applet features, or a bug that has been fixed still causes a failure on your machine, the local JAR files may need to be updated or removed. The browser and Java plug-ins use the classpath set in the client. If NJCL has been installed, the classpath usually points to some local copy of the JAR files. These will be used before the network is used, thus changes made to the Web site will be unavailable until the local JAR files are updated or removed. Also, keep in mind that the local JAR files cannot be updated while they are open (applet is running).

If you've updated the HTML file but the changes don't seem to take effect, make the changes in the original file and run the HTML again. We recommend that you not make changes to the converted applet HTML file because it is difficult to make the changes correctly. Instead, change the original file and rerun the HTML. Also, if the backup file exists, the HTML converter will not convert the file and does not report an error. Be sure to delete the backup before running the HTML converter, or specify another backup path.

3.4.3 NJCLApplet Source Code

These samples demonstrate how to create the functionality of an NJCL applet, which shows some of the capability of JNDI and NJCL.