

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02
Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

|
UserManagementBean中有关 GroupBean 的部分(很简单) |
| //********************************************************************** // 一对多的双向关系 //********************************************************************** /** * 创建组别 * @throws CreateException * @ejb.interface-method view-type="remote" */ public void createGroup(String groupName, String description) throws CreateException { groupHome.create(groupName, description); } /** * 删除组别 * @throws RemoveException * @throws EJBException * @ejb.interface-method view-type="remote" */ public void removeGroup(String groupName) throws EJBException, RemoveException { groupHome.remove(groupName); } /** * 显示所有组别 * @throws FinderException * @ejb.interface-method view-type="remote" */ public ArrayList getGroups() throws FinderException { ArrayList groupList = new ArrayList(30); Iterator iter = groupHome.findAll().iterator(); while (iter.hasNext()) { GroupLocal group = (GroupLocal) iter.next(); groupList.add(group.getName()); } return groupList; } /** * 将用户添加到组 * @throws FinderException * @ejb.interface-method view-type="remote" */ public void moveUserToGroup(String email, String groupName) throws FinderException { UserInfoLocal user = infoHome.findByPrimaryKey(email); GroupLocal group = groupHome.findByPrimaryKey(groupName); user.setGroup(group); } /** * 验证用户所在组 * @throws FinderException * @ejb.interface-method view-type="remote" */ public boolean inGroup(String email, String groupName) throws FinderException { UserInfoLocal user = infoHome.findByPrimaryKey(email); return user.getGroup().getName().equals(groupName); } /** * 给一组用户增加权限 * @throws FinderException * @ejb.interface-method view-type="remote" */ public void addRoleToUsers(String groupName, String roleName) throws FinderException { GroupLocal group = groupHome.findByPrimaryKey(groupName); RoleLocal role = roleHome.findByPrimaryKey(roleName); Iterator iter = group.getUsers().iterator(); while (iter.hasNext()) { UserInfoLocal user = (UserInfoLocal) iter.next(); user.getUser().getRoles().add(role); } } /** * 通过 ejb.finder 输出某组别的用户 * @throws FinderException * @ejb.interface-method view-type="remote" */ public ArrayList getUserIDsInGroup1(String groupName) throws FinderException { ArrayList userList = new ArrayList(30); GroupLocal group = groupHome.findByPrimaryKey(groupName); Iterator iter = group.getUsers().iterator(); while (iter.hasNext()) { UserInfoLocal element = (UserInfoLocal) iter.next(); userList.add(element.getEmail()); } return userList; } /** * 通过 ejb.select 输出某组别的用户 * Business method * @throws FinderException * @ejb.interface-method view-type = "remote" */ public ArrayList getUserIDsInGroup2(String groupName) throws FinderException { return groupHome.getUserIDs(groupName); } |
CMPClient4.java