KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > identity > Group


1 package org.jbpm.identity;
2
3 import java.util.*;
4
5 /**
6  * group of users.
7  *
8  * <p>The group type allows for the distinction of
9  * hierarchical groups, security roles and others.
10  * </p>
11  *
12  * <p>
13  * Following name convention is recommended for
14  * assigning group types :
15  * <ul>
16  * <li><b>hierarchy</b>: for hierarchical groups
17  * like teams, business units and companies.</li>
18  * <li><b>security-role</b>: for j2ee and servlet
19  * security roles like admin, user, ...</li>
20  * </ul>
21  * </p>
22  */

23 public class Group extends Entity {
24
25   private static final long serialVersionUID = 1L;
26
27   protected String JavaDoc type = null;
28   protected Group parent = null;
29   protected Set children = null;
30   protected Set memberships = null;
31
32   public Group() {
33   }
34
35   public Group(String JavaDoc name) {
36     super(name);
37   }
38
39   public Group(String JavaDoc name, String JavaDoc type) {
40     super(name);
41     this.type = type;
42   }
43
44   public void addMembership(Membership membership) {
45     if (memberships==null) memberships = new HashSet();
46     memberships.add(membership);
47     membership.setGroup(this);
48   }
49   
50   public void addChild(Group child) {
51     if (children==null) children = new HashSet();
52     children.add(child);
53     child.setParent(this);
54   }
55   
56   public Set getUsers() {
57     Set users = new HashSet();
58     if(memberships!=null) {
59       Iterator iter = memberships.iterator();
60       while (iter.hasNext()) {
61         Membership membership = (Membership) iter.next();
62         users.add(membership.getUser());
63       }
64     }
65     return users;
66   }
67
68   public Set getUsersForMembershipName(String JavaDoc membershipName) {
69     Set users = new HashSet();
70     if(memberships!=null) {
71       Iterator iter = memberships.iterator();
72       while (iter.hasNext()) {
73         Membership membership = (Membership) iter.next();
74         if (membershipName.equals(membership.getName())) {
75           users.add(membership.getUser());
76         }
77       }
78     }
79     return users;
80   }
81
82   public long getId() {
83     return id;
84   }
85   public Set getMemberships() {
86     return memberships;
87   }
88   public Set getChildren() {
89     return children;
90   }
91   public Group getParent() {
92     return parent;
93   }
94   public String JavaDoc getType() {
95     return type;
96   }
97   public void setType(String JavaDoc type) {
98     this.type = type;
99   }
100   public void setChildren(Set children) {
101     this.children = children;
102   }
103   public void setMemberships(Set memberships) {
104     this.memberships = memberships;
105   }
106   public void setParent(Group parent) {
107     this.parent = parent;
108   }
109 }
110
Popular Tags