Novell is now a part of Micro Focus

Understanding and Using Novell's Universal Component System

Articles and Tips: article

SHELDON BAGLEY
Software Engineer
Java Technologies Group

01 Apr 1999


Novell's UCS is a cross language, cross platform, late bound, local or remote bridging solution targeted at RAD tools and languages. This article describes how UCS solves the problems associated with using software objects/components written in different languages or by different vendors.

Introduction

One of the biggest benefits of Object Oriented programming and Component Model programming is that it reduces complexity. Equally as important is that the OOP/Component model saves a great deal of resources by allowing programmers and companies to share and reuse software components. However, reusing and sharing software components often becomes a complex and difficult task if software components are not written in the same (or compatible) programming or scripting language. More often than not, component technologies from different vendors are incompatible making software reuse and the sharing of software components very difficult.

Novell's Universal Component System (UCS) solves the problems associated with using software objects/components written in different languages or by different vendors. UCS is a cross language, cross platform, late bound, local or remote bridging solution targeted at Rapid Application Development (RAD) tools and languages. UCS allows the user or developer to write scripts or programs in a high level language or scripting language such as Visual Basic, Perl, NetBasic, Java, or C++ and access components and services on a NetWare, NT, or Windows 95/98 system. For example, with UCS a Perl or VB script can access an OLE Component on a Windows machine or an NLM/UCX on a NetWare machine.

Figure 1: UCS exposes NetWare services to programmers.

As depicted in Figure 1, UCS exposes NetWare services to high level programmers, scripting programmers, and programmers who are developing on a different platform (such as NT and in languages such as Perl, Visual Basic, Java or Java Script). This mid-tier NetWare solution allows Internet and intranet solution providers to easily utilize NetWare services.

Figure 2: Diagram of the UCS architecture.

Figure 2 provides a more detailed diagram of the UCS architecture. The Extension and Provider pieces in figure 2 are all included in the UCS install program. See the UCS documentation for a more complete explanation of the UCS architecture.

Getting Started with UCS

In this section we will take you step-by-step through the process of writing a first program that accesses software components via the UCS API. We will start with a trivial program that will get your feet wet using UCS.

Installing UCS

Go to Novell's DeveloperNet site at http://developer.novell.com/ndk/download.htm and download Novell Script for NetWare, Perl 5 for NetWare, or Novell NetBasic 6 (running any of these install programs will also install UCS). You may also install these components off the NDK CD. For our "getting started" sample, do a local install to your workstation. The install will set your "path" and "java classpath" unless you specify not to make these changes during the install.

Note: With a default install, directories and Path\Classpath settings are added: c:\Novell\ucs\bin contains UCS dlls needed to access UCS (added to system path). c:\Novell\Java\lib contains UCS Java classes ucs.jar (added to Java classpath).

Writing a Test Program

Java to Java

We start by writing a simple test program that creates a Java hash table and places a couple of items in the hash table without using UCS. First, we create a Java hash table directly through Java and place a boolean with a string "KeyBooloean" as the key. We also place an integer with a string "KeyInteger" as the key. We then stringify and print the hash table.

Next we add the code to create and make method calls to a second Java hash table via UCS. Here is a listing of the complete Java program. An explanation of the UCS portions of the code follows:

import java.util.Hashtable;

import com.novell.utility.ucs.*;



public class TestHash

{

  public static void main(String argv[])

  {

    try

    {

      Hashtable directJavaHash = new Hashtable();



      // Insert elements via the put method with TypeName as the key

      directJavaHash.put("KeyBoolean", new Boolean(true));

      directJavaHash.put("KeyInteger", new Integer(27));



      // Stringify the HashTable and print it out 

      String directJavaHashStr = directJavaHash.toString();

      System.out.println("\nValue of Hastable via Java directly");

      System.out.println(directHashStr);





      // - - - - - - - -  Now do the same thing using UCS - - -

      - - - - -



      UCSClassFactory classFactory = new UCSClassFactory();

      UCSClass cls = classFactory.getInstance("java.util.Hashtable");

      UCSObject obj = cls.createObject();

      UCSVariable args[] = new UCSVariable[2];



      // Insert elements via put method with TypeName as the key 

      args[0] = new UCSVariable("KeyBoolean");

      args[1] = new UCSVariable(true);

      obj.callMethod("put", args);

      args[0] = new UCSVariable("KeyInteger");

      args[1] = new UCSVariable((int)27);

      obj.callMethod("put", args);

      System.out.println("\nValue of Hashtable via UCS");

      System.out.println(Obj.callMethod("toString"));

    }

  }

}

