KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > Yasna > forum > GroupProxy


1 /**
2  * Copyright (C) 2001 Yasna.com. All rights reserved.
3  *
4  * ===================================================================
5  * The Apache Software License, Version 1.1
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * 3. The end-user documentation included with the redistribution,
20  * if any, must include the following acknowledgment:
21  * "This product includes software developed by
22  * Yasna.com (http://www.yasna.com)."
23  * Alternately, this acknowledgment may appear in the software itself,
24  * if and wherever such third-party acknowledgments normally appear.
25  *
26  * 4. The names "Yazd" and "Yasna.com" must not be used to
27  * endorse or promote products derived from this software without
28  * prior written permission. For written permission, please
29  * contact yazd@yasna.com.
30  *
31  * 5. Products derived from this software may not be called "Yazd",
32  * nor may "Yazd" appear in their name, without prior written
33  * permission of Yasna.com.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL YASNA.COM OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of Yasna.com. For more information
51  * on Yasna.com, please see <http://www.yasna.com>.
52  */

53
54 package com.Yasna.forum;
55
56 import java.util.Iterator JavaDoc;
57
58 /**
59  * Protection proxy for the Group interface. It restricts access of certain
60  * methods to those that have the proper permissions to administer this object.
61  */

62 public class GroupProxy implements Group {
63
64     /** Group object acting as proxy for. */
65     private Group group;
66     /** The authorization token used for gaining access to this proxy. */
67     private Authorization authorization;
68     /** The permissions for the group that correspond to the authorization. */
69     private ForumPermissions permissions;
70
71     public GroupProxy(Group group, Authorization authorization,
72             ForumPermissions permissions)
73     {
74         this.group = group;
75         this.authorization = authorization;
76         this.permissions = permissions;
77     }
78
79     public int getID() {
80         return group.getID();
81     }
82
83     public String JavaDoc getName() {
84         return group.getName();
85     }
86
87     public void setName(String JavaDoc name) throws UnauthorizedException {
88         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
89                 permissions.get(ForumPermissions.GROUP_ADMIN))
90         {
91             group.setName(name);
92         }
93         else {
94             throw new UnauthorizedException();
95         }
96     }
97        public boolean getAutoGroupMembership(){
98            return group.getAutoGroupMembership();
99        }
100     public void setAutoGroupMembership(boolean param) throws UnauthorizedException{
101         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
102                 permissions.get(ForumPermissions.GROUP_ADMIN))
103         {
104             group.setAutoGroupMembership(param);
105         }
106         else {
107             throw new UnauthorizedException();
108         }
109     }
110     public String JavaDoc getDescription() {
111         return group.getDescription();
112     }
113
114     public void setDescription(String JavaDoc description) throws UnauthorizedException
115     {
116         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
117                 permissions.get(ForumPermissions.GROUP_ADMIN))
118         {
119             group.setDescription(description);
120         }
121         else {
122             throw new UnauthorizedException();
123         }
124     }
125
126     public void addAdministrator(User user) throws UnauthorizedException {
127         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
128                 permissions.get(ForumPermissions.GROUP_ADMIN))
129         {
130             group.addAdministrator(user);
131         }
132         else {
133             throw new UnauthorizedException();
134         }
135     }
136
137     public void removeAdministrator(User user) throws UnauthorizedException {
138         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
139                 permissions.get(ForumPermissions.GROUP_ADMIN))
140         {
141             group.removeAdministrator(user);
142         }
143         else {
144             throw new UnauthorizedException();
145         }
146     }
147
148     public void addMember(User user) throws UnauthorizedException {
149         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
150                 permissions.get(ForumPermissions.GROUP_ADMIN))
151         {
152             group.addMember(user);
153         }
154         else {
155             throw new UnauthorizedException();
156         }
157     }
158
159     public void removeMember(User user) throws UnauthorizedException {
160         if (permissions.get(ForumPermissions.SYSTEM_ADMIN) ||
161                 permissions.get(ForumPermissions.GROUP_ADMIN))
162         {
163             group.removeMember(user);
164         }
165         else {
166             throw new UnauthorizedException();
167         }
168     }
169
170     public boolean isAdministrator(User user) {
171         return group.isAdministrator(user);
172     }
173
174     public boolean isMember(User user) {
175         return group.isMember(user);
176     }
177
178     public int getAdministratorCount() {
179         return group.getAdministratorCount();
180     }
181
182     public int getMemberCount() {
183         return group.getMemberCount();
184     }
185
186     public Iterator JavaDoc members() {
187         return group.members();
188     }
189
190     public Iterator JavaDoc administrators() {
191         return group.administrators();
192     }
193
194     public ForumPermissions getPermissions(Authorization authorization) {
195         return group.getPermissions(authorization);
196     }
197
198     public boolean hasPermission(int type) {
199         return permissions.get(type);
200     }
201 }
202
Popular Tags