Novell is now a part of Micro Focus

Configuring JavaBeans for Novell Services

Articles and Tips: article

BRUCE STANFORD
Senior Research Engineer
Developer Information

01 Jun 1999


Novell has developed Beans for Novell Services (BNS) that help build robust applications and easily access NDS. BNS creates a tool that rapid application programmers can use to quickly access NDS. JavaBeans provide methods that have abstracted many complex NDS concepts and help you quickly write a program.

Introduction

Novell has developed Beans for Novell Services (BNS) that help you build robust applications and easily access NDS. BNS creates a tool that Rapid Application Development (RAD) programmers can use to quickly access NDS. JavaBeans provide methods that have abstracted many complex NDS concepts and help you quickly write a program. The BNS JAR files are written to the JNDI methods. If you need some specific JNDI methods to complete a program, you can simply create a class file using the JNDI code. You have complete control over how complex a program needs to be to complete any task. This lesson will appear on the DeveloperNet University Web page at http://developer.novell.com/education/.

This lesson explains how to configure Beans for Novell Services and tells you how to:

  • Download the required programs.

  • Install the required programs.

  • Verify the JVM, JNDI, and BNS installations.

Once you complete these installations, you can use the following utilities to verify that NDS is working properly:

  • WhoAmI shows you what parameters NWSess requires to show you the short name.

  • FieldDesc shows you all of the fields in a designated tree.

  • SyntaxID adds every available field type to the schema you select.

The sample code in this lesson gives you a working BNS client and some utilities that will help you develop simple, robust applications that can access NDS.

Types of Novell Java Beans

Currently Novell supports six groups of JavaBeans. The Directory Bean allows access to and modification of the entries in an NDS tree. The Session Bean manages the log in and log out of a profile. The Bindery Bean manages access to NetWare 3.x servers or any bindery access. The Volume Admin Bean accesses information about files on a volume. The Print Queue Bean accesses NetWare print queues and jobs in a queue. The Queue Services Beans manage the various queues on NetWare servers.

Limitations

The BNS that are now available have the following limitations. The BNS objects require NetWare client32 version 3.x or above in order to access NDS. This means that the BNS is not portable. BNS must run on a client that supports the NetWare client. Therefore, BNS are not able to run in an applet. Since JNDI has developed the ability to access LDAP in an applet, the BNS should soon have the ability to access NDS with LDAP also. Accessing NDS with client32 still has many advantages over other languages.

Requirements

An account on DeveloperNet with Personal Identification Number (PIN) and password is required.

The basic system requirements have been tested so that you may quickly get the BNS working on your system. We used Windows98 with client version 3.1.99.210 installed from the NetWare 5.0 release. You can get your client information by placing your mouse arrow over the red N on your Windows98 screen and pressing the right mouse button. Then select Novell Client32 properties.

The server must have a connection to the client used for development. NetWare 5.x is the recommended operating system. NDS must be installed. This servers tree and schema will be modified and possibly damaged. A test server should therefore be used for schema extensions. This lesson will only read the data of an existing NDS tree and add field types.

Using any program that has NDS code should always be tested on a test server and not moved to a production server until all bugs have been removed. Novell assumes no liability, either express or implied, for damage done to any server as a result of any publication or lesson.

The client must have at least 64 megabytes of memory with Internet access. The MS-DOS command line interface will be used for all Java training. The command line will be used to compile and execute the examples. The MS-DOS window will only be used for educational purposes. Once you understand how easy BNS methods are, you will quickly be able to understand how to integrate the methods into a graphical program. An MS-DOS prompt with at least 4096K of memory is recommended. To change the memory just select the properties button on the MS-DOS window. Select the Memory tab and change Initial environment to 4096K memory.

ConsoleOne

The latest version of ConsoleOne has many useful features. One of these features is the ability to view class objects that have no associated SnapIn. You can also modify the User class to view the required output. ConsoleOne is Java based and many useful classes are available for general use.

Downloading Beans for Novell Services

Objective: To download all the required software for installing Beans for Novell Services.

  1. Login to DeveloperNet at http://developer.novell.com/ndk/download.htm

  2. Download software Beans for Novell Services.

  3. Download software Novell Class Libraries for Java (Novell Providers for JNDI).

  4. Change the URL to http://developer.novell.com/education/library.html

  5. Download software Configuring JavaBeans for Novell Services.

  6. Change URL tohttp://www.javasoft.com/products/jdk/1.1

  7. Download JDK 1.1 Win32 Release.

