001: package de.webman.acl;
002:
003: import com.teamkonzept.lib.ErrorCodes;
004: import com.teamkonzept.lib.TKException;
005: import com.teamkonzept.lib.TKVector;
006: import de.webman.acl.db.LoginDBData;
007: import com.teamkonzept.webman.mainint.events.TKUserException;
008: import com.teamkonzept.webman.mainint.events.UserCodes;
009:
010: /**
011: * A profile is a group of users. It may have sub-profiles as well as a parent profile.
012: *
013: * @version 1.0
014: * @since 1.0
015: * @author © 2001 Webman AG
016: */
017: public class Profile extends Login {
018:
019: // $Header: /cvsroot/webman-cms/source/webman/de/webman/acl/Profile.java,v 1.1 2001/08/20 08:25:07 mischa Exp $
020:
021: // Constructors
022:
023: /**
024: * Provide instantion only to package classes or subclasses.
025: *
026: * @param data the initial profile data.
027: */
028: protected Profile(LoginDBData data) {
029: super (data);
030: }
031:
032: // Method implementations
033:
034: /**
035: * Returns the factory of the object.
036: *
037: * @return the factory of the object.
038: * @exception com.teamkonzept.lib.TKException if an error occured during factory retrieval.
039: */
040: public final ObjectFactory getFactory() throws TKException {
041: return ProfileFactory.getInstance();
042: }
043:
044: /**
045: * Checks wether this login object represents a user.
046: *
047: * @return <CODE>false</CODE>.
048: */
049: public final boolean isUser() {
050: return false;
051: }
052:
053: /**
054: * Checks wether this login object represents a profile.
055: *
056: * @return <CODE>true</CODE>.
057: */
058: public final boolean isProfile() {
059: return true;
060: }
061:
062: /**
063: * Checks wether this login object is a parent of the given login object.
064: *
065: * @param login the login object.
066: * @return <CODE>true</CODE> if this login object is a parent of the
067: * given login object, otherwise <CODE>false</CODE>.
068: * @exception com.teamkonzept.lib.TKException if an error occured during login retrieval.
069: */
070: public final boolean isParent(Login login) throws TKException {
071: // Check children.
072: if (hasChild(login)) {
073: return true;
074: }
075:
076: // Check grandchildren.
077: TKVector children = getChildren();
078:
079: if (children != null) {
080: int index = 0;
081: int size = children.size();
082:
083: while (index < size) {
084: if (((Login) children.elementAt(index)).isParent(login)) {
085: return true;
086: }
087:
088: index++;
089: }
090: }
091:
092: // No such child or grandchild.
093: return false;
094: }
095:
096: /**
097: * Checks wether the given login is a member of this profile.
098: *
099: * @param login the login.
100: * @return <CODE>true</CODE> if the given login is a member of this profile,
101: * otherwise <CODE>false</CODE>.
102: * @exception com.teamkonzept.lib.TKException if an error occured during login retrieval.
103: * @deprecated
104: * @see #hasChild(Login)
105: */
106: public final boolean isMember(Login login) throws TKException {
107: return hasChild(login);
108: }
109:
110: /**
111: * Returns all children logins.
112: *
113: * @return all children logins.
114: * @exception com.teamkonzept.lib.TKException if an error occured during login retrieval.
115: */
116: public final TKVector getChildren() throws TKException {
117: return LoginFactory.getInstance().getObjects(
118: super .getAssociations());
119: }
120:
121: /**
122: * Associates the given child login with the profile.
123: *
124: * @param child the child login.
125: * @exception com.teamkonzept.lib.TKException if an error occured during login retrieval
126: * or the given child login is a parent of the profile.
127: */
128: public final void addChild(Login child) throws TKException {
129: // Perform self check.
130: if (child.equals(this )) {
131: throw new TKUserException("A group cannot contain itself.",
132: UserCodes.SELF_RELATION, ErrorCodes.USER_SEVERITY,
133: true, null);
134: }
135:
136: // Perform cycle check.
137: if (child.isParent(this )) {
138: throw new TKUserException("The group '" + child.getName()
139: + "' is already contains this group.",
140: UserCodes.CYCLIC_RELATION,
141: ErrorCodes.USER_SEVERITY, true,
142: new Object[] { child.getName() }, null);
143: }
144:
145: // Add child.
146: super .addAssociation(child);
147:
148: // Notify child.
149: child.updatedParents();
150: }
151:
152: /**
153: * Removes the association with the given child login.
154: *
155: * @param child the child login.
156: * @exception com.teamkonzept.lib.TKException if an error occured during login retrieval.
157: */
158: public final void removeChild(Login child) throws TKException {
159: // Remove child.
160: super .removeAssociation(child);
161:
162: // Notify child.
163: child.updatedParents();
164: }
165:
166: /**
167: * Removes the association with all children logins.
168: *
169: * @exception com.teamkonzept.lib.TKException if an error occured during login retrieval.
170: */
171: public final void removeChildren() throws TKException {
172: // Get all children.
173: TKVector children = LoginFactory.getInstance().getObjects(
174: super .getAssociations());
175:
176: // Remove all children.
177: super .removeAssociations();
178:
179: // Notify all children.
180: if (children != null) {
181: int index = 0;
182: int size = children.size();
183:
184: while (index < size) {
185: ((Login) children.elementAt(index++)).updatedParents();
186: }
187: }
188: }
189:
190: /**
191: * Checks wether there is an association with the given child login.
192: *
193: * @param login the child login.
194: * @return <CODE>true</CODE> if there is an association with the
195: * given child login, otherwise <CODE>false</CODE>.
196: * @exception com.teamkonzept.lib.TKException if an error occured during login retrieval.
197: */
198: public final boolean hasChild(Login login) throws TKException {
199: return super.containsAssociation(login);
200: }
201:
202: }
|