Oracle8i Enterprise JavaBeans and CORBA Developer's Guide
Release 8.1.5

A64683-01

Library

Product

Contents

Index

Prev  Chap Top Next

Applet Examples

innetscape

hello.idl

module hello {
  interface Hello {
    wstring helloWorld ();
    void setMessage (in wstring message);
  };
};

ClientApplet.htm

<!-- /* Adapted from Visigenic's ClientApplet example */ -->
<h1>Oracle 8i ORB Client Applet</h1>
<hr>
<center>
  <applet codebase="." code="ClientApplet" archive="applet.jar"
          width=200 height=80>
  <param name="serviceURL" value="sess_iiop://dlsun57:2481:javavm5">
  <param name="objectName" value="/test/myHello">
  <param name="user" value="scott">
  <param name="password" value="tiger">

  <h2>You are probably not running a Java enabled browser.
  Please use a Java enabled browser (or enable your browser for Java)
  to view this applet...</h2>

  </applet>
</center>
<hr>

ClientApplet.java

/* Adapted from Visigenic's ClientApplet example */
import hello.Hello;
import hello.HelloHelper;

import netscape.security.PrivilegeManager;

import oracle.aurora.jndi.sess_iiop.ServiceCtx;
import oracle.aurora.jndi.sess_iiop.SessionCtx;
import oracle.aurora.client.Login;
import oracle.aurora.AuroraServices.PublishedObject;
import oracle.aurora.AuroraServices.PublishedObjectHelper;
import oracle.aurora.AuroraServices.LoginServer;
import oracle.aurora.AuroraServices.LoginServerHelper;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;
import java.awt.*;

public class ClientApplet extends java.applet.Applet
{
  private TextField _messageField;
  private TextField _outputField;
  private Button _helloButton;

  private Hello hello;

  public boolean action (Event ev, Object arg) {
    if (ev.target == _helloButton) {
      if (hello != null) {

	// We need these privileges again as the ORB may connect
	PrivilegeManager.enablePrivilege ("UniversalConnect");
	PrivilegeManager.enablePrivilege ("UniversalPropertyRead");
	PrivilegeManager.enablePrivilege ("UniversalPropertyWrite");

	hello.setMessage (_messageField.getText ());
	_outputField.setText (hello.helloWorld ());
      }
      return true;
    }
    return false;
  }

  public void init() {
    // This GUI uses a 2 by 2 grid of widgets.
    setLayout(new GridLayout(2, 2, 5, 5));
    // Add the four widgets.
    add(new Label("Message"));
    add(_messageField = new TextField ("Hello World!"));
    add(_helloButton = new Button ("Hello"));
    add(_outputField = new TextField ());
    _outputField.setEditable (false);

    String serviceURL = getParameter ("serviceURL");
    String objectName = getParameter ("objectName");
    String user = getParameter ("user");
    String password = getParameter ("password");
    

    try {
      PrivilegeManager.enablePrivilege ("UniversalConnect");
      PrivilegeManager.enablePrivilege ("UniversalPropertyRead");
      PrivilegeManager.enablePrivilege ("UniversalPropertyWrite");

      Hashtable env = new Hashtable ();
      env.put (Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
      Context ic = new InitialContext (env);
      
      ServiceCtx service = (ServiceCtx)ic.lookup(serviceURL);
      SessionCtx session1 = (SessionCtx)service.createSubcontext (":session1");

      // Because the Netscape security mechanism prevents usage
      // of the reflection apis deep down in the JNDI runtime
      // we have to activate the objects by hand.

      // Manually activate the login object
      PublishedObject po1 =
	PublishedObjectHelper.narrow ((org.omg.CORBA.Object)
				      (session1.lookup ("/etc/login")));
      LoginServer login_server =
	LoginServerHelper.narrow (po1.activate_no_helper ());

      // Log in the database
      Login login1 = new Login (login_server);
      login1.authenticate (user, password, null);

      // Manually activate the hello object
      PublishedObject po2 =
	PublishedObjectHelper.narrow ((org.omg.CORBA.Object)
				      (session1.lookup (objectName)));
      hello = HelloHelper.narrow (po2.activate_no_helper ());

    } catch (Exception e) {
      _outputField.setText (e.toString ());
      hello = null;
    }
  }
}

helloServer/HelloImpl.java

package helloServer;

import hello.*;
import oracle.aurora.AuroraServices.ActivatableObject;

public class HelloImpl extends _HelloImplBase implements ActivatableObject 
{
  String message;

  public String helloWorld () {
    return message;
  }

  public void setMessage (String message) {
    this.message = message;
  }

  public org.omg.CORBA.Object _initializeAuroraObject () {
    return this;
  }
}

inappletviewer

hello.idl

module hello {
  interface Hello {
    wstring helloWorld ();
    void setMessage (in wstring message);
  };
};

Clientapplet.htm

<!-- /* Adapted from Visigenic's ClientApplet example */ -->
<h1>Oracle 8i ORB Client Applet</h1>
<hr>
<center>
  <applet code=ClientApplet.class width=200 height=80>
  <param name="service" value="sess_iiop://localhost:2481:javavm5">
  <param name="objectName" value="/test/myHello">
  <param name="user" value="scott">
  <param name="password" value="tiger">

  <h2>You are probably not running a Java enabled browser.
  Please use a Java enabled browser (or enable your browser for Java)
  to view this applet...</h2>

  </applet>
</center>
<hr>

ClientApplet.java

/* Adapted from Visigenic's ClientApplet example */
import hello.Hello;

import oracle.aurora.jndi.sess_iiop.ServiceCtx;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;
import java.awt.*;

public class ClientApplet extends java.applet.Applet
{
  private TextField _messageField;
  private TextField _outputField;
  private Button _helloButton;

  private Hello hello;

  public boolean action (Event ev, Object arg) {
    if (ev.target == _helloButton) {
      if (hello != null) {
	hello.setMessage (_messageField.getText ());
	_outputField.setText (hello.helloWorld ());
      }
      return true;
    }
    return false;
  }

  public void init() {
    // This GUI uses a 2 by 2 grid of widgets.
    setLayout(new GridLayout(2, 2, 5, 5));
    // Add the four widgets.
    add(new Label("Message"));
    add(_messageField = new TextField ("Hello World!"));
    add(_helloButton = new Button ("Hello"));
    add(_outputField = new TextField ());
    _outputField.setEditable (false);

    String serviceURL = getParameter ("service");
    String objectName = getParameter ("objectName");
    String user = getParameter ("user");
    String password = getParameter ("password");
    
    try {
      Hashtable env = new Hashtable ();
      env.put (Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
      env.put (Context.SECURITY_PRINCIPAL, user);
      env.put (Context.SECURITY_CREDENTIALS, password);
      env.put (Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
      Context ic = new InitialContext (env);
      
      hello = (Hello)ic.lookup (serviceURL + objectName);
    } catch (Exception e) {
      _outputField.setText (e.toString ());
      hello = null;
    }
  }
}

helloServer/HelloImpl.java

package helloServer;

import hello.*;
import oracle.aurora.AuroraServices.ActivatableObject;

public class HelloImpl extends _HelloImplBase implements ActivatableObject 
{
  String message;

  public String helloWorld () {
    return message;
  }

  public void setMessage (String message) {
    this.message = message;
  }

  public org.omg.CORBA.Object _initializeAuroraObject () {
    return this;
  }
}




Prev

Top

Next
Oracle
Copyright © 1999 Oracle Corporation.

All Rights Reserved.

Library

Product

Contents

Index