These steps bring all of the required install programs to your local machine. The Beans for Novell Services (BNS) and Java Naming and Directory Interface (JNDI) are both distributed by Novell and provide all the methods that are needed to develop a robust NDS application. The JDK by JavaSoft creates the Java operating system on your machine. BNS makes a method call into JNDI, which makes method calls into Novell Java Class Libraries (NJCL). All of these use the JDK distributed by JavaSoft.

Installation Instructions

Objective: To install the required software using the executables downloaded.

This section shows how to install the Beans for Novell Services that you will need to use for all of the DeveloperNet Java courses and verify that the environment is in good working condition. When complete, you will be able to build a Java program, use Novell Java Class Libraries (NJCL) with Java Naming and Directory Interface (JNDI) beans, and use an NDS bean.

Beans are stored in a Java Archive (JAR) format. JAR files are Zip-formatted archive files with an optional component called a manifest file that can contain additional information about the contents of the JAR file.

  1. Install JDK version 1.1 from the downloaded file. For example, JDK1_1_8-win.exe

  2. Install NJCL.EXE

  3. Install BNS.EXE

  4. Install BNSCNFG.EXE

When all the installation steps are complete, view your AUTOEXEC.BAT file and look for changes to your PATH and CLASSPATH environment variables. The PATH is where the system will access the Java Virtual Machine (JVM). When you type javac on the command line, JAVAC.EXE will read the .java file and create a .class file. When you type java on the command line, JAVA.EXE will parse the .class file and the program will execute. Your AUTOEXEC.BAT file must contain the following .JAR files to be able to access NDS methods. You should notice that JNDI.JAR and NJCL.JAR are present. These two files are where the NDS methods actual execution occurs. Novell Java Class Libraries (NJCL) are specific to Client32 and have native code to access the desired NDS methods. Java Naming and Directory Interface (JNDI) is a standard extension to the Java platform, providing a unified interface to multiple naming and directory services in the enterprise. The JNDI that is available from Novell contains all the methods needed to access NDS. The CLASSES.ZIP file contains the JVM method that are used in the import statement.

Verify that the CLASSPATH in your AUTOEXEC.BAT file includes the following:

SET CLASSPATH=%CLASSPATH%;

C:\Novell\Java\beans\NWSess.jar;

C:\Novell\Java\beans\NWDir.jar;

C:\Novell\Java\beans\NWPrtQAdm.jar;

C:\Novell\Java\beans\NWSockets.jar;

C:\Novell\Java\beans\NWVolAdm.jar;

C:\Novell\Java\beans\NWBind.jar;

C:\NOVELL\JAVA\lib\jndi.jar;

C:\NOVELL\JAVA\lib\njcl.jar;

C:\JDK1.1.**\LIB\CLASSES.ZIP;

You must replace the ** with the JDK version that was downloaded. This will require you to analyze your system specific tree structure. For example, C:\JDK1.1.8\LIB\CLASSES.ZIP would be added to your CLASSPATH variable if you had installed JDK1.1.8 successfully. You must have only one JDK version in your PATH and your CLASSPATH. The way that the JDK install is confirmed is by typing the JAVA.EXE command from a new MS-DOS prompt and the executable is found. When the configuration is verified, this test will be performed.

Verify that the PATH in your AUTOEXEC.BAT file includes the following

SET PATH=%PATH%;C:\JDK1.1.**\BIN;

Restart your computer. (You will always need to restart your computer whenever you modify these environment variables.)

Installation Testing

Objective: To verify that the installation of Beans for Novell Services is working on your client.

  1. Execute the batch file CheckUP.BAT from an MS-DOS prompt.

  2. Make sure you get passed messages for the following:

    • CheckUpJVM.

    • CheckUpJNDI.

    • CheckUpBNS.

    • CheckUpSess.

The batch file CheckUP.BAT contains the following code.

javac CheckUpJVM.java

java -version CheckUpJVM

java  CheckUpJVM

pause

javac CheckUpJNDI.java

java  CheckUpJNDI

pause

javac CheckUpBNS.java

java  CheckUpBNS

pause

javac CheckUpSess.java

java  CheckUpSess

