KickJava   Java API By Example, From Geeks To Geeks.

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


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.controller.ControllerRequest;
68 import com.jcorporate.expresso.core.db.DBException;
69 import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
70 import com.jcorporate.expresso.core.dbobj.ValidValue;
71
72 import java.util.Vector JavaDoc;
73
74
75 /**
76  * This class associates each registration domain with one
77  * or more registration objects. Regsitration objects are
78  * DBObjects required for extended registration info
79  * beyond the absolute minimum required by the User/UserInfo
80  * classes.
81  * <p/>
82  * Creation date: (5/15/2001 12:26:11 PM)
83  *
84  * @author Shash Chatterjee
85  */

86 public class RegistrationObjectMap
87         extends SecuredDBObject {
88     public static final String JavaDoc REG_DOMAIN_ID = "RegDomId";
89     public static final String JavaDoc REG_OBJ_CLASS = "RegObj";
90
91     /**
92      * Default constructor
93      *
94      * @throws com.jcorporate.expresso.core.db.DBException
95      * The exception description.
96      */

97     public RegistrationObjectMap()
98             throws DBException {
99         super();
100     } /* RegistrationObjectMap() */
101
102
103     /**
104      * Use over (String) constructor. Initializes the object in the context
105      * of the user who's uid belongs to the parameter.
106      *
107      * @param uid the Uid of the user context
108      * @throws DBException if there's an initialization problem
109      */

110     public RegistrationObjectMap(int uid)
111             throws DBException {
112         super(uid);
113     }
114
115     /**
116      * For using DBObjects within Controllers. Initializes based upon the current
117      * user and the requested db. [Of course this can be modified later]
118      *
119      * @param request - The controller request handed to you by the framework.
120      */

121     public RegistrationObjectMap(ControllerRequest request)
122             throws DBException {
123         super(request);
124     }
125
126     /**
127      * Extends the usual add method to check for duplicate entires and to provide an unique id
128      *
129      * @throws DBException If the next number could not be allocated
130      * or the add fails
131      * @see com.jcorporate.expresso.core.dbobj.SecuredDBObject#add
132      */

133     public void add()
134             throws com.jcorporate.expresso.core.db.DBException {
135         if (getField("RecMin").equals("")) {
136             setField("RecMin", "1");
137         }
138         if (getField("RecMax").equals("")) {
139             setField("RecMax", "1");
140         }
141         if (getField("RegOrder").equals("")) {
142             setField("RegOrder", "999");
143         }
144         if (getField("AllowEdit").equals("")) {
145             setField("AllowEdit", "Y");
146         }
147         if (getField("AllowDel").equals("")) {
148             setField("AllowDel", "Y");
149         }
150
151         super.add();
152     } /* add() */
153
154
155     /**
156      * Extends the checkAllRefs method to check for valid UserGroup
157      * or if referential integrity is violated
158      *
159      * @throws DBException If there is a problem checking the integrity
160      */

161     protected void checkAllRefs()
162             throws DBException {
163         checkRef("RegDomId",
164                 new RegistrationDomain(SecuredDBObject.SYSTEM_ACCOUNT),
165                 "Invalid " + getString(getMetaData().getDescription("RegDomId")));
166     } /* checkAllRefs() */
167
168
169     /**
170      * Override the method getValidValues to provide specific values for our
171      * multi-valued fields
172      *
173      * @param fieldName Field name for which values are requested
174      * @return Vector The ValidValues field
175      * @throws DBException If the values cannot be retrieved
176      */

177     public Vector JavaDoc getValidValues(String JavaDoc fieldName)
178             throws DBException {
179         if (fieldName.equals("AllowEdit") || fieldName.equals("AllowDel")) {
180             Vector JavaDoc myValues = new Vector JavaDoc(2);
181             myValues.addElement(new ValidValue("Y", "Yes"));
182             myValues.addElement(new ValidValue("N", "No"));
183
184             return myValues;
185         }
186
187         return super.getValidValues(fieldName);
188     } /* getValidValues(String) */
189
190
191     /**
192      * Method to set up the fields for this database object. This method should
193      * be defined in the implementing object and should make calls to addField,
194      * addKey, setMultiValued, etc. as required to define the content of
195      * the DBObject
196      *
197      * @throws DBException If there is an error setting up the fields
198      * as requested. For example, if a field allowing null is requested
199      * as part of the key
200      */

201     protected void setupFields()
202             throws DBException {
203         setTargetTable("REGOBJMAP");
204         setDescription("DBregObjMap");
205         setCharset("ISO-8859-1");
206         addField(REG_DOMAIN_ID, "int", 0, false, "regDomId");
207         addField(REG_OBJ_CLASS, "varchar", 128, false, "regObjClass");
208         addField("UidField", "char", 10, false, "uidFieldName");
209         addField("RecMin", "int", 0, true, "minRecords");
210         addField("RecMax", "int", 0, true, "maxRecords");
211         addField("RegFields", "text", 0, true, "fieldsInAuto");
212         addField("RegOrder", "int", 0, true, "displayOrder");
213         addField("AllowEdit", "char", 1, true, "userCanEdit");
214         addField("AllowDel", "char", 1, true, "userCanDelete");
215         setStringFilter(REG_OBJ_CLASS, "stripFilter");
216         setMultiValued(REG_DOMAIN_ID);
217         setMultiValued("AllowEdit");
218         setMultiValued("AllowDel");
219         setLookupObject(REG_DOMAIN_ID, RegistrationDomain.class.getName());
220         addKey(REG_DOMAIN_ID);
221         addKey(REG_OBJ_CLASS);
222     } /* setupFields() */
223
224
225     public void update()
226             throws com.jcorporate.expresso.core.db.DBException {
227         if (getField("RecMin").equals("")) {
228             setField("RecMin", "1");
229         }
230         if (getField("RecMax").equals("")) {
231             setField("RecMax", "1");
232         }
233         if (getField("RegOrder").equals("")) {
234             setField("RegOrder", "999");
235         }
236         if (getField("AllowEdit").equals("")) {
237             setField("AllowEdit", "Y");
238         }
239         if (getField("AllowDel").equals("")) {
240             setField("AllowDel", "Y");
241         }
242
243         super.update();
244     }
245 }
Popular Tags