KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > services > dbobj > GroupNest


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.services.dbobj;
66
67 import com.jcorporate.expresso.core.db.DBException;
68 import com.jcorporate.expresso.core.dbobj.RequestContext;
69 import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
70
71 import java.util.Iterator JavaDoc;
72
73
74 /**
75  * Group Nesting
76  *
77  * @author Michael Nash
78  * @version $Revision: 1.12 $ $Date: 2004/11/17 20:48:18 $
79  */

80 public class GroupNest
81         extends SecurityDBObject {
82
83     /**
84      * Field Names for the GROUPNEST table
85      */

86     public static final String JavaDoc FLD_GROUPNAME = "GroupName";
87     public static final String JavaDoc FLD_MEMBEROF = "MemberOf";
88
89     /**
90      * @see com.jcorporate.expresso.core.dbobj.SecuredDBObject
91      */

92     public GroupNest()
93             throws DBException {
94         super();
95     } /* GroupNest() */
96
97
98     /**
99      * @param uid the Expresso user id
100      * @throws DBException upon initialization error
101      */

102     public GroupNest(int uid)
103             throws DBException {
104         super(uid);
105     }
106
107     /**
108      * For using DBObjects within Controllers. Initializes based upon the current
109      * user and the requested db. [Of course this can be modified later]
110      *
111      * @param request - The controller request handed to you by the framework.
112      * @throws DBException upon initialization error
113      */

114     public GroupNest(RequestContext request)
115             throws DBException {
116         super(request);
117     }
118
119     /**
120      * Extend add to add all members of the "GroupName" group to the
121      * "MemberOf" group automatically
122      */

123     public void add()
124             throws DBException {
125         GroupMembers ml = new GroupMembers(SecuredDBObject.SYSTEM_ACCOUNT);
126         ml.setDataContext(getDataContext());
127
128         GroupMembers oneMember = null;
129         GroupMembers newMember = new GroupMembers(SecuredDBObject.SYSTEM_ACCOUNT);
130         newMember.setDataContext(getDataContext());
131         ml.setField(GroupMembers.GROUP_NAME, getField(FLD_GROUPNAME));
132
133         for (Iterator JavaDoc e = ml.searchAndRetrieveList().iterator(); e.hasNext();) {
134             oneMember = (GroupMembers) e.next();
135             newMember.clear();
136             newMember.setField(GroupMembers.EXPUID, oneMember.getField(GroupMembers.EXPUID));
137             newMember.setField(GroupMembers.GROUP_NAME, getField(FLD_MEMBEROF));
138
139             if (!newMember.find()) {
140                 newMember.add();
141             }
142         } /* for each member of the group */
143
144
145         super.add();
146     } /* add() */
147
148
149     /**
150      * Extends the checkAllRefs method to check for valid UserGroup
151      *
152      * @throws DBException If a referential integrity violation is found
153      */

154     protected void checkAllRefs()
155             throws DBException {
156         checkRef(FLD_GROUPNAME, new UserGroup(),
157                 "Invalid " + getString(getMetaData().getDescription(FLD_GROUPNAME)));
158         checkRef(FLD_MEMBEROF, new UserGroup(),
159                 "Invalid " + getString(getMetaData().getDescription(FLD_MEMBEROF)));
160     } /* checkAllRefs() */
161
162
163     /**
164      * Extend delete to remove all of the members of the "GroupName"
165      * group from the "MemberOf" group automatically
166      */

167     public void delete()
168             throws DBException {
169         GroupMembers ml = new GroupMembers(SecuredDBObject.SYSTEM_ACCOUNT);
170         ml.setDataContext(getDataContext());
171
172         GroupMembers oneMember = null;
173         GroupMembers newMember = new GroupMembers(SecuredDBObject.SYSTEM_ACCOUNT);
174         newMember.setDataContext(getDataContext());
175         ml.setField(GroupMembers.GROUP_NAME, getField(FLD_GROUPNAME));
176
177         for (Iterator JavaDoc e = ml.searchAndRetrieveList().iterator(); e.hasNext();) {
178             oneMember = (GroupMembers) e.next();
179             newMember.clear();
180             newMember.setField(GroupMembers.EXPUID, oneMember.getField(GroupMembers.EXPUID));
181             newMember.setField(GroupMembers.GROUP_NAME, getField(FLD_MEMBEROF));
182
183             if (newMember.find()) {
184                 newMember.delete();
185             }
186         } /* for each member of the group */
187
188
189         super.delete();
190     } /* delete() */
191
192
193     /**
194      * Set up the fields/tables for this object
195      */

196     protected synchronized void setupFields()
197             throws DBException {
198         setTargetTable("GROUPNEST");
199         setName("GROUPNEST");
200         setDescription("DBgroupNest");
201         setCharset("ISO-8859-1");
202         addField(FLD_GROUPNAME, "char", 10, false, "groupName");
203         addField(FLD_MEMBEROF, "char", 10, false, "memberOf");
204         addKey(FLD_GROUPNAME);
205         addKey(FLD_MEMBEROF);
206         setStringFilter(FLD_GROUPNAME, "stripFilter");
207         setStringFilter(FLD_MEMBEROF, "stripFilter");
208         setMultiValued(FLD_GROUPNAME);
209         setMultiValued(FLD_MEMBEROF);
210         setLookupObject(FLD_MEMBEROF,
211                 com.jcorporate.expresso.services.dbobj.UserGroup.class.getName());
212         setLookupObject(FLD_GROUPNAME,
213                 com.jcorporate.expresso.services.dbobj.UserGroup.class.getName());
214     } /* setupFields() */
215
216
217 } /* GroupNest */
218
219 /* GroupNest */
Popular Tags