KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > file > CmsGroup


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/file/CmsGroup.java,v $
3  * Date : $Date: 2006/07/20 13:46:39 $
4  * Version: $Revision: 1.21 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.file;
33
34 import org.opencms.main.OpenCms;
35 import org.opencms.security.CmsPrincipal;
36 import org.opencms.security.I_CmsPrincipal;
37 import org.opencms.util.CmsUUID;
38
39 /**
40  * A group principal in the OpenCms permission system.<p>
41  *
42  * @author Alexander Kandzior
43  * @author Michael Emmerich
44  *
45  * @version $Revision: 1.21 $
46  *
47  * @since 6.0.0
48  *
49  * @see CmsUser
50  */

51 public class CmsGroup extends CmsPrincipal implements I_CmsPrincipal {
52
53     /** The parent id of the group. */
54     private CmsUUID m_parentId;
55
56     /**
57      * Creates a new, empty OpenCms group principal.
58      */

59     public CmsGroup() {
60
61         // noop
62
}
63
64     /**
65      * Creates a new OpenCms group principal.
66      *
67      * @param id the unique id of the group
68      * @param parentId the is of the parent group
69      * @param name the name of the group
70      * @param description the description of the group
71      * @param flags the flags of the group
72      */

73     public CmsGroup(CmsUUID id, CmsUUID parentId, String JavaDoc name, String JavaDoc description, int flags) {
74
75         m_id = id;
76         m_name = name;
77         m_description = description;
78         m_flags = flags;
79         m_parentId = parentId;
80     }
81
82     /**
83      * Checks if the provided group name is valid and can be used as an argument value
84      * for {@link #setName(String)}.<p>
85      *
86      * A group name must not be empty or whitespace only.<p>
87      *
88      * @param name the group name to check
89      *
90      * @see org.opencms.security.I_CmsValidationHandler#checkGroupName(String)
91      */

92     public void checkName(String JavaDoc name) {
93
94         OpenCms.getValidationHandler().checkGroupName(name);
95     }
96
97     /**
98      * @see java.lang.Object#clone()
99      */

100     public Object JavaDoc clone() {
101
102         return new CmsGroup(m_id, m_parentId, m_name, m_description, m_flags);
103     }
104
105     /**
106      * Returns true if this group is disabled.<p>
107      *
108      * @return true if this group is disabled
109      *
110      * @deprecated use {@link CmsPrincipal#isEnabled()} instead
111      */

112     public boolean getDisabled() {
113
114         return !isEnabled();
115     }
116
117     /**
118      * Returns the parent group id of this group.<p>
119      *
120      * @return the parent group id of this group
121      */

122     public CmsUUID getParentId() {
123
124         return m_parentId;
125     }
126
127     /**
128      * Returns <code>true</code> if this group is enabled as a project user group.<p>
129      *
130      * @return <code>true</code> if this group is enabled as a project user group
131      */

132     public boolean getProjectCoWorker() {
133
134         return (getFlags() & I_CmsPrincipal.FLAG_GROUP_PROJECT_USER) == I_CmsPrincipal.FLAG_GROUP_PROJECT_USER;
135     }
136
137     /**
138      * Returns <code>true</code> if this group is enabled as a project manager group.<p>
139      *
140      * @return <code>true</code> if this group is enabled as a project manager group
141      */

142     public boolean getProjectManager() {
143
144         return (getFlags() & I_CmsPrincipal.FLAG_GROUP_PROJECT_MANAGER) == I_CmsPrincipal.FLAG_GROUP_PROJECT_MANAGER;
145     }
146
147     /**
148      * Returns <code>true</code> if this group is enabled as a role for tasks.<p>
149      *
150      * @return <code>true</code> if this group is enabled as a role for tasks
151      */

152     public boolean getRole() {
153
154         return (getFlags() & I_CmsPrincipal.FLAG_GROUP_WORKFLOW_ROLE) == I_CmsPrincipal.FLAG_GROUP_WORKFLOW_ROLE;
155     }
156
157     /**
158      * @see org.opencms.security.I_CmsPrincipal#isGroup()
159      */

160     public boolean isGroup() {
161
162         return true;
163     }
164
165     /**
166      * @see org.opencms.security.I_CmsPrincipal#isUser()
167      */

168     public boolean isUser() {
169
170         return false;
171     }
172
173     /**
174      * Disables this group.<p>
175      *
176      * @deprecated use {@link CmsPrincipal#setEnabled(boolean)} instead
177      */

178     public void setDisabled() {
179
180         setEnabled(false);
181     }
182
183     /**
184      * Enables this group.<p>
185      *
186      * @deprecated use {@link CmsPrincipal#setEnabled(boolean)} instead
187      */

188     public void setEnabled() {
189
190         setEnabled(true);
191     }
192
193     /**
194      * Sets the parent group id of this group.<p>
195      *
196      * @param parentId the parent group id to set
197      */

198     public void setParentId(CmsUUID parentId) {
199
200         m_parentId = parentId;
201     }
202
203     /**
204      * Sets the project user flag for this group to the given value.<p>
205      *
206      * @param value the value to set
207      */

208     public void setProjectCoWorker(boolean value) {
209
210         if (getProjectCoWorker() != value) {
211             setFlags(getFlags() ^ I_CmsPrincipal.FLAG_GROUP_PROJECT_USER);
212         }
213     }
214
215     /**
216      * Sets the project manager flag for this group to the given value.<p>
217      *
218      * @param value the value to set
219      */

220     public void setProjectManager(boolean value) {
221
222         if (getProjectManager() != value) {
223             setFlags(getFlags() ^ I_CmsPrincipal.FLAG_GROUP_PROJECT_MANAGER);
224         }
225     }
226
227     /**
228      * Sets the "role for tasks" flag for this group to the given value.<p>
229      *
230      * @param value the value to set
231      */

232     public void setRole(boolean value) {
233
234         if (getRole() != value) {
235             setFlags(getFlags() ^ I_CmsPrincipal.FLAG_GROUP_WORKFLOW_ROLE);
236         }
237     }
238
239     /**
240      * @see java.lang.Object#toString()
241      */

242     public String JavaDoc toString() {
243
244         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
245         result.append("[Group]");
246         result.append(" name:");
247         result.append(m_name);
248         result.append(" id:");
249         result.append(m_id);
250         result.append(" description:");
251         result.append(m_description);
252         return result.toString();
253     }
254 }
Popular Tags