package examples.t3client;

import java.io.*;
import java.net.*;
import java.util.*;
import weblogic.common.*;

/**
 * This simple example demonstrates how to use three of WebLogic's
 * facilities -- configuration, administration, and logging -- to get
 * and store information about a T3Client's environment.
 *
 * @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 FacilitiesTest {

  /**
   * Runs this example from the command line.
   */
  public static void main(String[] argv) {
    
    // Default URL value
    String URL = "t3://localhost:7001"; 
    
    // Use the first command line argument as the URL, if it exists
    if (argv.length > 0)
      URL = argv[0];  
    else
      System.out.println("no argument supplied, using default URL of " + URL);
    
    try {
      T3Client t3c = new T3Client(URL);
      t3c.connect();
      System.out.println("Successfully connected to WebLogic at: " + URL);
      
      // Get properties from the weblogic.properties file with the
      // config() factory method
      String systemHome     =
        t3c.services.config().getProperty("weblogic.system.home");
      String consoleEnabled =
        t3c.services.config().getProperty("weblogic.system.enableConsole");
      
      // Get license and version information for the WebLogic Server
      String license = t3c.services.admin().licenses();
      String version = t3c.services.admin().version();
      
      // Log a message in the WebLogic Server weblogic.log file
      String logmsg = "This message logged at " + new java.util.Date();
      t3c.services.log().info(logmsg);
      
      // Display the results
      System.out.println("License info: " + license);
      System.out.println("Version info: " + version);
      System.out.println("System home: "  + systemHome);
      System.out.println("Is console enabled? " + consoleEnabled);
      System.out.println("Logged: "       + logmsg);
      
      t3c.disconnect();
      System.out.println("Successfully disconnected from WebLogic");
      
    }
    catch (Exception e) {
      System.out.println("General exception occurred");
      e.printStackTrace();
    }
  }
}

