[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/utils Validators.java,1.2,1.3 ObjectStore.java,
Brought to you by:
bigman921
|
From: Marc B. <big...@us...> - 2003-01-08 06:02:08
|
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/utils
In directory sc8-pr-cvs1:/tmp/cvs-serv32140/dev/src/net/sourceforge/idrs/utils
Modified Files:
Validators.java ObjectStore.java
Removed Files:
RSMetaData.class DB.class CleanUp.class RequestWrapper.class
ReqAttr.class RS.class Application.class UserInfo.class
IDRSPrinter.class ObjectStore.class ReqReq.class
Log Message:
Added new validation capabilities, and all idrs object are given access to the idrs script oject without it being passed in as a parameter. Also fixed a security bug and setup for more memory effecient pooling. Finally add a new configuration file to simplify deployments.
Index: Validators.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/utils/Validators.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Validators.java 29 Dec 2002 04:39:08 -0000 1.2
--- Validators.java 8 Jan 2003 06:01:00 -0000 1.3
***************
*** 111,113 ****
--- 111,157 ----
return -1;
}
+
+
+ /**
+ *Function for determining if a value has been given and is an Integer.
+ *If no value has been given (null or empty), or the value given is not an integer then an error is created.
+ *@param name The Name of the field
+ *@param val The value to be tested
+ */
+ protected int parseValInt(String name, String val, int def) {
+ try {
+
+ int tmp = val != null && val.trim().length() != 0 ? Integer.parseInt(val) : def;
+ if (tmp != 0) {
+ return tmp;
+ }
+ else {
+ idrs.createError("The " + name + " is required");
+ }
+
+
+ }
+ catch (Exception e) {
+ idrs.createError("The " + name + " " + e.toString());
+ }
+
+ return -1;
+ }
+
+ /**
+ *Function for determining if a value has been given and is a non zero Integer.
+ *If no value has been given (null or empty), or the value given is not a non zero integer then an error is created.
+ *@param name The Name of the field
+ *@param val The value to be tested
+ */
+ protected int parseValIntZero(String name, String val,int def) {
+ try {
+ return val != null && val.trim().length() != 0 ? Integer.parseInt(val) : def;
+ }
+ catch (Exception e) {
+ idrs.createError("The " + name + " " + e.toString());
+ }
+
+ return -1;
+ }
}
Index: ObjectStore.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/utils/ObjectStore.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** ObjectStore.java 22 Nov 2002 07:16:24 -0000 1.7
--- ObjectStore.java 8 Jan 2003 06:01:01 -0000 1.8
***************
*** 1,353 ****
! /*
! 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 {
! protected transient HashMap methods;
! protected Object obj;
! protected String className;
! 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;
! protected Class[] varTypes;
! protected transient boolean addToMethVec = false;
! transient boolean sealed;
! static final long serialVersionUID = 3570053539799841110L;
! /**
! * Creates an ObjectStore based on an Id and a classname
! */
! public ObjectStore(String id, String className) {
! methods=new HashMap();
! this.id = id;
! this.className = className;
! try {
! cls = Class.forName(className);
! }
! catch (Exception e) {
! e.printStackTrace();
! }
! sealed = false;
! addToMethVec = false;
! }
!
! /**
! * Creates a ObjectStore based on an ID
! */
! public ObjectStore(String id) {
! this.id = id;
! addToMethVec = false;
! sealed=false;
! }
!
! /**
! * Loads given class
! */
! public void setClassName(String clsName) throws Exception {
! this.className = clsName;
! try {
! cls = Class.forName(className);
! }
! catch (Exception e) {
! throw new Exception("Class : " + clsName + " is not a vaild class");
! }
! /*
! Method[] meths = cls.getMethods();
!
! int i;
! Method meth;
! for (i = 0;i < meths.length;i++) {
! meth = meths[i];
! }
! */
! }
!
! /**
! * Loads given method for use
! */
! public void addMethod(String methodName, Class[] argsT) throws Exception {
! //Method[] meths = cls.getMethods();
! int i;
! Method meth;
!
!
!
!
! meth = cls.getMethod(methodName,argsT);
! //Class[] clss = meth.getParameterTypes();
! //clss = argTypes;
!
!
! methods.put(methodName,meth);
! if (addToMethVec) {
! bmethodNames.addElement(methodName);
! bmethodClasses.addElement(argsT);
! }
! }
!
! /**
! * Returns the class' of a given methods arguments
! */
! public Class[] getMethodTypes(String method) {
!
!
! Method meth = (Method) this.methods.get(method);
!
!
! Class[] clss = meth.getParameterTypes();
!
! return clss;
! }
!
! /**
! * Executes a given method with given arguments
! */
! public Object execMethod(String methodName, Object[] vals) throws Exception {
! Object retVal;
!
!
! retVal = ((Method) methods.get(methodName)).invoke(obj,vals);
!
!
! return retVal;
!
! }
!
! /**
! * Calls the constructor matching the artypes
! */
! public void initiate(Class[] argTypes, Object[] args) throws Exception {
!
! try {
!
! Constructor con = this.cls.getConstructor(argTypes);
! obj = con.newInstance(args);
!
!
! }
! catch (Exception e) {
! throw new Exception("No Matching Constructor");
! }
! }
!
! /**
! * Used to return a valid class for the ObjectStore
! */
! public static Object getValue(Class cls, String val,Connection con,IDRSScript idrs) throws Exception {
! val = val.trim();
! if (cls == String.class) {
! return val;
! }
! else if (cls == Integer.class) {
! return new Integer(val);
! }
! else if (cls == Float.class) {
! return new Float(val);
! }
! else if (cls == java.sql.Date.class) {
! return new java.sql.Date(java.sql.Date.parse(val));
! }
! else if (cls == java.sql.Time.class) {
! return new java.sql.Time(java.sql.Time.parse(val));
! }
! else if (cls == java.sql.Connection.class) {
! return con;
! }
! else if (cls == IDRSScript.class) {
! return idrs;
! }
! else
! throw new Exception(cls.toString() + " not a valid class for the ObjectStore");
!
! }
!
! public Object getRef() throws Exception {
! return obj;
! }
!
! //used for new IDRS
! /**
! Used for rebuilding and object after serialization when a report is called
! */
! public void rebuild(Object[] vals) throws Exception {
! Class objClass;
! Class[] propArgs = new Class[1];
! propArgs[0] = "".getClass();
!
! this.methods=new HashMap();
!
! Method init = cls.getMethod("reInit",this.varTypes);
! if (init == null) {
! throw new Exception("No init method");
! }
!
! try {
! init.invoke(obj,vals);
!
! int i;
!
! addToMethVec = false;
!
! for (i=0;i<methodNames.length;i++) {
!
!
! 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) {
! throw new Exception("No init method");
! }
! }
!
! /**
! Used for first initialization of object for empty constructor
! */
! public void firstInitiate(Class[] argTypes) throws Exception {
! try {
! obj = cls.newInstance();
! }
! catch (Exception noCon) {
! throw new Exception("No default constructor");
! }
!
!
!
! this.varTypes = argTypes;
! //System.out.println("Argtypes Size: " + this.varTypes.length);
!
! bmethodNames = new Vector();
! bmethodClasses = new Vector();
! addToMethVec = true;
! methods = new HashMap();
! }
!
! public Class[] getTypes() {
! return this.varTypes;
! }
!
!
!
! public String getID() {
! return id;
! }
!
! public void close() throws Exception {
! //methods.clear();
! if (obj instanceof net.sourceforge.idrs.utils.CleanUp)
! ((CleanUp) obj).cleanUp();
! }
!
! /**
! "Seals" the ObjectStore moving all vector data into arrays
! */
! public int seal() {
! if (! sealed) {
!
! methodNames = new String[bmethodNames.size()];
! methodClasses = new Class[bmethodClasses.size()][];
! int i;
!
!
!
! for (i = 0;i<methodNames.length;i++) {
! methodNames[i] = (String) bmethodNames.elementAt(i);
! methodClasses[i] = (Class[]) bmethodClasses.elementAt(i);
! }
!
! bmethodNames.removeAllElements();
! bmethodClasses.removeAllElements();
! sealed = true;
! }
!
! if (this.varTypes.length > 0) {
! return methodNames.length + 1;
! }
! else {
! return methodNames.length;
! }
!
! }
!
! /**
! *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()) || argClass.equals(String[].class))) {
! 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];
String[] vals;
! 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());
--- 1,358 ----
! /*
! 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 {
! protected transient HashMap methods;
! protected Object obj;
! protected String className;
! 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;
! protected Class[] varTypes;
! protected transient boolean addToMethVec = false;
! transient boolean sealed;
! static final long serialVersionUID = 3570053539799841110L;
!
! transient IDRSScript idrs;
!
! /**
! * Creates an ObjectStore based on an Id and a classname
! */
! public ObjectStore(String id, String className) {
! methods=new HashMap();
! this.id = id;
! this.className = className;
! try {
! cls = Class.forName(className);
! }
! catch (Exception e) {
! e.printStackTrace();
! }
! sealed = false;
! addToMethVec = false;
! }
!
! /**
! * Creates a ObjectStore based on an ID
! */
! public ObjectStore(String id) {
! this.id = id;
! addToMethVec = false;
! sealed=false;
! }
!
! /**
! * Loads given class
! */
! public void setClassName(String clsName) throws Exception {
! this.className = clsName;
! try {
! cls = Class.forName(className);
! }
! catch (Exception e) {
! throw new Exception("Class : " + clsName + " is not a vaild class");
! }
! /*
! Method[] meths = cls.getMethods();
!
! int i;
! Method meth;
! for (i = 0;i < meths.length;i++) {
! meth = meths[i];
! }
! */
! }
!
! /**
! * Loads given method for use
! */
! public void addMethod(String methodName, Class[] argsT) throws Exception {
! //Method[] meths = cls.getMethods();
! int i;
! Method meth;
!
!
!
!
! meth = cls.getMethod(methodName,argsT);
! //Class[] clss = meth.getParameterTypes();
! //clss = argTypes;
!
!
! methods.put(methodName,meth);
! if (addToMethVec) {
! bmethodNames.addElement(methodName);
! bmethodClasses.addElement(argsT);
! }
! }
!
! /**
! * Returns the class' of a given methods arguments
! */
! public Class[] getMethodTypes(String method) {
!
!
! Method meth = (Method) this.methods.get(method);
!
!
! Class[] clss = meth.getParameterTypes();
!
! return clss;
! }
!
! /**
! * Executes a given method with given arguments
! */
! public Object execMethod(String methodName, Object[] vals) throws Exception {
! Object retVal;
!
!
! retVal = ((Method) methods.get(methodName)).invoke(obj,vals);
!
!
! return retVal;
!
! }
!
! /**
! * Calls the constructor matching the artypes
! */
! public void initiate(Class[] argTypes, Object[] args) throws Exception {
!
! try {
!
! Constructor con = this.cls.getConstructor(argTypes);
! obj = con.newInstance(args);
!
!
! }
! catch (Exception e) {
! throw new Exception("No Matching Constructor");
! }
! }
!
! /**
! * Used to return a valid class for the ObjectStore
! */
! public static Object getValue(Class cls, String val,Connection con,IDRSScript idrs) throws Exception {
! val = val.trim();
! if (cls == String.class) {
! return val;
! }
! else if (cls == Integer.class) {
! return new Integer(val);
! }
! else if (cls == Float.class) {
! return new Float(val);
! }
! else if (cls == java.sql.Date.class) {
! return new java.sql.Date(java.sql.Date.parse(val));
! }
! else if (cls == java.sql.Time.class) {
! return new java.sql.Time(java.sql.Time.parse(val));
! }
! else if (cls == java.sql.Connection.class) {
! return con;
! }
! else if (cls == IDRSScript.class) {
! return idrs;
! }
! else
! throw new Exception(cls.toString() + " not a valid class for the ObjectStore");
!
! }
!
! public Object getRef() throws Exception {
! return obj;
! }
!
! //used for new IDRS
! /**
! Used for rebuilding and object after serialization when a report is called
! */
! public void rebuild(Object[] vals) throws Exception {
! Class objClass;
! Class[] propArgs = new Class[1];
! propArgs[0] = "".getClass();
!
! this.methods=new HashMap();
!
! Method init = cls.getMethod("reInit",this.varTypes);
! if (init == null) {
! throw new Exception("No init method");
! }
!
! try {
! init.invoke(obj,vals);
!
! ((CleanUp) obj).setContext(this.idrs);
!
! int i;
!
! addToMethVec = false;
!
! for (i=0;i<methodNames.length;i++) {
!
!
! 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) {
! throw new Exception("No init method");
! }
! }
!
! /**
! Used for first initialization of object for empty constructor
! */
! public void firstInitiate(Class[] argTypes) throws Exception {
! try {
! obj = cls.newInstance();
! }
! catch (Exception noCon) {
! throw new Exception("No default constructor");
! }
!
!
!
! this.varTypes = argTypes;
! //System.out.println("Argtypes Size: " + this.varTypes.length);
!
! bmethodNames = new Vector();
! bmethodClasses = new Vector();
! addToMethVec = true;
! methods = new HashMap();
! }
!
! public Class[] getTypes() {
! return this.varTypes;
! }
!
!
!
! public String getID() {
! return id;
! }
!
! public void close() throws Exception {
! //methods.clear();
! if (obj instanceof net.sourceforge.idrs.utils.CleanUp)
! ((CleanUp) obj).cleanUp();
! }
!
! /**
! "Seals" the ObjectStore moving all vector data into arrays
! */
! public int seal() {
! if (! sealed) {
!
! methodNames = new String[bmethodNames.size()];
! methodClasses = new Class[bmethodClasses.size()][];
! int i;
!
!
!
! for (i = 0;i<methodNames.length;i++) {
! methodNames[i] = (String) bmethodNames.elementAt(i);
! methodClasses[i] = (Class[]) bmethodClasses.elementAt(i);
! }
!
! bmethodNames.removeAllElements();
! bmethodClasses.removeAllElements();
! sealed = true;
! }
!
! if (this.varTypes.length > 0) {
! return methodNames.length + 1;
! }
! else {
! return methodNames.length;
! }
!
! }
!
! /**
! *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()) || argClass.equals(String[].class))) {
! 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];
String[] vals;
! 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());
***************
*** 360,375 ****
//args[0] = vals.length==1 ? vals[0] : vals;
! 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;
! }
!
! }
--- 365,388 ----
//args[0] = vals.length==1 ? vals[0] : vals;
! 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;
! }
!
! /**
! * Sets the idrs.
! * @param idrs The idrs to set
! */
! public void setIdrs(IDRSScript idrs) {
! this.idrs = idrs;
! }
!
! }
--- RSMetaData.class DELETED ---
--- DB.class DELETED ---
--- CleanUp.class DELETED ---
--- RequestWrapper.class DELETED ---
--- ReqAttr.class DELETED ---
--- RS.class DELETED ---
--- Application.class DELETED ---
--- UserInfo.class DELETED ---
--- IDRSPrinter.class DELETED ---
--- ObjectStore.class DELETED ---
--- ReqReq.class DELETED ---
|