Re: gnu.xml.dom.DomText implements Text and NodeList.
Hi Pedro, On Tue, 2006-01-10 at 04:31 -0400, Pedro Izecksohn wrote: We ask that people agree to the GNU Classpath Hackers requirements before granting CVS commit permissions. You can find them at: http://www.gnu.org/software/classpath/docs/hacking.html#SEC2 I'm submiting source code to this list to be included in the GNU classpath project, assuring that I wrote this code and it is legally mine, accepting that it will be distributed under the GNU General Public License with the linking exception, and I'm donating this code to the Free Software Foundation. If I need to sign on paper, tell me from where may I download the model. Thanks. I'll sent you the request form by email in a second. It really should be a static inner class (since no state of the outer class is used). inner: Inside which one? DocumentType, ProcessingInstruction, Comment, Text, CDATASection and Notation have no children. As: DomCDATASection extends DomText, DomText extends DomCharacterData, DomComment extends DomCharacterData, it would be better to modify DomCharacterData. DomDoctype, DomNotation and DomProcessingInstruction seem (to the test case below) to be OK. May be a public class as below. Ah, right, I missed that it had to be done in several places. Having one (package private?) class seems the way to go. Sorry for not picking this up yet, I have been a bit busy with preparing for the next (0.20) snapshot release (and was secretly hoping Chris would pick this up since he is much more familiar with this part of the code). About the test case below: I could not imagine a better class name. It needs a XML with DTD that contain all the elements that it tests. I need to learn about Mauve. Most of Mauve is fairly simple. See http://sources.redhat.com/cgi-bin/cvsweb.cgi/~checkout~/mauve/README?cvsroot=mauve If you take one of the existing testlets as example you will see that it basically is replacing the main() method with a test() method and replacing the System.out and if statements with harness.check() statements. You can load a simple XML file with harness.getResourceFile(). // Resource names are // just like file names. They are relative to the top level Mauve // directory, but '#' characters are used in place of directory // separators. Cheers, Mark -- Escape the Java Trap with GNU Classpath! http://www.gnu.org/philosophy/java-trap.html Join the community at http://planet.classpath.org/ signature.asc Description: This is a digitally signed message part ___ Classpath mailing list Classpath@gnu.org http://lists.gnu.org/mailman/listinfo/classpath
Re: gnu.xml.dom.DomText implements Text and NodeList.
Pedro Izecksohn wrote: And maybe we can share one instance of the EmptyNodeList for the whole dom tree so if a tree contains lots of empty node list we only allocate one. I was thinking on this issue. The cast in getChildNode() isn't necessary since EmptyNodeList already is a NodeList. I wrongly typed that. Add to gnu.xml.dom.DomCharacterData.java: import org.w3c.dom.NodeList; /** * Returns an EmptyNodeList. */ public NodeList getChildNodes() { return EmptyNodeList.getInstance(); } Add to gnu/xml/dom: EmptyNodeList.java: package gnu.xml.dom; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public final class EmptyNodeList implements NodeList { private static EmptyNodeList instance = new EmptyNodeList(); public static final EmptyNodeList getInstance() {return instance;} public EmptyNodeList () {} public final int getLength () {return 0;} public final Node item (int index) {return null;} } I would prefer: final class EmptyNodeList implements NodeList { static final EmptyNodeList instance = new EmptyNodeList(); public final int getLength() {return 0;} public final Node item(int index) {return null;} } That way: 1. you avoid the unnecessary overhead of a method call (getInstance). 2. that which has no need to be public is not public. -- Chris Burdess pgpfFzPe9eZ0b.pgp Description: PGP signature ___ Classpath mailing list Classpath@gnu.org http://lists.gnu.org/mailman/listinfo/classpath
Re: gnu.xml.dom.DomText implements Text and NodeList.
Em Ter 10 Jan 2006 04:50, Chris Burdess escreveu: I would prefer: final class EmptyNodeList implements NodeList { static final EmptyNodeList instance = new EmptyNodeList(); public final int getLength() {return 0;} public final Node item(int index) {return null;} } That way: 1. you avoid the unnecessary overhead of a method call (getInstance). OK. 2. that which has no need to be public is not public. Now I understood: If some user application uses gnu.xml.dom.EmptyNodeList, it loses portability, so it should not be public. And as it was verified that only DomCharacterData needs to be modified, it could even be a static inner class, as proposed by Mark Wielaard. ___ Classpath mailing list Classpath@gnu.org http://lists.gnu.org/mailman/listinfo/classpath
Re: gnu.xml.dom.DomText implements Text and NodeList.
We ask that people agree to the GNU Classpath Hackers requirements before granting CVS commit permissions. You can find them at: http://www.gnu.org/software/classpath/docs/hacking.html#SEC2 I'm submiting source code to this list to be included in the GNU classpath project, assuring that I wrote this code and it is legally mine, accepting that it will be distributed under the GNU General Public License with the linking exception, and I'm donating this code to the Free Software Foundation. If I need to sign on paper, tell me from where may I download the model. It really should be a static inner class (since no state of the outer class is used). inner: Inside which one? DocumentType, ProcessingInstruction, Comment, Text, CDATASection and Notation have no children. As: DomCDATASection extends DomText, DomText extends DomCharacterData, DomComment extends DomCharacterData, it would be better to modify DomCharacterData. DomDoctype, DomNotation and DomProcessingInstruction seem (to the test case below) to be OK. May be a public class as below. And maybe we can share one instance of the EmptyNodeList for the whole dom tree so if a tree contains lots of empty node list we only allocate one. I was thinking on this issue. The cast in getChildNode() isn't necessary since EmptyNodeList already is a NodeList. I wrongly typed that. Add to gnu.xml.dom.DomCharacterData.java: import org.w3c.dom.NodeList; /** * Returns an EmptyNodeList. */ public NodeList getChildNodes() { return EmptyNodeList.getInstance(); } Add to gnu/xml/dom: EmptyNodeList.java: package gnu.xml.dom; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public final class EmptyNodeList implements NodeList { private static EmptyNodeList instance = new EmptyNodeList(); public static final EmptyNodeList getInstance() {return instance;} public EmptyNodeList () {} public final int getLength () {return 0;} public final Node item (int index) {return null;} } About the test case below: I could not imagine a better class name. It needs a XML with DTD that contain all the elements that it tests. I need to learn about Mauve. import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.*; public class Jxml { public static final String version = 10/Jan/2006 03:45; private static void checkNode (Node node) throws NullPointerException { if (node==null) {throw new NullPointerException (checkNode (Node) received a null Node.);} int nChilds = node.getChildNodes().getLength(); if ( (node instanceof CDATASection)|| (node instanceof Comment)|| (node instanceof DocumentType)|| (node instanceof Notation)|| (node instanceof ProcessingInstruction)|| (node instanceof Text) ) { if (nChilds0) { System.err.println (node.getClass().getName()+ extends +node.getClass().getSuperclass().getName()+ does NOT implement .getChildNodes() correctly.); } else { System.out.println (node.getClass().getName()+ is OK.); } } } private static void recurse (NodeList nl) { for (int i=0; inl.getLength(); i++) { Node node = nl.item (i); if (node==null) {continue;} checkNode (node); if (node instanceof DocumentType) { DocumentType dt = (DocumentType) node; NamedNodeMap nnm = dt.getNotations(); for (int j=0; jnnm.getLength(); j++) { checkNode((Notation)nnm.item(j)); } } NodeList nl2 = node.getChildNodes(); int nChilds = nl2.getLength(); if (nChilds0) {recurse (nl2);} } } public static void main (String [] args) { System.out.println(getChildNodes() tester - version: +version); if (args.length==0) {System.out.print (I need a xml file to parse.\n); return;} String fileName = args[0]; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null; try { db = dbf.newDocumentBuilder(); } catch (javax.xml.parsers.ParserConfigurationException pce) { pce.printStackTrace(); return; } Document document = null; try { document = db.parse(fileName); } catch (Exception e) { System.err.println(e); return; } recurse (document.getChildNodes()); }// Ends public static void main (String [] args) . }// Ends public class Jxml . ___ Classpath mailing list Classpath@gnu.org http://lists.gnu.org/mailman/listinfo/classpath
Re: gnu.xml.dom.DomText implements Text and NodeList.
Hi, On Wed, 2006-01-04 at 07:16 +, Chris Burdess wrote: My proposed solution is: Add to gnu.xml.dom.DomText: import org.w3c.dom.NodeList; /** * Returns an EmptyNodeList. * * @author Pedro Izecksohn */ public NodeList getChildNodes() { return (NodeList) new EmptyNodeList(); } Add to gnu/xml/dom/ the file EmptyNodeList.java: package gnu.xml.dom; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** * @author Pedro Izecksohn */ public final class EmptyNodeList implements NodeList { public EmptyNodeList () {} public final int getLength () {return 0;} public final Node item (int index) {return null;} } That looks absolutely correct. Thanks Pedro. Some small suggestions for improvements. It really should be a static inner class (since no state of the outer class is used). And maybe we can share one instance of the EmptyNodeList for the whole dom tree so if a tree contains lots of empty node list we only allocate one. BTW. The cast in getChildNode() isn't necessary since EmptyNodeList already is a NodeList. Cheers, Mark signature.asc Description: This is a digitally signed message part ___ Classpath mailing list Classpath@gnu.org http://lists.gnu.org/mailman/listinfo/classpath
Re: gnu.xml.dom.DomText implements Text and NodeList.
Pedro Izecksohn wrote: DomText implements Text and NodeList. The problem is that method getLength() from interfaces NodeList and Text have different meanings. Text.getLength() must return the text content length in characters. NodeList.getLength() must return the number of nodes it contains. From DOM Level 3 Core Specification: Some types of nodes ... are leaf nodes that cannot have anything below them in the document structure. Text -- no children From C.6.1 Infoset to Text Node I understand that for any Text, text.getChildNodes() must return a NodeList whose getLength() equals 0. The problem appears in SableVM classpath because for gnu.xml.dom.DomNode, node.getChildNodes() returns itself. My proposed solution is: Add to gnu.xml.dom.DomText: import org.w3c.dom.NodeList; /** * Returns an EmptyNodeList. * * @author Pedro Izecksohn */ public NodeList getChildNodes() { return (NodeList) new EmptyNodeList(); } Add to gnu/xml/dom/ the file EmptyNodeList.java: package gnu.xml.dom; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** * @author Pedro Izecksohn */ public final class EmptyNodeList implements NodeList { public EmptyNodeList () {} public final int getLength () {return 0;} public final Node item (int index) {return null;} } That looks absolutely correct. -- Chris Burdess They that can give up essential liberty to obtain a little safety deserve neither liberty nor safety. - Benjamin Franklin pgp2s47Pk6Aaf.pgp Description: PGP signature ___ Classpath mailing list Classpath@gnu.org http://lists.gnu.org/mailman/listinfo/classpath