[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/utils ObjectStore.java,1.10,1.11 DB.java,1.15,1
Brought to you by:
bigman921
|
From: Marc B. <big...@us...> - 2004-08-22 05:17:58
|
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13680/src/net/sourceforge/idrs/utils Modified Files: ObjectStore.java DB.java Removed Files: RSMetaData.class Log Message: First pass at integration with Axis Index: ObjectStore.java =================================================================== RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/utils/ObjectStore.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ObjectStore.java 17 Feb 2003 02:48:48 -0000 1.10 --- ObjectStore.java 22 Aug 2004 05:17:39 -0000 1.11 *************** *** 16,19 **** --- 16,25 ---- import java.lang.reflect.*; import javax.servlet.http.HttpServletRequest; + + import org.w3c.dom.Element; + import org.w3c.dom.NamedNodeMap; + import org.w3c.dom.Node; + import org.w3c.dom.NodeList; + import net.sourceforge.idrs.script.IDRSScript; import java.io.*; *************** *** 420,423 **** --- 426,526 ---- return this.propName; } + + public void importDOM(Element root,String basePackage) throws Exception { + this.importDOM(root,this.obj,basePackage); + } + + /* + * Imports a DOM tree into this particuler object + * Rules: + * 1. All attributes are properties + * 2. All simple elements are properties + * 3. All complex elements are objects + * 4. After being created, objects are added via the addXXX method + * + * Performance in this method is currently horrible, needs to act similarly to to setProps + */ + public void importDOM(Element root,Object obj,String basePackage) throws Exception { + System.out.println("Entering importDOM"); + Method[] meths = obj.getClass().getMethods(); + + //first import all attributes + NamedNodeMap attribs = root.getAttributes(); + for (int i=0,m=attribs.getLength();i<m;i++) { + Node attrib = attribs.item(i); + String name = attrib.getNodeName(); + if (name.startsWith("xmlns")) { + continue; + } + String value = attrib.getNodeValue(); + + //convert the name into a java property, setXXXX + name = "set" + new String(new char[]{name.toUpperCase().charAt(0)}) + name.substring(1); + Method meth = this.getMethod(name,meths); + if (meth == null) { + throw new Exception("Can complete decoding, method " + name + " does not exist for class " + obj.getClass().getName()); + } + + meth.invoke(obj,new String[]{value}); + } + + //now iterate over the elements + NodeList nl = root.getChildNodes(); + for (int i=0,m=nl.getLength();i<m;i++) { + //we only care about elements at this point + Node node = nl.item(i); + if (! (node instanceof Element)) { + continue; + } + + Element elem = (Element) node; + String name = elem.getNodeName(); + //if the element's only child is a text node, it's a property + NodeList children = elem.getChildNodes(); + if (elem.getAttributes().getLength() == 0 && children.getLength() == 1 && children.item(0).getNodeType() == Node.TEXT_NODE) { + System.out.println("Seting property : " + name); + // convert the name into a java property, setXXXX + name = "set" + new String(new char[]{name.toUpperCase().charAt(0)}) + name.substring(1); + Method meth = this.getMethod(name,meths); + if (meth == null) { + throw new Exception("Can complete decoding, method " + name + " does not exist for class " + obj.getClass().getName()); + } + + meth.invoke(obj,new String[]{children.item(0).getNodeValue()}); + } else { + //it's an object, we'll instatiate a new instance and add it + + name = new String(new char[]{name.toUpperCase().charAt(0)}) + name.substring(1); + + String className = (basePackage != null && basePackage.trim().length() > 0 ? basePackage + "." : "") + name; + System.out.println("Creating object : " + className); + Object newobj = Class.forName(className).newInstance(); + + //add the new object + String addName = "add" + name; + + Method meth = this.getMethod(addName,meths); + if (meth == null) { + throw new Exception("Can complete decoding, method " + name + " does not exist for class " + obj.getClass().getName()); + } + + meth.invoke(obj,new Object[]{newobj}); + + //import all children nodes + this.importDOM(elem,newobj,basePackage); + + } + } + } + + private Method getMethod(String name,Method[] meths) { + for (int i=0,m=meths.length;i<m;i++) { + if (meths[i].getName().equals(name)) { + return meths[i]; + } + } + + return null; + } } Index: DB.java =================================================================== RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/utils/DB.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** DB.java 26 Mar 2003 21:33:11 -0000 1.15 --- DB.java 22 Aug 2004 05:17:39 -0000 1.16 *************** *** 387,398 **** ! ! for (i=0;i<vals.length;i++) { ! cls = clss[i]; ! val1 = ObjectStore.getValue(cls,vals[i],this.con,idrs); ! cls = val1.getClass(); ! finalVals[i] = val1; } if (direction == DB.OUTPUT) { // System.out.println("executing method"); --- 387,405 ---- + //hack to ensure that you can have a method that jsut takes a connection + if (vals.length > 0) { ! for (i=0;i<vals.length;i++) { ! cls = clss[i]; ! val1 = ObjectStore.getValue(cls,vals[i],this.con,idrs); ! cls = val1.getClass(); ! finalVals[i] = val1; ! } ! } else { ! finalVals = new Object[]{con}; } + + + if (direction == DB.OUTPUT) { // System.out.println("executing method"); --- RSMetaData.class DELETED --- |