Each .java file is compiled to verify that the Java Virtual Machine is installed correctly. Next we execute that .class file using the java executable and repeat this process for JNDI, BNS and the Sess files.

The command java -version CheckUpJVM checks the JVM version that has been installed. This is a critical step. BNS was created and tested with JVM version 1.1.8 from JavaSoft. Any JVM Version 1.1 should work with the Beans for Novell Services.

CheckUpJVM.java



public class CheckUpJVM

{

 public static void main(String[] args)

 {

    System.out.println("CheckUpJVM  PASSED");

 }

}

The file CheckUpJVM.java contains a simple program that verifies that the JVM download installed correctly. The output should be:

CheckUpJVM PASSED

The next line in CheckUP.BAT is designed to verify that Novells JNDI JAR files installed correctly.

The batch file executes the command:

java  CheckUpJNDI



import com.novell.service.session.SessionEnv;

import com.novell.service.session.SessionManager;

import com.novell.service.session.SessionManagerFactory;

import com.novell.service.session.Session;

import com.novell.service.session.SessionException;

import com.novell.service.session.SessionAttr;

import com.novell.service.session.SessionAttrs;

import com.novell.service.session.SessionEnumerator;

import com.novell.service.session.Authenticatable;



/**

* Create a session and search for all current sessions

  */

public class CheckUpJNDI

{                       

   /**

    * Used for testing this class.

    */

   public static void main(String args[])

   {

      try

      {

         // Initialize factories

         SessionEnv env = new SessionEnv();



// Define initial sessions and load order

         env.put(SessionEnv.INITIAL_SESSION_FACTORY,

            "com.novell.service.session.nds.NDSInitialSessionFactory:" +

            "com.novell.service.session.bindery.BinderyInitialSessionFactory");



         // Get the session manager

SessionManager sm = SessionManagerFactory.getSessionManager(env);

         System.out.println("Listing Trees:  ");

         doListing(sm, "NDS", "TREE");

         

         System.out.println("Listing NDS Connected Servers:  ");

         doListing(sm, "NDS", "SERVER");

         

         System.out.println("Listing Bindery Connected Servers:  ");

         doListing(sm, "BINDERY", "SERVER");

      }

      catch (Exception e)

      {

         System.out.println(e);

      }

      System.out.println("* denotes Authenticated Connection");

      System.out.println("CheckUpJNDI Passed ");



}

   

   static void doListing

   (

     Session sm,

     String provider,

     String session_type

   )

   throws SessionException

   {



// Look for existing sessions

      SessionAttr a1 = new SessionAttr(Session.PROVIDER_NAME_ATTR_ID, provider);

      SessionAttr a2 = new SessionAttr(Session.SESSION_TYPE_ATTR_ID, session_type);

      

      SessionAttrs as = new SessionAttrs();

      as.add(a1);

      as.add(a2);

      SessionEnumerator enum = sm.search(as);

      while (enum.hasMoreElements())

      {  

         Session found = enum.next();

         

         if (found.isAuthenticated())

            System.out.print(" * ");

         else

            System.out.print("  ");

                

         System.out.println(found.getDomainName());

      }

      System.out.println();

   }





  }





The CheckUpJNDI output should look something like this:



Listing Trees:  

 * TREE_INC



Listing NDS Connected Servers:  

 * SERVER1

 * SERVER2

 * SERVER3

 * SERVER4

 * SERVER5

 * SERVER6



Listing Bindery Connected Servers:  



* denotes Authenticated Connection

CheckUpJNDI Passed

The program, CheckUpJNDI.java, has several imports that come from the JAR files C:\NOVELL\JAVA\lib\jndi.jar and C:\NOVELL\JAVA\lib\njcl.jar located in the clients CLASSPATH. If these import packages are not found then various errors will occur when javac tries to parse the CheckUpJNDI.java file.

The next line in CheckUP.bat is designed to verify that Novell's BNS JAR file C:\Novell\Java\beans\NWDir.jar installed correctly.

The batch file executes the command:

java  CheckUpBNS

import java.util.*;

import com.novell.beans.NWDir.*;

import com.novell.beans.util.*;



public class CheckUpBNS

{



 public static void main(String[] args)

