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

📄 payoutsessionbeantestclient1.java

📁 人财务记账系统 非常完整的整个系统设计
💻 JAVA
字号:
package personal_payout_manage.frame;

import personal_payout_manage.ejbs.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.lang.String;
import java.util.Properties;
import java.util.Collection;
import java.rmi.RemoteException;
import java.util.Iterator;
import personal_payout_manage.wrappedobject.PersonObject;
import personal_payout_manage.wrappedobject.MaterialObject;
import personal_payout_manage.wrappedobject.PayoutObject;

public class PayoutSessionBeanTestClient1 {
  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 PayoutSession payoutSession = null;
  private PayoutSessionHome payoutSessionHome = null;

  //Construct the EJB test client
  public PayoutSessionBeanTestClient1() {
    initialize();
  }

  public void initialize() {
    long startTime = 0;
    if (logging) {
      log("Initializing bean access.");
      startTime = System.currentTimeMillis();
    }

    try {

      //get naming context
      Context context = getInitialContext();
      //look up jndi name
      Object ref = context.lookup("PayoutSessionBean");
      //look up jndi name and cast to Home interface
      payoutSessionHome = (PayoutSessionHome) PortableRemoteObject.narrow(ref,
          PayoutSessionHome.class);
      if (logging) {
        log("Succeeded initializing bean access through Home interface.");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }

    }
    catch (Exception e) {
      if (logging) {
        log("Failed initializing bean access.");
      }
      e.printStackTrace();
    }

  }

