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

📄 accountserver.java

📁 精通Jboss——Ejb和Web Services开发精解的随书源代码
💻 JAVA
字号:
/**
 * AccountServer.java Created on 2003-12-8
 *
 */
package com.liuyang.jmx.account;

import java.util.Collection;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

import com.liuyang.ejb.cmp.account.AccountLocal;
import com.liuyang.ejb.cmp.account.AccountLocalHome;

/**
 * @author liuyang
 * @jmx.mbean	name=":service=AccountServer"
 * 		
 */
public class AccountServer implements AccountServerMBean {

	AccountLocalHome home = null;
	/**
	 * @jmx.managed-operation
	 */
	public boolean authenticate(String username, String password) {
		try {
			if(home==null){
				Context iniCtx = new InitialContext();
				Object objRef = iniCtx.lookup("cmp/AccountHomeLocal");
				home = (AccountLocalHome)PortableRemoteObject.narrow(objRef, AccountLocalHome.class);			
			}		
			Collection users = home.findByUsername(username);	
			if((users!=null)&&(!users.isEmpty())){
				AccountLocal account = (AccountLocal) users.iterator().next();
				return password.equalsIgnoreCase(account.getPassword());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	
		return false;
	}
	/**
	 * 
	 *
	 * @jmx.managed-operation
	 */
	public String createAccount(String username, String password) {
		try {
			System.out.println("username : "+ username+" password : "+password);
			if(home==null){
				Context iniCtx = new InitialContext();
				Object objRef = iniCtx.lookup("cmp/AccountHomeLocal");
				home = (AccountLocalHome)PortableRemoteObject.narrow(objRef, AccountLocalHome.class);			
			}
			Collection users = home.findByUsername(username);	
			if((users!=null)&&(!users.isEmpty())){
				AccountLocal account = (AccountLocal) users.iterator().next();
				account.remove();
			}
			home.create(username,password);
			return username;
		} catch (Exception e) {
			e.printStackTrace();
		}						
		return null;
	}
}

⌨️ 快捷键说明

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