?? userusebean.java
字號(hào):
/* */package com.sun.j2ee.workflow.control.web;import java.util.Collection;import javax.naming.NamingException;import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.NamingEnumeration;import javax.naming.directory.InitialDirContext;import com.sun.j2ee.workflow.util.JNDINames;import com.sun.j2ee.workflow.user.model.UserModel;import com.sun.j2ee.workflow.user.dao.UserDAOImpl;import com.sun.j2ee.workflow.user.exceptions.*;import com.sun.j2ee.workflow.control.exceptions.GeneralFailureException;import com.sun.j2ee.workflow.control.exceptions.WorkflowAppException;import com.sun.j2ee.workflow.util.Debug;/** This class is the web-tier representation of the user. * @author Jian (James) Cai */public class UserUseBean implements java.io.Serializable { private UserModel user = null; private boolean cached = false; public UserUseBean() {} public UserModel getUser(String user_ID) { if (cached==false) { try { UserDAOImpl userDa = new UserDAOImpl(); String user_id = userDa.findByPrimaryKey(user_ID); Debug.println("found user id: "+user_id); user = userDa.load(user_id); //account = cust.getDetails(); } catch (UserDAOFinderException fe) { throw new GeneralFailureException("Unable to find the password details for user " ); } catch (UserDAOSysException se) { Debug.println("found UserDAOSysException se" + se.toString()); } return user; } else { user = loadFromCache(user_ID); return user; }} public Collection getUserByRole(String role) { Collection users = null; try { UserDAOImpl userDa = new UserDAOImpl(); users = getUserByField("role", role); Debug.println("found user with Role: "+ role); } catch (UserDAOSysException se) { Debug.println("found UserDAOSysException se" + se.toString()); } return users; } public Collection getUserList() { Collection users = null; try { UserDAOImpl userDa = new UserDAOImpl(); users = userDa.findAll(); } catch (UserDAOFinderException fe) { throw new GeneralFailureException("Unable to find all user by name "); } catch (UserDAOSysException se) { Debug.println("found UserDAOSysException se" + se.toString()); } return users; } public Collection getUserByField(String field, String key) { Collection users = null; try { UserDAOImpl userDa = new UserDAOImpl(); users = userDa.findByField(field, key); } catch (UserDAOFinderException fe) { throw new GeneralFailureException("Unable to find all user by name "); } catch (UserDAOSysException se) { Debug.println("found UserDAOSysException se" + se.toString()); } return users; } //method to retrieve Global JNDI information public String getGlobalUserInfor() { String tmp; String maxUser = "0"; String tempstr; Boolean booleanUser; Byte byteUser; Character characterUser; Double doubleUser; Float floatUser; Integer intergerUser; Long longUser; Short shortUser; String stringUser; StringBuffer gui = new StringBuffer(); Context ctx = null; try { ctx = new InitialContext(); } catch (NamingException e) { Debug.println("Can not create a initial context : " + e); return null; } try { Object value1 = ctx.lookup("java:/comp/env/booleanUser"); //boolean Object value2 = ctx.lookup("java:/comp/env/byteUser"); //byte // Object value3 = ctx.lookup("java:/comp/env/characterUser"); //character Object value4 = ctx.lookup("java:/comp/env/doubleUser"); //double Object value5 = ctx.lookup("java:/comp/env/floatUser"); //float Object value6 = ctx.lookup("java:/comp/env/integerUser"); //integer Object value7 = ctx.lookup("java:/comp/env/longUser"); //long Object value8 = ctx.lookup("java:/comp/env/shortUser"); //short Object value9 = ctx.lookup("java:/comp/env/stringUser"); //string Debug.println(" Individual Lookup: "); tempstr = ((Boolean)value1).toString(); gui.append("Boolean: "+ tempstr +"/n"); tempstr = ((Byte)value2).toString(); gui.append("Byte: "+ tempstr+"/n"); //tempstr = ((Character)value3).toString(); //gui.append("Character: "+ tempstr+"/n"); tempstr = ((Double)value4).toString(); gui.append("Double: "+ tempstr+"/n"); tempstr = ((Float)value5).toString(); gui.append("Float: "+ tempstr+"/n"); tempstr = ((Integer)value6).toString(); gui.append("Integer: "+ tempstr+"/n"); tempstr = ((Long)value7).toString(); gui.append("Long: "+ tempstr +"/n"); tempstr = ((Short)value8).toString(); gui.append("Short: "+ tempstr +"/n"); tempstr = ((String)value9).toString(); gui.append("String: "+ tempstr +"/n"); } catch (NamingException e) { Debug.println("JNDI lookup error : " + e); } try { Context envCtx = (Context) ctx.lookup("java:/comp/env/"); Debug.println("ctx.list() on /comp/env Context : "); NamingEnumeration enum = ctx.list("java:/comp/env/"); while (enum.hasMoreElements()) { Debug.print("Binding : "); Debug.println(enum.nextElement().toString()); } Debug.println("ctx.listBindings() on /comp/env Context : "); enum = ctx.listBindings("java:/comp/env/"); while (enum.hasMoreElements()) { Debug.print("Binding : "); tmp = enum.nextElement().toString(); int subindex = tmp.indexOf("@"); if (subindex > 1) { tmp = tmp.substring(0, subindex); } Debug.println(tmp); } } catch (NamingException e) { Debug.println("JNDI lookup error : " + e); } return gui.toString(); } private UserModel loadFromCache(String user_ID) { UserModel user = null; //need to be implemented return user; }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -