001: /* ====================================================================
002: * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
003: *
004: * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by Jcorporate Ltd.
021: * (http://www.jcorporate.com/)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. "Jcorporate" and product names such as "Expresso" must
026: * not be used to endorse or promote products derived from this
027: * software without prior written permission. For written permission,
028: * please contact info@jcorporate.com.
029: *
030: * 5. Products derived from this software may not be called "Expresso",
031: * or other Jcorporate product names; nor may "Expresso" or other
032: * Jcorporate product names appear in their name, without prior
033: * written permission of Jcorporate Ltd.
034: *
035: * 6. No product derived from this software may compete in the same
036: * market space, i.e. framework, without prior written permission
037: * of Jcorporate Ltd. For written permission, please contact
038: * partners@jcorporate.com.
039: *
040: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
041: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
042: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
043: * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
044: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
045: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
046: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
047: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
048: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
049: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
050: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
051: * SUCH DAMAGE.
052: * ====================================================================
053: *
054: * This software consists of voluntary contributions made by many
055: * individuals on behalf of the Jcorporate Ltd. Contributions back
056: * to the project(s) are encouraged when you make modifications.
057: * Please send them to support@jcorporate.com. For more information
058: * on Jcorporate Ltd. and its products, please see
059: * <http://www.jcorporate.com/>.
060: *
061: * Portions of this software are based upon other open source
062: * products and are subject to their respective licenses.
063: */
064:
065: package com.jcorporate.expresso.services.dbobj;
066:
067: import com.jcorporate.expresso.core.controller.ControllerRequest;
068: import com.jcorporate.expresso.core.db.DBException;
069: import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
070: import com.jcorporate.expresso.core.dbobj.ValidValue;
071:
072: import java.util.Vector;
073:
074: /**
075: * This class associates each registration domain with one
076: * or more registration objects. Regsitration objects are
077: * DBObjects required for extended registration info
078: * beyond the absolute minimum required by the User/UserInfo
079: * classes.
080: * <p/>
081: * Creation date: (5/15/2001 12:26:11 PM)
082: *
083: * @author Shash Chatterjee
084: */
085: public class RegistrationObjectMap extends SecuredDBObject {
086: public static final String REG_DOMAIN_ID = "RegDomId";
087: public static final String REG_OBJ_CLASS = "RegObj";
088:
089: /**
090: * Default constructor
091: *
092: * @throws com.jcorporate.expresso.core.db.DBException
093: * The exception description.
094: */
095: public RegistrationObjectMap() throws DBException {
096: super ();
097: } /* RegistrationObjectMap() */
098:
099: /**
100: * Use over (String) constructor. Initializes the object in the context
101: * of the user who's uid belongs to the parameter.
102: *
103: * @param uid the Uid of the user context
104: * @throws DBException if there's an initialization problem
105: */
106: public RegistrationObjectMap(int uid) throws DBException {
107: super (uid);
108: }
109:
110: /**
111: * For using DBObjects within Controllers. Initializes based upon the current
112: * user and the requested db. [Of course this can be modified later]
113: *
114: * @param request - The controller request handed to you by the framework.
115: */
116: public RegistrationObjectMap(ControllerRequest request)
117: throws DBException {
118: super (request);
119: }
120:
121: /**
122: * Extends the usual add method to check for duplicate entires and to provide an unique id
123: *
124: * @throws DBException If the next number could not be allocated
125: * or the add fails
126: * @see com.jcorporate.expresso.core.dbobj.SecuredDBObject#add
127: */
128: public void add()
129: throws com.jcorporate.expresso.core.db.DBException {
130: if (getField("RecMin").equals("")) {
131: setField("RecMin", "1");
132: }
133: if (getField("RecMax").equals("")) {
134: setField("RecMax", "1");
135: }
136: if (getField("RegOrder").equals("")) {
137: setField("RegOrder", "999");
138: }
139: if (getField("AllowEdit").equals("")) {
140: setField("AllowEdit", "Y");
141: }
142: if (getField("AllowDel").equals("")) {
143: setField("AllowDel", "Y");
144: }
145:
146: super .add();
147: } /* add() */
148:
149: /**
150: * Extends the checkAllRefs method to check for valid UserGroup
151: * or if referential integrity is violated
152: *
153: * @throws DBException If there is a problem checking the integrity
154: */
155: protected void checkAllRefs() throws DBException {
156: checkRef("RegDomId", new RegistrationDomain(
157: SecuredDBObject.SYSTEM_ACCOUNT), "Invalid "
158: + getString(getMetaData().getDescription("RegDomId")));
159: } /* checkAllRefs() */
160:
161: /**
162: * Override the method getValidValues to provide specific values for our
163: * multi-valued fields
164: *
165: * @param fieldName Field name for which values are requested
166: * @return Vector The ValidValues field
167: * @throws DBException If the values cannot be retrieved
168: */
169: public Vector getValidValues(String fieldName) throws DBException {
170: if (fieldName.equals("AllowEdit")
171: || fieldName.equals("AllowDel")) {
172: Vector myValues = new Vector(2);
173: myValues.addElement(new ValidValue("Y", "Yes"));
174: myValues.addElement(new ValidValue("N", "No"));
175:
176: return myValues;
177: }
178:
179: return super .getValidValues(fieldName);
180: } /* getValidValues(String) */
181:
182: /**
183: * Method to set up the fields for this database object. This method should
184: * be defined in the implementing object and should make calls to addField,
185: * addKey, setMultiValued, etc. as required to define the content of
186: * the DBObject
187: *
188: * @throws DBException If there is an error setting up the fields
189: * as requested. For example, if a field allowing null is requested
190: * as part of the key
191: */
192: protected void setupFields() throws DBException {
193: setTargetTable("REGOBJMAP");
194: setDescription("DBregObjMap");
195: setCharset("ISO-8859-1");
196: addField(REG_DOMAIN_ID, "int", 0, false, "regDomId");
197: addField(REG_OBJ_CLASS, "varchar", 128, false, "regObjClass");
198: addField("UidField", "char", 10, false, "uidFieldName");
199: addField("RecMin", "int", 0, true, "minRecords");
200: addField("RecMax", "int", 0, true, "maxRecords");
201: addField("RegFields", "text", 0, true, "fieldsInAuto");
202: addField("RegOrder", "int", 0, true, "displayOrder");
203: addField("AllowEdit", "char", 1, true, "userCanEdit");
204: addField("AllowDel", "char", 1, true, "userCanDelete");
205: setStringFilter(REG_OBJ_CLASS, "stripFilter");
206: setMultiValued(REG_DOMAIN_ID);
207: setMultiValued("AllowEdit");
208: setMultiValued("AllowDel");
209: setLookupObject(REG_DOMAIN_ID, RegistrationDomain.class
210: .getName());
211: addKey(REG_DOMAIN_ID);
212: addKey(REG_OBJ_CLASS);
213: } /* setupFields() */
214:
215: public void update()
216: throws com.jcorporate.expresso.core.db.DBException {
217: if (getField("RecMin").equals("")) {
218: setField("RecMin", "1");
219: }
220: if (getField("RecMax").equals("")) {
221: setField("RecMax", "1");
222: }
223: if (getField("RegOrder").equals("")) {
224: setField("RegOrder", "999");
225: }
226: if (getField("AllowEdit").equals("")) {
227: setField("AllowEdit", "Y");
228: }
229: if (getField("AllowDel").equals("")) {
230: setField("AllowDel", "Y");
231: }
232:
233: super.update();
234: }
235: }
|