 {

        NWDir BD = new NWDir();



        Enumeration tList=BD.getTrees();

        while(tList.hasMoreElements())

        {

          String name = (String)tList.nextElement();

          if(name != null)

          {

           System.out.println("Tree:"+name);

          }

        }

    System.out.println("CheckUpBNS  PASSED");

 }



}



The CheckUpBNS output should look something like this:



Tree: moneytree

CheckUpBNS  PASSED

Notice that the amount of code for the BNS methods are easier to understand and requires fewer lines of code. Again, the import lines will generate errors if JAVAC.EXE cannot locate the methods in the CLASSPATH environment variables.

The next line in CheckUP.BAT is designed to verify that Novell's BNS JAR file C:\Novell\Java\beans\NWSess.jar installed correctly.

The batch file executes the command:

java  CheckUpSess

import java.util.*;

import com.novell.beans.NWDir.*;

import com.novell.beans.util.NWBeanException;

import com.novell.beans.NWSess.*;

import com.novell.beans.NWBind.*;





public class CheckUpSess

{

 public static void main(String[] args)

 {

    NWSess sessionBean = new NWSess();

    NWNetworkNames serverNames;

    NWNetworkName serverName;

    serverNames = sessionBean.getServerNames();

    while(serverNames.hasMoreElements())

    {

      serverName = serverNames.next();



      System.out.println(serverName.getShortName() + " ");



    }

    System.out.println("CheckUpSess  PASSED");

 }

        

}



The CheckUpSess output should look something like this:

                    

TRUTH 

CheckUpSess  PASSED

Where TRUTH is the server name that is authenticated.

These set of programs have verified the status of the installed software. You should be able to complete the remainder of this lesson with confidence that you are not having configuration problems.

Important terms are defined below:


NWDir

The main class that implements the Directory Bean

NWEntry

Represents an entry in a directory

NWEntries

A collection of entry objects: implements the NWCollection interface

NWValue

The base class of all value class

NWLayoutDescription

Describes an individual layout type

NWLayoutDescriptions

A collection of NWLayoutDescription objects: implements the NWCollection interface

NWFieldDescription

Describes a field in a layout

NWFieldDescriptions

A collection of NWFieldDescription objects; implements the NWCollection interface

NWFieldType

Describes an individual field type

NWFieldTypes

A collection of NWFieldType objects; implements the NWCollection interface

NWSyntax

Describes an individual syntax

NWSyntaxes

A collection of NWSyntax objects; implements the NWCollection interface

Figures 1 and 2 show the relationship of the NWDir methods.

Figure 1: NWDir Bean Class Diagram.

Figure 2: Session Bean Class Diagram.

You should understand several utilities so that you can determine if a program has generated the correct output. The need to determine who you are logged in as becomes important when you need enough rights to modify data and schema attributes. The program WhoAmI.java will determine who is logged into NDS.

import com.novell.beans.NWSess.*;

import com.novell.beans.util.*;

import java.util.*;



//  NDS:\\tree

public class WhoAmI

{

  public static void main(String args[])

  {

   NWSess sB = new NWSess();

   try

   {

     NWNetworkName nN =  sB.getLoginName(args[0]);

     String sName = nN.getShortName();

     System.out.println(args[0]+" You are : "+sName);

   }

   catch (NWNetworkException e)

   {

     System.out.println(e.getMessage());

   }



  }



}

This program uses the Session Bean to gather user information. The import uses the method found in the C:\Novell\Java\beans\NWSess.JAR file found in you AUTOEXEC.BAT CLASSPATH environment variable.The "import com.novell.beans.util.*" is used for NWBeanException errors. This exception must be caught. The required arguments for this program to run are NDS:\\ with the tree name. To run this program type the following on the MS-DOS command line in the location of the WhoAmI.CLASS file. You must supply your tree name after the NDS:\\ command-line parameter.

Execute the program WhoAmI:

java WhoAmI NDS:\\TREE

The output should look something like this:

NDS:\\TREE You are : admin

The next utility that you might find useful is FieldDesc. This is an intermediate program that will look through the supplied NDS tree. The command-line parameter of NDS:\\TREE\\CONTEXT will return all the files (Layouts) and field descriptions. The TREE name must be the tree where you are logged into, and CONTEXT must be your current context. CONTEXT is found by typing the CX command in the MS-DOS prompt window. This program is useful when you want to access a field variable and do not know how the name is spelled.

import com.novell.beans.NWDir.*;

import com.novell.beans.util.*;

