KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > acl > Profile


1 package de.webman.acl;
2
3 import com.teamkonzept.lib.ErrorCodes;
4 import com.teamkonzept.lib.TKException;
5 import com.teamkonzept.lib.TKVector;
6 import de.webman.acl.db.LoginDBData;
7 import com.teamkonzept.webman.mainint.events.TKUserException;
8 import com.teamkonzept.webman.mainint.events.UserCodes;
9
10 /**
11  * A profile is a group of users. It may have sub-profiles as well as a parent profile.
12  *
13  * @version 1.0
14  * @since 1.0
15  * @author © 2001 Webman AG
16  */

17 public class Profile
18     extends Login
19 {
20
21     // $Header: /cvsroot/webman-cms/source/webman/de/webman/acl/Profile.java,v 1.1 2001/08/20 08:25:07 mischa Exp $
22

23     // Constructors
24

25     /**
26      * Provide instantion only to package classes or subclasses.
27      *
28      * @param data the initial profile data.
29      */

30     protected Profile (LoginDBData data)
31     {
32         super(data);
33     }
34
35
36     // Method implementations
37

38     /**
39      * Returns the factory of the object.
40      *
41      * @return the factory of the object.
42      * @exception com.teamkonzept.lib.TKException if an error occured during factory retrieval.
43      */

44     public final ObjectFactory getFactory ()
45         throws TKException
46     {
47         return ProfileFactory.getInstance();
48     }
49
50     /**
51      * Checks wether this login object represents a user.
52      *
53      * @return <CODE>false</CODE>.
54      */

55     public final boolean isUser ()
56     {
57         return false;
58     }
59
60     /**
61      * Checks wether this login object represents a profile.
62      *
63      * @return <CODE>true</CODE>.
64      */

65     public final boolean isProfile ()
66     {
67         return true;
68     }
69
70     /**
71      * Checks wether this login object is a parent of the given login object.
72      *
73      * @param login the login object.
74      * @return <CODE>true</CODE> if this login object is a parent of the
75      * given login object, otherwise <CODE>false</CODE>.
76      * @exception com.teamkonzept.lib.TKException if an error occured during login retrieval.
77      */

78     public final boolean isParent (Login login)
79         throws TKException
80     {
81         // Check children.
82
if (hasChild(login))
83         {
84             return true;
85         }
86
87         // Check grandchildren.
88
TKVector children = getChildren();
89
90         if (children != null)
91         {
92             int index = 0;
93             int size = children.size();
94
95             while (index < size)
96             {
97                 if (((Login) children.elementAt(index)).isParent(login))
98                 {
99                     return true;
100                 }
101
102                 index++;
103             }
104         }
105
106         // No such child or grandchild.
107
return false;
108     }
109
110     /**
111      * Checks wether the given login is a member of this profile.
112      *
113      * @param login the login.
114      * @return <CODE>true</CODE> if the given login is a member of this profile,
115      * otherwise <CODE>false</CODE>.
116      * @exception com.teamkonzept.lib.TKException if an error occured during login retrieval.
117      * @deprecated
118      * @see #hasChild(Login)
119      */

120     public final boolean isMember (Login login)
121         throws TKException
122     {
123         return hasChild(login);
124     }
125
126     /**
127      * Returns all children logins.
128      *
129      * @return all children logins.
130      * @exception com.teamkonzept.lib.TKException if an error occured during login retrieval.
131      */

132     public final TKVector getChildren ()
133         throws TKException
134     {
135         return LoginFactory.getInstance().getObjects(super.getAssociations());
136     }
137
138     /**
139      * Associates the given child login with the profile.
140      *
141      * @param child the child login.
142      * @exception com.teamkonzept.lib.TKException if an error occured during login retrieval
143      * or the given child login is a parent of the profile.
144      */

145     public final void addChild (Login child)
146         throws TKException
147     {
148         // Perform self check.
149
if (child.equals(this))
150         {
151             throw new TKUserException("A group cannot contain itself.",
152                                       UserCodes.SELF_RELATION,
153                                       ErrorCodes.USER_SEVERITY,
154                                       true,
155                                       null);
156         }
157
158         // Perform cycle check.
159
if (child.isParent(this))
160         {
161             throw new TKUserException("The group '" +
162                                            child.getName() +
163                                            "' is already contains this group.",
164                                       UserCodes.CYCLIC_RELATION,
165                                       ErrorCodes.USER_SEVERITY,
166                                       true,
167                                       new Object JavaDoc[]{child.getName()},
168                                       null);
169         }
170
171         // Add child.
172
super.addAssociation(child);
173
174         // Notify child.
175
child.updatedParents();
176     }
177
178     /**
179      * Removes the association with the given child login.
180      *
181      * @param child the child login.
182      * @exception com.teamkonzept.lib.TKException if an error occured during login retrieval.
183      */

184     public final void removeChild (Login child)
185         throws TKException
186     {
187         // Remove child.
188
super.removeAssociation(child);
189
190         // Notify child.
191
child.updatedParents();
192     }
193
194     /**
195      * Removes the association with all children logins.
196      *
197      * @exception com.teamkonzept.lib.TKException if an error occured during login retrieval.
198      */

199     public final void removeChildren ()
200         throws TKException
201     {
202         // Get all children.
203
TKVector children = LoginFactory.getInstance().getObjects(super.getAssociations());
204
205         // Remove all children.
206
super.removeAssociations();
207
208         // Notify all children.
209
if (children != null)
210         {
211             int index = 0;
212             int size = children.size();
213
214             while (index < size)
215             {
216                 ((Login) children.elementAt(index++)).updatedParents();
217             }
218         }
219     }
220
221     /**
222      * Checks wether there is an association with the given child login.
223      *
224      * @param login the child login.
225      * @return <CODE>true</CODE> if there is an association with the
226      * given child login, otherwise <CODE>false</CODE>.
227      * @exception com.teamkonzept.lib.TKException if an error occured during login retrieval.
228      */

229     public final boolean hasChild (Login login)
230         throws TKException
231     {
232         return super.containsAssociation(login);
233     }
234
235 }
236
Popular Tags