A.4 Samples

This section provides some samples to show how various scripting languages use UCS as a conversion layer for accessing other components on the network.

A.4.1 Hash table usage

NSN accesses Java class using UCS

This sample creates a hash table using CreateObject function, adds data to the table and retrieves the same data.

’ Create hash table
Set Hash = CreateObject("java.util.Hashtable")

’ Put one value into hash table
Hash.Put (1, TRUE)

’ Retrieve and print the same value
Print Hash.Get(1)

Perl accesses Java class using UCS

NOTE:The extension for accessing UCS from Perl is given as Perl2UCS in the following sample. This should be changed to UCSExt, if the version of Perl is 5.003.

This sample creates a hash table using Perl2UCS, adds data to the table and retrieves the same data.

use Perl2UCS;

# Create hash table
$hash = Perl2UCS->new("java.util.Hashtable");

# Put one value into hash table
$hash->put (1, TRUE);

# Retrieve and print the same value
print $hash->get(1) . "\n";

ScriptEase accesses Java class using UCS

This sample creates a hash table using SE2UCS, adds data to the table and retrieves the same data.

#link "se2ucs"

// Create hash table
var hash = CreateObject("java.util.Hashtable");

// Put one value into hash table
hash.put (1, TRUE);

// Retrieve and print the same value
Clib.printf (hash.get(1) + "\n");

A.4.2 NDS Login

Perl accesses UCX component using UCS

NOTE:The extension for accessing UCS from Perl is given as Perl2UCS in the following sample. This should be changed to UCSExt, if the version of Perl is 5.003.

This sample creates an NWDIR UCX component using Perl2UCS. It logs into a tree with an authorized user’s credentials and displays the short name of the context.

use Perl2UCS;

# Create NWDir UCX object
$nds = Perl2UCS->new("UCX:NWDir");

# Set tree and context to login
$nds->{"FullName"} = "nds:\\tree\\context";

# Enter the NDS login name and password
$nds->login ("username", "password");

# Print short name of current context
print "Short Name : " . $nds->{"ShortName"} . "\n";

# Logout of NDS tree
$nds->logout ();

ScriptEase accesses UCX component using UCS

This sample creates an NWDIR UCX component using SE2UCS. It logs into a tree with an authorized user’s credentials and displays the short name of the context.

#link "se2ucs"

// Create NWDir UCX object
var nds = CreateObject("UCX:NWDir");

// Set tree and context to login
nds.fullName = "nds:\\\\Tree\\Context";
nds.login ("Username", "Password");

// Print short name of current context
Clib.printf ("Short Name : %s\n",nds.shortName);

// Logout of NDS tree
nds.logout ();

NOTE:UCSJS is now renamed as SE2UCS. Hence, all old scripts should be modified in the link library usage line (#link) to work properly.

A.4.3 Browse NDS under specified context

This sample creates an instance of the registered NWDir ActiveX Control on the Windows server host_IP_address, on which the HTTP listener is running. By default, the HTTP Listener runs on port 80. If you are running it on a different port, specify that port number in the script.

The sample sets the full name to the context where the ADMIN resides on the NDS tree and gets the collection of entries from that context. The user should be authenticated to that tree from the Windows system

NSN accesses ActiveX Control using UCS

’ Create an instance of the NWDIR control with ProgID
’ NWDirLib.NWDirCtrl.1 on the Windows server identified by
’ the host_IP_address on which HTTP listener is running.
’ ProgID is the unique way for identifying the COM object.

Set DirCtrl = CreateObject ("OLE:NWDirLib.NWDirCtrl.1@host_IP_address;port")
’ Set the fullname of the instance to the context where
’ ADMIN resides in the NDS tree
DirCtrl.FullName = "NDS:\\tree\context"
’ Get the entries collection under the specified context
Set Entries = DirCtrl.Entries
Count = Entries.Count

’ List all the objects under the specified context
For I = 0 To (Count - 1)
    Set Entry = Entries.Item(I)
    Print (Entry.ShortName)
Next

Perl accesses ActiveX Control using UCS

NOTE:The extension for accessing UCS from Perl is given as Perl2UCS in the following sample. This should be changed to UCSExt, if the version of Perl is 5.003.

use Perl2UCS;

$dirCtrl = Perl2UCS->new("OLE:NWDirLib.NWDirCtrl.1\@host_IP_address;port");

# Set the fullname of the instance to the context where ADMIN
# resides in the NDS tree
$dirCtrl->{"fullname"} = "NDS:\\\\tree\\context";

# Get the Entries collection under the specified context
$entries = $dirCtrl->{"entries"};
$count = $entries->{"count"};

# List all the objects under the specified context
for ($i = 0; $i < $count; $i++)
{
    $entry = $entries->item($i);
    $shortName = $entry->{"shortname"};
    print ($shortName . "\n");
}

ScriptEase accesses ActiveX Control using UCS

// Create an instance of the NWDIR control with ProgID
// NWDirLib.NWDirCtrl.1 on the Windows server identified by
// the host_IP_address on which HTTP listener is running.
// ProgID is the unique way for identifying the COM object.

# link "se2ucs"

var dirCtrl = CreateObject("OLE:NWDirLib.NWDirCtrl.1@host_IP_address;port");

// Set the fullname of the instance to the context where
// ADMIN resides in the NDS tree.
dirCtrl.Fullname = "NDS:\\\\tree\\context";

// Get the entries collection under the specified context.
var entries = DirCtrl.Entries;
var count = entries.Count;

// List all the objects under the specified context
for (var i = 0; i < count; i++)
{
  var Entry = entries.Item(i);
  var shortname = Entry.Shortname;
  Clib.printf("\n%s", shortname);
}

See Also

For more information on NSN components, refer to NSN Documentation