package examples.com;

import weblogic.com.Variant;
import weblogic.com.remote.beeper.*;
import weblogic.rmi.*;

/**
 * This package uses a DLL file to illustrate how to invoke COM objects using 
 * the WebLogic COM Compiler. 
 * 
 * <p>
 * Included in this package is the <tt>beeper.dll</tt> file. The <tt>beep()</tt> 
 * method of this DLL causes the host computer to beep.
 *
 * <p>
 * The WebLogic COM compiler is used to generate the necessary 
 * Java classes from the COM object.  The generated implementation 
 * class is then deployed as a startup class in your WebLogic Server. Once the 
 * COM object is compiled and deployed, it becomes accessible from the network to 
 * any client via any of WebLogic's supported protocols. In this example, a simple
 * Java client looks up the deployed beeper object and invokes the <tt>beep()</tt> method, causing 
 * the server computer to beep.
 *
 * <p>
 * Build the example:
 * <ol>
 * <li>
 * Make sure that Microsoft SDK 3.1 (or later) for Java is installed and set 
 *up a development shell to use the Miscrosoft SDK, as described in 
 * <a href="../../techstart/environment.html">Setting up 
 * your environment</a>.
 * <li>
 * Place <tt>beeper.dll</tt> in a directory that is in the PATH of the WebLogic Server process. 
 * This can be any directory that is listed in the PATH variable in the Environment tab of the 
 * System Properties dialog. For this example, you place <tt>beeper.dll</tt> in 
 * the "c:\winnt\" directory.
 * <li>
 *Compile <tt>beeper.dll</tt> using the WebLogic COM compiler with the following command. 
 *This is a single command and should be typed on one command line. 
 *<pre><font face="Courier New">   $ <b>jview  weblogic.comc -nothreads -register c:\winnt\beeper.dll</b></font></pre>
 *In the above command, the 
 *<font face="Courier New" size = -1><b>-nothreads</font></b> option 
 *indicates that this DLL is not 
 * multithreaded.  The <font face="Courier New" size = -1><b>
 * -register</font></b> option registers the DLL with Windows.
 * <li>
 * Place the resulting classes, 
 * <tt>weblogic.com.beeper.Beeper</tt>, <tt>
 * weblogic.com.beeper.IBeeper</tt>, <tt>weblogic.com.remote.beeper.IBeeper</tt>, <tt>
 * weblogic.com.remote.beeper.IBeeper_WLSkel</tt>, 
 * <tt>weblogic.com.remote.beeper.IBeeperStub</tt>, 
 * <tt>weblogic.com.remote.beeper.IBeeperImpl</tt>, and 
 * <tt>weblogic.com.remote.beeper.Uitilities</tt> and their associate directory structure, 
 * into the <font face="Courier New" size = -1><i>weblogic</i>\myserver\serverclasses</font> 
 * directory.
 * <li>
 * Compile the <tt>ServerSideDLLClient.java</tt> file as shown in this example for Windows NT. 
 * <pre><font face="Courier New">  $ <b>jvc /d %CLIENT_CLASSES% ServerSideDLLClient.java</b></font></pre>
 *</ol>
 *Configure the server:
 *<ol>
 *  <li>
 * Add an entry for the beeper implementation class to the <tt>weblogic.properties</tt> file.  
 * The following entry registers the implementation class 
 * <tt>weblogic.com.remote.beeper.IBeeperImpl</tt> 
 * to become available at startup and binds the object in the WebLogic registry to the 
 * name "beeper".
 *  <pre>   weblogic.system.startupClass.beepertest=\
 *       weblogic.com.remote.beeper.IBeeperImpl
 *   weblogic.system.startupArgs.beepertest=beeper </pre>
 * </ol>
 * Run the example:
 * <ol>
 * <li>
 * Start the WebLogic Server using the Microsoft JVM (JView) in a new command shell.
 * <li>
 * In your development shell, start the client application using the following command.
 * <pre><font face="Courier New">  $ <b>jview examples.com.ServerSideDLLClient t3://<i>hostname:port</i></b></font></pre>
 * where:
 * <p>
 * <dl>
 *<dt><i><font face="Courier New" size = -1><b>hostname</b></font></i>
 * <dd>Host name of the WebLogic Server
 * <dt><i><font face="Courier New" size = -1><b>port</b></font></i>
 * <dd>Port where the WebLogic Server is listening for connections
 * (<font face="Courier New" size=-1>weblogic.system.ListenPort</font>). 
 * </dl>
 *If the argument is ommitted, "<tt>t3://localhost:7001</tt>" is assumed. If the machine
 * hosting WebLogic Server does not beep, you may need to turn up the volume settings 
 * on the machine.
 *</ol>
 * <dl>
 *   <dt> <b>Author:</b>
 *   <dd> Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
 *</dl>
 **/
public class ServerSideDLLClient {

   public static void main(String[] args) {
       // Default URL
       String url = args.length == 0 ? "t3://localhost:7001" : args[0];
       // Object name
       String name = "beeper";

       //Wrap lookup in a try block
       try {
           // Obtain a reference to the deployed beeper object
           IBeeper theBeeper = (IBeeper)Naming.lookup(url + "/" + name);;
           
           // Call beep method
           theBeeper.Beep();
       }

       // Catch exceptions
       catch (Exception e) {e.printStackTrace();}

       System.exit(0);
   }
}
