package examples.t3client;

import java.util.Hashtable;
import weblogic.common.*;
import weblogic.workspace.common.*;

/**
 * StartupTest is a simple example of the use of the T3StartupDef
 * interface for writing a startup class. Startup classes are specified
 * in the <tt>weblogic.properties</tt> file and are instantiated and executed
 * at the time the WebLogic Server starts up.
 * <p>
 * This simple example prints out the value of the logString argument
 * to the WebLogic log.
 * <p>
 * To run this example, first set the following properties
 * by adding them to the <tt>weblogic.properties</tt> file:
 * <p>
 * <pre>weblogic.system.startupClass.StartupTest=examples.t3client.StartupTest
 * weblogic.system.startupArgs.StartupTest=logString=SERVER STARTED</pre>
 * This example isn't run from the command line, but rather runs when
 * the WebLogic Server starts. Register this startup class in the
 * properties file and start your WebLogic Server. You'll see the
 * results in the log file.
 *
 * @author  Copyright (c) 1996-98 by WebLogic, Inc. All Rights Reserved.
 * @author Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
 */
public class StartupTest implements T3StartupDef {
  
  /**
   * Default constructor. A default constructor is required of any
   * class that implements <tt>weblogic.common.T3StartupDef</tt>.
   */
  public StartupTest() {}
  
  private T3ServicesDef services;
  
  /**
   * Sets the services stub. The services stub provides
   * runtime access to WebLogic services.
   */
  public void setServices(T3ServicesDef services) {
    this.services = services;
  }
  
  /**
   * The startup action belongs in this method. The string
   * argument specifies the virtual name of this class by which it
   * is registered in the <tt>weblogic.properties</tt> file,
   * under the <tt>weblogic.system.startupClass</tt> property.
   * The hashtable argument is a set of name-value pairs that
   * are supplied to this method from the 
   * <tt>weblogic.system.startupArgs</tt> property.
   *
   * @param name             Virtual name under which this class is registered
   * @param args             Set of name-value pairs of arguments for this method
   * @exception              java.lang.Exception if there is an error
   */
  public String startup(String name, Hashtable args) throws Exception {
    String logString = (String)args.get("logString");
    if (logString == null)
      logString = "Log String not specified in startup argument";
    
    // Call the Log Service to print out the log string
    services.log().log("StartupTest called with argument of " + logString);
    return "ok";
  }
}
