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

📄 privilegeejbtestclient1.java

📁 公司自己开发的工作流引擎
💻 JAVA
字号:
package cn.com.iaspec.workflow.extbusiness.task.business;
import cn.com.iaspec.workflow.privilege.ejb.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.lang.String;
import javax.naming.InitialContext;
import java.util.Hashtable;
import cn.com.iaspec.workflow.vo.workflow.UserInfo;
import java.util.List;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: IASPEC Technologies</p>
 *
 * @author not attributable
 * @version 1.0
 */


public class PrivilegeEJBTestClient1{
  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 PrivilegeEJB privilegeEJB=null;
  private PrivilegeEJBHome privilegeEJBHome=null;

  //Construct the EJB test client
  public PrivilegeEJBTestClient1(){
    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
      /**@todo Provide a valid JNDI lookup name for the Home interface*/
      Object ref=context.lookup("PrivilegeEJB");
      //look up jndi name and cast to Home interface
      privilegeEJBHome=(PrivilegeEJBHome)PortableRemoteObject.narrow(ref,
          PrivilegeEJBHome.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();
    }

  }

  private Context getInitialContext()
      throws NamingException{
    Hashtable environment=new Hashtable();

    environment.put(Context.INITIAL_CONTEXT_FACTORY,
        "org.jnp.interfaces.NamingContextFactory");
    environment.put(Context.URL_PKG_PREFIXES,
        "org.jboss.naming:org.jnp.interfaces");
    environment.put(Context.PROVIDER_URL,"jnp://localhost:1099");

    return new InitialContext(environment);
  }

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

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

    try{
      privilegeEJB=privilegeEJBHome.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(): "+privilegeEJB+".");
    }
    return privilegeEJB;
  }

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

  public UserInfo login(String loginName,String password){
    UserInfo returnValue=null;
    if(privilegeEJB==null){
      System.out.println("Error in login(): "+ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime=0;
    if(logging){
      log("Calling login("+loginName+", "+password+")");
      startTime=System.currentTimeMillis();
    }

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

  public List getUserSubFuncInfo(String userId,String funcId){
    List returnValue=null;
    if(privilegeEJB==null){
      System.out.println("Error in getUserSubFuncInfo(): "+ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime=0;
    if(logging){
      log("Calling getUserSubFuncInfo("+userId+", "+funcId+")");
      startTime=System.currentTimeMillis();
    }

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

  public List getUserFirstFuncInfo(String userId){
    List returnValue=null;
    if(privilegeEJB==null){
      System.out.println("Error in getUserFirstFuncInfo(): "+ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime=0;
    if(logging){
      log("Calling getUserFirstFuncInfo("+userId+")");
      startTime=System.currentTimeMillis();
    }

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

  public void modifyUserPassword(String loginId,String password){
    if(privilegeEJB==null){
      System.out.println("Error in modifyUserPassword(): "+ERROR_NULL_REMOTE);
      return;
    }
    long startTime=0;
    if(logging){
      log("Calling modifyUserPassword("+loginId+", "+password+")");
      startTime=System.currentTimeMillis();
    }

    try{
      privilegeEJB.modifyUserPassword(loginId,password);
      if(logging){
        log("Succeeded: modifyUserPassword("+loginId+", "+password+")");
        long endTime=System.currentTimeMillis();
        log("Execution time: "+(endTime-startTime)+" ms.");
      }
    }
    catch(Exception e){
      if(logging){
        log("Failed : modifyUserPassword("+loginId+", "+password+")");
      }
      e.printStackTrace();
    }
  }

  public void executeRemoteCallsWithDefaultArguments(){
    if(privilegeEJB==null){
      System.out.println("Error in executeRemoteCallsWithDefaultArguments(): "+
          ERROR_NULL_REMOTE);
      return;
    }

    try{
      login("","");
      getUserSubFuncInfo("","");
      getUserFirstFuncInfo("");
      modifyUserPassword("","");
    }
    catch(Exception e){
      e.printStackTrace();
    }
  }

  //----------------------------------------------------------------------------
  // 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 Exception{
    PrivilegeEJBTestClient1 client=new PrivilegeEJBTestClient1();
    PrivilegeEJB ejb=client.create();
    ejb.login("admin","123");
    // 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.
  }
}

⌨️ 快捷键说明

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