import java.util.*;

// NDS:\\money\\novell\\        input parameters 

public class FieldDesc

{

  public static void main(String args[])

  {



   NWDir dB = new NWDir();

   NWLayoutDescriptions layouts;

   NWLayoutDescription layout;



   try

   {

        System.out.println(args[0]+" ");

        dB.setFullName(args[0]);

        layouts = dB.getLayouts();

        while(layouts.hasMoreElements())

        {

         layout=layouts.next();

         NWFieldDescriptions fields = layout.getFields();

         NWFieldDescription  fDesc;

         NWFieldType         fType;

         while(fields.hasMoreElements())

         {

          fDesc=fields.next();

          fType=fDesc.getFieldType();

          System.out.println("Layout Name: "+layout.getName()+" Field Name"+fDesc.getName()+" Type Name "+fType.getSyntaxID());

         }

        }

   }

   catch(NWBeanException e)

   {

     System.out.println(e.getMessage());

   }



  }

}

The following section explains how FieldDesc.java operates. Examine the lines of code as they are explained. The "import com.novell.beans.util.*" is used for NWBeanException errors. This exception must be caught. The import com.novell.beans.NWDir.* contains the methods for accessing the Directory.

import com.novell.beans.NWDir.*;

import com.novell.beans.util.*;

Next, the dB variable is instantiated, and the FullName value is shown, along with the context supplied from the command-line arguments with the NWDir constructor.

System.out.println(args[0]+" ");

dB.setFullName(args[0]);

Next, we populate the NWLayoutDescriptions variable layouts with the getLayouts() method. The layouts variable now has a list of NWLayoutDescription objects. The hasMoreElements() method is best used in a while statement.

layouts = dB.getLayouts();

while(layouts.hasMoreElements())

We then extract a NWLayoutDescription object with the next() method. Each NWLayoutDescripton has several fields that describe what the layout contains. You can think of this as a struct or a class object. The NWFieldDescription variable fields are populated with the getFields() method, resulting in the NWFieldDescription of NWLayoutDescription. In traditional terms, we now have the fields that are in a record. These fields have types.

layout=layouts.next();

NWFieldDescriptions fields = layout.getFields();

Another while loop which hasMoreElements() extracts the fields datatypes, and the getFieldType() method populated the NWFieldType variables. We populate the NWFieldType variable with the getFieldType() method. We are now ready to show the information gathered from NDS. We want to show the NWLayoutDescription name, the NWFieldDescription name, and the NWFieldType syntax or type. We continue to show each and every field that is in the tree and context specified by the command-line argument.

while(fields.hasMoreElements())

         {

          fDesc=fields.next();

          fType=fDesc.getFieldType();

        System.out.println("Layout Name: "+layout.getName()+" Field Name" +fDesc.getName()+" Type Name "+fType.getSyntaxID());

         }

You need to examine all the output generated by java FieldDesc NDS:\\tree\\context > out by using edit. Type edit from the command line to view this file created by the output. You must supply your tree name and context after the NDS:\\ command-line parameter.

Execute the program FieldDesc:

java FieldDesc NDS:\\TREE\\CONTEXT > out

Your output of the NWLayoutDescription for User should look like the following output.

Layout Name: User Field Name CN Type Name 3

Layout Name: User Field Name Surname Type Name 3

Layout Name: User Field Name Object Class Type Name 20

Layout Name: User Field Name Group Membership Type Name 1

Layout Name: User Field Name Home Directory Type Name 15

Layout Name: User Field Name Login Allowed Time Map Type Name 9

Layout Name: User Field Name Login Disabled Type Name 7

Layout Name: User Field Name Login Expiration Time Type Name 24

Layout Name: User Field Name Login Grace Limit Type Name 8

Layout Name: User Field Name Login Grace Remaining Type Name 22

Layout Name: User Field Name Login Intruder Address Type Name 12

Layout Name: User Field Name Login Intruder Attempts Type Name 22

Layout Name: User Field Name Login Intruder Reset Time Type Name 24

You need to examine all the output generated by java FieldDesc NDS:\\tree\\context > out by using edit. Type edit from the command line to view this file created by the output. Notice that the method fType.getSyntaxID() shows a number. What do you think that this number means? The SyntaxID() code answers this question.

