[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/utils ObjectStore.java,1.4,1.5
Brought to you by:
bigman921
|
From: Marc B. <big...@us...> - 2002-03-04 23:05:38
|
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/utils
In directory usw-pr-cvs1:/tmp/cvs-serv28790/src/net/sourceforge/idrs/utils
Modified Files:
ObjectStore.java
Log Message:
Completed initial xml compilation system
Index: ObjectStore.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/utils/ObjectStore.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ObjectStore.java 6 Nov 2001 23:03:14 -0000 1.4
--- ObjectStore.java 4 Mar 2002 23:05:35 -0000 1.5
***************
*** 11,68 ****
*/
public final class ObjectStore implements Serializable {
! protected transient HashMap methods;
! protected Object obj;
! protected String className;
! protected Class cls;
! protected String id;
!
! protected transient Vector bmethodNames;
! protected transient Vector bmethodClasses;
!
! protected String[] methodNames;
! protected Class[][] methodClasses;
! protected Class[] varTypes;
! protected transient boolean addToMethVec = false;
! 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();
! }
! addToMethVec = false;
! }
!
! /**
! * Creates a ObjectStore based on an ID
! */
! public ObjectStore(String id) {
! this.id = id;
! addToMethVec = 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;
--- 11,69 ----
*/
public final class ObjectStore implements Serializable {
! protected transient HashMap methods;
! protected Object obj;
! protected String className;
! protected Class cls;
! protected String id;
! protected transient Vector bmethodNames;
! protected transient Vector bmethodClasses;
! 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;
***************
*** 70,263 ****
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 {
-
- 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]);
- }
- }
- 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() {
! 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();
!
! if (this.varTypes.length > 0) {
! return methodNames.length + 1;
! }
! else {
! return methodNames.length;
! }
!
! }
!
}
--- 71,279 ----
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 {
!
! 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]);
! }
! }
! 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;
! }
!
! }
!
}
|