⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 14a.txt

📁 一本关于JBuilder 应用开发的书籍,希望大家喜欢,其实我没看过的,
💻 TXT
字号:
package ejbprj;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
public class myBean1TestClient1
{
  private static final String ERROR_NULL_REMOTE = "Remote interface reference is null.  It must be created by calling one of the Home interface methods first.";
  private static final int MAX_OUTPUT_LINE_LENGTH = 100;
  private boolean logging = true;
  private myBean1Home myBean1HomeObject = null;
  private myBean1Remote myBean1RemoteObject = null;
  /**Construct the EJB test client*/
  public myBean1TestClient1()
  {
    long startTime = 0;
    if (logging)
    {
      log("Initializing bean access.");
      startTime = System.currentTimeMillis();
    }
    try
    {
      //get naming context
      Context ctx = new InitialContext();
      //look up jndi name
      Object ref = ctx.lookup("myBean1");
      //cast to Home interface
      myBean1HomeObject = (myBean1Home) PortableRemoteObject.narrow(ref, myBean1Home.class);
      if (logging)
      {
        long endTime = System.currentTimeMillis();
        log("Succeeded initializing bean access.");
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch(Exception e)
    {
      if (logging)
      {
        log("Failed initializing bean access.");
      }
      e.printStackTrace();
    }
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
  //----------------------------------------------------------------------------
  // Methods that use Home interface methods to generate a Remote interface reference
  //----------------------------------------------------------------------------
  public myBean1Remote create()
  {
    long startTime = 0;
    if (logging)
    {
      log("Calling create()");
      startTime = System.currentTimeMillis();
    }
    try
    {
      myBean1RemoteObject = myBean1HomeObject.create();
      if (logging)
      {
        long endTime = System.currentTimeMillis();
        log("Succeeded: create()");
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch(Exception e)
    {
      if (logging)
      {
        log("Failed: create()");
      }
      e.printStackTrace();
    }
    if (logging)
    {
      log("Return value from create(): " + myBean1RemoteObject + ".");
    }
    return myBean1RemoteObject;
  }
  //----------------------------------------------------------------------------
  // Methods that use Remote interface methods to access data through the bean
  //----------------------------------------------------------------------------
  public void setMyProperty(String myProperty)
  {
    if (myBean1RemoteObject == null)
    {
      System.out.println("Error in setMyProperty(): " + ERROR_NULL_REMOTE);
      return ;
    }
    long startTime = 0;
    if (logging)
    {
      log("Calling setMyProperty(" + myProperty + ")");
      startTime = System.currentTimeMillis();
    }
    try
    {
      myBean1RemoteObject.setMyProperty(myProperty);
      if (logging)
      {
        long endTime = System.currentTimeMillis();
        log("Succeeded: setMyProperty(" + myProperty + ")");
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch(Exception e)
    {
      if (logging)
      {
        log("Failed: setMyProperty(" + myProperty + ")");
      }
      e.printStackTrace();
    }
  }
  public String getMyProperty()
  {
    String returnValue = "";
    if (myBean1RemoteObject == null)
    {
      System.out.println("Error in getMyProperty(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging)
    {
      log("Calling getMyProperty()");
      startTime = System.currentTimeMillis();
    }
    try
    {
      returnValue = myBean1RemoteObject.getMyProperty();
      if (logging)
      {
        long endTime = System.currentTimeMillis();
        log("Succeeded: getMyProperty()");
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch(Exception e)
    {
      if (logging)
      {
        log("Failed: getMyProperty()");
      }
      e.printStackTrace();
    }
    if (logging)
    {
      log("Return value from getMyProperty(): " + returnValue + ".");
    }
    return returnValue;
  }
  //----------------------------------------------------------------------------
  // Utility Methods
  //----------------------------------------------------------------------------
  private void log(String message)
  {
    if (message == null)
    {
      System.out.println("-- null");
      return ;
    }
    if (message.length() > MAX_OUTPUT_LINE_LENGTH)
    {
      System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) + " ...");
    }
    else
    {
      System.out.println("-- " + message);
    }
  }
  /**Main method*/
//main函数
  public static void main(String[] args)
  {
    myBean1TestClient1 client = new myBean1TestClient1();
    // Use the client object to call one of the Home interface wrappers
    // above, to create a Remote interface reference to the bean.
    // If the return value is of the Remote interface type, you can use it
    // to access the remote interface methods.  You can also just use the
    // client object to call the Remote interface wrappers.
  }
  private void jbInit() throws Exception
  {
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -