001: /*
002: * JBoss, Home of Professional Open Source
003: * Copyright 2005, JBoss Inc., and individual contributors as indicated
004: * by the @authors tag. See the copyright.txt in the distribution for a
005: * full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jbpm.identity;
023:
024: import java.util.*;
025:
026: /**
027: * group of users.
028: *
029: * <p>The group type allows for the distinction of
030: * hierarchical groups, security roles and others.
031: * </p>
032: *
033: * <p>
034: * Following name convention is recommended for
035: * assigning group types :
036: * <ul>
037: * <li><b>hierarchy</b>: for hierarchical groups
038: * like teams, business units and companies.</li>
039: * <li><b>security-role</b>: for j2ee and servlet
040: * security roles like admin, user, ...</li>
041: * </ul>
042: * </p>
043: */
044: public class Group extends Entity {
045:
046: private static final long serialVersionUID = 1L;
047:
048: protected String type = null;
049: protected Group parent = null;
050: protected Set children = null;
051: protected Set memberships = null;
052:
053: public Group() {
054: }
055:
056: public Group(String name) {
057: super (name);
058: }
059:
060: public Group(String name, String type) {
061: super (name);
062: this .type = type;
063: }
064:
065: public void addMembership(Membership membership) {
066: if (memberships == null)
067: memberships = new HashSet();
068: memberships.add(membership);
069: membership.setGroup(this );
070: }
071:
072: public void addChild(Group child) {
073: if (children == null)
074: children = new HashSet();
075: children.add(child);
076: child.setParent(this );
077: }
078:
079: public Set getUsers() {
080: Set users = new HashSet();
081: if (memberships != null) {
082: Iterator iter = memberships.iterator();
083: while (iter.hasNext()) {
084: Membership membership = (Membership) iter.next();
085: users.add(membership.getUser());
086: }
087: }
088: return users;
089: }
090:
091: public Set getUsersForMembershipRole(String membershipRole) {
092: Set users = new HashSet();
093: if (memberships != null) {
094: Iterator iter = memberships.iterator();
095: while (iter.hasNext()) {
096: Membership membership = (Membership) iter.next();
097: if (membershipRole.equals(membership.getRole())) {
098: users.add(membership.getUser());
099: }
100: }
101: }
102: return users;
103: }
104:
105: public long getId() {
106: return id;
107: }
108:
109: public Set getMemberships() {
110: return memberships;
111: }
112:
113: public Set getChildren() {
114: return children;
115: }
116:
117: public Group getParent() {
118: return parent;
119: }
120:
121: public String getType() {
122: return type;
123: }
124:
125: public void setType(String type) {
126: this .type = type;
127: }
128:
129: public void setChildren(Set children) {
130: this .children = children;
131: }
132:
133: public void setMemberships(Set memberships) {
134: this .memberships = memberships;
135: }
136:
137: public void setParent(Group parent) {
138: this.parent = parent;
139: }
140: }
|