The next utility that you might find useful is SyntaxID.java. This is an advanced program that will teach you about field types. You will require rights to modify the schema. The user "admin" should give you the ability to modify the schema. The command-line parameter of NDS:\\TREE\\CONTEXT will create all the possible field types that NDS currently allows. The TREE name must be the tree where you are logged into, and CONTEXT must be your current context. CONTEXT is found by typing the CX command in the MS-DOS prompt window. This program is useful when you want to access a field variable and do not know the field type that is needed.

SyntaxID.java

import com.novell.beans.NWDir.*;

import com.novell.beans.util.*;

// NDS:\\money\novell\\     command line parameter

public class SyntaxID

{

  public static void main(String args[])

  {



   NWDir dB = new NWDir();

   NWFieldTypes fieldTypes;

   NWFieldType myFieldType;



   try

   {

        System.out.println(args[0]+" ");

        dB.setFullName(args[0]);

        fieldTypes=dB.getFieldTypes();

        while(fieldTypes.hasMoreElements())

        {

          myFieldType=fieldTypes.next();

          System.out.println(" "+myFieldType);



        }

        // create all test types tt...



        myFieldType=dB.createFieldType("ttBack Link",NWSyntax.BACK_LINK_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttBoolean",NWSyntax.BOOLEAN_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttCaseExactString",NWSyntax.CASE_EXACT_STRING_ ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttCaseIgnoreList",NWSyntax.CASE_IGNORE_LIST_ID );

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttCaseIgnoreString",NWSyntax.CASE_IGNORE_STRIN G_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

System.out.println("Success");



myFieldType=dB.createFieldType("ttClassName",NWSyntax.CLASS_NAME_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttCounter",NWSyntax.COUNTER_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttDistinguishedName",NWSyntax.DISTINGUISHED_NA ME_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttEMail",NWSyntax.EMAIL_ADDRESS_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttFAX",NWSyntax.FAX_NUMBER_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttHold",NWSyntax.HOLD_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttInteger",NWSyntax.INTEGER_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttInterval",NWSyntax.INTERVAL_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttNetAddr",NWSyntax.NET_ADDRESS_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttNumString",NWSyntax.NUMERIC_STRING_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttACL",NWSyntax.OBJECT_ACL_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttOctList",NWSyntax.OCTET_LIST_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttOctString",NWSyntax.OCTET_STRING_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttPath",NWSyntax.PATH_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttPostal",NWSyntax.POSTAL_ADDRESS_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttPrintable",NWSyntax.PRINTABLE_STRING_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttReplica",NWSyntax.REPLICA_POINTER_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttStream",NWSyntax.STREAM_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttPhoneNO",NWSyntax.TELEPHONE_NUMBER_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttTime",NWSyntax.TIME_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttTimeStamp",NWSyntax.TIMESTAMP_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttTyped",NWSyntax.TYPED_NAME_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("Success");



        myFieldType=dB.createFieldType("ttUnknown",NWSyntax.UNKNOWN_ID);

        myFieldType.setSingleValued(false);

        fieldTypes.addElement(myFieldType);

        System.out.println("All Created");

        // show all new field types

        while(fieldTypes.hasMoreElements())

        {

          myFieldType=fieldTypes.next();

          System.out.println(" "+myFieldType);



        }



   }

   catch(NWBeanException e)

   {

     System.out.println(e.getMessage());

   }



  }

}

The following section explains how SyntaxID.java operates. Follow along in the source and examine the lines of code as they are explained. The "import com.novell.beans.util.*" is used for NWBeanException errors. This exception must be caught. The "import com.novell.beans.NWDir.*" contains the methods for accessing the Directory.

import com.novell.beans.NWDir.*;

import com.novell.beans.util.*;

Next, the dB variable is instantiatied, and the FullName value is shown, alaong with the context supplied from the command-line arguements with the NWDir constructor.

System.out.println(args[0]+ " ");

dB.setFullName(args[0]);

Next, we populate the NWFieldTypes variable fieldTypes with the getFieldTypes() method. The fieldTypes variable now has a list of NWFieldType objects. The hasMoreElements() method is best used in a while statement.

fieldTypes=dB.getFieldTypes();

while(fieldTypes.hasMoreElements())

We then extract a NWFieldType object with the next() method. You can think of this as a struct or a class object. In traditional terms, we now have the fields that are in a record. These fields have types. We are now ready to show the information gathered from NDS. We want to show the NWFieldType. We continue to show each and every field that is in the tree and context specified by the command line argument.

myFieldType=fieldTypes.next();

System.out.println(" "+myFieldType);

Your output of the NWFieldType for User should look like the following output.

10 EMail Address .....[EMail Addre] false false -1 0 ...0,0]

10 Employee ID .......[Case Ignore] true true -1 0 [6,11,...0,0,0]

10 Entrust:AttributeCe[Octet Strin] false true -1 0 [6,9,...0,0,0,0,0]

You need to examine all the output generated by java SyntaxID NDS:\\tree\\context > out by using edit. Type edit from the command line to view this file created by the output. Notice that the NWFieldType shows a number. This number is equivalent to a Syntax ID. The Syntax IDs are declared as final static data members of the NWSyntax class.

We will now create a field with the NWSyntax.BACK_LINK_ID syntax ID and use the createFieldType() method. The first parameter is the name of the new field we want to create. If this field already exists we will get an error. The second parameter is the syntax ID. The syntax ID is the desired field type. Set the setSingleValued() method to false so that this field only holds one piece of data and also use the addElement() method to update NDS with the new field.

myFieldType=dB.createFieldType("ttBack Link",NWSyntax.BACK_LINK_ID);

myFieldType.setSingleValued(false);

fieldTypes.addElement(myFieldType);

You should examine the following output from FieldDesc to learn which syntaxIDs have which NWFieldType numbers.

Layout Name: Group Field Name ttBack Link Type Name 23

Layout Name: Group Field Name ttBoolean Type Name 7

Layout Name: Group Field Name ttCaseExactString Type Name 2

Layout Name: Group Field Name ttCaseIgnoreList Type Name 6

Layout Name: Group Field Name ttCaseIgnoreString Type Name 3

Layout Name: Group Field Name ttClassName Type Name 20

Layout Name: Group Field Name ttCounter Type Name 22

Layout Name: Group Field Name ttDistinguishedName Type Name 1

Layout Name: Group Field Name ttEMail Type Name 14

Layout Name: Group Field Name ttFAX Type Name 11

Layout Name: Group Field Name ttHold Type Name 26

Layout Name: Group Field Name ttInteger Type Name 8

Layout Name: Group Field Name ttInterval Type Name 27

Layout Name: Group Field Name ttNetAddr Type Name 12

Layout Name: Group Field Name ttNumString Type Name 5

Layout Name: Group Field Name ttACL Type Name 17

Layout Name: Group Field Name ttOctList Type Name 13

Layout Name: Group Field Name ttOctString Type Name 9

Layout Name: Group Field Name ttPath Type Name 15

Layout Name: Group Field Name ttPostal Type Name 18

Layout Name: Group Field Name ttPrintable Type Name 4

Layout Name: Group Field Name ttReplica Type Name 16

Layout Name: Group Field Name ttStream Type Name 21

Layout Name: Group Field Name ttPhoneNO Type Name 10

Layout Name: Group Field Name ttTime Type Name 24

Layout Name: Group Field Name ttTimeStamp Type Name 19

Layout Name: Group Field Name ttTyped Type Name 25

Layout Name: Group Field Name ttUnknown Type Name 0

This output will give you an easy lookup for syntax names in the future. The numbers associated with the name can aid in resolving what field types are displayed from the FieldDesc utility.

Conclusion

This lesson has included considerable detail about configuring Beans for Novell Services. It has shown where to download the required programs and where to install these programs. It then verified that these programs were installed correctly with a batch program. This batch program verified the JVM installation, the JNDI installation, and the BNS installation. Once you completed these installations, you were able to verify that NDS was working properly with several utilities. The first utility was WhoAmI. WhoAmI showed you what parameters that NWSess required to show you the short name. The next utility FieldDesc showed you all of the fields in a given tree. Finally, SyntaxID added every available field type to the schema. You now have a working BNS client and some utilities that will help you in writing programs that will access NDS that are simple and yet robust.

References

The code for this lesson can be found at http://developer.novell.com/education/library.html

Additional sample code can be found at http://developer.novell.com/education/sampdemo.htm

* Originally published in Novell AppNotes


Disclaimer

The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.

© Copyright Micro Focus or one of its affiliates