[jdom-commits] CVS update: jdom/src/java/org/jdom

jhunter at cvs.jdom.org jhunter at cvs.jdom.org
Wed Jul 26 00:57:06 PDT 2000


Date:	Wednesday July 26, 2000 @ 8:57
Author:	jhunter

Update of /home/cvspublic/jdom/src/java/org/jdom
In directory www.nmemonix.com:/tmp/cvs-serv10003

Modified Files:
	Attribute.java Element.java IllegalAddException.java 
	Namespace.java 
Log Message:
Made Elements and Attributes with Namespaces serializable.  I didn't 
make Namespace serializable, because that would allow duplicate ns objects
for the same data, which we want to disallow for efficiency reasons.
Instead I had Element and Attribute mark their Namespace members as
transient and has them implement custom hooks for serialization
so on deserialization their namespaces are recreated using
Namespace.getNamespace().  To increase deserialization speed we should 
really have a way to avoid the redundant validity checks on known 
valid data.

I wrote a little test case to make sure I got things working.  (Shown
below.)  The right answers are true/true/false.  It's also proper
that the bytes file contains only one repetition of "abcdefg...".
That makes sure we don't reproduce the uri text for every element
and just reproduce a serialized pointer.

I also made the Namespace comments conform to the 80 column rule,
and fixed a comment typo in IllegalAddEx.

-jh-

C:/tmp/jdom 91 % cat SerTestWrite.java SerTestRead.java
import org.jdom.*;
import java.io.*;

public class SerTestWrite {
  public static void main(String[] args) throws Exception {
    String big = "abcdefghijklmnopqrstuvwxyz";
    Namespace ns1 = Namespace.getNamespace("foo", big);
    Namespace ns2 = Namespace.getNamespace("apple", "orange");
    Document d1 = new Document(new Element("root", ns1));
    Document d2 = new Document(new Element("root", ns2));
    Document d3 = new Document(new Element("root", ns1));
    ObjectOutputStream out = new ObjectOutputStream(
                             new FileOutputStream("/tmp/jdom/bytes"));
    out.writeObject(d1);
    out.writeObject(d2);
    out.writeObject(d3);
    out.close();
  }
}

import org.jdom.*;
import java.io.*;

public class SerTestRead {
  public static void main(String[] args) throws Exception {
    String big = "abcdefghijklmnopqrstuvwxyz";
    ObjectInputStream in = new ObjectInputStream(
                           new FileInputStream("/tmp/jdom/bytes"));
    Document d1 = (Document) in.readObject();
    Document d2 = (Document) in.readObject();
    Document d3 = (Document) in.readObject();
    in.close();
    Namespace ns1 = Namespace.getNamespace("foo", big);
    Namespace ns2 = Namespace.getNamespace("apple", "orange");
    System.out.println("ns1 match (s/b true): " +
                       (d1.getRootElement().getNamespace() == ns1));
    System.out.println("ns2 match (s/b true): " +
                       (d2.getRootElement().getNamespace() == ns2));
    System.out.println("mix match (s/b false): " +
                       (d1.getRootElement().getNamespace() == ns2));
  }
}


===================================================================
File: Attribute.java   	Status: Up-to-date

   Working revision:	1.8	Wed Jul 26 07:57:04 2000
   Repository revision:	1.8	/home/cvspublic/jdom/src/java/org/jdom/Attribute.java,v

   Existing Tags:
	start                    	(revision: 1.1.1.1)
	jdom                     	(branch: 1.1.1)

===================================================================
File: Element.java     	Status: Up-to-date

   Working revision:	1.15	Wed Jul 26 07:57:05 2000
   Repository revision:	1.15	/home/cvspublic/jdom/src/java/org/jdom/Element.java,v

   Existing Tags:
	start                    	(revision: 1.1.1.1)
	jdom                     	(branch: 1.1.1)

===================================================================
File: IllegalAddException.java	Status: Up-to-date

   Working revision:	1.2	Wed Jul 26 07:57:05 2000
   Repository revision:	1.2	/home/cvspublic/jdom/src/java/org/jdom/IllegalAddException.java,v

   Existing Tags:
	start                    	(revision: 1.1.1.1)
	jdom                     	(branch: 1.1.1)

===================================================================
File: Namespace.java   	Status: Up-to-date

   Working revision:	1.6	Wed Jul 26 07:57:05 2000
   Repository revision:	1.6	/home/cvspublic/jdom/src/java/org/jdom/Namespace.java,v

   Existing Tags:
	start                    	(revision: 1.1.1.1)
	jdom                     	(branch: 1.1.1)




More information about the jdom-commits mailing list