  public Context getInitialContext() throws Exception {
    String url = "t3://localhost:7001";
    String user = null;
    String password = null;
    Properties properties;
    try {
      properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY,
                     "weblogic.jndi.WLInitialContextFactory");
      properties.put(Context.PROVIDER_URL, url);
      if (user != null) {
        properties.put(Context.SECURITY_PRINCIPAL, user);
        properties.put(Context.SECURITY_CREDENTIALS,
                       password == null ? "" : password);
      }
      return new javax.naming.InitialContext(properties);
    }
    catch (Exception e) {
      log("Unable to connect to WebLogic server at " + url);
      log("Please make sure that the server is running.");
      throw e;
    }
  }

  //----------------------------------------------------------------------------
  // Methods that use Home interface methods to generate a Remote interface reference
  //----------------------------------------------------------------------------

  public PayoutSession create() {
    long startTime = 0;
    if (logging) {
      log("Calling create()");
      startTime = System.currentTimeMillis();
    }

    try {
      payoutSession = payoutSessionHome.create();
      if (logging) {
        log("Succeeded: create()");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch (Exception e) {
      if (logging) {
        log("Failed : create()");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("Return value from create(): " + payoutSession + ".");
    }
    return payoutSession;
  }

  //----------------------------------------------------------------------------
  // Methods that use Remote interface methods to access data through the bean
  //----------------------------------------------------------------------------

  public Collection getAllPayoutList() {
    Collection returnValue = null;
    if (payoutSession == null) {
      System.out.println("Error in getAllPayoutList(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging) {
      log("Calling getAllPayoutList()");
      startTime = System.currentTimeMillis();
    }

    try {
      returnValue = payoutSession.getAllPayoutList();
      if (logging) {
        log("Succeeded: getAllPayoutList()");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch (Exception e) {
      if (logging) {
        log("Failed : getAllPayoutList()");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("Return value from getAllPayoutList(): " + returnValue + ".");
    }
    return returnValue;
  }

  public Collection getAllMaterial() {
    Collection returnValue = null;
    if (payoutSession == null) {
      System.out.println("Error in getAllMaterial(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging) {
      log("Calling getAllMaterial()");
      startTime = System.currentTimeMillis();
    }

    try {
      returnValue = payoutSession.getAllMaterial();
      if (logging) {
        log("Succeeded: getAllMaterial()");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch (Exception e) {
      if (logging) {
        log("Failed : getAllMaterial()");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("Return value from getAllMaterial(): " + returnValue + ".");
    }
    return returnValue;
  }

  public Collection getAllPerson() {
    Collection returnValue = null;
    if (payoutSession == null) {
      System.out.println("Error in getAllPerson(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging) {
      log("Calling getAllPerson()");
      startTime = System.currentTimeMillis();
    }

    try {
      returnValue = payoutSession.getAllPerson();
      if (logging) {
        log("Succeeded: getAllPerson()");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch (Exception e) {
      if (logging) {
        log("Failed : getAllPerson()");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("Return value from getAllPerson(): " + returnValue + ".");
    }
    return returnValue;
  }

  public Collection getPayoutListByPsn(String psn) {
    Collection returnValue = null;
    if (payoutSession == null) {
      System.out.println("Error in getPayoutListByPsn(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging) {
      log("Calling getPayoutListByPsn(" + psn + ")");
      startTime = System.currentTimeMillis();
    }

    try {
      returnValue = payoutSession.getPayoutListByPsn(psn);
      if (logging) {
        log("Succeeded: getPayoutListByPsn(" + psn + ")");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch (Exception e) {
      if (logging) {
        log("Failed : getPayoutListByPsn(" + psn + ")");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("Return value from getPayoutListByPsn(" + psn + "): " + returnValue +
          ".");
    }
    return returnValue;
  }

  public Collection getPayoutListByMsn(String msn) {
    Collection returnValue = null;
    if (payoutSession == null) {
      System.out.println("Error in getPayoutListByMsn(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging) {
      log("Calling getPayoutListByMsn(" + msn + ")");
      startTime = System.currentTimeMillis();
    }

    try {
      returnValue = payoutSession.getPayoutListByMsn(msn);
      if (logging) {
        log("Succeeded: getPayoutListByMsn(" + msn + ")");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch (Exception e) {
      if (logging) {
        log("Failed : getPayoutListByMsn(" + msn + ")");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("Return value from getPayoutListByMsn(" + msn + "): " + returnValue +
          ".");
    }
    return returnValue;
  }

  public Collection getPayoutListByPMsn(String psn, String msn) {
    Collection returnValue = null;
    if (payoutSession == null) {
      System.out.println("Error in getPayoutListByPMsn(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging) {
      log("Calling getPayoutListByPMsn(" + psn + ", " + msn + ")");
      startTime = System.currentTimeMillis();
    }

    try {
      returnValue = payoutSession.getPayoutListByPMsn(psn, msn);
      if (logging) {
        log("Succeeded: getPayoutListByPMsn(" + psn + ", " + msn + ")");
        long endTime = System.currentTimeMillis();
        log("Execution time: " + (endTime - startTime) + " ms.");
      }
    }
    catch (Exception e) {
      if (logging) {
        log("Failed : getPayoutListByPMsn(" + psn + ", " + msn + ")");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("Return value from getPayoutListByPMsn(" + psn + ", " + msn + "): " +
          returnValue + ".");
    }
    return returnValue;
  }

  //----------------------------------------------------------------------------
  // Utility Methods
  //----------------------------------------------------------------------------

  private void log(String message) {

    if (message == null) {
      System.out.println("-- null");
    }
    if (message.length() > MAX_OUTPUT_LINE_LENGTH) {
      System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) +
                         " ...");
    }
    else {
      System.out.println("-- " + message);
    }
  }

  //Main method
  public static void main(String[] args) throws RemoteException{
    PayoutSessionBeanTestClient1 client = new PayoutSessionBeanTestClient1();
    // 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.
    Collection col = null;
    client.create();

//    col = client.getAllPerson();
//    prtPerson(col);
//    col = client.getAllMaterial();
//    prtMa(col);
    System.out.println("all payoutlist :");
    col = client.getAllPayoutList();
    prtPayoutList(col);

    System.out.println("田孟武 payout list :");
    col = client.getPayoutListByPsn("tmw");
    prtPayoutList(col);

    System.out.println("房租 payoutlist :");
    col = client.getPayoutListByMsn("rent");
     prtPayoutList(col);

     System.out.println("田孟武 房租 payoutList :");
     col = client.getPayoutListByPMsn("tmw","rent");

  }
 public static void prtPerson(Collection col)
 {
   for (Iterator iter = col.iterator(); iter.hasNext(); ) {
      PersonObject item = (PersonObject)iter.next();
     System.out.println("PersonObject name = " + item.getPname());
   }
 }
 public static void prtMa(Collection col)
{
  for (Iterator iter = col.iterator(); iter.hasNext(); ) {
    MaterialObject item = (MaterialObject)iter.next();
    System.out.println("MaterialObject name = " + item.getMname());
  }
}
public static void prtPayoutList(Collection col)
{
 for (Iterator iter = col.iterator(); iter.hasNext(); ) {
   PayoutObject item = (PayoutObject)iter.next();
   System.out.println("payoutlist   = " + item);
 }
}
}

⌨️ 快捷键说明

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