private PersonBean createPerson(int rating, String name, String interests, String gender) { PersonBean person = new PersonBeanImpl(); person.setGender(gender); person.setName(name); person.setInterests(interests); person.setHotOrNotRating(rating); return person; }
private void changePersonBean(PersonBean proxy, String name, int rating, String interests) { try { proxy.setHotOrNotRating(rating); } catch (Exception e) { System.out.println("Can't set Rating from owner proxy"); } try { proxy.setName(name); proxy.setInterests(interests); } catch (Exception e) { System.out.println("Can't set name/interests from non owner proxy"); } // proxy.setInterests(interests); }
private PersonBean getNonOwnerProxy(PersonBean person) { return (PersonBean) Proxy.newProxyInstance( person.getClass().getClassLoader(), person.getClass().getInterfaces(), new NonOwnerInvocationHandler(person)); }
/** 为借用 查询所有记录 */ public String[][] searchAllForUse() { Database DB = new Database(); AssetsBean aBean = new AssetsBean(); PersonBean pBean = new PersonBean(); String[][] sn = null; int row = 0; int i = 0; sql = "select * from AssetsTrjn where FromAcc ='设备借用' order by JourNo"; try { DB.OpenConn(); rs = DB.executeQuery(sql); if (rs.last()) { row = rs.getRow(); } if (row == 0) { sn = new String[1][6]; sn[0][0] = " "; sn[0][1] = " "; sn[0][2] = " "; sn[0][3] = " "; sn[0][4] = " "; sn[0][5] = " "; } else { sn = new String[row][6]; rs.first(); rs.previous(); while (rs.next()) { sn[i][0] = rs.getString("JourNo"); sn[i][1] = aBean.getAssetsName(rs.getString("AssetsID")); sn[i][2] = rs.getString("RegDate"); sn[i][3] = pBean.getPersonName(rs.getString("PersonID")); sn[i][4] = rs.getString("Use"); sn[i][5] = rs.getString("Other"); i++; } } } catch (Exception e) { } finally { DB.closeStmt(); DB.closeConn(); } return sn; }
private void testDrive() { PersonBean person1 = getPerson("Kamal Kaur"); PersonBean ownerProxy = getOwnerProxy(person1); System.out.println("Name is " + ownerProxy.getName()); changePersonBean(ownerProxy, "Lotus", 8, "Singing"); System.out.println("Gender ----" + ownerProxy.getGender()); System.out.println("Name set from owner proxy"); System.out.println("Name ----" + ownerProxy.getName()); System.out.println("Interests set from owner proxy"); System.out.println("Interests ----" + ownerProxy.getInterests()); System.out.println("Ratings set from owner proxy"); System.out.println("Ratings------" + ownerProxy.getHotOrNotRating()); PersonBean person2 = getPerson("Arvind Gupta"); PersonBean nonOwnerProxy = getNonOwnerProxy(person2); changePersonBean(nonOwnerProxy, "Arv Gupta", 10, "Reading"); System.out.println("Gender ----" + nonOwnerProxy.getGender()); System.out.println("Name set from non owner proxy"); System.out.println("Name ----" + nonOwnerProxy.getName()); System.out.println("Interests set from non owner proxy"); System.out.println("Interests ----" + nonOwnerProxy.getInterests()); System.out.println("Ratings set from non owner proxy"); System.out.println("Ratings------" + nonOwnerProxy.getHotOrNotRating()); }
void initialiseDatabase() { PersonBean p1 = createPerson(6, "Kamal Kaur", "Shopping,Music", "Female"); PersonBean p2 = createPerson(9, "Arvind Gupta", "Cars,Music", "Male"); dbEntry.put(p1.getName(), p1); dbEntry.put(p2.getName(), p2); }
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) { PersonBean profile = (PersonBean) arg2; return String.valueOf(profile.getId()); }
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) { PersonBean personBean = new PersonBean(); personBean.setId(new Integer(arg2)); return personBean; }