As mentioned earlier, UCS employs "late binding" which requires a class factory in Java. Once the UCS class factory is created, you can make a "getInstance" method call to the class factory passing in the desired class name as a string. The class name (java.util.Hashtable in this example) could have been passed in as a command line argument, resolved according to your program logic at runtime, or even hard coded as in this example. The result of the "getInstance" call is a UCSClass. With the UCS class you can make static method calls, get properties, get methods, or create an instance of the class as we do in this example. We use the "createObject" method call to create a UCSObject.

With a UCS Object ("obj" in our example) we can now make method calls to the object. All arguments are passed as UCS Variables in Java and C++. In our example, the "put" method requires two arguments so we will create an array of two UCSVariables. Next we put the string "KeyBoolean" into entry zero of the array with the following line of code. Notice that the contructors for UCSVariable allow us to pass in primitive types.

args[0] = new UCSVariable("KeyBoolean");

Next we put the boolean (true) into entry one of the UCS Variable array with the following line of code.

args[1] = new UCSVariable(true);

Now we are ready to make the "put" method call via the UCS Object "callMethod" method. The method name to call is passed in as a string ("put" in this example). The UCS variable (or variable array) is passed in as the second argument. These are the arguments that will be passed to the component being called"a string ("KeyBooloean") and a boolean (true) in this example.

Obj.callMethod("put", args);

Next we put an integer (27) in the hash table with a string key of "KeyInteger" with the following lines of code.

args[0] = new UCSVariable("KeyInteger");

   args[1] = new UCSVariable((int)27);

    Obj.callMethod("put", args);

Next we stringify and print the UCS Object for comparison against the hash table we created with Java directly. This is a very simple Java to Java test program that doesn't accomplish anything we couldn't do without UCS. However, now that we have written our first UCS program, we can simply change the name of the component to begin accessing and making method calls to UCX components, ActiveX components or Java Beans.

C++ to Java

We can also call this same component with C++, Perl, Visual Basic, Java Script or Novell Script for Netware (NSN). Here is a snippet of code to create and access a Java hash table from C++. We place a string "KeyInteger" as the hash table key in entry 0 and an integer as the value in entry 1 then make the put call with the number of arguments (2) and the UCSVariable array (args). Next get the value out of the hash table using "KeyInteger" as the key and print the return value.

try

  {

    UCSClass cls("java.util.Hashtable");

    UCSObject obj = cls.createObject();



    UCSVariable args[2];

    UCSVariable returnValue;



    args[0] = "KeyInteger";

    args[1] = (UCSInteger) 27;

    obj.callMethod("put", 2, args);

    returnValue = obj.callMethod("get", 1, args);



    printf("returnValue = %d\n",UCSInteger(returnValue));

  }

Visual Basic to Java

This next snippet of code creates a Java hash table with Visual Basic via UCS. We create and place three items (a boolean, a integer, and a string) in the hash table using integers as keys. Next we get and print the values from the hash table.

Dim jHash As Object



    Set jHash = CreateObject("java.util.Hashtable");

    jHash.put 1, True

    jHash.put 2, 27

    jHash.put 3, "This is a string"

    For i = 1 to 9

      RetVal = jHash.get(i)

      Print "key =" & i; "value=" & i;
    Next

Accessing the UCS Remote Bridge

Programming to the UCS Remote Bridge is a very simple task as a programmer. To access a component on another machine you simply place an @ sign with the machine name (or IP address) after the name of the component you wish to access. The syntax looks like this: componentName@machineName. In our examples above, the only line of code that changes is the create line that names the component.

Java to Java Hash Table example:

UCSClass cls = classFactory.getInstance("java.util.Hashtable@sbagleyNT");

C++ to Java Hash Table example:

UCSClass cls("java.util.Hashtable@137.85.121.55");

Visual Basic to Java Hash Table example:

Set jHash = CreateObject("java.util.Hashtable@sbagleyNT");

Note: In any of these examples the machine name or the IP address can be used to resolve the machine where the component resides.

The UCS Remote Bridge operates as an extension to your Web server. On the client side UCS sends XML/HTTP requests on port 80. On the server side UCS extends the Web server to intercept the UCS requests which are then handed off to UCS. Responses come back through the Web server and are processed by the UCS client side code. On NetWare, UCS Remote tunnels through the FastTrack Web server using NSAPI extensions. On NT, UCS Remote tunnels through Microsoft's Internet Information Server (IIS) using ISAPI filters and extensions. Apache Web server on NT can be supported as soon as ISAPI filter support on NT is finished for the Apache Web Server.

For a detailed explanation of how to install the UCS NSAPI and ISAPI filters and extensions on your Web server, see the UCS documentation and readme files.

* 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