[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/utils DB.java,1.5,1.6 ObjectStore.java,1.5,1.6
Brought to you by:
bigman921
|
From: Marc B. <big...@us...> - 2002-03-23 04:48:31
|
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/utils In directory usw-pr-cvs1:/tmp/cvs-serv12732/src/net/sourceforge/idrs/utils Modified Files: DB.java ObjectStore.java Log Message: Added setprops tag Index: DB.java =================================================================== RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/utils/DB.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DB.java 1 Feb 2002 01:34:27 -0000 1.5 --- DB.java 23 Mar 2002 04:48:28 -0000 1.6 *************** *** 1,4 **** --- 1,15 ---- package net.sourceforge.idrs.utils; + /* + DB.java + Copyright (C) 2001 Marc Boorshtein + + The contents of this file are subject to the Mozilla Public License Version 1.0 (the License); + you may not use this file except in compliance with the License. You may obtain a copy of the + License at http://www.mozilla.org/MPL/ [...1615 lines suppressed...] ! if (this.cache == null) { ! this.cache = new DbCache(rows); ! } ! ! cache.setRows(rows); ! cache.setPosition(this.cursurLocation); ! ! return cache; ! } ! ! public void setCache(DbCache cache) { ! this.cursur = DB.CLIENT; ! this.cache = cache; ! this.cursurLocation = cache.getPosition(); ! this.rows = cache.getRows(); ! this.beginWith = this.cursurLocation; ! this.wasCached = true; } } Index: ObjectStore.java =================================================================== RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/utils/ObjectStore.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ObjectStore.java 4 Mar 2002 23:05:35 -0000 1.5 --- ObjectStore.java 23 Mar 2002 04:48:28 -0000 1.6 *************** *** 1,12 **** package net.sourceforge.idrs.utils; import java.util.*; import java.sql.*; import java.lang.reflect.*; import net.sourceforge.idrs.script.IDRSScript; import java.io.*; /** * ObjectStore.java - * Copyright (C) 2000 Marc Boorshtein under the GNU General Public License offered - * without warenty */ public final class ObjectStore implements Serializable { --- 1,23 ---- + /* + ObjectStore.java + Copyright (C) 2001 Marc Boorshtein + + The contents of this file are subject to the Mozilla Public License Version 1.0 (the License); + you may not use this file except in compliance with the License. You may obtain a copy of the + License at http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" basis, + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific + language governing rights and limitations under the License. + */ package net.sourceforge.idrs.utils; import java.util.*; import java.sql.*; import java.lang.reflect.*; + import javax.servlet.http.HttpServletRequest; import net.sourceforge.idrs.script.IDRSScript; import java.io.*; /** * ObjectStore.java */ public final class ObjectStore implements Serializable { *************** *** 16,23 **** protected Class cls; protected String id; ! protected transient Vector bmethodNames; protected transient Vector bmethodClasses; protected String[] methodNames; protected Class[][] methodClasses; --- 27,36 ---- protected Class cls; protected String id; ! protected boolean setProps; protected transient Vector bmethodNames; protected transient Vector bmethodClasses; + protected String[] propNames; + protected transient Method[] props; protected String[] methodNames; protected Class[][] methodClasses; *************** *** 182,185 **** --- 195,201 ---- */ public void rebuild(Object[] vals) throws Exception { + Class objClass; + Class[] propArgs = new Class[1]; + propArgs[0] = "".getClass(); this.methods=new HashMap(); *************** *** 202,205 **** --- 218,232 ---- addMethod((String) methodNames[i],methodClasses[i]); } + + objClass = obj.getClass(); + + if (this.setProps) { + this.props = new Method[propNames.length]; + for (i=0;i<propNames.length;i++) { + props[i] = objClass.getMethod(propNames[i],propArgs); + } + } + + } catch (Exception e) { *************** *** 275,278 **** --- 302,364 ---- } + } + + /** + *Retrieves all method names of Java Bean properties + *@param retrieve Will properties be autimaticly set? + */ + public void retrieveProps(boolean retrieve) { + LinkedList props = new LinkedList(); + Method[] meths; + String name; + Class argClass; + int numArgs; + + if (retrieve) { + this.setProps = true; + meths = obj.getClass().getMethods(); + + for (int i=0;i<meths.length;i++) { + name = meths[i].getName(); + numArgs = meths[i].getParameterTypes().length; + if (numArgs == 1) { + argClass = meths[i].getParameterTypes()[0]; + if (name.substring(0,3).equalsIgnoreCase("set") && argClass.equals("".getClass())) { + props.add(meths[i].getName()); + } + } + } + + this.propNames = new String[props.size()]; + System.arraycopy(props.toArray(),0,this.propNames,0,this.propNames.length); + } + else { + this.setProps = false; + } + } + + /** + *Sets all properties<br> + *All property values must have the name objId-prop_propName + *@param req The current request + */ + public void setProps(HttpServletRequest req) throws Exception { + StringBuffer buf = new StringBuffer(); + String[] args = new String[1]; + for (int i=0,m=this.propNames.length;i<m;i++) { + buf.setLength(0); + buf.append(this.id).append('-').append("prop").append('_').append(propNames[i].substring(3)); + args[0] = req.getParameter(buf.toString()); + props[i].invoke(this.obj,args); + } + + } + + /** + *Determines if props are to be set + *@return true If properties are being set + */ + public boolean setProps() { + return this.setProps; } |